CanvasRenderingContext2D.font loses a lot of precision. |
||||
Issue description
Chrome Version : Trunk
OS Version: Linux
Other browsers tested:
Add OK or FAIL after other browsers where you have tested this issue:
Safari: FAIL
Firefox: PASS
IE/Edge: didn't test.
What steps will reproduce the problem?
1. Open a devtools terminal.
Run the following:
> let ctx = document.createElement("canvas").getContext("2d")
< undefined
> ctx.font = "10.5px monospace"
< "10.5px monospace"
> ctx.font
< "11px monospace"
What is the expected result?
"10.5px monospace", just like:
> document.body.style.font = "10.5px monospace"
< "10.5px monospace"
> document.body.style.font
< "10.5px monospace"
What happens instead of that?
The number is rounded, which is not interoperable with Firefox, and seems like a bug.
See https://bugzilla.mozilla.org/show_bug.cgi?id=1518684 for an interop issue that causes Firefox problems due to this.
,
Jan 15
,
Jan 15
I understand the interop argument, but I can't seem to find any spec that backs what's the proper solution here. As far as I can see on CSS: "CSS theoretically supports infinite precision and infinite ranges for all value types; however in reality implementations have finite capacity. UAs should support reasonably useful ranges and precisions." Which suggests that those rounding issues are WAI? Or at least that there's no obvious direction to fix this, right? As for the CSS escaping you are probably right, but we should have a separate bug for that.
,
Jan 15
Well, sure. The reason I decided to file a bug is that Blink is inconsistent within itself. That is, normal CSS properties (including font-size) preserve much more precision than canvas, for no particular reason except that: https://cs.chromium.org/chromium/src/third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.cc?l=458&rcl=4cab5afa8de7cb96a9a375d8585de59a01140e63 Rounds to an integer (intentionally, I'd think). Feel free to close as WontFix if you want, that's fine for me I guess, but I don't see the "there's no obvious direction to fix this" bit. Not rounding when serializing it would fix it, afaict.
,
Jan 17
(5 days ago)
Ahn, I didn't notice that. My bad. Let's fix this and the font one. |
||||
►
Sign in to add a comment |
||||
Comment 1 by emilio@chromium.org
, Jan 14