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 - Suggestion: adding TTF_SetFontSize() to set font size dynamically
Summary: Suggestion: adding TTF_SetFontSize() to set font size dynamically
Status: RESOLVED FIXED
Alias: None
Product: SDL_ttf
Classification: Unclassified
Component: misc (show other bugs)
Version: unspecified
Hardware: All All
: P2 API change
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
: 2486 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-04-09 13:54 UTC by George Wu
Modified: 2019-01-31 14:01 UTC (History)
2 users (show)

See Also:


Attachments
The TTF_SetFontSize() function. (2.15 KB, text/plain)
2014-04-09 13:54 UTC, George Wu
Details
patch (1.97 KB, patch)
2018-10-30 19:43 UTC, Sylvain
Details | Diff
test case (8.05 KB, text/x-csrc)
2018-10-30 19:48 UTC, Sylvain
Details

Note You need to log in before you can comment on or make changes to this bug.
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. ***