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/gfx/driver.h"
00027 
00028 #include "common/archive.h"
00029 #include "common/ini-file.h"
00030 
00031 #include "graphics/font.h"
00032 #include "graphics/fontman.h"
00033 #include "graphics/fonts/ttf.h"
00034 
00035 namespace Stark {
00036 
00037 FontProvider::FontProvider() {
00038 }
00039 
00040 FontProvider::~FontProvider() {
00041 }
00042 
00043 void FontProvider::initFonts() {
00044     // TODO: Use SystemFontMan instead when it gets merged
00045     _ttfFileMap["Garamond"] = "Gara.ttf";
00046     _ttfFileMap["Florentine Script"] = "flornt.TTF";
00047     _ttfFileMap["Folkard"] = "folkard.ttf";
00048     _ttfFileMap["Folkard\231"] = "folkard.ttf";
00049     _ttfFileMap["Arial"] = "ARIAL.TTF";
00050     _ttfFileMap["Bradley Hand ITC"] = "bradhitc.ttf";
00051     _ttfFileMap["Slurry"] = "SLURRY.TTF";
00052     _ttfFileMap["President Cyr"] = "President Cyr Regular.Ttf";
00053     _ttfFileMap["VictorianCyr"] = "Victorian Cyr.ttf";
00054     _ttfFileMap["Zapf Chance Italic"] = "Zapf Chance Italic.Ttf";
00055     _ttfFileMap["Arial_tlj"] = "arial_tlj.ttf";
00056 
00057     // Load the font settings from gui.ini when possible
00058     Common::INIFile gui;
00059     if (gui.loadFromFile("gui.ini")) {
00060         readFontEntry(&gui, _smallFont,        "smallfont", "smallheight");
00061         readFontEntry(&gui, _bigFont,          "bigfont",   "bigheight");
00062         readFontEntry(&gui, _customFonts[0],   "font0",     "fontsize0");
00063         readFontEntry(&gui, _customFonts[1],   "font1",     "fontsize1");
00064         readFontEntry(&gui, _customFonts[2],   "font2",     "fontsize2");
00065         readFontEntry(&gui, _customFonts[3],   "font3",     "fontsize3");
00066         readFontEntry(&gui, _customFonts[4],   "font4",     "fontsize4");
00067         readFontEntry(&gui, _customFonts[5],   "font5",     "fontsize5");
00068         readFontEntry(&gui, _customFonts[6],   "font6",     "fontsize6");
00069         readFontEntry(&gui, _customFonts[7],   "font7",     "fontsize7");
00070     } else {
00071         warning("Unable to open 'gui.ini' to read the font settings");
00072     }
00073 
00074     // Default fonts
00075     if (!_smallFont._font)      _smallFont      = FontHolder(this, "Garamond", 12);
00076     if (!_bigFont._font)        _bigFont        = FontHolder(this, "Florentine Script", 19);
00077     if (!_customFonts[0]._font) _customFonts[0] = FontHolder(this, "Folkard", 20);
00078     if (!_customFonts[1]._font) _customFonts[1] = FontHolder(this, "Folkard", 12);
00079     if (!_customFonts[2]._font) _customFonts[2] = FontHolder(this, "Arial", 14);
00080     if (!_customFonts[3]._font) _customFonts[3] = FontHolder(this, "Bradley Hand ITC", 16);
00081     if (!_customFonts[4]._font) _customFonts[4] = FontHolder(this, "Bradley Hand ITC", 20);
00082     if (!_customFonts[5]._font) _customFonts[5] = FontHolder(this, "Bradley Hand ITC", 16);
00083     if (!_customFonts[6]._font) _customFonts[6] = FontHolder(this, "Bradley Hand ITC", 15);
00084     if (!_customFonts[7]._font) _customFonts[7] = FontHolder(this, "Florentine Script", 13);
00085 }
00086 
00087 void FontProvider::readFontEntry(const Common::INIFile *gui, FontHolder &holder, const char *nameKey, const char *sizeKey) {
00088     Common::String section = "TEXT95";
00089     if (gui->hasSection("Western")) {
00090         section = "Western";
00091     }
00092 
00093     Common::String name, sizeStr;
00094     bool gotName = gui->getKey(nameKey, section, name);
00095     bool gotSize = gui->getKey(sizeKey, section, sizeStr);
00096 
00097     long size = strtol(sizeStr.c_str(), nullptr, 10);
00098 
00099     if (gotName && gotSize && size > 0) {
00100         holder = FontHolder(this, name, size);
00101     } else {
00102         warning("Unable to read font entry '%s' from 'gui.ini'", nameKey);
00103     }
00104 }
00105 
00106 FontProvider::FontHolder::FontHolder(FontProvider *fontProvider, const Common::String &name, uint32 height) {
00107     _name = name;
00108     _originalHeight = height;
00109     _scaledHeight = StarkGfx->scaleHeightOriginalToCurrent(_originalHeight);
00110 
00111     // Fetch the font file name
00112     Common::String ttfFileName = "fonts/" + fontProvider->_ttfFileMap[_name];
00113 
00114     // Initialize the font
00115     Common::SeekableReadStream *s = SearchMan.createReadStreamForMember(ttfFileName);
00116     if (s) {
00117         _font = Common::SharedPtr<Graphics::Font>(
00118                 Graphics::loadTTFFont(*s, _scaledHeight, Graphics::kTTFSizeModeCell, 0, Graphics::kTTFRenderModeMonochrome)
00119         );
00120         delete s;
00121     } else {
00122         warning("Unable to load the font '%s'", ttfFileName.c_str());
00123     }
00124 }
00125 
00126 FontProvider::FontHolder *FontProvider::getFontHolder(FontProvider::FontType type, int32 customFontIndex) {
00127     if (type == kSmallFont) {
00128         return &_smallFont;
00129     } else if (type == kBigFont) {
00130         return &_bigFont;
00131     } else {
00132         assert(customFontIndex >= 0 && customFontIndex < 8);
00133         return &_customFonts[customFontIndex];
00134     }
00135 }
00136 
00137 const Graphics::Font *FontProvider::getScaledFont(FontProvider::FontType type, int32 customFontIndex) {
00138     FontHolder *holder = getFontHolder(type, customFontIndex);
00139     if (holder->_font) {
00140         return holder->_font.get();
00141     } else {
00142         // Fallback to a default font
00143         return FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
00144     }
00145 }
00146 
00147 uint FontProvider::getScaledFontHeight(FontProvider::FontType type, int32 customFontIndex) {
00148     FontHolder *holder = getFontHolder(type, customFontIndex);
00149     return holder->_scaledHeight;
00150 }
00151 
00152 uint FontProvider::getOriginalFontHeight(FontProvider::FontType type, int32 customFontIndex) {
00153     FontHolder *holder = getFontHolder(type, customFontIndex);
00154     return holder->_originalHeight;
00155 }
00156 
00157 } // End of namespace Stark


Generated on Sat Feb 23 2019 05:01:03 for ResidualVM by doxygen 1.7.1
curved edge   curved edge