Intent to Ship: TextMetrics API in Canvas

35 views
Skip to first unread message

David Quiroz Marin

unread,
Sep 2, 2018, 7:04:10 PM9/2/18
to blin...@chromium.org, Fernando Serboncini

Contact emails

dav...@chromium.org, fs...@chromium.org


Spec

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


Summary

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. We fixed the problems and implemented a new version of the spec including an array of advances per character and a dictionary returning baselines.

The feature bug (https://crbug.com/277215) has strong user support (21 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 “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 some of the metrics implemented but since the spec was recently updated some work still needs to be done (advances and getBaselines) to have full interoperability with Chrome. Firefox started development 4 years ago but never shipped. Edge is the only one that has no public signals of implementing yet.


Edge: No signals

Firefox: In development

Safari: Partially 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 not only requires a draw call but also doesn’t help obtaining the advances or the more granular metrics.


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



--
David

Chris Harrelson

unread,
Sep 4, 2018, 9:23:28 PM9/4/18
to dav...@chromium.org, blink-dev, Fernando Serboncini
I think this one is a duplicate of the other thread right?

--
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/CAP%3Dr99Qn-Wyd6WPVva8NapLViurY-uvRaskyZaZYH%2BAKvp-mNQ%40mail.gmail.com.

Daniel Bratell

unread,
Sep 5, 2018, 5:17:39 AM9/5/18
to dav...@chromium.org, Chris Harrelson, blink-dev, Fernando Serboncini
Yes, we should all pretend this thread doesn't exist and talk in https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CADp2-T9J%2BO%3D7AxKx0Ab1isbszhXrr9_xa-7Ck5A6EFhEqmnp1Q%40mail.gmail.com?utm_medium=email&utm_source=footer ([blink-dev] Intent to Ship: New TextMetrics API in Canvas)

/Daniel
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CAOMQ%2Bw-%2BSTyU%2BPJTZBpbG_r%3DyQE9zd3jfvJ8JuiYGDn_hrnxzg%40mail.gmail.com.



--
/* Opera Software, Linköping, Sweden: CEST (UTC+2) */
Reply all
Reply to author
Forward
0 new messages