Intent to Prototype: Enhanced Canvas TextMetrics

84 views
Skip to first unread message

Florin Malita

unread,
Jun 11, 2025, 9:14:43 AMJun 11
to blink-dev
Contact emails
sche...@chromium.org, fma...@chromium.org

Explainer
https://github.com/fserb/canvas2D/blob/master/spec/enhanced-textmetrics.md
https://github.com/Igalia/explainers/blob/main/canvas-formatted-text/text-metrics-additions.md
https://github.com/whatwg/html/issues/10677

Specification
https://github.com/whatwg/html/pull/11000

Summary
Expand the TextMetrics Canvas API to support selection rectangles, bounding box queries, and grapheme cluster-based operations.

This new functionality should enable complex text editing applications with accurate selection, caret positioning, and hit testing.  Additionally, cluster-based rendering facilitates sophisticated text effects such as independent character animations and styling.



Blink component
Blink>Canvas

Motivation
The existing TextMetrics API provides measurements for atomic text, but offers no facilities to break down that information to a more granular level.

Sophisticated text applications (editors in particular) require such granular information in order to support accurate selection, caret positioning and hit testing at a grapheme level.  Currently they are resorting to various inaccurate approximations to work around API limitations.

Another complex use case involves rendering fragments of pre-shaped text with different attributes - e.g. different colors or different transforms.  This is of particular interest to animation frameworks which allow characters to be animated independently.  Such functionality is not directly supported in existing APIs, and implementers must again resort to approximate workarounds.

The enhanced TextMetrics proposal aims to address the current API shortcomings and to offer first class support for the above use cases.



Initial public proposal
https://github.com/whatwg/html/pull/11000

TAG review
https://github.com/w3ctag/design-reviews/issues/1095

TAG review status
Pending

Risks


Interoperability and Compatibility
These are new features and we will get vendor agreement at WHATWG before shipping. So minimal interop risks beyond platform-specific metrics differences.


Gecko: No signal (https://github.com/mozilla/standards-positions/issues/1144)

WebKit: No signal (https://github.com/WebKit/standards-positions/issues/436)

Web developers: Positive Developers want the ability to animate glyphs independently (such as exploding sentences) and the ability to do e.g. selection on canvas text. The proposed APIs support these use cases and more.

Other signals:

Ergonomics
None.



Activation
None.



Security
There is always a fingerprinting concern with HTML canvas. THe new features expose no novel fingerprinting surface (text metrics are already a fingerprinting concern).



WebView application risks
Does this intent deprecate or change behavior of existing APIs, such that it has potentially high risk for Android WebView-based applications?

None



Debuggability
DevTools supports querying the APIs by default.



Is this feature fully tested by web-platform-tests?
Yes
html/canvas/[element|offscreen]/text...
2d.text.measure.index-from-offset*
2d.text.measure.selection-rects*
2d.text.measure.text-clusters*



Flag name on about://flags
Experimental Web Platform Features

Finch feature name
ExtendedTextMetrics

Requires code in //chrome?
False

Measurement
UMA counters will be added for the new APIs.

Estimated milestones
No milestones specified



Link to entry on the Chrome Platform Status
https://chromestatus.com/feature/5075532483657728?gate=5122812490285056

This intent message was generated by Chrome Platform Status.
Reply all
Reply to author
Forward
0 new messages