FreeType string width and height?

Started by
0 comments, last by swiftcoder 16 years, 1 month ago
Is there a way to find the length of a string will be before you render each glyph of the string? And if there is not, what is a safe estimate? I thought the font size multiplied by the string length would be a safe guess, but it is showing that it is a little short some times.
Advertisement
Query FreeType for the glyphs for each character, and place these in an array. The 'advance' field of each glyph is the width, so loop through your string adding the advance for that particular character.

Of course, this doesn't take tab stops into account, but you probably don't need those.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement