Intent to Ship: FontBoundingBoxAscent/Descent in New TextMetrics API in Canvas

94 views
Skip to first unread message

Yi Xu

unread,
Sep 24, 2020, 1:18:09 PM9/24/20
to blink-dev

Contact emails

yi...@chromium.org, fs...@chromium.org


Spec

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

We are launching the following attributes in TextMetrics: fontBoundingBoxAscent, fontBoundingBoxDescent

 

TAG Review:

https://github.com/w3ctag/design-reviews/issues/302

 

Summary

This is 3nd attempt to ship TextMetrics (first attempt link, second attempt). The current canvas TextMetrics API exposes the width, actualBoundingBoxLeft, actualBoundingBoxRight, actualBoundingBoxAscent, actualBoundingBoxDescent of the measured text. Part of the new API was already implemented under a flag, but there were some inconsistencies and bugs, especially with RightToLeft text.

The original feature bug (https://crbug.com/277215) has strong user support (23 stars).

 

Link to “Intent to Implement” blink-dev discussion

https://groups.google.com/a/chromium.org/forum/?fromgroups#!searchin/blink-dev/textmetrics|sort:date/blink-dev/SgofW_bQ3ps/jNYamQHplAMJ

The thread was titled “Intent to ship”, but it was seen as “Intent to implement” and was never actually shipped.

 

Is this feature supported on all six Blink platforms (Windows, Mac, Linux, Chrome OS, Android, and Android WebView)?

Yes

 

Demo link

-

 

Debuggability

No DevTools needed for debug. Users can console print the full TextMetrics object in one line.

 

Risks

Interoperability and Compatibility

Safari already has already shipped these metrics following this spec. Firefox started development 4 years ago but never shipped

 

Firefox: In development

Safari: Shipped

 

We know this is a feature requested by developers (as well as internal Google teams like Google Docs). This API will help developers have more control and more accurate text rendering. As of today a different way to achieve this is by using rendering text to the DOM and using getBoundingClientRect to get some measurements. This process requires a relayout of the page.

 

Activation

Enable the platform experiment ExtendedTextMetrics

 

Is this feature fully tested by web-platform-tests? Link to test suite results from wpt.fyi.

A set of test for each metric, prefixed by “2d.text.measure”:

https://wpt.fyi/results/html/canvas/element/drawing-text-to-the-canvas?label=experimental&label=master&aligned

 

 

Entry on the feature dashboard

https://www.chromestatus.com/feature/5739117189005312

Alex Russell

unread,
Sep 24, 2020, 3:35:32 PM9/24/20
to blink-dev, yi...@chromium.org
LGTM1

Chris Harrelson

unread,
Sep 24, 2020, 3:42:36 PM9/24/20
to Alex Russell, blink-dev, yi...@chromium.org
Were the ascent and descent actually shipped? The last comment on the WebKit bug indicates otherwise.
 

 

We know this is a feature requested by developers (as well as internal Google teams like Google Docs). This API will help developers have more control and more accurate text rendering. As of today a different way to achieve this is by using rendering text to the DOM and using getBoundingClientRect to get some measurements. This process requires a relayout of the page.

 

Activation

Enable the platform experiment ExtendedTextMetrics

 

Is this feature fully tested by web-platform-tests? Link to test suite results from wpt.fyi.

A set of test for each metric, prefixed by “2d.text.measure”:

https://wpt.fyi/results/html/canvas/element/drawing-text-to-the-canvas?label=experimental&label=master&aligned

 

 

Entry on the feature dashboard

https://www.chromestatus.com/feature/5739117189005312

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/0a8b7cfb-e4ca-4568-b93b-5afb7efb970cn%40chromium.org.

Yi Xu

unread,
Sep 24, 2020, 3:45:32 PM9/24/20
to Chris Harrelson, Alex Russell, blink-dev
Sorry, what do you mean? i am trying to ship FontBoundingBoxAscent/Descent. The actualBoundingBoxLeft/right/ascent/descent are actually shipped in the second attempt.

Yi Xu

Chris Harrelson

unread,
Sep 24, 2020, 4:08:09 PM9/24/20
to Yi Xu, Alex Russell, blink-dev
I meant in WebKit. The link you provided (https://bugs.webkit.org/show_bug.cgi?id=157629) has a comment from Myles that "I think this API is too nascent to implement right now." as the last update.

Yi Xu

unread,
Sep 25, 2020, 1:23:25 AM9/25/20
to Chris Harrelson, Yi Xu, Alex Russell, blink-dev
Myles is talking about advances, which we agree it's not ready to ship (including the baselines), and this intent is only about fontBoudingBoxAscent and fontBoundingBoxDescent, which WebKit has already shipped.

Chris Harrelson

unread,
Sep 25, 2020, 11:22:23 AM9/25/20
to Yi Xu, Yi Xu, Alex Russell, blink-dev

Yoav Weiss

unread,
Sep 28, 2020, 4:33:09 PM9/28/20
to Chris Harrelson, Yi Xu, Yi Xu, Alex Russell, blink-dev
Reply all
Reply to author
Forward
0 new messages