We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2487

Summary: Suggestion: adding TTF_SetFontSize() to set font size dynamically
Product: SDL_ttf Reporter: George Wu <micstu>
Component: miscAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: API change    
Priority: P2 CC: philipp.wiesemann, sylvain.becker
Version: unspecified   
Hardware: All   
OS: All   
Attachments: The TTF_SetFontSize() function.
patch
test case

Description George Wu 2014-04-09 13:54:11 UTC
Created attachment 1612 [details]
The TTF_SetFontSize() function.

In SDL_ttf-2.0.12, the font size cannot be set dynamically. To reset the font, I must close the original font, and load it with a new size again.
This patch suggests an API change of SDL_ttf. It adds a function TTF_SetFontSize(), whose code is uploaded as attachment.
Robustness fixme:
Original height and new height of a font are both integers, the final glyph_italics field (integer) will not be so accurate after re-setting the size many times.
Source:
Fixed from the code on http://blog.csdn.net/fghjkldf/article/details/11562443 (line 77).
Comment 1 Philipp Wiesemann 2014-04-13 18:53:29 UTC
The TTF_SetFontSize() function uses TTF_CloseFont() on the TTF_Font if there was an error which then also deletes the TTF_Font.
I think this is confusing because I would expect the TTF_Font to be still usable after calling TTF_SetFontSize(). There is no return value which tells me that I can not use it again.

The other TTF_Set*() also do not have return values so maybe a consistent solution would be to have TTF_SetFontSize() set the error message but not delete the TTF_Font. (This assumes that trying to set the font size and failing does not corrupt the TTF_Font in any way.)

To make TTF_SetFontSize() usable it also needs to be added to SDL_ttf.h.

The function TF_SetFontSize() is also available in an attachment at bug 2486.
Comment 2 Sylvain 2018-10-30 19:43:24 UTC
Created attachment 3418 [details]
patch

Add a patch for this based on head with similar behaviour.
Comment 3 Sylvain 2018-10-30 19:48:43 UTC
Created attachment 3419 [details]
test case

test case to try it. keyboard o/p to change increase/decrease the font size.
Comment 4 Sylvain 2019-01-31 13:49:22 UTC
Fixed in ttps://hg.libsdl.org/SDL_ttf/rev/1f3d498496da
Comment 5 Sylvain 2019-01-31 14:01:31 UTC
*** Bug 2486 has been marked as a duplicate of this bug. ***