From 749d56573a0012a6e384522ba0a9603c1f2882f8 Mon Sep 17 00:00:00 2001 From: cirdan Date: Thu, 24 Nov 2016 18:06:49 +0100 Subject: [PATCH] Extract creation of the fallback question mark sprite Extract creation of the built-in fallback question mark sprite into its own function MakeBuiltinQuestionMark to reduce the size of FreeTypeFontCache::GetGlyph, as this code can stand on its own. --- src/fontcache.cpp | 64 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/src/fontcache.cpp b/src/fontcache.cpp index 99ad017c2..e7bf3a8d5 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -505,6 +505,40 @@ static bool GetFontAAState(FontSize size) } +static Sprite *MakeBuiltinQuestionMark (void) +{ + /* The font misses the '?' character. Use built-in sprite. + * Note: We cannot use the baseset as this also has to work + * in the bootstrap GUI. */ +#define CPSET { 0, 0, 0, 0, 1 } +#define CP___ { 0, 0, 0, 0, 0 } + static SpriteLoader::CommonPixel builtin_questionmark_data[10 * 8] = { + CP___, CP___, CPSET, CPSET, CPSET, CPSET, CP___, CP___, + CP___, CPSET, CPSET, CP___, CP___, CPSET, CPSET, CP___, + CP___, CP___, CP___, CP___, CP___, CPSET, CPSET, CP___, + CP___, CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, + CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___, + CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___, + CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___, + CP___, CP___, CP___, CP___, CP___, CP___, CP___, CP___, + CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___, + CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___, + }; +#undef CPSET +#undef CP___ + static const SpriteLoader::Sprite builtin_questionmark = { + 10, // height + 8, // width + 0, // x_offs + 0, // y_offs + builtin_questionmark_data + }; + + Sprite *spr = Blitter::get()->Encode (&builtin_questionmark, true, AllocateFont); + assert (spr != NULL); + return spr; +} + const Sprite *FreeTypeFontCache::GetGlyph(GlyphID key) { if ((key & SPRITE_GLYPH) != 0) return parent->GetGlyph(key); @@ -521,34 +555,8 @@ const Sprite *FreeTypeFontCache::GetGlyph(GlyphID key) if (key == 0) { GlyphID question_glyph = this->MapCharToGlyph('?'); if (question_glyph == 0) { - /* The font misses the '?' character. Use built-in sprite. - * Note: We cannot use the baseset as this also has to work in the bootstrap GUI. */ -#define CPSET { 0, 0, 0, 0, 1 } -#define CP___ { 0, 0, 0, 0, 0 } - static SpriteLoader::CommonPixel builtin_questionmark_data[10 * 8] = { - CP___, CP___, CPSET, CPSET, CPSET, CPSET, CP___, CP___, - CP___, CPSET, CPSET, CP___, CP___, CPSET, CPSET, CP___, - CP___, CP___, CP___, CP___, CP___, CPSET, CPSET, CP___, - CP___, CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, - CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___, - CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___, - CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___, - CP___, CP___, CP___, CP___, CP___, CP___, CP___, CP___, - CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___, - CP___, CP___, CP___, CPSET, CPSET, CP___, CP___, CP___, - }; -#undef CPSET -#undef CP___ - static const SpriteLoader::Sprite builtin_questionmark = { - 10, // height - 8, // width - 0, // x_offs - 0, // y_offs - builtin_questionmark_data - }; - - Sprite *spr = Blitter::get()->Encode (&builtin_questionmark, true, AllocateFont); - assert(spr != NULL); + /* The font misses the '?' character. Use built-in sprite. */ + Sprite *spr = MakeBuiltinQuestionMark(); new_glyph.sprite = spr; new_glyph.width = spr->width + (this->fs != FS_NORMAL); this->SetGlyphPtr(key, &new_glyph, false); -- 2.11.4.GIT