Closed Bug 1801198 Opened 2 years ago Closed 1 year ago

fontBoundingBoxAscent is not enabled

Categories

(Core :: Graphics: Canvas2D, defect)

defect

Tracking

()

RESOLVED FIXED
116 Branch
Tracking Status
firefox-esr115 --- wontfix
firefox116 --- fixed

People

(Reporter: matias.kenig, Assigned: jfkthame)

References

(Blocks 1 open bug)

Details

(Keywords: dev-doc-complete)

Attachments

(2 files)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
Firefox for Android

Steps to reproduce:

var _ctx = document.createElement("canvas").getContext("2d");
var m = _ctx.measureText("");
return m.fontBoundingBoxAscent

Actual results:

No results found for fontBoundingBoxAscent

Expected results:

a ascent number of the font need to return

It looks like this property is currently disabled by the pref dom.textMetrics.fontBoundingBox.enabled. Anyways, this is not a security bug so I'm going to unhide it.

Group: firefox-core-security
Component: Untriaged → Graphics: Canvas2D
Product: Firefox → Core
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: fontBoundingBoxAscent Compatibility → fontBoundingBoxAscent is not enabled
Status: RESOLVED → REOPENED
Component: General → Graphics: Canvas2D
Product: Invalid Bugs → Core
Resolution: INVALID → ---

Jonathan, what's the status of shipping the extended attributes?

Flags: needinfo?(jfkthame)

We could, we've got an implementation. But last I checked, the values returned by webkit/blink/gecko aren't necessarily interoperable, e.g. see https://github.com/web-platform-tests/interop/issues/159#issuecomment-1303361603.

For these to really be useful to authors, I think they need to be more carefully specified so that we can all give consistent values. (Which may get tricky because of the legacy of fonts containing multiple, conflicting versions of metrics; and different platforms/applications having various heuristics to decide which to use...)

Flags: needinfo?(jfkthame)
Severity: -- → S3

According to https://wpt.fyi/results/html/canvas?label=master&label=stable&aligned&q=fontboundingbox, it looks like the other browsers are shipping this, and we're the odd one out. I'm inclined to think we could pref it on.

(Looking more broadly at https://wpt.fyi/results/html/canvas?label=master&label=stable&aligned&q=2d.text.measure, there's less interop for other extended TextMetrics attributes like baselines and emheights, so I'm proposing only to flip the pref for fontBoundingBox at this stage.)

Testing locally, with the pref enabled we pass the test using Ahem, but on the one using the CanvasTest font, we have a 1px discrepancy from Chrome's result. This is because we're rounding the font metrics to pixels differently. The font and styles used by the test would in theory result in fractional-pixel metrics, but Chrome rounds the ascent and descent to the nearest pixel, while we round them up. AFAIK, the spec doesn't explicitly address this (I don't see any reason we couldn't return precise fractional-pixel values, even), and in practice metrics that come from various font backends are likely to show minor discrepancies between platforms. So I think the way forward here is to make the test use an "approx_equals" assertion, to allow for variations in how the font system computes/rounds metrics.

Taking that into account, we seem to have interoperability at a basic level on this feature, and it would be useful for authors to have it available.

Assignee: nobody → jfkthame
Keywords: dev-doc-needed
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/7f41dfa25b93 patch 1 - Allow 1px of variation in canvas TextMetrics.fontBoundingBox* test, rather than assuming a specific rounding behavior. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/bca7a8665982 patch 2 - Enable the fontBoundingBox{Ascent,Descent} attributes in canvas TextMetrics. r=gfx-reviewers,lsalzman
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/40619 for changes under testing/web-platform/tests
Upstream PR was closed without merging
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/fbaae95aa864 patch 1 - Allow 1px of variation in canvas TextMetrics.fontBoundingBox* test, rather than assuming a specific rounding behavior. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/b2d23872d92d patch 2 - Enable the fontBoundingBox{Ascent,Descent} attributes in canvas TextMetrics. r=gfx-reviewers,lsalzman

Backed out for causing wpt failures in idlharness.worker.html

Upstream PR was closed without merging

Maybe make this depend on bug 1102584 and block bug 1119470 so it's easier to find.

Blocks: 1119470
Depends on: 1102584
Flags: needinfo?(jfkthame)
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/16840df74cb4 patch 1 - Allow 1px of variation in canvas TextMetrics.fontBoundingBox* test, rather than assuming a specific rounding behavior. r=gfx-reviewers,lsalzman https://hg.mozilla.org/integration/autoland/rev/d238e609ab5c patch 2 - Enable the fontBoundingBox{Ascent,Descent} attributes in canvas TextMetrics. r=gfx-reviewers,lsalzman
Status: REOPENED → RESOLVED
Closed: 2 years ago1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 116 Branch
Upstream PR merged by moz-wptsync-bot
Blocks: 1897067
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: