mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
(svn r23275) -Codechange: allow loading of the monospace (freetype) font at another moment than the other fonts
This commit is contained in:
parent
dfefcab47d
commit
9512838a5e
@ -25,13 +25,17 @@ int _font_height[FS_END];
|
||||
|
||||
/**
|
||||
* 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;
|
||||
} else {
|
||||
_font_height[FS_SMALL] = 6;
|
||||
_font_height[FS_NORMAL] = 10;
|
||||
_font_height[FS_LARGE] = 18;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WITH_FREETYPE
|
||||
@ -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.
|
||||
@ -837,16 +841,20 @@ static void UnloadFace(FT_Face *face)
|
||||
|
||||
/**
|
||||
* (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();
|
||||
ResetGlyphCache();
|
||||
ResetFontSizes(monospace);
|
||||
ResetGlyphCache(monospace);
|
||||
|
||||
if (monospace) {
|
||||
UnloadFace(&_face_mono);
|
||||
} else {
|
||||
UnloadFace(&_face_small);
|
||||
UnloadFace(&_face_medium);
|
||||
UnloadFace(&_face_large);
|
||||
}
|
||||
|
||||
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");
|
||||
@ -863,15 +871,18 @@ void InitFreeType()
|
||||
}
|
||||
|
||||
/* Load each font */
|
||||
if (monospace) {
|
||||
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.medium_font, &_face_medium, "medium");
|
||||
LoadFreeTypeFont(_freetype.large_font, &_face_large, "large");
|
||||
|
||||
/* Set each font size */
|
||||
if (_face_mono != NULL) {
|
||||
SetFontGeometry(_face_mono, FS_MONO, _freetype.mono_size);
|
||||
}
|
||||
if (_face_small != NULL) {
|
||||
SetFontGeometry(_face_small, FS_SMALL, _freetype.small_size);
|
||||
}
|
||||
@ -881,6 +892,7 @@ void InitFreeType()
|
||||
if (_face_large != NULL) {
|
||||
SetFontGeometry(_face_large, FS_LARGE, _freetype.large_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -888,7 +900,8 @@ void InitFreeType()
|
||||
*/
|
||||
void UninitFreeType()
|
||||
{
|
||||
ResetGlyphCache();
|
||||
ResetGlyphCache(true);
|
||||
ResetGlyphCache(false);
|
||||
|
||||
UnloadFace(&_face_small);
|
||||
UnloadFace(&_face_medium);
|
||||
@ -933,10 +946,14 @@ struct GlyphEntry {
|
||||
*/
|
||||
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++) {
|
||||
if (monospace != (i == FS_MONO)) continue;
|
||||
if (_glyph_ptr[i] == NULL) continue;
|
||||
|
||||
for (int j = 0; j < 256; j++) {
|
||||
|
@ -42,7 +42,7 @@ struct FreeTypeSettings {
|
||||
|
||||
extern FreeTypeSettings _freetype;
|
||||
|
||||
void InitFreeType();
|
||||
void InitFreeType(bool monospace);
|
||||
void UninitFreeType();
|
||||
const Sprite *GetGlyph(FontSize size, uint32 key);
|
||||
uint GetGlyphWidth(FontSize size, uint32 key);
|
||||
@ -63,7 +63,7 @@ bool SetFallbackFont(FreeTypeSettings *settings, const char *language_isocode, i
|
||||
#else
|
||||
|
||||
/* 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() {}
|
||||
|
||||
/** Get the Sprite for a glyph */
|
||||
|
@ -697,8 +697,8 @@ int ttd_main(int argc, char *argv[])
|
||||
/* enumerate language files */
|
||||
InitializeLanguagePacks();
|
||||
|
||||
/* Initialize FreeType */
|
||||
InitFreeType();
|
||||
/* Initialize the regular font for FreeType */
|
||||
InitFreeType(false);
|
||||
|
||||
/* This must be done early, since functions use the SetWindowDirty* calls */
|
||||
InitWindowSystem();
|
||||
|
@ -1750,7 +1750,7 @@ const char *GetCurrentLanguageIsoCode()
|
||||
*/
|
||||
bool MissingGlyphSearcher::FindMissingGlyphs(const char **str)
|
||||
{
|
||||
InitFreeType();
|
||||
InitFreeType(false);
|
||||
const Sprite *question_mark[FS_END];
|
||||
|
||||
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
|
||||
* user chosen font as that is more likely to be any good than
|
||||
* the wild guess we made */
|
||||
InitFreeType();
|
||||
InitFreeType(false);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user