3

All browsers except Firefox return a number without a fraction part from the Canvas element's measureText() method. FF returns values like 26.45682955697084. Since the measurement is said to be in pixels, I am wondering why the fraction in FF?

So that my question is not shut down by overzealous moderators, please do not argue for or against the behavior! I simply want to know if there was a rationale for the behavior, and if so, what it was. Maybe there are nuances to rendered glyph measurements in the Canvas that I should be aware of?

katspaugh
  • 17,449
  • 11
  • 66
  • 103
blint
  • 191
  • 1
  • 9

1 Answers1

2

It seems that Firefox is doing the right thing. The spec says that width is returned as a double. http://dev.w3.org/html5/2dcontext/#textmetrics .

Also note that the canvas supports rendering fractions of a pixel, in which case it uses some kind of interpolation to make your image blurry and render slowly. ;-) I found http://sebleedelisle.com/2011/02/html5-canvas-sprite-optimisation/ to be very informative about this.

erturne
  • 1,799
  • 1
  • 15
  • 29