pygame-ce
pygame-ce copied to clipboard
Add `Font.set_linesize()` (TTF 2.24.0 feature)
We've long had the ability to get the line size with get_linesize(), but we've never had the ability to set the spacing between lines when rendering multiline text. Thanks to SDL_TTF 2.24.0 this PR adds the functionality.
@itzpr3d4t0r I believe your tests are failing here because it runs the test suite over font as well as ftfont, and ftfont doesn't support this feature. Some other font tests specifically exclude themselves from running on ftfont.
This will be a great feature to get in! Left a few small notes / a question.
Wrote a sample program to test around with:
import pygame
pygame.init()
screen = pygame.display.set_mode((680, 420))
clock = pygame.time.Clock()
running = True
font = pygame.font.SysFont("Arial", 32)
def generate_text():
return font.render(
"Hello world\nThis is an example of\nmultiline text\nusing different spacings.",
True,
"black",
)
text = generate_text()
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN and event.key == pygame.K_UP:
font.set_linesize(font.get_linesize() + 5)
print(font.get_linesize())
text = generate_text()
if event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN:
font.set_linesize(font.get_linesize() - 5)
print(font.get_linesize())
text = generate_text()
screen.fill("purple")
for i in range(4):
pygame.draw.rect(
screen,
"orangered" if i % 2 else "lightblue",
[0, i * font.get_linesize(), 300, font.get_linesize()],
)
screen.blit(text)
pygame.display.flip()
clock.tick(60)
pygame.quit()
Last time I talked to itzpr he was busy IRL and okay with people taking over his PRs.
@aatle I was wondering if you were interested in taking this over, since you’re a member now you can push to itzprs branch. This could be a good first C PR for you, as it just needs some polishing up to get over the finish line.