Home > Back-end >  How do I find out font width and height with SDL_ttf?
How do I find out font width and height with SDL_ttf?

Time:01-08

I want to find out the width and height of a font in SDL_ttf. I have the font (TTF_Font *), and the text (const char *). Is there any way I could calculate the with and height with these two properties? I tried searching the internet but there wasn't much information on this topic.

I don't want to use something like:

calculate_font_example(font, text, width, height);

I want to use something like this:

calculate_font_example(font, text) // Outputs font width and height

CodePudding user response:

A ttf font is like a svg, it is defined using curves and lines, so it has no fixed size. It can be drawn in any hight and width (or even thickness). So you don't need to calculate the font size, use any size you like.

  • Related