Interface: FontMetricsOracle
Experimental
Synchronous, cached text measurement for layout. Every method honors the font's textcase and variant (see the module notes).
Properties
| Property | Modifier | Type | Description |
|---|---|---|---|
measurer | readonly | TextMeasurer | Experimental |
Methods
clear()
clear(): void;Experimental
Drop cached measurements (e.g. after a web font finished loading).
Returns
void
ellipsize()
ellipsize(
text,
font,
maxWidth,
ellipsis?
): string;Experimental
Truncate each line of text so it fits maxWidth, appending ellipsis (default …) to truncated lines. Returns '' for a line when not even the ellipsis fits.
Parameters
| Parameter | Type |
|---|---|
text | string |
font | TextFont |
maxWidth | number |
ellipsis? | string |
Returns
string
measureAdvance()
measureAdvance(text, font): number;Experimental
Advance width in px of one line of text, trailing whitespace included: where the next run of a rich-text line starts (E2.10). text must not contain \n.
Parameters
| Parameter | Type |
|---|---|
text | string |
font | TextFont |
Returns
number
measureText()
measureText(
text,
font,
lineHeight?
): MeasuredText;Experimental
Width, vertical metrics, and block height. lineHeight is a multiple of the font size.
Parameters
| Parameter | Type |
|---|---|
text | string |
font | TextFont |
lineHeight? | number |
Returns
measureWidth()
measureWidth(text, font): number;Experimental
Width in px of the widest line of text (trailing whitespace excluded).
Parameters
| Parameter | Type |
|---|---|
text | string |
font | TextFont |
Returns
number
wrapText()
wrapText(
text,
font,
maxWidth
): string[];Experimental
Greedy word wrap like troika's whiteSpace: 'normal': breaks after whitespace and hyphens, honors \n, and lets a single word wider than maxWidth overflow on its own line.
Parameters
| Parameter | Type |
|---|---|
text | string |
font | TextFont |
maxWidth | number |
Returns
string[]