blockly > utils > dom > getFastTextWidthWithSizeString

utils.dom.getFastTextWidthWithSizeString() 函式

使用比 getTextWidth 更快的方法取得文字元素的寬度。這種方法需要事先知道文字元素的字型系列和大小。與 getTextWidth 類似,我們會快取我們計算的寬度。這個方法與 getFastTextWidth 類似,但預期字型大小參數是字串。

Signature:

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

參數

參數 類型 說明
textElement SVGTextElement SVG 的「text」元素。
fontSize 字串 要使用的字型大小。
fontWeight 字串 要使用的字型粗細。
fontFamily 字串 要使用的字型系列。

傳回:

號碼

元素的寬度。