Closed Bug 1841692 Opened 5 months ago Closed 4 months ago

Expose glyph emHeights in TextMetrics


(Core :: Graphics: Canvas2D, task)




118 Branch
Tracking Status
firefox118 --- fixed


(Reporter: twisniewski, Assigned: jfkthame)


(Blocks 1 open bug)


(Keywords: dev-doc-complete)


(5 files)

Severity: -- → S4
Type: defect → task

We have support for this behind a pref, but last I checked, there was some lack of clarity about exactly what the values should be. We should look into that again, and see if there's a solid enough spec to move forward, or potentially push back against this being part of interop-2023 if the spec isn't ready.

Without the explicit USE_TYPO_METRICS flag, it's unclear whether metrics should be derived
from the font's 'OS/2' table's sTypo* fields, its usWin* fields, or the separate 'hhea' table,
and the values are quite different. (And legacy behavior varies among applications/platforms.)

Setting this flag is recommended by the OpenType spec to provide an unambiguous signal that
the OS/2 "typographical metrics" fields should be used, and so improves the chance of
getting reliably interoperable results.

Note that this means the fontBoundingBox test expectations need to be updated to reflect
the use of the sTypo* metrics fields to determine ascent/descent.

Assignee: nobody → jfkthame

The CanvasTest font's metrics indicate that its ascent is 75% of the em-size, and descent is 25%.
But using a font-size of 50px means these will be fractional-pixel dimensions, which introduces
the possibility of rounding resulting in minor discrepancies.

Changing the font-size to 40px allows the resulting ascent and descent to be integer values that
can more reliably be tested/compared.

Depends on D184605

Trying to enable this, I noticed that we're returning it with the wrong sign;
it's expected to be measured positive-downwards.

Depends on D184606

Note that patch 1 here modifies the existing CanvasTest font, and affects other tests that use it. I've opened about this change.

Pushed by
patch 1 - Update the CanvasTest font to use OS/2 table version 4, with the USE_TYPO_METRICS flag set in the fsSelection field. r=gfx-reviewers,lsalzman
patch 2 - Adjust font-size used in 2d.text.measure.emHeights tests to avoid rounding issues for fractional-pixel metrics. r=gfx-reviewers,lsalzman
patch 3 - Fix sign error when returning canvas2d TextMetrics.emHeightDescent. r=gfx-reviewers,lsalzman
patch 4 - Expose the TextMetrics.emHeight{Ascent,Descent} attributes for Canvas2D text. r=gfx-reviewers,lsalzman
patch 5 - Add testcases for emHeights and fontBoundingBox where the font's typographic ascent+descent does not equal the em size. r=gfx-reviewers,lsalzman
Failed to create upstream wpt PR due to merge conflicts. This requires fixup from a wpt sync admin.

The browser compat data for this needs to be updated. So adding the dev-doc-needed flag.


Keywords: dev-doc-needed
Flags: needinfo?(james)
Flags: needinfo?(aborovova)
Created web-platform-tests PR for changes under testing/web-platform/tests
Upstream PR merged by moz-wptsync-bot
Flags: needinfo?(aborovova)
Flags: needinfo?(james)

FF118 Docs work for this done/tracked in

You need to log in before you can comment on or make changes to this bug.