- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
TextMetrics API返回一些具有相似名称的字段:
fontBoundingBoxAscent
与 actualBoundingBoxAscent
fontBoundingBoxDescent
与 actualBoundingBoxDescent
MDN 文档不是很清楚,也没有提供视觉效果。它们有什么区别?
另外,作为后续,我如何根据这些值计算文本的高度?
最佳答案
也许这些文档更清楚:
fontBoundingBoxAscent
The distance from the horizontal line indicated by the textBaseline attribute to the top of the highest bounding rectangle of all the fonts used to render the text, in CSS pixels; positive numbers indicating a distance going up from the given baseline.'
fontBoundingBoxDescent
The distance from the horizontal line indicated by the textBaseline attribute to the bottom of the lowest bounding rectangle of all the fonts used to render the text, in CSS pixels; positive numbers indicating a distance going down from the given baseline.
actualBoundingBoxAscent
The distance from the horizontal line indicated by the textBaseline attribute to the top of the bounding rectangle of the given text, in CSS pixels; positive numbers indicating a distance going up from the given baseline.
actualBoundingBoxDescent
The distance from the horizontal line indicated by the textBaseline attribute to the bottom of the bounding rectangle of the given text, in CSS pixels; positive numbers indicating a distance going down from the given baseline.
Source:
https://webplatform.github.io/docs/apis/canvas/TextMetrics/fontBoundingBoxAscent/ https://webplatform.github.io/docs/apis/canvas/TextMetrics/fontBoundingBoxDescent/ https://webplatform.github.io/docs/apis/canvas/TextMetrics/actualBoundingBoxAscent/ https://webplatform.github.io/docs/apis/canvas/TextMetrics/actualBoundingBoxDescent/
要计算文本高度,您可以执行以下操作:
fontHeight = fontBoundingBoxAscent + fontBoundingBoxDescent;
actualHeight = actualBoundingBoxAscent + actualBoundingBoxDescent;
fontHeight
是边界框高度,与呈现的字符串无关。 actualHeight
特定于正在呈现的字符串。
关于javascript - HTML5 Canvas : fontBoundingBoxAscent vs. actualBoundingBoxAscent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46949891/
TextMetrics API返回一些具有相似名称的字段: fontBoundingBoxAscent 与 actualBoundingBoxAscent fontBoundingBoxDescent
我是一名优秀的程序员,十分优秀!