demo · v136

Canvas lang

Some glyphs differ across locales (e.g. CJK han characters). The 2D context now carries a lang property so OffscreenCanvas and main-thread canvases can render the right variant.

Probing…

main-thread canvas (ctx.lang)

offscreen worker canvas (lang passed in)

ctx.lang on main canvas
getContextAttributes()

the code

const ctx = canvas.getContext("2d");
ctx.lang = "ja";                                 // 136+
ctx.font = "48px sans-serif";
ctx.fillText("骨", 20, 80);                       // renders ja form

// Or from a Worker on an OffscreenCanvas
const off = new OffscreenCanvas(480, 160);
const octx = off.getContext("2d");
octx.lang = "zh-Hans";

see also