v136 · 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

    CanvasTextDrawingStyles.lang lets the canvas pick locale-correct glyph variants and shaping. Critical for CJK and other locale-sensitive scripts.

  2. OffscreenCanvas in worker

    The chromestatus motivation: a worker-side OffscreenCanvas has no DOM to inherit lang from. Render four locale-targeted Han glyphs side by side, each in a worker that sets ctx.lang directly.

  3. Han Comparator

    Same CJK string, five locales: empty, zh-Hans, zh-Hant, ja-JP, ko-KR. Type any text and watch the Han Unification glyph variants change as ctx.lang flips.

  4. Locale Font Tester

    Enter any text, pick a canvas font, and the tester renders it across seven BCP-47 language tags simultaneously — including Arabic and CJK scripts — letting you confirm your font stack produces the correct locale-specific glyphs with ctx.lang.

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