aboutsummaryrefslogtreecommitdiff
path: root/graphics/fontman.cpp
diff options
context:
space:
mode:
authorAlyssa Milburn2012-03-28 19:17:13 +0200
committerAlyssa Milburn2012-03-28 19:17:13 +0200
commit6d3927cd7a6e93452366085e179b156558f78a2b (patch)
tree52159d36200f71a19f4259d87d88873ab49dc722 /graphics/fontman.cpp
parentfdee01bf04f1d66e4365e39c871c4b00d7b78946 (diff)
downloadscummvm-rg350-6d3927cd7a6e93452366085e179b156558f78a2b.tar.gz
scummvm-rg350-6d3927cd7a6e93452366085e179b156558f78a2b.tar.bz2
scummvm-rg350-6d3927cd7a6e93452366085e179b156558f78a2b.zip
GRAPHICS: Take ownership of fonts passed to FontManager.
Diffstat (limited to 'graphics/fontman.cpp')
-rw-r--r--graphics/fontman.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/graphics/fontman.cpp b/graphics/fontman.cpp
index 8d967d595f..99dd3d664f 100644
--- a/graphics/fontman.cpp
+++ b/graphics/fontman.cpp
@@ -47,6 +47,13 @@ FontManager::FontManager() {
}
FontManager::~FontManager() {
+ for (uint i = 0; i < _ownedFonts.size(); ++i) {
+ const Font *font = _ownedFonts[i];
+ if (font == g_sysfont || font == g_sysfont_big || font == g_consolefont)
+ continue;
+ delete font;
+ }
+
delete g_sysfont;
g_sysfont = 0;
delete g_sysfont_big;
@@ -90,6 +97,8 @@ bool FontManager::assignFontToName(const Common::String &name, const Font *font)
Common::String lowercaseName = name;
lowercaseName.toLowercase();
_fontMap[lowercaseName] = font;
+ if (Common::find(_ownedFonts.begin(), _ownedFonts.end(), font) == _ownedFonts.end())
+ _ownedFonts.push_back(font);
return true;
}
@@ -116,8 +125,35 @@ bool FontManager::setFont(FontUsage usage, const BdfFont *font) {
void FontManager::removeFontName(const Common::String &name) {
Common::String lowercaseName = name;
lowercaseName.toLowercase();
+ if (!_fontMap.contains(lowercaseName))
+ return;
+
+ const Font *font = _fontMap[lowercaseName];
_fontMap.erase(lowercaseName);
+ // Check if we still have a copy of this font in the map.
+ bool stillHasFont = false;
+ for (Common::HashMap<Common::String, const Font *>::iterator i = _fontMap.begin(); i != _fontMap.end(); ++i) {
+ if (i->_value != font)
+ continue;
+ stillHasFont = true;
+ break;
+ }
+
+ if (!stillHasFont) {
+ // We don't have a copy of the font, so remove it from our list and delete it.
+ stillHasFont = true;
+ for (uint i = 0; i < _ownedFonts.size(); ++i) {
+ if (_ownedFonts[i] != font)
+ continue;
+ stillHasFont = false;
+ _ownedFonts.remove_at(i);
+ break;
+ }
+ assert(!stillHasFont);
+ delete font;
+ }
+
// In case the current localized font is removed, we fall back to the
// default font again.
if (_localizedFontName == lowercaseName)