mikolalysenko / vectorize-text

Turns a text string into a 2D poly line
MIT License
311 stars 21 forks source link

Example fails due to context being null #2

Closed prewk closed 9 years ago

prewk commented 9 years ago

Hi, The example code fails like this for me:

......./node_modules/vectorize-text/lib/vtext.js:197
  context.font = size + "px " + family
               ^
TypeError: Cannot set property 'font' of null

Which makes sense, because defaultContext gets set to null in your index.js, and I don't pass in an options.context so it defaults to that on index.js:23.

Am I missing something?

The Readme says it works both in Node and Browserify, but the code seems to require a canvas to be passed in?

mikolalysenko commented 9 years ago

Ah good catch.

The behavior of this module changed recently and the docs need to be updated to reflect this. Basically to remove the node.js' canvas dependency the module requires that you pass in a WebGL context. I'll update the example to reflect this.

prewk commented 9 years ago

Excellent, thanks!

prewk commented 9 years ago

Hm, played around and couldn't get it to work with gl (a headless WebGL lib) and from what I could gather some other libs required desktop graphics, and wouldn't work on a server. Will I be able to render server-side with your package?

mikolalysenko commented 9 years ago

Errr, sorry I typoed that. It isn't a webgl context but a canvas 2d context, as would be produced for example from node-canvas

prewk commented 9 years ago

Ah, okay. Bummer, I was primarily looking for a module not relying on external libs (node-canvas needs non-node libs installed, different on different systems etc)

Thanks anyway!

mikolalysenko commented 9 years ago

Yeah, it is unfortunate. Text rendering is really complicated though, and there aren't easy solutions.

unphased commented 8 years ago

I have same original problem described by @prewk.

I'm confused because the source code still wants a canvas. The example code isn't passing it.

What can I edit to make this work?

Update: I looked at code some more... probably on node.js no context exists? (it's just gonna get left as null) Isn't it blatantly false advertising to make this thing look like it works for node.js without a browser context (first sentence of readme)? Incidentally, this entire issue discussion makes a lot more sense at this point. I'll try injecting node-canvas into this to see if it works...

Update: node-canvas on osx is a shit-show, build fails spectacularly