(svn r23275) -Codechange: allow loading of the monospace (freetype) font at another moment than the other fonts

pull/155/head
rubidium 13 years ago
parent 49047246fa
commit 17db686187

@ -25,14 +25,18 @@ int _font_height[FS_END];
/** /**
* Reset the font sizes to the defaults of the sprite based fonts. * Reset the font sizes to the defaults of the sprite based fonts.
* @param monospace Whether to reset the monospace or regular fonts.
*/ */
void ResetFontSizes() void ResetFontSizes(bool monospace)
{ {
if (monospace) {
_font_height[FS_MONO] = 10; _font_height[FS_MONO] = 10;
} else {
_font_height[FS_SMALL] = 6; _font_height[FS_SMALL] = 6;
_font_height[FS_NORMAL] = 10; _font_height[FS_NORMAL] = 10;
_font_height[FS_LARGE] = 18; _font_height[FS_LARGE] = 18;
} }
}
#ifdef WITH_FREETYPE #ifdef WITH_FREETYPE
#include <ft2build.h> #include <ft2build.h>
@ -821,7 +825,7 @@ static void LoadFreeTypeFont(const char *font_name, FT_Face *face, const char *t
} }
static void ResetGlyphCache(); static void ResetGlyphCache(bool monospace);
/** /**
* Unload a face and set it to NULL. * Unload a face and set it to NULL.
@ -837,16 +841,20 @@ static void UnloadFace(FT_Face *face)
/** /**
* (Re)initialize the freetype related things, i.e. load the non-sprite fonts. * (Re)initialize the freetype related things, i.e. load the non-sprite fonts.
* @param monospace Whether to initialise the monospace or regular fonts.
*/ */
void InitFreeType() void InitFreeType(bool monospace)
{ {
ResetFontSizes(); ResetFontSizes(monospace);
ResetGlyphCache(); ResetGlyphCache(monospace);
if (monospace) {
UnloadFace(&_face_mono); UnloadFace(&_face_mono);
} else {
UnloadFace(&_face_small); UnloadFace(&_face_small);
UnloadFace(&_face_medium); UnloadFace(&_face_medium);
UnloadFace(&_face_large); UnloadFace(&_face_large);
}
if (StrEmpty(_freetype.small_font) && StrEmpty(_freetype.medium_font) && StrEmpty(_freetype.large_font) && StrEmpty(_freetype.mono_font)) { if (StrEmpty(_freetype.small_font) && StrEmpty(_freetype.medium_font) && StrEmpty(_freetype.large_font) && StrEmpty(_freetype.mono_font)) {
DEBUG(freetype, 1, "No font faces specified, using sprite fonts instead"); DEBUG(freetype, 1, "No font faces specified, using sprite fonts instead");
@ -863,15 +871,18 @@ void InitFreeType()
} }
/* Load each font */ /* Load each font */
if (monospace) {
LoadFreeTypeFont(_freetype.mono_font , &_face_mono, "mono"); LoadFreeTypeFont(_freetype.mono_font , &_face_mono, "mono");
if (_face_mono != NULL) {
SetFontGeometry(_face_mono, FS_MONO, _freetype.mono_size);
}
} else {
LoadFreeTypeFont(_freetype.small_font, &_face_small, "small"); LoadFreeTypeFont(_freetype.small_font, &_face_small, "small");
LoadFreeTypeFont(_freetype.medium_font, &_face_medium, "medium"); LoadFreeTypeFont(_freetype.medium_font, &_face_medium, "medium");
LoadFreeTypeFont(_freetype.large_font, &_face_large, "large"); LoadFreeTypeFont(_freetype.large_font, &_face_large, "large");
/* Set each font size */ /* Set each font size */
if (_face_mono != NULL) {
SetFontGeometry(_face_mono, FS_MONO, _freetype.mono_size);
}
if (_face_small != NULL) { if (_face_small != NULL) {
SetFontGeometry(_face_small, FS_SMALL, _freetype.small_size); SetFontGeometry(_face_small, FS_SMALL, _freetype.small_size);
} }
@ -882,13 +893,15 @@ void InitFreeType()
SetFontGeometry(_face_large, FS_LARGE, _freetype.large_size); SetFontGeometry(_face_large, FS_LARGE, _freetype.large_size);
} }
} }
}
/** /**
* Free everything allocated w.r.t. fonts. * Free everything allocated w.r.t. fonts.
*/ */
void UninitFreeType() void UninitFreeType()
{ {
ResetGlyphCache(); ResetGlyphCache(true);
ResetGlyphCache(false);
UnloadFace(&_face_small); UnloadFace(&_face_small);
UnloadFace(&_face_medium); UnloadFace(&_face_medium);
@ -933,10 +946,14 @@ struct GlyphEntry {
*/ */
static GlyphEntry **_glyph_ptr[FS_END]; static GlyphEntry **_glyph_ptr[FS_END];
/** Clear the complete cache */ /**
static void ResetGlyphCache() * Clear the complete cache
* @param monospace Whether to reset the monospace or regular font.
*/
static void ResetGlyphCache(bool monospace)
{ {
for (FontSize i = FS_BEGIN; i < FS_END; i++) { for (FontSize i = FS_BEGIN; i < FS_END; i++) {
if (monospace != (i == FS_MONO)) continue;
if (_glyph_ptr[i] == NULL) continue; if (_glyph_ptr[i] == NULL) continue;
for (int j = 0; j < 256; j++) { for (int j = 0; j < 256; j++) {

@ -42,7 +42,7 @@ struct FreeTypeSettings {
extern FreeTypeSettings _freetype; extern FreeTypeSettings _freetype;
void InitFreeType(); void InitFreeType(bool monospace);
void UninitFreeType(); void UninitFreeType();
const Sprite *GetGlyph(FontSize size, uint32 key); const Sprite *GetGlyph(FontSize size, uint32 key);
uint GetGlyphWidth(FontSize size, uint32 key); uint GetGlyphWidth(FontSize size, uint32 key);
@ -63,7 +63,7 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
#else #else
/* Stub for initializiation */ /* Stub for initializiation */
static inline void InitFreeType() { extern void ResetFontSizes(); ResetFontSizes(); } static inline void InitFreeType(bool monospace) { extern void ResetFontSizes(bool monospace); ResetFontSizes(monospace); }
static inline void UninitFreeType() {} static inline void UninitFreeType() {}
/** Get the Sprite for a glyph */ /** Get the Sprite for a glyph */

@ -697,8 +697,8 @@ int ttd_main(int argc, char *argv[])
/* enumerate language files */ /* enumerate language files */
InitializeLanguagePacks(); InitializeLanguagePacks();
/* Initialize FreeType */ /* Initialize the regular font for FreeType */
InitFreeType(); InitFreeType(false);
/* This must be done early, since functions use the SetWindowDirty* calls */ /* This must be done early, since functions use the SetWindowDirty* calls */
InitWindowSystem(); InitWindowSystem();

@ -1750,7 +1750,7 @@ const char *GetCurrentLanguageIsoCode()
*/ */
bool MissingGlyphSearcher::FindMissingGlyphs(const char **str) bool MissingGlyphSearcher::FindMissingGlyphs(const char **str)
{ {
InitFreeType(); InitFreeType(false);
const Sprite *question_mark[FS_END]; const Sprite *question_mark[FS_END];
for (FontSize size = FS_BEGIN; size < FS_END; size++) { for (FontSize size = FS_BEGIN; size < FS_END; size++) {
@ -1856,7 +1856,7 @@ void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
/* Our fallback font does miss characters too, so keep the /* Our fallback font does miss characters too, so keep the
* user chosen font as that is more likely to be any good than * user chosen font as that is more likely to be any good than
* the wild guess we made */ * the wild guess we made */
InitFreeType(); InitFreeType(false);
} }
} }
#endif #endif

Loading…
Cancel
Save