Mercurial > hg > openttd
changeset 18425:c96f355f853d draft
(svn r23267) -Codechange: unify the font name setting of the font cache
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sat, 19 Nov 2011 21:02:37 +0000 |
parents | aeb8d6b635a1 |
children | 1d2007127c55 |
files | src/fontcache.cpp src/strings.cpp src/strings_func.h |
diffstat | 3 files changed, 21 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -347,9 +347,7 @@ if (!found) return 1; - strecpy(info->settings->small_font, font_name, lastof(info->settings->small_font)); - strecpy(info->settings->medium_font, font_name, lastof(info->settings->medium_font)); - strecpy(info->settings->large_font, font_name, lastof(info->settings->large_font)); + callback->SetFontNames(info->settings, font_name); if (info->callback->FindMissingGlyphs(NULL)) return 1; DEBUG(freetype, 1, "Fallback font: %s (%s)", font_name, english_name); return 0; // stop enumerating @@ -487,9 +485,7 @@ strncmp(name, "GB18030 Bitmap", 14) == 0) continue; /* Save result. */ - strecpy(settings->small_font, name, lastof(settings->small_font)); - strecpy(settings->medium_font, name, lastof(settings->medium_font)); - strecpy(settings->large_font, name, lastof(settings->large_font)); + callback->SetFontNames(settings, name); DEBUG(freetype, 2, "CT-Font for %s: %s", language_isocode, name); result = true; break; @@ -574,9 +570,7 @@ name[act_len > 127 ? 127 : act_len] = '\0'; /* Save Result. */ - strecpy(settings->small_font, name, lastof(settings->small_font)); - strecpy(settings->medium_font, name, lastof(settings->medium_font)); - strecpy(settings->large_font, name, lastof(settings->large_font)); + callback->SetFontNames(settings, name); DEBUG(freetype, 2, "ATSUI-Font for %s: %s", language_isocode, name); result = true; } @@ -598,9 +592,7 @@ /* Init FreeType if needed. */ if ((ft_init || FT_Init_FreeType(&_library) == FT_Err_Ok) && GetFontByFaceName("Arial Unicode MS", &face) == FT_Err_Ok) { FT_Done_Face(face); - strecpy(settings->small_font, "Arial Unicode MS", lastof(settings->small_font)); - strecpy(settings->medium_font, "Arial Unicode MS", lastof(settings->medium_font)); - strecpy(settings->large_font, "Arial Unicode MS", lastof(settings->large_font)); + callback->SetFontNames(settings, "Arial Unicode MS"); DEBUG(freetype, 1, "Replacing font 'Geeza Pro' with 'Arial Unicode MS'"); } if (!ft_init) { @@ -719,9 +711,7 @@ continue; } - strecpy(settings->small_font, (const char*)file, lastof(settings->small_font)); - strecpy(settings->medium_font, (const char*)file, lastof(settings->medium_font)); - strecpy(settings->large_font, (const char*)file, lastof(settings->large_font)); + callback->SetFontNames(settings, (const char*)file); bool missing = callback->FindMissingGlyphs(NULL); DEBUG(freetype, 1, "Font \"%s\" misses%s glyphs", file, missing ? "" : " no");
--- a/src/strings.cpp +++ b/src/strings.cpp @@ -1798,12 +1798,12 @@ this->j = 0; } - FontSize DefaultSize() + /* virtual */ FontSize DefaultSize() { return FS_NORMAL; } - const char *NextString() + /* virtual */ const char *NextString() { if (this->i >= 32) return NULL; @@ -1817,6 +1817,13 @@ return ret; } + + /* virtual */ void SetFontNames(FreeTypeSettings *settings, const char *font_name) + { + strecpy(settings->small_font, font_name, lastof(settings->small_font)); + strecpy(settings->medium_font, font_name, lastof(settings->medium_font)); + strecpy(settings->large_font, font_name, lastof(settings->large_font)); + } }; /**
--- a/src/strings_func.h +++ b/src/strings_func.h @@ -222,6 +222,13 @@ */ virtual void Reset() = 0; + /** + * Set the right font names. + * @param settings The settings to modify. + * @param font_name The new font name. + */ + virtual void SetFontNames(struct FreeTypeSettings *settings, const char *font_name) = 0; + bool FindMissingGlyphs(const char **str); };