ScummVM API documentation
macfontmanager.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef GRAPHICS_MACGUI_MACFONTMANAGER_H
23 #define GRAPHICS_MACGUI_MACFONTMANAGER_H
24 
25 #include "common/language.h"
26 #include "graphics/fonts/bdf.h"
27 #include "graphics/fontman.h"
28 
29 #ifdef USE_FREETYPE2
30 #include "graphics/fonts/ttf.h"
31 #endif
32 
33 namespace Common {
34  class SeekableReadStream;
35  class MacResManager;
36 }
37 
38 namespace Graphics {
39 
40 struct TTFMap {
41  const char *ttfName;
42  uint16 slant;
43 };
44 
45 class MacFONTFont;
46 class MacFontFamily;
47 
48 enum {
49  kMacFontNonStandard = -1,
50  kMacFontSystem = 0,
51  kMacFontApplication = 1,
52 
53  kMacFontNewYork = 2,
54  kMacFontGeneva = 3,
55  kMacFontMonaco = 4,
56  kMacFontVenice = 5,
57  kMacFontLondon = 6,
58  kMacFontAthens = 7,
59  kMacFontSanFrancisco = 8,
60  kMacFontToronto = 9,
61  kMacFontCairo = 11,
62  kMacFontLosAngeles = 12,
63  kMacFontZapfDingbats = 13,
64  kMacFontBookman = 14,
65  kMacFontHelveticaNarrow = 15,
66  kMacFontPalatino = 16,
67  kMacFontZapfChancery = 18,
68  kMacFontTimes = 20,
69  kMacFontHelvetica = 21,
70  kMacFontCourier = 22,
71  kMacFontSymbol = 23,
72  kMacFontTaliesin = 24,
73  kMacFontAvantGarde = 33,
74  kMacFontNewCenturySchoolbook = 34,
75  kMacFontChicago = 16383,
76 
77  kMacFontOsaka = 16384,
78  kMacFontBookMinchoM = 16396,
79  kMacFontMonoGothic = 16433,
80  kMacFontMonoMing = 16435,
81  kMacFontOsakaMono = 16436,
82  kMacFontMediumGothic = 16640,
83  kMacFontMing = 16641,
84  kMacFontHeiseiMincho = 16700,
85  kMacFontHeiseiKakuGothic = 16701
86 };
87 
88 enum {
89  kMacFontRegular,
90  kMacFontBold = 1,
91  kMacFontItalic = 2,
92  kMacFontUnderline = 4,
93  kMacFontOutline = 8,
94  kMacFontShadow = 16,
95  kMacFontCondense = 32,
96  kMacFontExtend = 64
97 };
98 
99 class Font;
100 
101 struct FontInfo {
102  Common::Language lang;
103  Common::CodePage encoding;
104  int aliasForId;
105  Common::String name;
106 
107  FontInfo() : lang(Common::UNK_LANG), encoding(Common::kCodePageInvalid), aliasForId(-1) {}
108 };
109 
110 class MacFont {
111 public:
112  MacFont(int id = kMacFontSystem, int size = 12, int slant = kMacFontRegular) {
113  _id = id;
114  _size = size ? size : 12;
115  _slant = slant;
116  _fallback = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
117  _fallbackName = Common::String(((const BdfFont *)_fallback)->getFamilyName());
118  _generated = false;
119  _truetype = false;
120  _font = NULL;
121  }
122 
123  int getId() const { return _id; };
124  void setId(int id) { _id = id; }
125  int getSize() const { return _size; }
126  int getSlant() const { return _slant; }
127  Common::String getName() const { return _name; }
128  void setName(Common::String &name) { setName(name.c_str()); }
129  void setName(const char *name);
130  const Graphics::Font *getFallback() const { return _fallback; }
131  bool isGenerated() const { return _generated; }
132  void setGenerated(bool gen) { _generated = gen; }
133  bool isTrueType() const { return _truetype; }
134  Font *getFont() const { return _font; }
135  void setFont(Font *font, bool truetype) { _font = font; _truetype = truetype; }
136  void setFallback(const Font *font, Common::String name = "");
137  Common::String getFallbackName() const { return _fallbackName; }
138 
139 private:
140  int _id;
141  int _size;
142  int _slant;
143  bool _truetype;
144  Common::String _name;
145  const Graphics::Font *_fallback;
146  Common::String _fallbackName;
147 
148  bool _generated;
149  Font *_font;
150 };
151 
153 public:
154  MacFontManager(uint32 mode, Common::Language language);
155  ~MacFontManager();
156 
157  void setLocalizedFonts();
158 
163  bool hasBuiltInFonts() { return _builtInFonts; }
170  const Font *getFont(MacFont *macFont);
171  const Font *getFont(MacFont macFont);
172 
179  const Common::String getFontName(uint16 id, int size, int slant = kMacFontRegular, bool tryGen = false);
180  const Common::String getFontName(const MacFont &font);
181  int getFontIdByName(Common::String name);
182 
183  Common::Language getFontLanguage(uint16 id);
184  Common::CodePage getFontEncoding(uint16 id);
185  int getFontAliasForId(uint16 id);
186  Common::String getFontName(uint16 id);
187 
188  void loadFonts(Common::SeekableReadStream *stream);
189  void loadFonts(const Common::Path &fileName);
190  void loadFonts(Common::MacResManager *fontFile);
191  void loadWindowsFont(const Common::Path &fileName);
192 
198  int registerFontName(Common::String name, int preferredId = -1);
199 
200  void forceBuiltinFonts() { _builtInFonts = true; }
201  int parseSlantFromName(const Common::String &name);
202  Common::String getNameFromSlant(int slantVal);
203 
204  const Common::Array<MacFontFamily *> &getFontFamilies() { return _fontFamilies; }
205 
206  void printFontRegistry(int debugLevel, uint32 channel);
207 
208  int registerTTFFont(const Graphics::TTFMap ttfList[]);
209 
210  int getFamilyId(int newId, int newSlant);
211 
212 #ifdef USE_FREETYPE2
213 
218  void setTTFRenderMode(TTFRenderMode mode) { _ttfRenderMode = mode; }
219  TTFRenderMode getTTFRenderMode() const { return _ttfRenderMode; }
220 #endif
221 
222 private:
223  void loadFontsBDF();
224  void loadFonts();
225  void loadJapaneseFonts();
226 
227  void generateFontSubstitute(MacFont &macFont);
228  void generateFONTFont(MacFont &toFont, MacFont &fromFont);
229 
230 #ifdef USE_FREETYPE2
231  void generateTTFFont(MacFont &toFront, Common::SeekableReadStream *stream);
232  TTFRenderMode _ttfRenderMode = Graphics::kTTFRenderModeMonochrome;
233 #endif
234 
235 private:
236  bool _builtInFonts;
237  bool _japaneseFontsLoaded;
238  uint32 _mode;
239  Common::Language _language;
242  Common::Array<MacFontFamily *> _fontFamilies;
243 
246 
247  int parseFontSlant(Common::String slant);
248 
249  /* Unicode font */
251 
253 };
254 
255 } // End of namespace Graphics
256 
257 #endif
Definition: macresman.h:126
Definition: str.h:59
Definition: font.h:83
Definition: array.h:52
Definition: macfontmanager.h:152
#define FontMan
Definition: fontman.h:135
Definition: path.h:52
Definition: macfont.h:165
Definition: stream.h:745
Definition: macfontmanager.h:40
Definition: macfontmanager.h:101
Definition: hashmap.h:85
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: bdf.h:60
Definition: macfontmanager.h:110
bool hasBuiltInFonts()
Definition: macfontmanager.h:163
Definition: macfont.h:34
Language
Definition: language.h:45