diff options
author | Eugene Sandulenko | 2016-10-08 14:46:49 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2016-10-08 14:47:38 +0200 |
commit | c0b76581d8e4c1938c3f2f617edf553105dc6fdc (patch) | |
tree | 7abe2f4426d9bbfcda01fe619b7b6b3711d39b6e /graphics | |
parent | 66a0ca6f646a40ba48315c171f268027e4705849 (diff) | |
download | scummvm-rg350-c0b76581d8e4c1938c3f2f617edf553105dc6fdc.tar.gz scummvm-rg350-c0b76581d8e4c1938c3f2f617edf553105dc6fdc.tar.bz2 scummvm-rg350-c0b76581d8e4c1938c3f2f617edf553105dc6fdc.zip |
GRAPHICS: Detect substitute for Mac fonts
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/macgui/macfontmanager.cpp | 158 | ||||
-rw-r--r-- | graphics/macgui/macfontmanager.h | 12 |
2 files changed, 123 insertions, 47 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 diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h index a263ab52ed..e09e1dc984 100644 --- a/graphics/macgui/macfontmanager.h +++ b/graphics/macgui/macfontmanager.h @@ -28,6 +28,7 @@ namespace Graphics { enum { + kMacFontNonStandard = -1, kMacFontChicago = 0 }; @@ -46,6 +47,7 @@ public: _size = size; _slant = slant; _fallback = fallback; + _generated = false; } int getId() { return _id; }; @@ -55,6 +57,8 @@ public: void setName(Common::String &name) { _name = name; } void setName(const char *name) { _name = name; } FontManager::FontUsage getFallback() { return _fallback; } + bool isGenerated() { return _generated; } + void setGenerated(bool gen) { _generated = gen; } private: int _id; @@ -62,6 +66,8 @@ private: int _slant; Common::String _name; FontManager::FontUsage _fallback; + + bool _generated; }; class MacFontManager { @@ -98,7 +104,11 @@ private: private: bool _builtInFonts; - Common::HashMap<Common::String, BdfFont *> _fontRegistry; + Common::HashMap<Common::String, MacFont *> _fontRegistry; + + Common::HashMap<Common::String, int> _fontNames; + + int parseFontSlant(Common::String slant); }; } // End of namespace Graphics |