Node / Text Rendering · guide
measureText — layout metrics
Current Apexify.js 6.0.0 documentation for measureText — layout metrics.
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
| Field | Role |
|---|---|
includeCharMetrics | When 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:
| Field | Meaning |
|---|---|
width | measureText(text).width on the whole string before wrapping adjustments |
height | fontSize scalar |
lineHeight | **`(layout.lineHeight |
baseline, top, bottom | Authoring helpers derived from ascent/descent |
centerX, centerY | Based on width / height / baseline |
When layout.maxWidth is set:
| Field | Meaning |
|---|---|
lines | Each wrapped row with text, width, height, nested metrics |
totalHeight | lines.length * lineHeight |
lineCount | lines.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).