Skip to content
Apexify.jsDocs
Apexify.js version v5.4.5

Node / Text Rendering · guide

measureText — layout metrics

Current Apexify.js 6.0.0 documentation for measureText — layout metrics.

apexify.jsRuntime: nodeCURRENTSince 6.0.0
SOURCEtypescript
typescript
Studio
const metrics = await painter.measureText(textProps[, painterOpts]);

TextMetricsCreator (lib-next/text/text-metrics.ts) mirrors EnhancedTextRenderer font registration, ctx.font, letterSpacing, wordSpacing, textAlign, and textBaseline — then derives boxes using measureText + optional wrapping (computeWrappedTextLines).


Options that affect measurement only

FieldRole
includeCharMetricsWhen true, fills charWidths[] and charPositions[] by iterating measureText per UTF-16 code unit (not grapheme clusters).
measurementCanvas{ width?, height? } overrides internal scratch canvas dimensions (defaults derive from text length / maxWidth heuristics).

Painting-related fields (effects, stroke) do not change measureText output — measurement reflects typography only.


Returned shape (TextMetrics)

Always includes Canvas TextMetrics fields copied through (actualBoundingBox*, fontBoundingBox*, optional baseline extras when the runtime exposes them).

Derived convenience fields:

FieldMeaning
widthmeasureText(text).width on the whole string before wrapping adjustments
heightfontSize scalar
lineHeight**`(layout.lineHeight
baseline, top, bottomAuthoring helpers derived from ascent/descent
centerX, centerYBased on width / height / baseline

When layout.maxWidth is set:

FieldMeaning
linesEach wrapped row with text, width, height, nested metrics
totalHeightlines.length * lineHeight
lineCountlines.length

Use lines[i].width for accurate per-line widths — top-level width remains the unwrapped measureText width.


Arc-aware sizing

If textOnCurve has 0 < sweepAngle < 360, measureText adjusts width/height using resolveArcRadiusAndSweep + curvedArcBoundingChord to approximate chord length and sagitta (horizontal footprint grows vs straight measurement).


Example

SOURCEtypescript
typescript
Studio
const m = await painter.measureText({  text: longCopy,  x: 0,  y: 0,  font: { size: 18, family: 'Arial' },  layout: { maxWidth: 400, lineHeight: 1.5 },  includeCharMetrics: true,}); console.log(m.lineCount, m.totalHeight, m.lines?.[0]?.width);

Next steps