aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCameron Cawley2020-01-02 21:56:51 +0000
committerFilippos Karapetis2020-01-11 17:34:12 +0200
commite49282577fb10e65fd06fcb7808e300cf97b3ca8 (patch)
tree57d31691c648076bf1f6385dbdb909fb310ae02a
parentaa9a41545ad331acb37dde0790adfa8298b1f8b5 (diff)
downloadscummvm-rg350-e49282577fb10e65fd06fcb7808e300cf97b3ca8.tar.gz
scummvm-rg350-e49282577fb10e65fd06fcb7808e300cf97b3ca8.tar.bz2
scummvm-rg350-e49282577fb10e65fd06fcb7808e300cf97b3ca8.zip
GRAPHICS: Simplify loading Windows fonts
-rw-r--r--graphics/fonts/winfont.cpp67
-rw-r--r--graphics/fonts/winfont.h4
2 files changed, 17 insertions, 54 deletions
diff --git a/graphics/fonts/winfont.cpp b/graphics/fonts/winfont.cpp
index 6ba0136a52..6494f006b3 100644
--- a/graphics/fonts/winfont.cpp
+++ b/graphics/fonts/winfont.cpp
@@ -77,68 +77,34 @@ static WinFontDirEntry readDirEntry(Common::SeekableReadStream &stream) {
}
bool WinFont::loadFromFON(const Common::String &fileName, const WinFontDirEntry &dirEntry) {
- // First try loading via the NE code
- if (loadFromNE(fileName, dirEntry))
- return true;
-
- // Then try loading via the PE code
- return loadFromPE(fileName, dirEntry);
-}
-
-bool WinFont::loadFromNE(const Common::String &fileName, const WinFontDirEntry &dirEntry) {
- Common::NEResources *exe = new Common::NEResources();
-
- if (!exe->loadFromEXE(fileName)) {
- delete exe;
- return false;
- }
-
- // Let's pull out the font directory
- Common::SeekableReadStream *fontDirectory = exe->getResource(Common::kWinFontDir, Common::String("FONTDIR"));
- if (!fontDirectory) {
- warning("No font directory in '%s'", fileName.c_str());
- delete exe;
- return false;
- }
-
- uint32 fontId = getFontIndex(*fontDirectory, dirEntry);
-
- delete fontDirectory;
+ Common::WinResources *exe;
- // Couldn't match the face name
- if (fontId == 0xffffffff) {
- warning("Could not find face '%s' in '%s'", dirEntry.faceName.c_str(), fileName.c_str());
+ // First try loading via the NE code
+ exe = new Common::NEResources();
+ if (exe->loadFromEXE(fileName)) {
+ bool ok = loadFromEXE(exe, fileName, dirEntry);
delete exe;
- return false;
+ return ok;
}
+ delete exe;
- // Actually go get our font now...
- Common::SeekableReadStream *fontStream = exe->getResource(Common::kWinFont, fontId);
- if (!fontStream) {
- warning("Could not find font %d in %s", fontId, fileName.c_str());
+ // Then try loading via the PE code
+ exe = new Common::PEResources();
+ if (exe->loadFromEXE(fileName)) {
+ bool ok = loadFromEXE(exe, fileName, dirEntry);
delete exe;
- return false;
+ return ok;
}
-
- bool ok = loadFromFNT(*fontStream);
- delete fontStream;
delete exe;
- return ok;
-}
-
-bool WinFont::loadFromPE(const Common::String &fileName, const WinFontDirEntry &dirEntry) {
- Common::PEResources *exe = new Common::PEResources();
- if (!exe->loadFromEXE(fileName)) {
- delete exe;
- return false;
- }
+ return false;
+}
+bool WinFont::loadFromEXE(Common::WinResources *exe, const Common::String &fileName, const WinFontDirEntry &dirEntry) {
// Let's pull out the font directory
Common::SeekableReadStream *fontDirectory = exe->getResource(Common::kWinFontDir, Common::String("FONTDIR"));
if (!fontDirectory) {
warning("No font directory in '%s'", fileName.c_str());
- delete exe;
return false;
}
@@ -149,7 +115,6 @@ bool WinFont::loadFromPE(const Common::String &fileName, const WinFontDirEntry &
// Couldn't match the face name
if (fontId == 0xffffffff) {
warning("Could not find face '%s' in '%s'", dirEntry.faceName.c_str(), fileName.c_str());
- delete exe;
return false;
}
@@ -157,13 +122,11 @@ bool WinFont::loadFromPE(const Common::String &fileName, const WinFontDirEntry &
Common::SeekableReadStream *fontStream = exe->getResource(Common::kWinFont, fontId);
if (!fontStream) {
warning("Could not find font %d in %s", fontId, fileName.c_str());
- delete exe;
return false;
}
bool ok = loadFromFNT(*fontStream);
delete fontStream;
- delete exe;
return ok;
}
diff --git a/graphics/fonts/winfont.h b/graphics/fonts/winfont.h
index 3354fc2381..f1c661f270 100644
--- a/graphics/fonts/winfont.h
+++ b/graphics/fonts/winfont.h
@@ -28,6 +28,7 @@
namespace Common {
class SeekableReadStream;
+class WinResources;
}
namespace Graphics {
@@ -67,8 +68,7 @@ public:
void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const;
private:
- bool loadFromPE(const Common::String &fileName, const WinFontDirEntry &dirEntry);
- bool loadFromNE(const Common::String &fileName, const WinFontDirEntry &dirEntry);
+ bool loadFromEXE(Common::WinResources *exe, const Common::String &fileName, const WinFontDirEntry &dirEntry);
uint32 getFontIndex(Common::SeekableReadStream &stream, const WinFontDirEntry &dirEntry);
bool loadFromFNT(Common::SeekableReadStream &stream);