pygame-community / pygame-ce

🐍🎮 pygame - Community Edition is a FOSS Python library for multimedia applications (like games). Built on top of the excellent SDL library.
https://pyga.me
853 stars 140 forks source link

font.point_size is not equal to parameter size #2781

Closed LondonClass closed 6 months ago

LondonClass commented 6 months ago

Environment:

You can get some of this info from the text that pops up in the console when you run a pygame program.

Current behavior:

font.point_size is not equal to parameter size

Test code

If possible add a simple test program that shows the problem described in this report.

import pygame

pygame.init()

# Define font file path and a list of fonts with different sizes
font_path = None
font_sizes = [10, 16, 24, 32, 40]  # List of different font sizes

# Iterate through different font sizes and check if their width matches the passed size
for size in font_sizes:
    font = pygame.font.Font(font_path, size)
    point_size = font.point_size

    if size == point_size:
        print(f"Font size {size} matches the point size {point_size}.")
    else:
        print(f"Font size {size} does not match the point size {point_size}.")
oddbookworm commented 6 months ago

Does it behave the same way with any non-default font? There’s some weirdness going on with the default font that gives it half the size that is currently kept around for backwards compatibility

novialriptide commented 6 months ago

Hi, I wrote .point_size.

It's stated that it "will not be accurate upon initializing the font object when the font name is initialized as None" as said here: https://pyga.me/docs/ref/font.html#pygame.font.Font.point_size and as Andrew has stated, this is meant to happen because of backward-compatibility.