From d93c1280aafb17334cbb66c2f1d37efd54975ecc Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Sat, 4 Jan 2014 13:47:00 +0100 Subject: [PATCH] Font: Open TTF font as late as possible This reduces opened fonts that were never going to be used anyway. --- src/font.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/font.cpp b/src/font.cpp index b29d86e..11c37c7 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -146,6 +146,9 @@ struct FontPrivate static Color defaultColorTmp; + /* The actual font is opened as late as possible + * (when it is queried by a Bitmap), prior it is + * set to null */ TTF_Font *sdlFont; FontPrivate(const char *name = 0, @@ -155,11 +158,9 @@ struct FontPrivate bold(defaultBold), italic(defaultItalic), color(&colorTmp), - colorTmp(*defaultColor) - { - sdlFont = shState->fontPool().request(this->name.c_str(), - this->size); - } + colorTmp(*defaultColor), + sdlFont(0) + {} FontPrivate(const FontPrivate &other) : name(other.name), @@ -214,7 +215,7 @@ void Font::setName(const char *value) return; p->name = value; - p->sdlFont = shState->fontPool().request(value, p->size); + p->sdlFont = 0; } void Font::setSize(int value) @@ -223,7 +224,7 @@ void Font::setSize(int value) return; p->size = value; - p->sdlFont = shState->fontPool().request(p->name.c_str(), value); + p->sdlFont = 0; } #undef CHK_DISP @@ -251,6 +252,10 @@ void Font::setDefaultName(const char *value) _TTF_Font *Font::getSdlFont() { + if (!p->sdlFont) + p->sdlFont = shState->fontPool().request(p->name.c_str(), + p->size); + int style = TTF_STYLE_NORMAL; if (p->bold)