diff options
author | Filippos Karapetis | 2014-12-22 02:52:55 +0200 |
---|---|---|
committer | Filippos Karapetis | 2014-12-22 02:52:55 +0200 |
commit | f364756bcfa952e85c2111270ffda15c9809a4b8 (patch) | |
tree | f4528a6167c2f4b846995df74bae662fecd226b2 /engines | |
parent | c2d83d287faec2bdfd6fac7d665c156670c7b7f7 (diff) | |
download | scummvm-rg350-f364756bcfa952e85c2111270ffda15c9809a4b8.tar.gz scummvm-rg350-f364756bcfa952e85c2111270ffda15c9809a4b8.tar.bz2 scummvm-rg350-f364756bcfa952e85c2111270ffda15c9809a4b8.zip |
ZVISION: Add support for GNU Freefont fonts. Also, cleanup font loading
The Freefont fonts can just be dropped into the extras ScummVM folder,
to get the game working under non-Windows systems
Diffstat (limited to 'engines')
-rw-r--r-- | engines/zvision/graphics/truetype_font.cpp | 145 |
1 files changed, 54 insertions, 91 deletions
diff --git a/engines/zvision/graphics/truetype_font.cpp b/engines/zvision/graphics/truetype_font.cpp index 2dbd7ca358..5c8aa03f6a 100644 --- a/engines/zvision/graphics/truetype_font.cpp +++ b/engines/zvision/graphics/truetype_font.cpp @@ -54,105 +54,68 @@ bool StyledTTFont::loadFont(const Common::String &fontName, int32 point, uint st } bool StyledTTFont::loadFont(const Common::String &fontName, int32 point) { + struct FontStyle { + const char *zorkFont; + const char *fontBase; + const char *freeFontBase; + const char *freeFontItalicName; + }; + + const FontStyle systemFonts[] = { + { "*times new roman*", "times", "FreeSerif", "Italic" }, + { "*times*", "times", "FreeSerif", "Italic" }, + { "*century schoolbook*", "censcbk", "FreeSerif", "Italic" }, + { "*garamond*", "gara", "FreeSerif", "Italic" }, + { "*courier new*", "cour", "FreeMono", "Oblique" }, + { "*courier*", "cour", "FreeMono", "Oblique" }, + { "*ZorkDeath*", "cour", "FreeMono", "Oblique" }, + { "*arial*", "arial", "FreeSans", "Oblique" }, + { "*ZorkNormal*", "arial", "FreeSans", "Oblique" }, + }; + Common::String newFontName; - if (fontName.matchString("*times new roman*", true) || fontName.matchString("*times*", true)) { - if ((_style & (STTF_BOLD | STTF_ITALIC)) == (STTF_BOLD | STTF_ITALIC)) - newFontName = "timesbi.ttf"; - else if (_style & STTF_BOLD) - newFontName = "timesbd.ttf"; - else if (_style & STTF_ITALIC) - newFontName = "timesi.ttf"; - else - newFontName = "times.ttf"; - - } else if (fontName.matchString("*courier new*", true) || fontName.matchString("*courier*", true) || fontName.matchString("*ZorkDeath*", true)) { - if ((_style & (STTF_BOLD | STTF_ITALIC)) == (STTF_BOLD | STTF_ITALIC)) - newFontName = "courbi.ttf"; - else if (_style & STTF_BOLD) - newFontName = "courbd.ttf"; - else if (_style & STTF_ITALIC) - newFontName = "couri.ttf"; - else - newFontName = "cour.ttf"; - - } else if (fontName.matchString("*century schoolbook*", true)) { - if ((_style & (STTF_BOLD | STTF_ITALIC)) == (STTF_BOLD | STTF_ITALIC)) - newFontName = "censcbkbi.ttf"; - else if (_style & STTF_BOLD) - newFontName = "censcbkbd.ttf"; - else if (_style & STTF_ITALIC) - newFontName = "censcbki.ttf"; - else - newFontName = "censcbk.ttf"; - - } else if (fontName.matchString("*garamond*", true)) { - if ((_style & (STTF_BOLD | STTF_ITALIC)) == (STTF_BOLD | STTF_ITALIC)) - newFontName = "garabi.ttf"; - else if (_style & STTF_BOLD) - newFontName = "garabd.ttf"; - else if (_style & STTF_ITALIC) - newFontName = "garai.ttf"; - else - newFontName = "gara.ttf"; - - } else if (fontName.matchString("*arial*", true) || fontName.matchString("*ZorkNormal*", true)) { - if ((_style & (STTF_BOLD | STTF_ITALIC)) == (STTF_BOLD | STTF_ITALIC)) - newFontName = "arialbi.ttf"; - else if (_style & STTF_BOLD) - newFontName = "arialbd.ttf"; - else if (_style & STTF_ITALIC) - newFontName = "ariali.ttf"; - else - newFontName = "arial.ttf"; + Common::String freeFontName; + + for (int i = 0; i < ARRAYSIZE(systemFonts); i++) { + if (fontName.matchString(systemFonts[i].zorkFont, true)) { + newFontName = systemFonts[i].fontBase; + freeFontName = systemFonts[i].freeFontBase; + + if ((_style & STTF_BOLD) && (_style & STTF_ITALIC)) { + newFontName += "bi"; + freeFontName += "Bold"; + freeFontName += systemFonts[i].freeFontItalicName; + } else if (_style & STTF_BOLD) { + newFontName += "bd"; + freeFontName += "Bold"; + } else if (_style & STTF_ITALIC) { + newFontName += "i"; + freeFontName += systemFonts[i].freeFontItalicName; + } - } else { + newFontName += ".ttf"; + freeFontName += ".ttf"; + break; + } + } + + if (newFontName.empty()) { debug("Could not identify font: %s. Reverting to Arial", fontName.c_str()); newFontName = "arial.ttf"; + freeFontName = "FreeSans.ttf"; } bool sharp = (_style & STTF_SHARP) == STTF_SHARP; - Common::File *file = _engine->getSearchManager()->openFile(newFontName); - - if (!file) { - Common::SeekableReadStream *themeFile = nullptr; - if (ConfMan.hasKey("themepath")) { - Common::FSNode themePath(ConfMan.get("themepath")); - if (themePath.exists()) { - Common::FSNode scummModern = themePath.getChild("scummmodern.zip"); - if (scummModern.exists()) { - themeFile = scummModern.createReadStream(); - } - } - } - if (!themeFile) { // Fallback : Search for ScummModern.zip in SearchMan. - themeFile = SearchMan.createReadStreamForMember("scummmodern.zip"); - } - if (themeFile) { - Common::Archive *themeArchive = Common::makeZipArchive(themeFile); - if (themeArchive->hasFile("FreeSans.ttf")) { - Common::SeekableReadStream *stream = nullptr; - stream = themeArchive->createReadStreamForMember("FreeSans.ttf"); - Graphics::Font *_newFont = Graphics::loadTTFFont(*stream, point, 60, (sharp ? Graphics::kTTFRenderModeMonochrome : Graphics::kTTFRenderModeNormal)); // 66 dpi for 640 x 480 on 14" display - if (_newFont) { - if (!_font) - delete _font; - _font = _newFont; - } - if (stream) - delete stream; - } - delete themeArchive; - themeArchive = nullptr; - } - } else { - Graphics::Font *_newFont = Graphics::loadTTFFont(*file, point, 60, (sharp ? Graphics::kTTFRenderModeMonochrome : Graphics::kTTFRenderModeNormal)); // 66 dpi for 640 x 480 on 14" display - if (_newFont) { - if (!_font) - delete _font; - _font = _newFont; - } - delete file; + Common::File file; + if (!file.open(newFontName) && !file.open(freeFontName)) + error("Unable to open font file %s (free alternative: %s)", newFontName.c_str(), freeFontName.c_str()); + + Graphics::Font *_newFont = Graphics::loadTTFFont(file, point, 60, (sharp ? Graphics::kTTFRenderModeMonochrome : Graphics::kTTFRenderModeNormal)); // 66 dpi for 640 x 480 on 14" display + if (_newFont) { + if (!_font) + delete _font; + _font = _newFont; } _fntName = fontName; |