Skip to main content

Home > blockly > utils > dom > getFastTextWidth

utils.dom.getFastTextWidth() function

Gets the width of a text element using a faster method than getTextWidth. This method requires that we know the text element's font family and size in advance. Similar to getTextWidth, we cache the width we compute.

Signature:

export declare function getFastTextWidth(textElement: SVGTextElement, fontSize: number, fontWeight: string, fontFamily: string): number;

Parameters

ParameterTypeDescription
textElementSVGTextElementAn SVG 'text' element.
fontSizenumberThe font size to use.
fontWeightstringThe font weight to use.
fontFamilystringThe font family to use.

Returns:

number

Width of element.