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 namespace Common {
30  class SeekableReadStream;
31  class MacResManager;
32 }
33 
34 namespace Graphics {
35 
36 struct TTFMap {
37  const char *ttfName;
38  uint16 slant;
39 };
40 
41 class MacFONTFont;
42 class MacFontFamily;
43 
44 enum {
45  kMacFontNonStandard = -1,
46  kMacFontSystem = 0,
47  kMacFontApplication = 1,
48 
49  kMacFontNewYork = 2,
50  kMacFontGeneva = 3,
51  kMacFontMonaco = 4,
52  kMacFontVenice = 5,
53  kMacFontLondon = 6,
54  kMacFontAthens = 7,
55  kMacFontSanFrancisco = 8,
56  kMacFontToronto = 9,
57  kMacFontCairo = 11,
58  kMacFontLosAngeles = 12,
59  kMacFontZapfDingbats = 13,
60  kMacFontBookman = 14,
61  kMacFontHelveticaNarrow = 15,
62  kMacFontPalatino = 16,
63  kMacFontZapfChancery = 18,
64  kMacFontTimes = 20,
65  kMacFontHelvetica = 21,
66  kMacFontCourier = 22,
67  kMacFontSymbol = 23,
68  kMacFontTaliesin = 24,
69  kMacFontAvantGarde = 33,
70  kMacFontNewCenturySchoolbook = 34,
71  kMacFontChicago = 16383,
72 
73  kMacFontOsaka = 16384,
74  kMacFontBookMinchoM = 16396,
75  kMacFontMonoGothic = 16433,
76  kMacFontMonoMing = 16435,
77  kMacFontOsakaMono = 16436,
78  kMacFontMediumGothic = 16640,
79  kMacFontMing = 16641,
80  kMacFontHeiseiMincho = 16700,
81  kMacFontHeiseiKakuGothic = 16701
82 };
83 
84 enum {
85  kMacFontRegular,
86  kMacFontBold = 1,
87  kMacFontItalic = 2,
88  kMacFontUnderline = 4,
89  kMacFontOutline = 8,
90  kMacFontShadow = 16,
91  kMacFontCondense = 32,
92  kMacFontExtend = 64
93 };
94 
95 class Font;
96 
97 struct FontInfo {
98  Common::Language lang;
99  Common::CodePage encoding;
100  int aliasForId;
101  Common::String name;
102 
103  FontInfo() : lang(Common::UNK_LANG), encoding(Common::kCodePageInvalid), aliasForId(-1) {}
104 };
105 
106 class MacFont {
107 public:
108  MacFont(int id = kMacFontSystem, int size = 12, int slant = kMacFontRegular) {
109  _id = id;
110  _size = size ? size : 12;
111  _slant = slant;
112  _fallback = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
113  _fallbackName = Common::String(((const BdfFont *)_fallback)->getFamilyName());
114  _generated = false;
115  _truetype = false;
116  _font = NULL;
117  }
118 
119  int getId() const { return _id; };
120  void setId(int id) { _id = id; }
121  int getSize() const { return _size; }
122  int getSlant() const { return _slant; }
123  Common::String getName() const { return _name; }
124  void setName(Common::String &name) { setName(name.c_str()); }
125  void setName(const char *name);
126  const Graphics::Font *getFallback() const { return _fallback; }
127  bool isGenerated() const { return _generated; }
128  void setGenerated(bool gen) { _generated = gen; }
129  bool isTrueType() const { return _truetype; }
130  Font *getFont() const { return _font; }
131  void setFont(Font *font, bool truetype) { _font = font; _truetype = truetype; }
132  void setFallback(const Font *font, Common::String name = "");
133  Common::String getFallbackName() const { return _fallbackName; }
134 
135 private:
136  int _id;
137  int _size;
138  int _slant;
139  bool _truetype;
140  Common::String _name;
141  const Graphics::Font *_fallback;
142  Common::String _fallbackName;
143 
144  bool _generated;
145  Font *_font;
146 };
147 
149 public:
150  MacFontManager(uint32 mode, Common::Language language);
151  ~MacFontManager();
152 
153  void setLocalizedFonts();
154 
159  bool hasBuiltInFonts() { return _builtInFonts; }
166  const Font *getFont(MacFont *macFont);
167  const Font *getFont(MacFont macFont);
168 
175  const Common::String getFontName(uint16 id, int size, int slant = kMacFontRegular, bool tryGen = false);
176  const Common::String getFontName(const MacFont &font);
177  int getFontIdByName(Common::String name);
178 
179  Common::Language getFontLanguage(uint16 id);
180  Common::CodePage getFontEncoding(uint16 id);
181  int getFontAliasForId(uint16 id);
182  Common::String getFontName(uint16 id);
183 
184  void loadFonts(Common::SeekableReadStream *stream);
185  void loadFonts(const Common::Path &fileName);
186  void loadFonts(Common::MacResManager *fontFile);
187  void loadWindowsFont(const Common::Path &fileName);
188 
194  int registerFontName(Common::String name, int preferredId = -1);
195 
196  void forceBuiltinFonts() { _builtInFonts = true; }
197  int parseSlantFromName(const Common::String &name);
198 
199  const Common::Array<MacFontFamily *> &getFontFamilies() { return _fontFamilies; }
200 
201  void printFontRegistry(int debugLevel, uint32 channel);
202 
203  int registerTTFFont(const Graphics::TTFMap ttfList[]);
204 
205  int getFamilyId(int newId, int newSlant);
206 
207 private:
208  void loadFontsBDF();
209  void loadFonts();
210  void loadJapaneseFonts();
211 
212  void generateFontSubstitute(MacFont &macFont);
213  void generateFONTFont(MacFont &toFont, MacFont &fromFont);
214 
215 #ifdef USE_FREETYPE2
216  void generateTTFFont(MacFont &toFront, Common::SeekableReadStream *stream);
217 #endif
218 
219 private:
220  bool _builtInFonts;
221  bool _japaneseFontsLoaded;
222  uint32 _mode;
223  Common::Language _language;
226  Common::Array<MacFontFamily *> _fontFamilies;
227 
230 
231  int parseFontSlant(Common::String slant);
232 
233  /* Unicode font */
235 
237 };
238 
239 } // End of namespace Graphics
240 
241 #endif
Definition: macresman.h:125
Definition: str.h:59
Definition: font.h:83
Definition: array.h:52
Definition: macfontmanager.h:148
#define FontMan
Definition: fontman.h:127
Definition: path.h:52
Definition: macfont.h:165
Definition: stream.h:745
Definition: macfontmanager.h:36
Definition: macfontmanager.h:97
Definition: hashmap.h:85
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: bdf.h:60
Definition: macfontmanager.h:106
bool hasBuiltInFonts()
Definition: macfontmanager.h:159
Definition: macfont.h:34
Language
Definition: language.h:45