← Back to release summary

Enhanced Canvas TextMetrics

Category
Graphics
Type
New or changed feature
Status
Proposed (Chrome Proposed)
Intent stage
None

Summary

Expand the TextMetrics Canvas API to support selection rectangles, bounding box queries, and glyph 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.

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.

Standards & signals

Explainers: 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

View on chromestatus.com