FreeType2: get global font limiter in pixels?

I use FreeType2 to render fonts, and I need to get a global bounding box for all fonts, so I can align them in a nice grid. I call FT_Set_Char_Size and then retrieve the global borders with

 int pixels_x = ::FT_MulFix((face->bbox.xMax - face->bbox.xMin), face->size->metrics.x_scale ); int pixels_y = ::FT_MulFix((face->bbox.yMax - face->bbOx.yMin), face->size->metrics.y_scale ); return Size (pixels_x / 64, pixels_y / 64); 

which works, but it's pretty big. I also tried to calculate the usage of two-local ones ( as described in the FreeType2 tutorial ), but the results are almost the same. Even when using only face->bbox.xMax , face->bbox.xMax are face->bbox.xMax too wide. Am I doing it right or just some huge glyph in my font (Arial.ttf in this case?) Any way to check which glyph is supposedly large?

+4
source share
2 answers

Why not calculate min / max from the characters you use in the string you want to align? Just scroll through the characters and keep the high and low of the characters you are using. You can save these values โ€‹โ€‹after rendering them, so you donโ€™t have to look for them every time you render glyphs.

0
source

I have a similar problem using freetype to display a bunch of text elements that will appear in the grid. Not all text elements have the same dimension, and I need to pre-define them before I know where they will be laid out. Different sizes were the biggest problem when changing heights, for example, for letters with descending parts (for example, "j" or "Q").

In the end, I used the height that is on the face (sort of like with bbox). But, as you already mentioned, this value was great. It should be basic for the base distance, but it turned out to be about twice as large. So, I made an easy exit and divided the reported height by 2 and used this as the total height value. Most likely, the height is too high, because there are some characters in the font that go high or low.

I suggest that a better way could be to loop through all the characters that are expected to be used, get their glyph metrics and keep the highest found height. But this is not like anything that would be great.

0
source

Source: https://habr.com/ru/post/1343238/


All Articles