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  kMacFontChicago = 0,
47  kMacFontGeneva = 1,
48  kMacFontNewYork = 2,
49  kMacFontMonaco = 4,
50  kMacFontVenice = 5,
51  kMacFontLondon = 6,
52  kMacFontAthens = 7,
53  kMacFontSanFrancisco = 8,
54  kMacFontCairo = 11,
55  kMacFontLosAngeles = 12,
56  kMacFontPalatino = 16,
57  kMacFontTimes = 20,
58  kMacFontHelvetica = 21,
59  kMacFontCourier = 22,
60  kMacFontSymbol = 23
61 };
62 
63 enum {
64  kMacFontRegular,
65  kMacFontBold = 1,
66  kMacFontItalic = 2,
67  kMacFontUnderline = 4,
68  kMacFontOutline = 8,
69  kMacFontShadow = 16,
70  kMacFontCondense = 32,
71  kMacFontExtend = 64
72 };
73 
74 class Font;
75 
76 struct FontInfo {
77  Common::Language lang;
78  Common::CodePage encoding;
79  int aliasForId;
80  Common::String name;
81 
82  FontInfo() : lang(Common::UNK_LANG), encoding(Common::kCodePageInvalid), aliasForId(-1) {}
83 };
84 
85 class MacFont {
86 public:
87  MacFont(int id = kMacFontChicago, int size = 12, int slant = kMacFontRegular) {
88  _id = id;
89  _size = size ? size : 12;
90  _slant = slant;
91  _fallback = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
92  _fallbackName = Common::String(((const BdfFont *)_fallback)->getFamilyName());
93  _generated = false;
94  _truetype = false;
95  _font = NULL;
96  }
97 
98  int getId() const { return _id; };
99  void setId(int id) { _id = id; }
100  int getSize() const { return _size; }
101  int getSlant() const { return _slant; }
102  Common::String getName() const { return _name; }
103  void setName(Common::String &name) { setName(name.c_str()); }
104  void setName(const char *name);
105  const Graphics::Font *getFallback() const { return _fallback; }
106  bool isGenerated() const { return _generated; }
107  void setGenerated(bool gen) { _generated = gen; }
108  bool isTrueType() const { return _truetype; }
109  Font *getFont() const { return _font; }
110  void setFont(Font *font, bool truetype) { _font = font; _truetype = truetype; }
111  void setFallback(const Font *font, Common::String name = "");
112  Common::String getFallbackName() const { return _fallbackName; }
113 
114 private:
115  int _id;
116  int _size;
117  int _slant;
118  bool _truetype;
119  Common::String _name;
120  const Graphics::Font *_fallback;
121  Common::String _fallbackName;
122 
123  bool _generated;
124  Font *_font;
125 };
126 
128 public:
129  MacFontManager(uint32 mode, Common::Language language);
130  ~MacFontManager();
131 
132  void setLocalizedFonts();
133 
138  bool hasBuiltInFonts() { return _builtInFonts; }
145  const Font *getFont(MacFont *macFont);
146  const Font *getFont(MacFont macFont);
147 
154  const Common::String getFontName(uint16 id, int size, int slant = kMacFontRegular, bool tryGen = false);
155  const Common::String getFontName(const MacFont &font);
156  int getFontIdByName(Common::String name);
157 
158  Common::Language getFontLanguage(uint16 id);
159  Common::CodePage getFontEncoding(uint16 id);
160  int getFontAliasForId(uint16 id);
161  Common::String getFontName(uint16 id);
162 
163  void loadFonts(Common::SeekableReadStream *stream);
164  void loadFonts(const Common::Path &fileName);
165  void loadFonts(Common::MacResManager *fontFile);
166  void loadWindowsFont(const Common::Path &fileName);
167 
173  int registerFontName(Common::String name, int preferredId = -1);
174 
175  void forceBuiltinFonts() { _builtInFonts = true; }
176  int parseSlantFromName(const Common::String &name);
177 
178  const Common::Array<MacFontFamily *> &getFontFamilies() { return _fontFamilies; }
179 
180  void printFontRegistry(int debugLevel, uint32 channel);
181 
182  int registerTTFFont(const Graphics::TTFMap ttfList[]);
183 
184  int getFamilyId(int newId, int newSlant);
185 
186 private:
187  void loadFontsBDF();
188  void loadFonts();
189  void loadJapaneseFonts();
190 
191  void generateFontSubstitute(MacFont &macFont);
192  void generateFONTFont(MacFont &toFont, MacFont &fromFont);
193 
194 #ifdef USE_FREETYPE2
195  void generateTTFFont(MacFont &toFront, Common::SeekableReadStream *stream);
196 #endif
197 
198 private:
199  bool _builtInFonts;
200  bool _japaneseFontsLoaded;
201  uint32 _mode;
202  Common::Language _language;
205  Common::Array<MacFontFamily *> _fontFamilies;
206 
209 
210  int parseFontSlant(Common::String slant);
211 
212  /* Unicode font */
214 
216 };
217 
218 } // End of namespace Graphics
219 
220 #endif
Definition: macresman.h:125
Definition: str.h:59
Definition: font.h:83
Definition: array.h:52
Definition: macfontmanager.h:127
#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:76
Definition: hashmap.h:85
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: bdf.h:60
Definition: macfontmanager.h:85
bool hasBuiltInFonts()
Definition: macfontmanager.h:138
Definition: macfont.h:34
Language
Definition: language.h:45