aboutsummaryrefslogtreecommitdiff
path: root/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'graphics')
-rw-r--r--graphics/fonts/bdf.cpp7
-rw-r--r--graphics/macgui/macfontmanager.cpp22
-rw-r--r--graphics/macgui/macfontmanager.h6
3 files changed, 24 insertions, 11 deletions
diff --git a/graphics/fonts/bdf.cpp b/graphics/fonts/bdf.cpp
index a783a22f5e..34155fcec1 100644
--- a/graphics/fonts/bdf.cpp
+++ b/graphics/fonts/bdf.cpp
@@ -701,6 +701,11 @@ BdfFont *BdfFont::loadFromCache(Common::SeekableReadStream &stream) {
}
BdfFont *BdfFont::scaleFont(BdfFont *src, int newSize) {
+ if (!src) {
+ warning("Emtpy font reference in scale font");
+ return NULL;
+ }
+
if (src->getFontSize()) {
warning("Requested to scale 0 size font");
return NULL;
@@ -720,6 +725,8 @@ BdfFont *BdfFont::scaleFont(BdfFont *src, int newSize) {
data.firstCharacter = src->_data.firstCharacter;
data.defaultCharacter = src->_data.defaultCharacter;
data.numCharacters = src->_data.numCharacters;
+ data.familyName = strdup(src->_data.familyName);
+ data.slant = strdup(src->_data.slant);
BdfBoundingBox *boxes = new BdfBoundingBox[data.numCharacters];
for (int i = 0; i < data.numCharacters; ++i) {
diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index ce9493580b..52e82584c7 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -127,6 +127,7 @@ void MacFontManager::loadFonts() {
}
FontMan.assignFontToName(fontName, font);
+ macfont->setBdfFont(font);
_fontRegistry.setVal(fontName, macfont);
debug(2, " %s", fontName.c_str());
@@ -150,7 +151,7 @@ const Font *MacFontManager::getFont(MacFont macFont) {
font = FontMan.getFontByName(macFont.getName());
if (!font) {
- warning("Cannot load font %s", macFont.getName().c_str());
+ warning("Cannot load font '%s'", macFont.getName().c_str());
font = FontMan.getFontByName(MacFont(kMacFontChicago, 12).getName());
}
@@ -219,7 +220,7 @@ void MacFontManager::generateFontSubstitute(MacFont &macFont) {
// Now half size
name = getFontName(macFont.getId(), macFont.getSize() / 2, macFont.getSlant());
- if (_fontRegistry.contains(name)) {
+ if (_fontRegistry.contains(name) && !_fontRegistry[name]->isGenerated()) {
generateFont(macFont, *_fontRegistry[name]);
return;
@@ -230,7 +231,7 @@ void MacFontManager::generateFontSubstitute(MacFont &macFont) {
// First we gather all font sizes for this font
Common::Array<int> sizes;
for (Common::HashMap<Common::String, MacFont *>::iterator i = _fontRegistry.begin(); i != _fontRegistry.end(); ++i) {
- if (i->_value->getId() == macFont.getId() && i->_value->getSlant() == macFont.getSlant())
+ if (i->_value->getId() == macFont.getId() && i->_value->getSlant() == macFont.getSlant() && !i->_value->isGenerated())
sizes.push_back(i->_value->getSize());
}
@@ -251,7 +252,7 @@ void MacFontManager::generateFontSubstitute(MacFont &macFont) {
}
if (candidate != 1000) {
- generateFont(macFont, MacFont(macFont.getId(), candidate, macFont.getSlant()));
+ generateFont(macFont, *_fontRegistry[getFontName(macFont.getId(), candidate, macFont.getSlant())]);
return;
}
@@ -260,17 +261,18 @@ void MacFontManager::generateFontSubstitute(MacFont &macFont) {
}
void MacFontManager::generateFont(MacFont toFont, MacFont fromFont) {
- debugN("Found font substitute for font %s ", getFontName(fromFont));
- debug("as %s", getFontName(toFont));
-
- Graphics::BdfFont *bdfFont = (Graphics::BdfFont *)getFont(fromFont);
+ debugN("Found font substitute for font '%s' ", getFontName(toFont));
+ debug("as '%s'", getFontName(fromFont));
- Graphics::BdfFont *font = Graphics::BdfFont::scaleFont(bdfFont, toFont.getSize());
+ Graphics::BdfFont *font = Graphics::BdfFont::scaleFont(fromFont.getBdfFont(), toFont.getSize());
toFont.setGenerated(true);
+ toFont.setBdfFont(font);
FontMan.assignFontToName(getFontName(toFont), font);
- _fontRegistry.setVal(getFontName(toFont), &toFont);
+ _fontRegistry.setVal(getFontName(toFont), new MacFont(toFont));
+
+ debug("Generated font '%s'", getFontName(toFont));
}
} // End of namespace Graphics
diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
index e09e1dc984..3e90818cda 100644
--- a/graphics/macgui/macfontmanager.h
+++ b/graphics/macgui/macfontmanager.h
@@ -48,6 +48,7 @@ public:
_slant = slant;
_fallback = fallback;
_generated = false;
+ _bdfFont = NULL;
}
int getId() { return _id; };
@@ -59,6 +60,8 @@ public:
FontManager::FontUsage getFallback() { return _fallback; }
bool isGenerated() { return _generated; }
void setGenerated(bool gen) { _generated = gen; }
+ BdfFont *getBdfFont() { return _bdfFont; }
+ void setBdfFont(BdfFont *bdfFont) { _bdfFont = bdfFont; }
private:
int _id;
@@ -68,6 +71,7 @@ private:
FontManager::FontUsage _fallback;
bool _generated;
+ BdfFont *_bdfFont;
};
class MacFontManager {
@@ -100,7 +104,7 @@ private:
const char *getFontName(MacFont &font);
void generateFontSubstitute(MacFont &macFont);
- void generateFont(MacFont fromFont, MacFont toFont);
+ void generateFont(MacFont toFont, MacFont fromFont);
private:
bool _builtInFonts;