研究调查问卷:请告诉我们您使用 Blockly 的体验
开始调查问卷
blockly >实用程序 >dom >getFastTextWidth
utils.dom.getFastTextWidth() 函数
使用比 getTextWidth
更快的方法获取文本元素的宽度。此方法要求我们事先知道文本元素的字体系列和大小。与 getTextWidth
类似,我们会缓存所计算的宽度。
Signature:
export declare function getFastTextWidth(textElement: SVGTextElement, fontSize: number, fontWeight: string, fontFamily: string): number;
参数
参数 |
类型 |
说明 |
textElement |
SVGTextElement |
SVG“文本”元素。 |
fontSize |
number |
要使用的字体大小。 |
fontWeight |
字符串 |
要使用的字体粗细。 |
fontFamily |
字符串 |
要使用的字体系列。 |
返回:
number
元素的宽度。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-09-12。
[null,null,["最后更新时间 (UTC):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."]]],[]]