Skip to content

Commit 2991871

Browse files
committed
GRAPHICS: Refactor Mac font loading into per file method
1 parent d99036a commit 2991871

File tree

2 files changed

+50
-40
lines changed

2 files changed

+50
-40
lines changed

graphics/macgui/macfontmanager.cpp

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -158,68 +158,72 @@ void MacFontManager::loadFonts() {
158158
for (Common::ArchiveMemberList::iterator it = list.begin(); it != list.end(); ++it) {
159159
Common::SeekableReadStream *stream = dat->createReadStreamForMember((*it)->getName());
160160

161-
Common::MacResManager *fontFile = new Common::MacResManager();
161+
loadFontsFromStream(stream);
162+
}
162163

163-
if (!fontFile->loadFromMacBinary(*stream))
164-
continue;
164+
_builtInFonts = false;
165165

166-
Common::MacResIDArray fonds = fontFile->getResIDArray(MKTAG('F','O','N','D'));
167-
if (fonds.size() > 0) {
168-
for (Common::Array<uint16>::iterator iterator = fonds.begin(); iterator != fonds.end(); ++iterator) {
169-
Common::SeekableReadStream *fond = fontFile->getResource(MKTAG('F', 'O', 'N', 'D'), *iterator);
166+
delete dat;
167+
}
170168

171-
Common::String familyName = fontFile->getResName(MKTAG('F', 'O', 'N', 'D'), *iterator);
169+
void MacFontManager::loadFontsFromStream(Common::SeekableReadStream *stream) {
170+
Common::MacResManager *fontFile = new Common::MacResManager();
172171

173-
Graphics::MacFontFamily *fontFamily = new MacFontFamily();
174-
fontFamily->load(*fond);
172+
if (!fontFile->loadFromMacBinary(*stream))
173+
return;
175174

176-
Common::Array<Graphics::MacFontFamily::AsscEntry> *assoc = fontFamily->getAssocTable();
175+
Common::MacResIDArray fonds = fontFile->getResIDArray(MKTAG('F','O','N','D'));
176+
if (fonds.size() > 0) {
177+
for (Common::Array<uint16>::iterator iterator = fonds.begin(); iterator != fonds.end(); ++iterator) {
178+
Common::SeekableReadStream *fond = fontFile->getResource(MKTAG('F', 'O', 'N', 'D'), *iterator);
177179

178-
for (uint i = 0; i < assoc->size(); i++) {
179-
debug("size: %d style: %d id: %d", (*assoc)[i]._fontSize, (*assoc)[i]._fontStyle,
180-
(*assoc)[i]._fontID);
180+
Common::String familyName = fontFile->getResName(MKTAG('F', 'O', 'N', 'D'), *iterator);
181181

182-
Common::SeekableReadStream *fontstream;
183-
MacFont *macfont;
184-
Graphics::MacFONTFont *font;
182+
Graphics::MacFontFamily *fontFamily = new MacFontFamily();
183+
fontFamily->load(*fond);
185184

186-
fontstream = fontFile->getResource(MKTAG('N', 'F', 'N', 'T'), (*assoc)[i]._fontID);
185+
Common::Array<Graphics::MacFontFamily::AsscEntry> *assoc = fontFamily->getAssocTable();
187186

188-
if (!fontstream)
189-
fontstream = fontFile->getResource(MKTAG('F', 'O', 'N', 'T'), (*assoc)[i]._fontID);
187+
for (uint i = 0; i < assoc->size(); i++) {
188+
debug("size: %d style: %d id: %d", (*assoc)[i]._fontSize, (*assoc)[i]._fontStyle,
189+
(*assoc)[i]._fontID);
190190

191-
if (!fontstream) {
192-
warning("Unknown FontId: %d", (*assoc)[i]._fontID);
191+
Common::SeekableReadStream *fontstream;
192+
MacFont *macfont;
193+
Graphics::MacFONTFont *font;
193194

194-
continue;
195-
}
195+
fontstream = fontFile->getResource(MKTAG('N', 'F', 'N', 'T'), (*assoc)[i]._fontID);
196196

197-
font = new Graphics::MacFONTFont;
198-
font->loadFont(*fontstream, fontFamily, (*assoc)[i]._fontSize, (*assoc)[i]._fontStyle);
197+
if (!fontstream)
198+
fontstream = fontFile->getResource(MKTAG('F', 'O', 'N', 'T'), (*assoc)[i]._fontID);
199199

200-
delete fontstream;
200+
if (!fontstream) {
201+
warning("Unknown FontId: %d", (*assoc)[i]._fontID);
201202

202-
Common::String fontName = Common::String::format("%s-%d-%d", familyName.c_str(), (*assoc)[i]._fontStyle, (*assoc)[i]._fontSize);
203+
continue;
204+
}
203205

204-
macfont = new MacFont(_fontNames.getVal(familyName, kMacFontNonStandard), (*assoc)[i]._fontSize, (*assoc)[i]._fontStyle);
206+
font = new Graphics::MacFONTFont;
207+
font->loadFont(*fontstream, fontFamily, (*assoc)[i]._fontSize, (*assoc)[i]._fontStyle);
205208

206-
FontMan.assignFontToName(fontName, font);
207-
macfont->setFont(font);
208-
_fontRegistry.setVal(fontName, macfont);
209+
delete fontstream;
209210

210-
debug(2, " %s", fontName.c_str());
211-
}
211+
Common::String fontName = Common::String::format("%s-%d-%d", familyName.c_str(), (*assoc)[i]._fontStyle, (*assoc)[i]._fontSize);
212212

213-
delete fond;
213+
macfont = new MacFont(_fontNames.getVal(familyName, kMacFontNonStandard), (*assoc)[i]._fontSize, (*assoc)[i]._fontStyle);
214+
215+
FontMan.assignFontToName(fontName, font);
216+
macfont->setFont(font);
217+
_fontRegistry.setVal(fontName, macfont);
218+
219+
debug(2, " %s", fontName.c_str());
214220
}
215-
}
216221

217-
delete fontFile;
222+
delete fond;
223+
}
218224
}
219225

220-
_builtInFonts = false;
221-
222-
delete dat;
226+
delete fontFile;
223227
}
224228

225229
const Font *MacFontManager::getFont(MacFont macFont) {

graphics/macgui/macfontmanager.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
#include "graphics/fontman.h"
2727

28+
namespace Common {
29+
class SeekableReadStream;
30+
}
31+
2832
namespace Graphics {
2933

3034
class MacFONTFont;
@@ -122,6 +126,8 @@ class MacFontManager {
122126
const char *getFontName(MacFont &font);
123127
int getFontIdByName(Common::String name);
124128

129+
void loadFontsFromStream(Common::SeekableReadStream *stream);
130+
125131
private:
126132
void loadFontsBDF();
127133
void loadFonts();

0 commit comments

Comments
 (0)