v135 · graphics

Language support for CanvasTextDrawingStyles

The <canvas> DOM element, like all DOM elements, accepts a `lang` attribute that is used to define language specific treatment for font selection (when fonts have locale specific glyphs). Browsers respect this attribute. However, when an OffscreenCanvas is created there is no way to set locale information, possibly resulting in a state where an offscreen can

concepts

  1. Canvas lang — raw property

    Setting ctx.lang on a regular canvas; pairs the live capability pill with a rendering side-by-side.

  2. Same characters, three locales

    The spec's motivating example: U+9AA8 ("bone") rendered with lang=ja, lang=zh-Hans, lang=zh-Hant — three distinct glyph shapes from one string.

  3. Multilingual canvas test

    Type any string and swap the canvas lang property to see ambiguous Han characters re-render with locale-specific glyph forms across zh-Hans, zh-Hant, ja, and ko.

  4. RTL Script Canvas

    Arabic, Persian, Hebrew, and Urdu rendered side-by-side — once with ctx.lang set (Chrome 135) and once without. Shows how locale-specific glyph selection and ligature shaping differ between Arabic (ar) and Persian (fa) sharing the same Unicode code points.

  5. OffscreenCanvas worker locale

    The actual motivating use case: OffscreenCanvas runs in a Worker with no DOM, so there's no lang attribute to inherit. Before Chrome 135, Workers had no way to specify locale for glyph selection. Now ctx.lang = 'ja' solves it — this demo shows locale-aware CJK rendering directly from a Worker context.

why it shipped

Provide a way to set the primary language for font resolution in OffscreenCanvas, so that offscreen and regular canvas content uses the same font information. This is blocking Canvas Text Metrics Additions because it was raised in the spec discussion.

references