mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r25157) -Feature: Determine the default font height for vector fonts according to the minimum readable height that the font provides.
This commit is contained in:
parent
2b6669a7ff
commit
55ba9320f3
|
@ -20,9 +20,12 @@
|
||||||
#include "table/control_codes.h"
|
#include "table/control_codes.h"
|
||||||
|
|
||||||
static const int ASCII_LETTERSTART = 32; ///< First printable ASCII letter.
|
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. */
|
/** Semi-constant for the height of the different sizes of fonts. */
|
||||||
int _font_height[FS_END];
|
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.
|
* 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)
|
void ResetFontSizes(bool monospace)
|
||||||
{
|
{
|
||||||
if (monospace) {
|
if (monospace) {
|
||||||
_font_height[FS_MONO] = 10;
|
_font_height[FS_MONO] = _default_font_height[FS_MONO];
|
||||||
} else {
|
} else {
|
||||||
_font_height[FS_SMALL] = 6;
|
_font_height[FS_SMALL] = _default_font_height[FS_SMALL];
|
||||||
_font_height[FS_NORMAL] = 10;
|
_font_height[FS_NORMAL] = _default_font_height[FS_NORMAL];
|
||||||
_font_height[FS_LARGE] = 18;
|
_font_height[FS_LARGE] = _default_font_height[FS_LARGE];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +46,7 @@ void ResetFontSizes(bool monospace)
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
#include FT_FREETYPE_H
|
#include FT_FREETYPE_H
|
||||||
#include FT_GLYPH_H
|
#include FT_GLYPH_H
|
||||||
|
#include FT_TRUETYPE_TABLES_H
|
||||||
|
|
||||||
#ifdef WITH_FONTCONFIG
|
#ifdef WITH_FONTCONFIG
|
||||||
#include <fontconfig/fontconfig.h>
|
#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)
|
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);
|
FT_Error err = FT_Set_Pixel_Sizes(face, 0, pixels);
|
||||||
if (err == FT_Err_Invalid_Pixel_Size) {
|
if (err == FT_Err_Invalid_Pixel_Size) {
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ ifdef = WITH_FREETYPE
|
||||||
name = ""small_size""
|
name = ""small_size""
|
||||||
type = SLE_UINT
|
type = SLE_UINT
|
||||||
var = _freetype.small_size
|
var = _freetype.small_size
|
||||||
def = 8
|
def = 0
|
||||||
min = 0
|
min = 0
|
||||||
max = 72
|
max = 72
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ ifdef = WITH_FREETYPE
|
||||||
name = ""medium_size""
|
name = ""medium_size""
|
||||||
type = SLE_UINT
|
type = SLE_UINT
|
||||||
var = _freetype.medium_size
|
var = _freetype.medium_size
|
||||||
def = 10
|
def = 0
|
||||||
min = 0
|
min = 0
|
||||||
max = 72
|
max = 72
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ ifdef = WITH_FREETYPE
|
||||||
name = ""large_size""
|
name = ""large_size""
|
||||||
type = SLE_UINT
|
type = SLE_UINT
|
||||||
var = _freetype.large_size
|
var = _freetype.large_size
|
||||||
def = 16
|
def = 0
|
||||||
min = 0
|
min = 0
|
||||||
max = 72
|
max = 72
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ ifdef = WITH_FREETYPE
|
||||||
name = ""mono_size""
|
name = ""mono_size""
|
||||||
type = SLE_UINT
|
type = SLE_UINT
|
||||||
var = _freetype.mono_size
|
var = _freetype.mono_size
|
||||||
def = 10
|
def = 0
|
||||||
min = 0
|
min = 0
|
||||||
max = 72
|
max = 72
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue