封鎖 >utils >數字 >getFastTextWidth
utils.dom.getFastTextWidth() 函式
使用比 getTextWidth
更快的方法取得文字元素的寬度。這種方法需要事先瞭解文字元素的字型系列和大小。與 getTextWidth
類似,我們會快取計算出的寬度。
Signature:
export declare function getFastTextWidth(textElement: SVGTextElement, fontSize: number, fontWeight: string, fontFamily: string): number;
參數
參數 |
類型 |
說明 |
textElement |
SVGTextElement |
SVG 的「文字」元素。 |
fontSize |
數字 |
要使用的字型大小。 |
fontWeight |
字串 |
要使用的字型粗細。 |
fontFamily |
字串 |
要使用的字型系列。 |
傳回:
數字
元素的寬度。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-09-12 (世界標準時間)。
[null,null,["上次更新時間:2024-09-12 (世界標準時間)。"],[[["`utils.dom.getFastTextWidth` calculates the width of an SVG text element more quickly than `getTextWidth` by pre-requiring font information and caching results."],["The function requires the SVG text element, font size, font weight, and font family as input to calculate and return the element's width."]]],[]]