summaryrefslogtreecommitdiff
path: root/src/fontcache.cpp
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2013-04-06 22:06:44 +0000
committermichi_cc <michi_cc@openttd.org>2013-04-06 22:06:44 +0000
commit55ba9320f311f37d16cf8f456a555aa5fba8d1a3 (patch)
tree9ee732acd5c8e10b733620fbefd8d0ca423cc715 /src/fontcache.cpp
parent2b6669a7fffa237ddd818b0a461eb96081f15dd9 (diff)
downloadopenttd-55ba9320f311f37d16cf8f456a555aa5fba8d1a3.tar.xz
(svn r25157) -Feature: Determine the default font height for vector fonts according to the minimum readable height that the font provides.
Diffstat (limited to 'src/fontcache.cpp')
-rw-r--r--src/fontcache.cpp25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/fontcache.cpp b/src/fontcache.cpp
index 1d7f528d6..27c908678 100644
--- a/src/fontcache.cpp
+++ b/src/fontcache.cpp
@@ -20,9 +20,12 @@
#include "table/control_codes.h"
static const int ASCII_LETTERSTART = 32; ///< First printable ASCII letter.
+static const int MAX_FONT_SIZE = 72; ///< Maximum font size.
/** Semi-constant for the height of the different sizes of fonts. */
int _font_height[FS_END];
+/** Default heights for the different sizes of fonts. */
+static const int _default_font_height[FS_END] = {10, 6, 18, 10};
/**
* Reset the font sizes to the defaults of the sprite based fonts.
@@ -31,11 +34,11 @@ int _font_height[FS_END];
void ResetFontSizes(bool monospace)
{
if (monospace) {
- _font_height[FS_MONO] = 10;
+ _font_height[FS_MONO] = _default_font_height[FS_MONO];
} else {
- _font_height[FS_SMALL] = 6;
- _font_height[FS_NORMAL] = 10;
- _font_height[FS_LARGE] = 18;
+ _font_height[FS_SMALL] = _default_font_height[FS_SMALL];
+ _font_height[FS_NORMAL] = _default_font_height[FS_NORMAL];
+ _font_height[FS_LARGE] = _default_font_height[FS_LARGE];
}
}
@@ -43,6 +46,7 @@ void ResetFontSizes(bool monospace)
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
+#include FT_TRUETYPE_TABLES_H
#ifdef WITH_FONTCONFIG
#include <fontconfig/fontconfig.h>
@@ -815,6 +819,19 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
static void SetFontGeometry(FT_Face face, FontSize size, int pixels)
{
+ if (pixels == 0) {
+ /* Try to determine a good height based on the minimal height recommended by the font. */
+ pixels = _default_font_height[size];
+
+ TT_Header *head = (TT_Header *)FT_Get_Sfnt_Table(face, ft_sfnt_head);
+ if (head != NULL) {
+ /* Font height is minimum height plus the difference between the default
+ * height for this font size and the small size. */
+ int diff = _default_font_height[size] - _default_font_height[FS_SMALL];
+ pixels = Clamp(min(head->Lowest_Rec_PPEM, 20) + diff, _default_font_height[size], MAX_FONT_SIZE);
+ }
+ }
+
FT_Error err = FT_Set_Pixel_Sizes(face, 0, pixels);
if (err == FT_Err_Invalid_Pixel_Size) {