Skip to content

[font-metrics-api] Revised proposal of font metrics for each character #828

@kojiishi

Description

@kojiishi

One of the feedback to the previous proposal was about use cases. This proposal tries to solve use cases such as knowing caret positions of characters, or drawing background, text decoration effects, or selection to the text.

This proposal adds characters as an array of metrics for each grapheme cluster in the logical order. This change helps not to expose the details of shaping, which is sometimes complicated and may vary by platforms, as indicated by feedback.

interface TextMetrics {
  readonly attribute FrozenArray<TextMetricUnit> characters;
};

interface TextMetricUnit {
  readonly attribute long codeUnitIndex;
  readonly attribute double position;
  readonly attribute double advance;
  readonly attribute bool isRightToLeft;
};

The codeUnitIndex attribute provides the index of the first code unit of the base character.

When there are ligatures of multiple grapheme clusters, UA may produce one TextMetricUnit for a ligature, or compute metrics for each grapheme cluster in the ligature by using the information in the font, or by synthesizing.

UA may tailor UAX#29 if needed for the caret positioning purpose.

This interface supports RTL, by adding the isRightToLeft attribute which represents the resolved direction of the grapheme cluster, and by adding the position attribute which represents the start-side position of the grapheme cluster from the origin. With position and advance, this interface can represent the ambiguous caret positioning at BiDi boundaries. The position attribute may also help rearrangement of glyphs while shaping some scripts if it occurs across grapheme cluster boundaries.

I think this new proposal covers feedback at whatwg/html#4026 and whatwg/html#3994, applies to both the Font Metrics API and to Canvas Text Metrics API.

Appreciate feedback in advance: @litherum @FremyCompany @dbaron @jfkthame @r12a @annevk @fserb @domenic @eaenet @chrishtr @drott (Can't seem to mention @whatwg/canvas, anyone know how?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    font-metrics-api-1i18n-trackerGroup bringing to attention of Internationalization, or tracked by i18n but not needing response.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions