Skip to content

Interface: FontMetricsOracle ​

Experimental

Synchronous, cached text measurement for layout. Every method honors the font's textcase and variant (see the module notes).

Properties ​

PropertyModifierTypeDescription
measurerreadonlyTextMeasurerExperimental

Methods ​

clear() ​

ts
clear(): void;

Experimental

Drop cached measurements (e.g. after a web font finished loading).

Returns ​

void


ellipsize() ​

ts
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 ​

ParameterType
textstring
fontTextFont
maxWidthnumber
ellipsis?string

Returns ​

string


measureAdvance() ​

ts
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 ​

ParameterType
textstring
fontTextFont

Returns ​

number


measureText() ​

ts
measureText(
   text,
   font,
   lineHeight?
): MeasuredText;

Experimental

Width, vertical metrics, and block height. lineHeight is a multiple of the font size.

Parameters ​

ParameterType
textstring
fontTextFont
lineHeight?number

Returns ​

MeasuredText


measureWidth() ​

ts
measureWidth(text, font): number;

Experimental

Width in px of the widest line of text (trailing whitespace excluded).

Parameters ​

ParameterType
textstring
fontTextFont

Returns ​

number


wrapText() ​

ts
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 ​

ParameterType
textstring
fontTextFont
maxWidthnumber

Returns ​

string[]

Released under the MIT License.