blockly > utils > dom > getFastTextWidth

utils.dom.getFastTextWidth() 函式

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

Signature:

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

參數

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

傳回:

號碼

元素的寬度。