Closed Bug 1841692 Opened 10 months ago Closed 9 months ago

Expose glyph emHeights in TextMetrics

Categories

(Core :: Graphics: Canvas2D, task)

task

Tracking

()

RESOLVED FIXED
118 Branch
Tracking Status
firefox118 --- fixed

People

(Reporter: twisniewski, Assigned: jfkthame)

References

(Blocks 1 open bug)

Details

(Keywords: dev-doc-complete)

Attachments

(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.

https://learn.microsoft.com/en-gb/typography/opentype/spec/os2#fsselection

Assignee: nobody → jfkthame
Status: NEW → ASSIGNED

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 https://github.com/web-platform-tests/interop/issues/386 about this change.

Pushed by jkew@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/81d8c94a76f7
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
https://hg.mozilla.org/integration/autoland/rev/4f1878e8cb86
patch 2 - Adjust font-size used in 2d.text.measure.emHeights tests to avoid rounding issues for fractional-pixel metrics. r=gfx-reviewers,lsalzman
https://hg.mozilla.org/integration/autoland/rev/110166695d5e
patch 3 - Fix sign error when returning canvas2d TextMetrics.emHeightDescent. r=gfx-reviewers,lsalzman
https://hg.mozilla.org/integration/autoland/rev/b61d00e3d775
patch 4 - Expose the TextMetrics.emHeight{Ascent,Descent} attributes for Canvas2D text. r=gfx-reviewers,lsalzman
https://hg.mozilla.org/integration/autoland/rev/90b19e0d07e5
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.

Sebastian

Keywords: dev-doc-needed
Flags: needinfo?(james)
Flags: needinfo?(aborovova)
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/41364 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 https://github.com/mdn/content/issues/28852

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

Attachment

General

Created:
Updated:
Size: