Open Bug 2020917 Opened 5 months ago Updated 4 months ago

canvas measureText() resolves system-ui / -apple-system to a different font than DOM on macOS

Categories

(Core :: Layout: Text and Fonts, defect)

Firefox 148
defect

Tracking

()

UNCONFIRMED

People

(Reporter: chenglou92, Unassigned, NeedInfo)

Details

Attachments

(1 file)

Attached file system-ui-repro.html

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:

  1. Open the attached system-ui-repro.html in Firefox on macOS
  2. Observe the table comparing canvas measureText width vs DOM span.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-ui and -apple-system are 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> and OffscreenCanvas are 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.

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.

Component: Untriaged → Graphics: Canvas2D
Product: Firefox → Core

Lower priority for now. I'm not sure if this is in canvas or with fonts, Lee, care to comment?

Severity: -- → S3
Flags: needinfo?(lsalzman)
Priority: -- → P3

Jonathan, ideas?

Component: Graphics: Canvas2D → Layout: Text and Fonts
Flags: needinfo?(lsalzman) → needinfo?(jfkthame)

The component has been changed since the backlog priority was decided, so we're resetting it.
For more information, please visit BugBot documentation.

Priority: P3 → --
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: