Changeset - r20179:3d62e5438cc2
[Not reviewed]
master
0 2 0
michi_cc - 11 years ago 2013-04-06 22:06:44
michi_cc@openttd.org
(svn r25157) -Feature: Determine the default font height for vector fonts according to the minimum readable height that the font provides.
2 files changed with 25 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/fontcache.cpp
Show inline comments
 
@@ -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 *s
 

	
 
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) {
 

	
src/table/misc_settings.ini
Show inline comments
 
@@ -164,7 +164,7 @@ ifdef    = WITH_FREETYPE
 
name     = ""small_size""
 
type     = SLE_UINT
 
var      = _freetype.small_size
 
def      = 8
 
def      = 0
 
min      = 0
 
max      = 72
 

	
 
@@ -173,7 +173,7 @@ ifdef    = WITH_FREETYPE
 
name     = ""medium_size""
 
type     = SLE_UINT
 
var      = _freetype.medium_size
 
def      = 10
 
def      = 0
 
min      = 0
 
max      = 72
 

	
 
@@ -182,7 +182,7 @@ ifdef    = WITH_FREETYPE
 
name     = ""large_size""
 
type     = SLE_UINT
 
var      = _freetype.large_size
 
def      = 16
 
def      = 0
 
min      = 0
 
max      = 72
 

	
 
@@ -191,7 +191,7 @@ ifdef    = WITH_FREETYPE
 
name     = ""mono_size""
 
type     = SLE_UINT
 
var      = _freetype.mono_size
 
def      = 10
 
def      = 0
 
min      = 0
 
max      = 72
 

	
0 comments (0 inline, 0 general)