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 2951 - PATCH: addition of optional DPI-scaling of fonts
Summary: PATCH: addition of optional DPI-scaling of fonts
Status: RESOLVED FIXED
Alias: None
Product: SDL_ttf
Classification: Unclassified
Component: misc (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-18 18:51 UTC by David Ludwig
Modified: 2019-12-28 21:25 UTC (History)
4 users (show)

See Also:


Attachments
SDL_ttf DPI-scaling patch (4.99 KB, text/plain)
2015-04-18 18:51 UTC, David Ludwig
Details
(same thing from glebm@ for reference) (4.17 KB, patch)
2019-12-28 01:44 UTC, Gleb Mazovetskiy
Details | Diff
updated DPI-scaling patch for default/2.0 branch (6.04 KB, patch)
2019-12-28 10:50 UTC, Ozkan Sezer
Details | Diff
updated DPI-scaling patch for SDL-1.2 branch (4.10 KB, patch)
2019-12-28 10:51 UTC, Ozkan Sezer
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Ludwig 2015-04-18 18:51:06 UTC
Created attachment 2128 [details]
SDL_ttf DPI-scaling patch

This patch allows TTF_Fonts to be created with DPI resolutions other than
FreeType's default (of 72 DPI).  Doing so allows fonts to be scaled
linearly (at runtime), whereas point-sizes often do not scale linearly.

Four new functions are added to SDL_ttf to facilitate this change:

SDL_OpenFontDPI
SDL_OpenFontIndexDPI
SDL_OpenFontDPIRW
SDL_OpenFontIndexDPIRW

Each DPI-enabled SDL_OpenFont* call adds two parameters to the end:
 1. unsigned int hdpi: specifies the DPI resolution along the horizontal axis
 2. unsigned int vdpi: specifies the DPI resolution along the vertical axis

Both parameters are passed directly into FreeType, which processes them as
such:
 * if both hdpi and vdpi are 0, then FreeType will use its default DPI of 72
 * if only hdpi, or only vdpi, is 0, then FreeType will use the non-zero
   value for both hdpi and vdpi.  For example, if hdpi is 0 and vdpi is 144,
   FreeType will use 144 DPI on both axes.
 * if both hdpi and vdpi are NOT 0, then FreeType will use the DPI
   resolutions as specified, along their respective axes.

This addition requires no modifications to FreeType 2.x itself, and does not
modify any existing SDL_ttf API (for source and binary level compatibility).
Comment 1 David Ludwig 2015-04-18 18:52:11 UTC
If this patch looks good, and you'd like me to push it to hg.libsdl.org, let me know, and I'll be happy to do so.

If you have any concerns, comments, or questions, please let me know as well!

Cheers!
-- David L.
Comment 2 Gleb Mazovetskiy 2019-12-28 01:43:47 UTC
I've made an almost identical patch today and then discovered this!

Can someone please merge this? Thanks!

Background:
Many retro-gaming devices, such as RG300, LDK, etc, use non-square pixels (320x480 with wide 2:1 pixels). These devices run Linux and most apps on them use SDL1.2 (but generally just upscale from 320x240). With this change, it will be possible to improve font rendering in many of these apps.

(attaching my patch for reference, it's basically identical except for a tiny function naming difference)
Comment 3 Gleb Mazovetskiy 2019-12-28 01:44:48 UTC
Created attachment 4141 [details]
(same thing from glebm@ for reference)
Comment 4 Ozkan Sezer 2019-12-28 10:50:11 UTC
Created attachment 4142 [details]
updated DPI-scaling patch for default/2.0 branch

dludwig: Here is an updated version of your patch to default/2.0 branch:

- Updated so that it applies to current hg and builds: Required adding
  another DPI function, i.e. TTF_SetFontSizeDPI().
- Minor tidy-ups to comments and the commit message.

Please confirm the changes are OK.

Sylvain, Sam: Is this OK to apply?
Comment 5 Ozkan Sezer 2019-12-28 10:51:14 UTC
Created attachment 4143 [details]
updated DPI-scaling patch for SDL-1.2 branch

glebm: Here is an updated version of your patch to SDL-1.2 branch:

- Fixes TTF_OpenFontRWDPI() to use dpi params instead of 0.
- Changes ??RWDPI function names to ??DPIRW for consistency. (RW
  is a suffix to an existing function name.)
- Changes the horz_resolution and vert_resolution parameter names
  to short hdpi and vdpi as dludwig's version.
- Adds the small DPI documentation before FT_Set_Char_Size() like
  in dludwig's version.

Please confirm the changes are OK.

I'd be willing to apply this to SDL-1.2 branch, only if dludwig's
patch to default/2.0 branch is OK'ed.
Comment 6 Gleb Mazovetskiy 2019-12-28 14:16:43 UTC
Thank you Ozkan, the changes look good!
Comment 7 Sylvain 2019-12-28 21:05:49 UTC
Hi, the patch looks good ! I'm not really a user of DPI functions but it seems convenient, especially if one want a stretching by setting a different vertical/horizontal DPI !
Comment 8 Ozkan Sezer 2019-12-28 21:25:37 UTC
(In reply to Sylvain from comment #7)
> Hi, the patch looks good ! I'm not really a user of DPI functions but it
> seems convenient, especially if one want a stretching by setting a different
> vertical/horizontal DPI !

OK then, patches are applied.
SDL-1.2 branch: http://hg.libsdl.org/SDL_ttf/rev/7dbd7cd826d6
default branch: http://hg.libsdl.org/SDL_ttf/rev/d56d67db41d8

Closing as fixed.