Text
Place shaped runs or collect values for a text exporter.
node.textRuns holds shaped runs in visual order. A run's x and y mark the start of its baseline in the node's border-box space.
Place runs
Use node.matrix for the box. Apply run.transform after it when present; the walker adds that transform when text-fit scales a line.
import { } from "takumi-paint";
const = await ("<p>Hello <b>world</b></p>", { : 320 });
for (const { , } of .()) {
.(., ., ., ., ..);
}run.font is the font instance selected during shaping. run.fontIndex refers to the same instance in tree.fonts. Runs shaped with the same instance share the same font object.
Draw glyphs
run.glyphs contains font glyph IDs and positions relative to the run origin. Native drawing APIs can use those values with run.fontIndex. run.width is the run's advance. run.letterSpacing is already reflected in glyph positions.
run.decorations contains placed underline, overline, or line-through rectangles. run.stroke records visible -webkit-text-stroke. node.textShadows applies under the node's runs.
Lay text out again
A presentation writer can build a text box from node.contentBox and node.textAlign. The box is relative to the node's border box; transform it through node.matrix when needed.
| Value | Field |
|---|---|
| Text box | node.contentBox |
| Alignment | node.textAlign |
| Text and face | run.text, run.font |
| Font size | run.fontSize |
| Line height | run.lineHeight |
| Letter spacing | run.letterSpacing |
| Baseline | run.x, run.y |
import { } from "takumi-paint";
const = await (
'<div style="width: 240px; padding: 12px; text-align: center; line-height: 30px">Title</div>',
{ : 320 },
);
const = [...]
.(() => .. > 0)
.(() => ({
: .,
: .,
: .,
: ..(() => ({
: .,
: .,
: .,
: .,
: .,
: [., .],
})),
}));
.();run.ascent and run.descent are typographic distances from the baseline. run.top equals run.y - run.ascent; run.bottom equals run.y + run.descent. Under line-height: normal, a fallback face can grow run.lineHeight to its own height.
Trace source text
run.textByteRange identifies the UTF-8 byte range within the node's inline text. run.spanId identifies the source inline span when available.
Last updated on