photopea / Typr.js

Typr.js - process fonts in Javascript
MIT License
914 stars 73 forks source link

Confusing API name: pathToContext() #37

Closed lehni closed 3 years ago

lehni commented 3 years ago

First of all, congrats on what looks like a really great library, and thanks for making it!

There is just one thing that I noted and thought I should maybe point it out: I find the naming of pathToContext() quite confusing. This seems to suggest that the path gets converted to something else, in this case a context, but that's not the case?

You create the context before, and when calling the method, the path gets drawn into it.
Wouldn't drawPath(path, ctx) be much clearer for what it does?

photopea commented 3 years ago

This function converts the path and calls vector-drawing methods of the "ctx" - the second argumetn. We expect, that you use a "2d" context of a html5 canvas - https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D .

But you can pass any object, which has methods like "lineTo" and "curveTo", etc. This object does not have to draw anything, it could simply record the calls and store them into some other format, e.g. PostScript.

It is hard to tell what function name is the best, but since we are working with a CanvasRenderingContext2D, I decided to use Context.

photopea commented 3 years ago

You can think of it as "drawPathToContext", but we omit the verb, as it does not have to be drawing.