Firefox 等应用程序如何有效地计算文本高度?
我很好奇快速应用程序(也许 Safari 是一个更好的例子)使用什么技术来计算非常长的文本页面(例如聊天日志或巨大的文档)的高度。
考虑到有大量具有相同行高的文本,这已经可以乘以这些行数了。但是,如何知道
在特定宽度内会跨越多少行?
我可以得到的是它们:
- 计算每个字符的宽度并将其存储以进行快速添加,
- 用它来计算单词的宽度,
- 在与块级宽度进行比较的同时添加单词和空格的宽度,根据需要添加行。
这看起来确实非常快,因为添加和比较比在 GDI+ 中测量字符串要快得多。但我不知道是否做了这样的事情,因为可靠性是第一位的,并且据我所知文本渲染通常会引入字距调整,而且我不知道从 GDI+ 获取此信息有多容易或多困难。
另外,ReactOS 的屏幕截图让我相信 Firefox 会计算每个字母的大小和位置。
I'm curious about what technique fast applications (maybe Safari is a better example here) do to calculate the height of a terribly long page of text (for example, a chat log or a huge document).
Considering there is a huge amount of text with the same line height, this is already something that can be multiplied by the number of those lines. However, how to know how many lines a <p>
will span in a specific width?
What I can come with is that they:
- Calculate the width of every character and store it for quick addition,
- Use that to calculate the width of words,
- Add words and spaces' widths while comparing with the block-level width, adding lines as needed.
This seems indeed very fast, since additions and comparisons are way, way faster than measuring a string in GDI+. But I have no idea if something like this is done, since reliability comes first, and AFAIK text rendering normally introduces kerning, and I have no idea how easy or hard it is to get this information from GDI+.
Also, a screenshot from ReactOS was what made me believe Firefox calculates each letter's size and position.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论