aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sandulenko2017-01-26 18:50:33 +0100
committerEugene Sandulenko2017-01-26 18:50:33 +0100
commit2991871d03a93e3ea543f23d10586d428ffbccc7 (patch)
tree279e08e2770f937a90fadc53323d5629e8884a06
parentd99036a480eda3a0449215f7b240e0ee12aadaa1 (diff)
downloadscummvm-rg350-2991871d03a93e3ea543f23d10586d428ffbccc7.tar.gz
scummvm-rg350-2991871d03a93e3ea543f23d10586d428ffbccc7.tar.bz2
scummvm-rg350-2991871d03a93e3ea543f23d10586d428ffbccc7.zip
GRAPHICS: Refactor Mac font loading into per file method
-rw-r--r--graphics/macgui/macfontmanager.cpp84
-rw-r--r--graphics/macgui/macfontmanager.h6
2 files changed, 50 insertions, 40 deletions
diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 4c8b9eb06c..9d66e495ad 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -158,68 +158,72 @@ void MacFontManager::loadFonts() {
for (Common::ArchiveMemberList::iterator it = list.begin(); it != list.end(); ++it) {
Common::SeekableReadStream *stream = dat->createReadStreamForMember((*it)->getName());
- Common::MacResManager *fontFile = new Common::MacResManager();
+ loadFontsFromStream(stream);
+ }
- if (!fontFile->loadFromMacBinary(*stream))
- continue;
+ _builtInFonts = false;
- Common::MacResIDArray fonds = fontFile->getResIDArray(MKTAG('F','O','N','D'));
- if (fonds.size() > 0) {
- for (Common::Array<uint16>::iterator iterator = fonds.begin(); iterator != fonds.end(); ++iterator) {
- Common::SeekableReadStream *fond = fontFile->getResource(MKTAG('F', 'O', 'N', 'D'), *iterator);
+ delete dat;
+}
- Common::String familyName = fontFile->getResName(MKTAG('F', 'O', 'N', 'D'), *iterator);
+void MacFontManager::loadFontsFromStream(Common::SeekableReadStream *stream) {
+ Common::MacResManager *fontFile = new Common::MacResManager();
- Graphics::MacFontFamily *fontFamily = new MacFontFamily();
- fontFamily->load(*fond);
+ if (!fontFile->loadFromMacBinary(*stream))
+ return;
- Common::Array<Graphics::MacFontFamily::AsscEntry> *assoc = fontFamily->getAssocTable();
+ Common::MacResIDArray fonds = fontFile->getResIDArray(MKTAG('F','O','N','D'));
+ if (fonds.size() > 0) {
+ for (Common::Array<uint16>::iterator iterator = fonds.begin(); iterator != fonds.end(); ++iterator) {
+ Common::SeekableReadStream *fond = fontFile->getResource(MKTAG('F', 'O', 'N', 'D'), *iterator);
- for (uint i = 0; i < assoc->size(); i++) {
- debug("size: %d style: %d id: %d", (*assoc)[i]._fontSize, (*assoc)[i]._fontStyle,
- (*assoc)[i]._fontID);
+ Common::String familyName = fontFile->getResName(MKTAG('F', 'O', 'N', 'D'), *iterator);
- Common::SeekableReadStream *fontstream;
- MacFont *macfont;
- Graphics::MacFONTFont *font;
+ Graphics::MacFontFamily *fontFamily = new MacFontFamily();
+ fontFamily->load(*fond);
- fontstream = fontFile->getResource(MKTAG('N', 'F', 'N', 'T'), (*assoc)[i]._fontID);
+ Common::Array<Graphics::MacFontFamily::AsscEntry> *assoc = fontFamily->getAssocTable();
- if (!fontstream)
- fontstream = fontFile->getResource(MKTAG('F', 'O', 'N', 'T'), (*assoc)[i]._fontID);
+ for (uint i = 0; i < assoc->size(); i++) {
+ debug("size: %d style: %d id: %d", (*assoc)[i]._fontSize, (*assoc)[i]._fontStyle,
+ (*assoc)[i]._fontID);
- if (!fontstream) {
- warning("Unknown FontId: %d", (*assoc)[i]._fontID);
+ Common::SeekableReadStream *fontstream;
+ MacFont *macfont;
+ Graphics::MacFONTFont *font;
- continue;
- }
+ fontstream = fontFile->getResource(MKTAG('N', 'F', 'N', 'T'), (*assoc)[i]._fontID);
- font = new Graphics::MacFONTFont;
- font->loadFont(*fontstream, fontFamily, (*assoc)[i]._fontSize, (*assoc)[i]._fontStyle);
+ if (!fontstream)
+ fontstream = fontFile->getResource(MKTAG('F', 'O', 'N', 'T'), (*assoc)[i]._fontID);
- delete fontstream;
+ if (!fontstream) {
+ warning("Unknown FontId: %d", (*assoc)[i]._fontID);
- Common::String fontName = Common::String::format("%s-%d-%d", familyName.c_str(), (*assoc)[i]._fontStyle, (*assoc)[i]._fontSize);
+ continue;
+ }
- macfont = new MacFont(_fontNames.getVal(familyName, kMacFontNonStandard), (*assoc)[i]._fontSize, (*assoc)[i]._fontStyle);
+ font = new Graphics::MacFONTFont;
+ font->loadFont(*fontstream, fontFamily, (*assoc)[i]._fontSize, (*assoc)[i]._fontStyle);
- FontMan.assignFontToName(fontName, font);
- macfont->setFont(font);
- _fontRegistry.setVal(fontName, macfont);
+ delete fontstream;
- debug(2, " %s", fontName.c_str());
- }
+ Common::String fontName = Common::String::format("%s-%d-%d", familyName.c_str(), (*assoc)[i]._fontStyle, (*assoc)[i]._fontSize);
- delete fond;
+ macfont = new MacFont(_fontNames.getVal(familyName, kMacFontNonStandard), (*assoc)[i]._fontSize, (*assoc)[i]._fontStyle);
+
+ FontMan.assignFontToName(fontName, font);
+ macfont->setFont(font);
+ _fontRegistry.setVal(fontName, macfont);
+
+ debug(2, " %s", fontName.c_str());
}
- }
- delete fontFile;
+ delete fond;
+ }
}
- _builtInFonts = false;
-
- delete dat;
+ delete fontFile;
}
const Font *MacFontManager::getFont(MacFont macFont) {
diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
index 8c1ed5025c..6d6122e2e7 100644
--- a/graphics/macgui/macfontmanager.h
+++ b/graphics/macgui/macfontmanager.h
@@ -25,6 +25,10 @@
#include "graphics/fontman.h"
+namespace Common {
+ class SeekableReadStream;
+}
+
namespace Graphics {
class MacFONTFont;
@@ -122,6 +126,8 @@ public:
const char *getFontName(MacFont &font);
int getFontIdByName(Common::String name);
+ void loadFontsFromStream(Common::SeekableReadStream *stream);
+
private:
void loadFontsBDF();
void loadFonts();