2

I just can't seem to get pygame fonts to work how I want them to.

What I want is for the rendered text itself to have a pixel height of 100. In other words, font.get_rect(text).height should be 100. The only way I've found to do this is brute force the resolution until I get 100. However, this doesn't work for all text, and I want to be able to change the desired height without having to also change the resolution.

Here's an example:

# pygame.freetype.Font(file, size)
font = pygame.freetype.Font(None, 100)
print(font.get_rect("text").height)             # prints 69
font = pygame.freetype.Font(None, 100, resolution=104)
print(font.get_rect("text").height)             # prints 100

font = pygame.freetype.Font(None, 100)
print(font.get_rect("Other Text!").height)      # prints 76
font = pygame.freetype.Font(None, 100, resolution=104)
print(font.get_rect("Other Text!").height)      # prints 110

What am I not understanding?

  • 1
    The bounding rectangle will conform to the largest character. Compare the heights of `"_"` and `"$"` for a clearer indication of the difference. If there's a specific letter you want to be 100 pixels high then I'd suggest you calibrate off that. I think you should be changing the size of the font rather than the resolution. – import random Apr 29 '22 at 14:17

0 Answers0