ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

fontprovider.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/stark/services/fontprovider.h"
00024 
00025 #include "engines/stark/services/services.h"
00026 #include "engines/stark/services/settings.h"
00027 #include "engines/stark/gfx/driver.h"
00028 
00029 #include "common/archive.h"
00030 #include "common/ini-file.h"
00031 
00032 #include "graphics/font.h"
00033 #include "graphics/fontman.h"
00034 #include "graphics/fonts/ttf.h"
00035 
00036 namespace Stark {
00037 
00038 FontProvider::FontProvider() {
00039 }
00040 
00041 FontProvider::~FontProvider() {
00042 }
00043 
00044 void FontProvider::initFonts() {
00045     // TODO: Use SystemFontMan instead when it gets merged
00046     _ttfFileMap["Garamond"] = "Gara.ttf";
00047     _ttfFileMap["Florentine Script"] = "flornt.TTF";
00048     _ttfFileMap["Folkard"] = "folkard.ttf";
00049     _ttfFileMap["Folkard\231"] = "folkard.ttf";
00050     _ttfFileMap["Arial"] = "ARIAL.TTF";
00051     _ttfFileMap["Bradley Hand ITC"] = "bradhitc.ttf";
00052     _ttfFileMap["Slurry"] = "SLURRY.TTF";
00053     _ttfFileMap["President Cyr"] = "President Cyr Regular.Ttf";
00054     _ttfFileMap["VictorianCyr"] = "Victorian Cyr.ttf";
00055     _ttfFileMap["Zapf Chance Italic"] = "Zapf Chance Italic.Ttf";
00056     _ttfFileMap["Arial_tlj"] = "arial_tlj.ttf";
00057 
00058     // Clear any previously used fonts
00059     _smallFont = FontHolder();
00060     _bigFont   = FontHolder();
00061     for (uint i = 0; i < ARRAYSIZE(_customFonts); i++) {
00062         _customFonts[i] = FontHolder();
00063     }
00064 
00065     // Load the font settings from gui.ini when possible
00066     if (!StarkSettings->shouldIgnoreFontSettings()) {
00067         Common::INIFile gui;
00068         if (gui.loadFromFile("gui.ini")) {
00069             readFontEntry(&gui, _smallFont,        "smallfont", "smallheight");
00070             readFontEntry(&gui, _bigFont,          "bigfont",   "bigheight");
00071             readFontEntry(&gui, _customFonts[0],   "font0",     "fontsize0");
00072             readFontEntry(&gui, _customFonts[1],   "font1",     "fontsize1");
00073             readFontEntry(&gui, _customFonts[2],   "font2",     "fontsize2");
00074             readFontEntry(&gui, _customFonts[3],   "font3",     "fontsize3");
00075             readFontEntry(&gui, _customFonts[4],   "font4",     "fontsize4");
00076             readFontEntry(&gui, _customFonts[5],   "font5",     "fontsize5");
00077             readFontEntry(&gui, _customFonts[6],   "font6",     "fontsize6");
00078             readFontEntry(&gui, _customFonts[7],   "font7",     "fontsize7");
00079         } else {
00080             warning("Unable to open 'gui.ini' to read the font settings");
00081         }
00082     }
00083 
00084     // Default fonts
00085     if (!_smallFont._font)      _smallFont      = FontHolder(this, "Garamond", 12);
00086     if (!_bigFont._font)        _bigFont        = FontHolder(this, "Florentine Script", 19);
00087     if (!_customFonts[0]._font) _customFonts[0] = FontHolder(this, "Folkard", 20);
00088     if (!_customFonts[1]._font) _customFonts[1] = FontHolder(this, "Folkard", 12);
00089     if (!_customFonts[2]._font) _customFonts[2] = FontHolder(this, "Arial", 14);
00090     if (!_customFonts[3]._font) _customFonts[3] = FontHolder(this, "Bradley Hand ITC", 16);
00091     if (!_customFonts[4]._font) _customFonts[4] = FontHolder(this, "Bradley Hand ITC", 20);
00092     if (!_customFonts[5]._font) _customFonts[5] = FontHolder(this, "Bradley Hand ITC", 16);
00093     if (!_customFonts[6]._font) _customFonts[6] = FontHolder(this, "Bradley Hand ITC", 15);
00094     if (!_customFonts[7]._font) _customFonts[7] = FontHolder(this, "Florentine Script", 13);
00095 }
00096 
00097 void FontProvider::readFontEntry(const Common::INIFile *gui, FontHolder &holder, const char *nameKey, const char *sizeKey) {
00098     Common::String section = "TEXT95";
00099     if (gui->hasSection("Western")) {
00100         section = "Western";
00101     }
00102 
00103     Common::String name, sizeStr;
00104     bool gotName = gui->getKey(nameKey, section, name);
00105     bool gotSize = gui->getKey(sizeKey, section, sizeStr);
00106 
00107     long size = strtol(sizeStr.c_str(), nullptr, 10);
00108 
00109     // WORKAROUND: In the GOG.com release the computer font (location 36 00)
00110     // is too small, preventing the "White Cardinal" label from being clickable.
00111     if (strcmp(nameKey, "font2") == 0 && name.equalsIgnoreCase("Arial") && size < 14) {
00112         size = 14;
00113     }
00114 
00115     if (gotName && gotSize && size > 0) {
00116         holder = FontHolder(this, name, size);
00117     } else {
00118         warning("Unable to read font entry '%s' from 'gui.ini'", nameKey);
00119     }
00120 }
00121 
00122 FontProvider::FontHolder::FontHolder(FontProvider *fontProvider, const Common::String &name, uint32 height) {
00123     _name = name;
00124     _originalHeight = height;
00125     _scaledHeight = StarkGfx->scaleHeightOriginalToCurrent(_originalHeight);
00126 
00127     // Fetch the font file name
00128     Common::String ttfFileName = "fonts/" + fontProvider->_ttfFileMap[_name];
00129 
00130     // Initialize the font
00131     Common::SeekableReadStream *s = SearchMan.createReadStreamForMember(ttfFileName);
00132     if (s) {
00133         Graphics::TTFRenderMode renderMode = StarkSettings->isFontAntialiasingEnabled() ?
00134                     Graphics::kTTFRenderModeLight : Graphics::kTTFRenderModeMonochrome;
00135         bool stemDarkening = StarkSettings->isFontAntialiasingEnabled();
00136 
00137         _font = Common::SharedPtr<Graphics::Font>(
00138                 Graphics::loadTTFFont(*s, _scaledHeight, Graphics::kTTFSizeModeCell, 0, renderMode, nullptr, stemDarkening)
00139         );
00140         delete s;
00141     } else {
00142         warning("Unable to load the font '%s'", ttfFileName.c_str());
00143     }
00144 }
00145 
00146 FontProvider::FontHolder *FontProvider::getFontHolder(FontProvider::FontType type, int32 customFontIndex) {
00147     if (type == kSmallFont) {
00148         return &_smallFont;
00149     } else if (type == kBigFont) {
00150         return &_bigFont;
00151     } else {
00152         assert(customFontIndex >= 0 && customFontIndex < 8);
00153         return &_customFonts[customFontIndex];
00154     }
00155 }
00156 
00157 const Graphics::Font *FontProvider::getScaledFont(FontProvider::FontType type, int32 customFontIndex) {
00158     FontHolder *holder = getFontHolder(type, customFontIndex);
00159     if (holder->_font) {
00160         return holder->_font.get();
00161     } else {
00162         // Fallback to a default font
00163         return FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
00164     }
00165 }
00166 
00167 uint FontProvider::getScaledFontHeight(FontProvider::FontType type, int32 customFontIndex) {
00168     FontHolder *holder = getFontHolder(type, customFontIndex);
00169     return holder->_scaledHeight;
00170 }
00171 
00172 uint FontProvider::getOriginalFontHeight(FontProvider::FontType type, int32 customFontIndex) {
00173     FontHolder *holder = getFontHolder(type, customFontIndex);
00174     return holder->_originalHeight;
00175 }
00176 
00177 } // End of namespace Stark


Generated on Sat Aug 17 2019 05:00:42 for ResidualVM by doxygen 1.7.1
curved edge   curved edge