aboutsummaryrefslogtreecommitdiff
path: root/graphics/macgui/macfontmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/macgui/macfontmanager.cpp')
-rw-r--r--graphics/macgui/macfontmanager.cpp158
1 files changed, 112 insertions, 46 deletions
diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 97da1a6d96..bf3532dc51 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -28,7 +28,55 @@
namespace Graphics {
+// Source: Apple IIGS Technical Note #41, "Font Family Numbers"
+// http://apple2.boldt.ca/?page=til/tn.iigs.041
+static const char *const fontNames[] = {
+ "Chicago", // system font
+ "Geneva", // application font
+ "New York",
+ "Geneva",
+
+ "Monaco",
+ "Venice",
+ "London",
+ "Athens",
+
+ "San Francisco",
+ "Toronto",
+ NULL,
+ "Cairo",
+ "Los Angeles", // 12
+
+ "Zapf Dingbats",
+ "Bookman",
+ "Helvetica Narrow",
+ "Palatino",
+ NULL,
+ "Zapf Chancery",
+ NULL,
+
+ "Times", // 20
+ "Helvetica",
+ "Courier",
+ "Symbol",
+ "Taliesin", // mobile?
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL, // 30
+ NULL,
+ NULL,
+ "Avant Garde",
+ "New Century Schoolbook"
+};
+
MacFontManager::MacFontManager() {
+ for (uint i = 0; i < ARRAYSIZE(fontNames); i++)
+ if (fontNames[i])
+ _fontNames.setVal(fontNames[i], i);
+
loadFonts();
}
@@ -55,8 +103,12 @@ void MacFontManager::loadFonts() {
delete stream;
Common::String fontName;
+ MacFont *macfont;
+
if (font->getFamilyName() && *font->getFamilyName()) {
fontName = Common::String::format("%s-%s-%d", font->getFamilyName(), font->getFontSlant(), font->getFontSize());
+
+ macfont = new MacFont(_fontNames.getVal(font->getFamilyName(), kMacFontNonStandard), font->getFontSize(), parseFontSlant(font->getFontSlant()));
} else { // Get it from the file name
fontName = (*it)->getName();
@@ -69,10 +121,13 @@ void MacFontManager::loadFonts() {
break;
}
}
+
+ macfont = new MacFont(kMacFontNonStandard);
+ macfont->setName(fontName);
}
FontMan.assignFontToName(fontName, font);
- _fontRegistry.setVal(fontName, font);
+ _fontRegistry.setVal(fontName, macfont);
debug(2, " %s", fontName.c_str());
}
@@ -107,49 +162,20 @@ const Font *MacFontManager::getFont(MacFont macFont) {
return font;
}
-// Source: Apple IIGS Technical Note #41, "Font Family Numbers"
-// http://apple2.boldt.ca/?page=til/tn.iigs.041
-static const char *const fontNames[] = {
- "Chicago", // system font
- "Geneva", // application font
- "New York",
- "Geneva",
+int MacFontManager::parseFontSlant(Common::String slant) {
+ slant.toUppercase();
- "Monaco",
- "Venice",
- "London",
- "Athens",
-
- "San Francisco",
- "Toronto",
- NULL,
- "Cairo",
- "Los Angeles", // 12
+ if (slant == "I")
+ return kMacFontItalic;
+ if (slant == "B")
+ return kMacFontBold;
+ if (slant == "R")
+ return kMacFontRegular;
- "Zapf Dingbats",
- "Bookman",
- "Helvetica Narrow",
- "Palatino",
- NULL,
- "Zapf Chancery",
- NULL,
+ warning("Unknown font slant '%s'", slant.c_str());
- "Times", // 20
- "Helvetica",
- "Courier",
- "Symbol",
- "Taliesin", // mobile?
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL, // 30
- NULL,
- NULL,
- "Avant Garde",
- "New Century Schoolbook"
-};
+ return kMacFontRegular;
+}
const char *MacFontManager::getFontName(int id, int size, int slant) {
static char name[128];
@@ -181,21 +207,61 @@ const char *MacFontManager::getFontName(MacFont &font) {
}
void MacFontManager::generateFontSubstitute(MacFont &macFont) {
- if (_fontRegistry.contains(getFontName(macFont.getId(), macFont.getSize() * 2, macFont.getSlant()))) {
- generateFont(macFont, MacFont(macFont.getId(), macFont.getSize() * 2, macFont.getSlant()));
+ Common::String name;
+
+ // First we try twice size
+ name = getFontName(macFont.getId(), macFont.getSize() * 2, macFont.getSlant());
+ if (_fontRegistry.contains(name) && !_fontRegistry[name]->isGenerated()) {
+ generateFont(macFont, *_fontRegistry[name]);
return;
}
- if (_fontRegistry.contains(getFontName(macFont.getId(), macFont.getSize() / 2, macFont.getSlant()))) {
- generateFont(macFont, MacFont(macFont.getId(), macFont.getSize() / 2, macFont.getSlant()));
+ // Now half size
+ name = getFontName(macFont.getId(), macFont.getSize() / 2, macFont.getSlant());
+ if (_fontRegistry.contains(name)) {
+ generateFont(macFont, *_fontRegistry[name]);
return;
}
+
+ // No simple substitute was found. Looking for neighborhood fonts
+
+ // 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())
+ sizes.push_back(i->_value->getSize());
+ }
+
+ if (sizes.empty()) {
+ warning("No viable substitute found for font %s", getFontName(macFont));
+ return;
+ }
+
+ // Now looking next larger font, and store the largest one for next check
+ int candidate = 1000;
+ int maxSize = sizes[0];
+ for (uint i = 0; i < sizes.size(); i++) {
+ if (sizes[i] > macFont.getSize() && sizes[i] < candidate)
+ candidate = sizes[i];
+
+ if (sizes[i] > maxSize)
+ maxSize = sizes[i];
+ }
+
+ if (candidate != 1000) {
+ generateFont(macFont, MacFont(macFont.getId(), candidate, macFont.getSlant()));
+ return;
+ }
+
+ // Now next smaller font, which is the biggest we have
+ generateFont(macFont, MacFont(macFont.getId(), maxSize, macFont.getSlant()));
}
void MacFontManager::generateFont(MacFont fromFont, MacFont toFont) {
- warning("Found font substitute from font %s to %s", getFontName(fromFont), getFontName(toFont));
+ debugN("Found font substitute for font %s ", getFontName(fromFont));
+ debug("as %s", getFontName(toFont));
}
} // End of namespace Graphics