fillText/strokeText MaxWidth Not Implemented? #119

Open
jeffv opened this Issue Sep 28, 2011 · 2 comments

Projects

None yet

2 participants

jeffv commented Sep 28, 2011

It appears that when using fillText and strokeText the optional maxWidth parameter does nothing.

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#text-0

Contributor
tj commented Sep 28, 2011

hmm i dont believe that was there when i implemented node-canvas

jeffv commented Sep 29, 2011

Yah. I did a bit more research and it doesn't look like it's implemented in all the major browsers either.

I'd actually do a patch myself, but I'm not entirely sure how best to handle the different potential font measurements (em vs. px). The regex for parsing it out the different parts of the font might be fun as well.

        do {
          ctx.font = fontWeight + ' ' + fontSizePx + 'px ' + fontStack
          if (ctx.measureText(text).width > maxWidth) {
            fontSizePx--
          }
        } while (fontSizePx > 1 && ctx.measureText(text).width > maxWidth)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment