Slide 1

Slide 1 text

Canvas 2D Context Next JSConf JP 2026 pixiv Inc. 森内建太 @petamoriken 2026.11.22

Slide 2

Slide 2 text

How do you feel? 2

Slide 3

Slide 3 text

This is a fake OGP image! 3

Slide 4

Slide 4 text

Real GitHub OGP image! 4

Slide 5

Slide 5 text

Fake: satori (SVG 1.1) Real: Puppeteer (HTML/CSS) SVG 1.1 does not support -webkit-line-clamp! 5

Slide 6

Slide 6 text

Is it better to use Puppeteer for server-side image rendering? 🤔 6

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Canvas 2D ● Context creation via getContext("2d") on HTMLCanvasElement () 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

Slide 9

Slide 9 text

New Canvas 2D Features Discovered While Implementing in Deno (Not Covering HTML-in-Canvas) 9

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Table of Contents ● Canvas Text Proposals ○ Enhanced Text Metrics ○ Text Shaping ● High Dynamic Range (HDR) Color ● Other Proposals 11

Slide 12

Slide 12 text

Canvas Text Proposals 12

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Proposal: Text Shaping (2026) [Exposed=(Window,Worker)] interface ShapedText { readonly attribute double width; sequence glyphRuns(); sequence glyphClusters(); sequence glyphClusters([EnforceRange] unsigned long start, [EnforceRange] unsigned long end); sequence 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

Slide 17

Slide 17 text

High Dynamic Range (HDR) Color 17

Slide 18

Slide 18 text

18

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

Other Proposals 21

Slide 22

Slide 22 text

fserb/canvas2D 22

Slide 23

Slide 23 text

Do you have any questions? ● Canvas Text Proposals ○ Enhanced Text Metrics ○ Text Shaping ● High Dynamic Range (HDR) Color ● Other Proposals 23