The measure() API
Measure node dimensions and text runs with Renderer.measure() before rendering an image.
measure() returns a node's laid-out size without rendering it. Use it to fit a headline into a fixed width, or to place a badge against the measured box.
import { } from "takumi-js/node";
import { } from "takumi-js/helpers/jsx";
const = new ();
const { , } = await (< ="text-xl">I'm a text node</>);
const { width, } = await .(, { }); Returned fields
measure() resolves to a MeasuredNode.
Prop
Type
Description
width?numberLaid-out width
height?numberLaid-out height
transform?[number, number, number, number, number, number]Transformation matrix that places the box on the page
children?MeasuredNode[]Measured child nodes
Every length is a device pixel. A 20px box measures 40 under a devicePixelRatio of 2.
Text runs
A node that lays out text reports one MeasuredTextRun per shaped run.
Prop
Type
Description
text?stringThe run's text
x?numberLeft edge, measured from the content box of the node that owns the run
y?numberTop edge, measured from the content box of the node that owns the run
width?numberRun width
height?numberRun height
Coordinates
transform is absolute. It places the box on the page, and every node carries one, including the
boxes takumi generates to lay out inline content.
A run's x and y are not absolute. They start at the content box of the node that owns the run,
so add that node's padding and border to place a run on the page.
Last updated on