pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

Add `Font.set_linesize()` (TTF 2.24.0 feature)

Open itzpr3d4t0r opened this issue 10 months ago • 2 comments
trafficstars

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 avatar Jan 05 '25 13:01 itzpr3d4t0r

@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.

Starbuck5 avatar Jan 28 '25 07:01 Starbuck5

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()

Starbuck5 avatar Feb 22 '25 07:02 Starbuck5

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.

Starbuck5 avatar May 11 '25 20:05 Starbuck5