As of Firefox 116, I intend to turn the baseline attributes[*] of the Canvas2D TextMetrics interface on by default.

This was developed behind the dom.textMetrics.baselines.enabled preference.

Status in other browsers is:
Chrome - not yet implemented (they have an older non-standard baselines() function that addresses similar functionality)
  Safari - shipping, though results are not always accurate

Bug to turn on by default: https://bugzilla.mozilla.org/show_bug.cgi?id=1840075

Standard: https://html.spec.whatwg.org/multipage/canvas.html#textmetrics

These attributes were originally implemented behind a pref in bug 1102584, but used fallback baseline heuristics rather than reading real baseline data from the font, and were not shipped due to concerns over the interoperability of the resulting values.

In bug 1840075, I'm updating the implementation to correctly respect the actual baseline information in the font (when present), and therefore we can expose the attributes as they will be returning accurate values.

JK

[*] This covers three individual TextMetrics attributes:
        alphabeticBaseline
        hangingBaseline
        ideographicBaseline


- - -
Original "Intent to Prototype" email, from 2020-01-17 (as I can't find it in the Google Groups archive to link to...)
- - -

The TextMetrics interface represents the dimensions of a piece of text in the canvas, as created by the CanvasRenderingContext2D.measureText() method.

Currently, Gecko only supports the .width attribute, but authors would also like to determine the actual dimensions that the rendered text would have in both x- and y-directions, as well as overall font metrics to assist with line spacing, etc.

Safari supports the full set of TextMetrics attributes as currently documented in the HTML spec. Chrome has recently shipped support for the actualBoundingBox attributes; it has support for additional font-metrics attributes behind the "experimental web features" flag.

Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1102584

Standard: https://html.spec.whatwg.org/multipage/canvas.html#textmetrics

Note that there are a number of open issues regarding the spec (see https://github.com/w3ctag/design-reviews/issues/302#issuecomment-427996200). For this reason, I propose to implement these attributes behind several prefs, and initially enable only the actualBoundingBox* attributes by default (matching what Chrome has shipped); the others will be preffed-off, but can be selectively enabled by authors who want to experiment with them.

Testing: Some (limited) tests are in web-platform/tests/2dcontext/drawing-text-to-the-canvas/2d.text.measure.*

Platform coverage: All

Restricted to secure contexts: No. The existing TextMetrics interface is not restricted, and other browsers support the extended attributes in all contexts.

Target Release: 74

Preferences behind which this will be implemented:
  dom.textMetrics.actualBoundingBox.enabled  (default: true)
  dom.textMetrics.baselines.enabled          (default: false)
  dom.textMetrics.emHeight.enabled           (default: false)
  dom.textMetrics.fontBoundingBox.enabled    (default: false)

--
You received this message because you are subscribed to the Google Groups 
"[email protected]" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/a/mozilla.org/d/msgid/dev-platform/a0b5ffd8-8418-0dc8-ff5a-7d2117f9a538%40gmail.com.

Reply via email to