Intent to Ship: New TextMetrics API in Canvas

202 views
Skip to first unread message

Yi Xu

unread,
May 31, 2019, 1:14:53 PM5/31/19
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: actualBoundingBoxLeft, actualBoundingBoxRight, fontBoundingBoxAscent, fontBoundingBoxDescent, actualBoundingBoxAscent, actualBoundingBoxDescent, emHeightAscent and emHeightDescent.


TAG Review:

Summary

this is 2nd attempt to ship TextMetrics (first attempt link). The current canvas TextMetrics API only exposes the width 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 feature bug (https://crbug.com/277215) has strong user support (24 stars, 3 more stars since Sept 2018).


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 “Intend to ship”, but it was seen as “Intend 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 major 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/2dcontext/drawing-text-to-the-canvas



Entry on the feature dashboard

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

Philip Jägenstedt

unread,
Jun 3, 2019, 5:45:03 AM6/3/19
to Yi Xu, L. David Baron, Domenic Denicola, blink-dev
It looks like the TAG review on this was brief because part of the API was reverted in the spec. +L. David Baron filed 4 spec issues as part of that review, which remain open:

I haven't studied the issues, but are any of them relevant to the subset of this API that you're proposing to ship? If so, can those issues be settled first?


--
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/CAC3hXJcjN0i2%3Dp3aCfXEOQgS_Btwu%3D6nJZU%2BBfVDHVptEmz_ag%40mail.gmail.com.

oj...@google.com

unread,
Jun 6, 2019, 3:31:07 PM6/6/19
to blink-dev, yi...@chromium.org, dba...@mozilla.com, d...@domenic.me
Clarification: Regarding the "In development" for Mozilla, that bug looks like it hasn't gotten attention in 9 months, so it's probably not being actively worked on unless you have some other signal that it is. That does imply at least that there isn't significant opposition though. :)
To unsubscribe from this group and stop receiving emails from it, send an email to blin...@chromium.org.

Yi Xu

unread,
Jun 10, 2019, 3:44:29 PM6/10/19
to oj...@google.com, blink-dev, yi...@chromium.org, dba...@mozilla.com, d...@domenic.me
The open bugs are related to some description used on specs, it doesn't change the behavior of the implementation. 

L. David Baron

unread,
Jun 10, 2019, 5:46:53 PM6/10/19
to Yi Xu, oj...@google.com, blink-dev, yi...@chromium.org, d...@domenic.me
I don't think that's quite right:

#4070 is suggesting that perhaps the APIs should be renamed
(although it seems like maybe there's consensus that the current
names are OK)

#4073 might also result in substantive behavioral changes; I
initially thought the issue was editorial, but given that the
response was that the text was as intended means that there are now
substantive questions of implementation behavior.

-David

On Monday 2019-06-10 15:34 -0400, Yi Xu wrote:
> The open bugs are related to some description used on specs, it doesn't
> change the behavior of the implementation.
>
> On Thu, Jun 6, 2019 at 3:31 PM <oj...@google.com> wrote:
>
> > Clarification: Regarding the "In development" for Mozilla, that bug looks
> > like it hasn't gotten attention in 9 months, so it's probably not being
> > actively worked on unless you have some other signal that it is. That does
> > imply at least that there isn't significant opposition though. :)
> >
> > On Monday, June 3, 2019 at 2:45:03 AM UTC-7, Philip Jägenstedt wrote:
> >>
> >> It looks like the TAG review
> >> <https://github.com/w3ctag/design-reviews/issues/302> on this was brief
> >> because part of the API was reverted
> >> <https://github.com/whatwg/html/pull/4037> in the spec. +L. David Baron filed
> >> 4 spec issues as part of that review, which remain open:
> >> https://github.com/whatwg/html/issues/4070
> >> https://github.com/whatwg/html/issues/4071
> >> https://github.com/whatwg/html/issues/4072
> >> https://github.com/whatwg/html/issues/4073
> >>
> >> I haven't studied the issues, but are any of them relevant to the subset
> >> of this API that you're proposing to ship? If so, can those issues be
> >> settled first?
> >>
> >> +Domenic Denicola
> >>
> >> On Fri, May 31, 2019 at 7:14 PM Yi Xu <yi...@chromium.org> wrote:
> >>
> >>> 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:
> >>> actualBoundingBoxLeft, actualBoundingBoxRight, fontBoundingBoxAscent,
> >>> fontBoundingBoxDescent, actualBoundingBoxAscent, actualBoundingBoxDescent,
> >>> emHeightAscent and emHeightDescent.
> >>>
> >>>
> >>> *TAG Review:*
> >>> https://github.com/w3ctag/design-reviews/issues/302
> >>>
> >>> Summary
> >>>
> >>> this is 2nd attempt to ship TextMetrics (first attempt link
> >>> <https://groups.google.com/a/chromium.org/forum/#!searchin/blink-dev/intent$20to$20ship$20textmetrics%7Csort:date/blink-dev/KQW4thKogkk/SiE-xZ7OAQAJ>).
> >>> The current canvas TextMetrics API only exposes the width 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 feature bug (https://crbug.com/277215) has strong user support (24
> >>> stars, 3 more stars since Sept 2018).
> >>>
> >>> 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 “Intend to ship”, but it was seen as “Intend 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
> >>> <https://bugzilla.mozilla.org/show_bug.cgi?id=1102584>
> >>>
> >>> Safari: Shipped <https://bugs.webkit.org/show_bug.cgi?id=157629>
> >>>
> >>> We know this is a major 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
> >>> <https://chromium.googlesource.com/chromium/src/+/master/docs/testing/web_platform_tests.md>?
> >>> Link to test suite results from wpt.fyi
> >>> <https://wpt.fyi/results/?label=experimental>.
> >>>
> >>> A set of test for each metric, prefixed by “2d.text.measure”:
> >>>
> >>> https://wpt.fyi/results/2dcontext/drawing-text-to-the-canvas
> >>>
> >>>
> >>> Entry on the feature dashboard <http://www.chromestatus.com/>
> >>>
> >>> https://www.chromestatus.com/feature/5307344997056512
> >>>
> >>> --
> >>> 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 blin...@chromium.org.
> >>> To view this discussion on the web visit
> >>> https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CAC3hXJcjN0i2%3Dp3aCfXEOQgS_Btwu%3D6nJZU%2BBfVDHVptEmz_ag%40mail.gmail.com
> >>> <https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CAC3hXJcjN0i2%3Dp3aCfXEOQgS_Btwu%3D6nJZU%2BBfVDHVptEmz_ag%40mail.gmail.com?utm_medium=email&utm_source=footer>
> >>> .
> >>>
> >>

--
𝄞 L. David Baron http://dbaron.org/ 𝄂
𝄢 Mozilla https://www.mozilla.org/ 𝄂
Before I built a wall I'd ask to know
What I was walling in or walling out,
And to whom I was like to give offense.
- Robert Frost, Mending Wall (1914)
signature.asc

Yi Xu

unread,
Jun 13, 2019, 4:12:33 PM6/13/19
to L. David Baron, Yi Xu, oj...@google.com, blink-dev, d...@domenic.me
I think #4070 is agreed on.

For #4073, I think there's a misunderstanding of how the line box works. We may try to clear the language, but I don't think the implementation will change at all. Let me try to explain why:
we are using the line box to describe a baseline, so we can have EmHeightAscent/Descent relative to that baseline. Even if we would change the definition, it's still clear that we want the baseline of the line box itself (which is what I think the spec is describing and what both implementations - Safari and Chrome - did), as any other baseline will be useless (for example, on multiline text, or if there are fallback fonts).

Chris Harrelson

unread,
Jun 20, 2019, 3:17:25 PM6/20/19
to Yi Xu, L. David Baron, Yi Xu, Ojan Vafai, blink-dev, Domenic Denicola
Hi, is there a resolution on #4073? I see that there seems to be continuing discussion there.

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/CAC3hXJe2F3p0w9pv3UdUnKmU514UW%3DFfv2KOtoHoopZMHN6ChA%40mail.gmail.com.

Yi Xu

unread,
Jun 26, 2019, 3:01:25 PM6/26/19
to Chris Harrelson, Yi Xu, L. David Baron, Ojan Vafai, blink-dev, Domenic Denicola
There is some confusion on the definition of fontBoundingBoxAscent/Descent and EmHeightAscent/Descent. We will try to launch actualBoundingBoxLeft, actualBoundingBoxRight, actualBoundingBoxAscent, actualBoundingBoxDescent first. 

Thank you,

Yi Xu

Fernando Serboncini

unread,
Jun 26, 2019, 4:06:01 PM6/26/19
to Yi Xu, Chris Harrelson, Yi Xu, L. David Baron, Ojan Vafai, blink-dev, Domenic Denicola
If we just launch actualBoundingBox* now, we don't need to resolve #4073, and then can come back to launch the remaining entries once all conversations are resolved.

Fernando Serboncini

unread,
Jul 2, 2019, 2:46:42 PM7/2/19
to Yi Xu, Chris Harrelson, Yi Xu, L. David Baron, Ojan Vafai, blink-dev, Domenic Denicola
Just to restate:
We will be launching only actualBoundingBox*, which is not touched by any of the open spec bugs.

After we finish with this, we will keep addressing the open issues and publish a new I2S, once those issues are resolved.

Thanks.

Chris Harrelson

unread,
Jul 2, 2019, 4:35:51 PM7/2/19
to Fernando Serboncini, Yi Xu, Yi Xu, L. David Baron, Ojan Vafai, blink-dev, Domenic Denicola
Hi Fernando,

Could you update the chromestatus entry accordingly?


I also think it would be good idea to ping the TAG review with this update.


Yi Xu

unread,
Jul 5, 2019, 1:22:11 PM7/5/19
to Chris Harrelson, Fernando Serboncini, Yi Xu, L. David Baron, Ojan Vafai, blink-dev, Domenic Denicola

I am updating the intent to ship to match what we want to release now:


Spec

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

we are launching the following attributes in TextMetrics: actualBoundingBoxLeft, actualBoundingBoxRight, actualBoundingBoxAscent, actualBoundingBoxDescent.


TAG Review:

Summary

this is 2nd attempt to ship TextMetrics (first attempt link). The current canvas TextMetrics API only exposes the width 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 feature bug (https://crbug.com/277215) has strong user support (25 stars, 4 more stars since Sept 2018).


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 “Intend to ship”, but it was seen as “Intend 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: Started implementing a while ago

Safari: Shipped


We know this is a major 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”:


Entry on the feature dashboard

Chris Harrelson

unread,
Jul 11, 2019, 3:14:52 PM7/11/19
to Yi Xu, Fernando Serboncini, Yi Xu, L. David Baron, Ojan Vafai, blink-dev, Domenic Denicola

Daniel Bratell

unread,
Jul 11, 2019, 4:08:23 PM7/11/19
to Yi Xu, Chris Harrelson, Fernando Serboncini, Yi Xu, L. David Baron, Ojan Vafai, blink-dev, Domenic Denicola
LGTM2

/Daniel
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CAOMQ%2Bw_HXd6-s%3DGHya%3DqdBZpw%3DYEfCGCm2H_jYypuSDxhyKyFg%40mail.gmail.com.



--
/* Opera Software, Linköping, Sweden: CEST (UTC+2) */

Yoav Weiss

unread,
Jul 15, 2019, 4:29:48 PM7/15/19
to Daniel Bratell, Yi Xu, Chris Harrelson, Fernando Serboncini, Yi Xu, L. David Baron, Ojan Vafai, blink-dev, Domenic Denicola
Reply all
Reply to author
Forward
0 new messages