I know how to get this height of a font:
通过将文本放置在 div 中并获取 div 的偏移高度。
But I would like to get this actual height (Which will depend on font family):
使用基于网络的编程是否有可能实现这一点?
有一个简单的解决方案吗?我想答案是否定的。
如果您愿意使用更复杂(且处理器密集型)的解决方案,您可以尝试以下方法:
将文本渲染到画布上,然后使用canvasCtx.getImageData(..)
检索像素信息。接下来,您将执行类似于此伪代码所描述的操作:
first_y : null
last_y : null
for each y:
for each x:
if imageData[x][y] is black:
if first_y is null:
first_y = y
last_y = y
height = last_y - first_y
这基本上是查找字母(黑色像素)的顶部(最低 y 索引)和底部(最高 y 索引),然后减去以检索高度。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)