Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Canvas 2D Context Next

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

Canvas 2D Context Next

JSConf JP 2026
http://jsconf.jp/2026/

petamoriken / 森建

November 22, 2026

Transcript

23 slides
  1. Image rendering in server-side web stacks SVG 1.1 (satori) HTML/CSS

    (Puppeteer) Canvas 2D Declarative Declarative ⚠ Imperative ⚠ Text Expressiveness ⚠ ✅ ✅ Rendering Speed ✅ ❌ ✅ Memory Consumption ✅ ❌ ✅ Paradigm 7
  2. Canvas 2D • Context creation via getContext("2d") on HTMLCanvasElement (<canvas>)

    or OffscreenCanvas • Supported in non-browser runtimes using libraries like node-canvas or skia-canvas • Native non-browser runtime support (OffscreenCanvas) ◦ Deno: WIP by me ◦ Andromeda: supported 8
  3. Self-Introduction petamoriken pixiv WebDev engineer in Fukuoka 10 • A

    Deno contributor • An advocate for ES2025 Float16Array • I like to keep up with Web Standards
  4. Table of Contents • Canvas Text Proposals ◦ Enhanced Text

    Metrics ◦ Text Shaping • High Dynamic Range (HDR) Color • Other Proposals 11
  5. Measure width of each character const text = "じぇーえすかんふ󰏦"; //

    Measure width per Grapheme Cluster for (const { segment } of new Intl.Segmenter().segment(text)) { const textMetrics = ctx.measureText(segment); console.log(textMetrics.width); } • Limitations of Grapheme Clusters: ◦ Ligatures ◦ Contextual shaping (e.g., Arabic, Devanagari) 13
  6. Proposal: Enhanced Text Metrics (2021~) const text = "じぇーえすかんふ󰏦"; const

    textMetrics = ctx.measureText(text); // Measure width position per Glyph Cluster at once for (const { begin, end } of textMetrics.getTextClusters()) { const rect = textMetrics.getActualBoundingBox(begin, end); console.log(rect.width); } • Planned to ship in Chrome 160 (2027-01-25) ◦ But... 14
  7. Proposal: Text Shaping (2026) const text = "じぇーえすかんふ󰏦"; const shapedText

    = ctx.shapeText(text); // Measure width position per Glyph Cluster at once for (const { begin, end } of shapedText.glyphClusters()) { const rect = shapedText.getActualBoundingBox(begin, end); console.log(rect.width); } • Create Shaped Text, not Enhanced Text Metrics • WebKit spotted preparing a proposal (last week) 15
  8. Proposal: Text Shaping (2026) [Exposed=(Window,Worker)] interface ShapedText { readonly attribute

    double width; sequence<GlyphRun> glyphRuns(); sequence<GlyphRun> glyphClusters(); sequence<GlyphRun> glyphClusters([EnforceRange] unsigned long start, [EnforceRange] unsigned long end); sequence<DOMRectReadOnly> selectionRects([EnforceRange] unsigned long start, [EnforceRange] unsigned long end); DOMRectReadOnly actualBoundingBox([EnforceRange] unsigned long start, [EnforceRange] unsigned long end); unsigned long advanceToPosition(double advance); double positionToAdvance([EnforceRange] unsigned long position); }; 16
  9. 18

  10. Color Types: unorm8 vs float16 unorm8 (Uint8ClampedArray) 0 255 sRGB

    255 Display P3 float16 (Float16Array) 0.0 sRGB Display P3 19 1.0 1.0
  11. Canvas Floating Point Color Values const ctx = canvas.getContext("2d", {

    colorSpace: "display-p3", colorType: "float16", }); const imageData = ctx.getImageData(0, 0, 1, 1, { pixelFormat: "rgba-float16", }); console.log(imageData.data); // Float16Array 20
  12. Do you have any questions? • Canvas Text Proposals ◦

    Enhanced Text Metrics ◦ Text Shaping • High Dynamic Range (HDR) Color • Other Proposals 23

More Decks by petamoriken / 森建

Other Decks in Programming