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
-
Canvas lang — raw property
Setting
ctx.langon a regular canvas; pairs the live capability pill with a rendering side-by-side. -
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. -
Multilingual canvas test
Type any string and swap the canvas
langproperty to see ambiguous Han characters re-render with locale-specific glyph forms acrosszh-Hans,zh-Hant,ja, andko. -
RTL Script Canvas
Arabic, Persian, Hebrew, and Urdu rendered side-by-side — once with
ctx.langset (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. -
OffscreenCanvas worker locale
The actual motivating use case:
OffscreenCanvasruns in a Worker with no DOM, so there's nolangattribute to inherit. Before Chrome 135, Workers had no way to specify locale for glyph selection. Nowctx.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.