Skip to content
Shapemetry

@huukhanhnguyen/model / nodeMethods/font

nodeMethods/font

fontOf()

fontOf(font): FontData | null

The font to shape with. The registry hands font args through raw, so the value may be a bare string (an unresolved url) rather than a loaded font — anything that is not a FontData falls back.

Parameters

font

unknown

Returns

FontData | null


getFallbackFont()

getFallbackFont(): FontData | null

Returns

FontData | null


parse()

parse(buffer): Promise<FontData>

Register a font file with the kernel. Still async: shaping itself is synchronous once the wasm module graph is loaded, but every caller (Store.loadFonts, the upload picker, the fallback bootstrap) already awaits, and the fetch in front of it dominates either way.

Parameters

buffer

ArrayBuffer

Returns

Promise<FontData>


setFallbackFont()

setFallbackFont(font): void

Parameters

font

FontData

Returns

void


textClean()

textClean(font, content, fontSize, baselineY?): PolyCurve2d[]

Text as clean (boolean-unioned) outline rings: one closed PolyCurve2d per filled area, counters as separate rings, overlaps between glyphs merged by the kernel's region boolean. baselineY is subtracted from y — the multi-line layout's per-line step. Converts the wasm untagged segment bag into Curve2d curves[] at this door.

Parameters

font

FontData

content

string

fontSize

number

baselineY?

number = 0

Returns

PolyCurve2d[]


wrapText()

wrapText(font, content, fontSize, width): string[]

wrapTextLines on real shaped advances — same contract (\n always breaks, width 0 = manual breaks only, words never split), one wasm crossing.

Parameters

font

FontData

content

string

fontSize

number

width

number

Returns

string[]


wrapTextLines()

wrapTextLines(content, width, measure): string[]

Greedy word-wrap: split content into lines no wider than width per measure. Explicit \n breaks always apply; width 0 = manual breaks only. A single word wider than width keeps its own line — never split mid-word (drafting convention, same as AutoCAD MTEXT).

The callback form, for callers with no font: annotation's note block measures by character advance. With a font, use wrapText — the kernel wraps on real shaped advances in one crossing.

Parameters

content

string

width

number

measure

(text) => number

Returns

string[]

Last updated: 📖 2 min readEdit on GitHub