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.