-
-
Notifications
You must be signed in to change notification settings - Fork 183
Add Font.set_linesize()
(TTF 2.24.0 feature)
#3282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@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. |
7065340
to
47527c8
Compare
47527c8
to
dd6854c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As much as I don't like set_/get_ methods, get_linesize was already there, so not adding it would be rather weird (we can have just properties with pygame 3, I guess!). And Font.linesize
can be added by another PR, too, so this LGTM, thanks for adding it :)
return NULL; | ||
|
||
if (linesize < 0) | ||
return RAISE(PyExc_ValueError, "linesize must be >= 0"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does SDL_ttf do if this isn't true? Also could be good to specify in the docs that this needs to be a positive number including zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I tried allowing negative sizes, font.render()
raised pygame.error
for a large negative size (possibly when greater than height).
Documented constraint.
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. |
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.