canvas measureText() resolves system-ui / -apple-system to a different font than DOM on macOS
Categories
(Core :: Layout: Text and Fonts, defect)
Tracking
()
People
(Reporter: chenglou92, Unassigned, NeedInfo)
Details
Attachments
(1 file)
|
1.08 KB,
text/html
|
Details |
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.3 Safari/605.1.15
Steps to reproduce:
- Open the attached
system-ui-repro.htmlin Firefox on macOS - Observe the table comparing canvas
measureTextwidth vs DOMspan.getBoundingClientRect()width
Actual results:
16px system-ui: canvas=375.2 dom=423.5 diff=-48.4 MISMATCH
16px -apple-system: canvas=375.2 dom=423.5 diff=-48.4 MISMATCH
16px sans-serif: canvas=410.1 dom=410.1 diff=0.0 OK
16px "Helvetica Neue": canvas=414.4 dom=414.4 diff=0.0 OK
16px Georgia: canvas=406.4 dom=406.4 diff=0.0 OK
Expected results:
Canvas and DOM return the same width for the same font string. (Chrome and Safari do this correctly.)
Additional observations
- Only
system-uiand-apple-systemare affected — all named fonts and other generic families match perfectly - The difference is ~48px on a ~400px string (12% error)
- Chrome and Safari canvas/DOM agree for system-ui on macOS
- Both regular
<canvas>andOffscreenCanvasare affected
Impact
Canvas-based text measurement libraries that predict line breaks cannot use system-ui or -apple-system on Firefox macOS. The canvas measurements are too far off from DOM rendering to produce correct results.
Comment 1•5 months ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::Graphics: Canvas2D' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Comment 2•5 months ago
|
||
Lower priority for now. I'm not sure if this is in canvas or with fonts, Lee, care to comment?
Comment 3•5 months ago
|
||
Jonathan, ideas?
Comment 4•5 months ago
|
||
The component has been changed since the backlog priority was decided, so we're resetting it.
For more information, please visit BugBot documentation.
Description
•