Skip to content

Account for the Firefox font size quantization in the text layer - #21810

Open
calixteman wants to merge 1 commit into
mozilla:masterfrom
calixteman:quantize_measured_font_size
Open

Account for the Firefox font size quantization in the text layer#21810
calixteman wants to merge 1 commit into
mozilla:masterfrom
calixteman:quantize_measured_font_size

Conversation

@calixteman

Copy link
Copy Markdown
Contributor

Firefox rounds the font size set on a canvas 2d context, once divided by the device pixel ratio, to 7 bits of precision. Hence measureText can return a width up to ~1% off the one the spans are laid out with, which made --scale-x slightly wrong in a zoom dependent way. Measure with a size left untouched by that rounding and rescale the returned width, which is linear in the font size.

@codecov-commenter

codecov-commenter commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.19%. Comparing base (0f26334) to head (cb79d37).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21810      +/-   ##
==========================================
- Coverage   90.20%   90.19%   -0.01%     
==========================================
  Files         264      264              
  Lines       67339    67345       +6     
==========================================
+ Hits        60741    60743       +2     
- Misses       6598     6602       +4     
Flag Coverage Δ
browsertest 66.30% <90.90%> (-0.03%) ⬇️
fonttest 8.91% <ø> (ø)
integrationtest 69.40% <100.00%> (+<0.01%) ⬆️
unittest 58.36% <90.90%> (-0.01%) ⬇️
unittestcli 56.93% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/display/text_layer.js Outdated
Firefox rounds the font size set on a canvas 2d context, once divided by
the device pixel ratio, to 7 bits of precision. Hence `measureText` can
return a width up to ~1% off the one the spans are laid out with, which
made `--scale-x` slightly wrong in a zoom dependent way.
Measure with a size left untouched by that rounding and rescale the
returned width, which is linear in the font size.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants