textWidth

Returns how wide a piece of text is at a size in a face, in pixels, measured by the browser where there is one and estimated from an average glyph where there is not.

@internote/canvas-sdkFunction
On this page
import { textWidth } from '@internote/canvas-sdk';

Cached, except while the face is still downloading: a measurement taken against the fallback must not be remembered as the answer.

#Signature

(text: string, px: number, family?: string): number

#Parameters

text
The text to measure.
px
The font size in pixels.
family
The CSS font stack, which may name a var().

#Example

const gutter = textWidth(renderedText(axisName), labelPx(size, unit)) + unit;

Declared in packages/canvas-sdk/src/text/index.ts:94.

Last updated