Skip to content

Commit

Permalink
WAGE: Load fonts from wage.dat
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Dec 31, 2015
1 parent a3cc6cd commit dad200e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
46 changes: 46 additions & 0 deletions engines/wage/gui.cpp
Expand Up @@ -46,8 +46,10 @@
*/

#include "common/system.h"
#include "common/unzip.h"
#include "graphics/fontman.h"
#include "graphics/font.h"
#include "graphics/fonts/bdf.h"
#include "wage/wage.h"
#include "wage/design.h"
#include "wage/entities.h"
Expand All @@ -74,8 +76,11 @@ Gui::Gui() {
Common::Rect r(0, 0, _screen.w, _screen.h);

_scrollPos = 0;
_builtInFonts = false;

Design::drawFilledRect(&_screen, r, kColorBlack, p, 1);

loadFonts();
}

Gui::~Gui() {
Expand Down Expand Up @@ -308,5 +313,46 @@ void Gui::renderConsole(Graphics::Surface *g, int x, int y, int width, int heigh
g->copyRectToSurface(_console, x - kConOverscan, y - kConOverscan, boundsR);
}

void Gui::loadFonts() {
Common::Archive *dat;

dat = Common::makeZipArchive("wage.dat");

if (!dat) {
warning("Could not find wage.dat. Falling back to built-in fonts");
_builtInFonts = true;
}

Common::ArchiveMemberList list;
dat->listMembers(list);

for (Common::ArchiveMemberList::iterator it = list.begin(); it != list.end(); ++it) {
Common::SeekableReadStream *stream = dat->createReadStreamForMember((*it)->getName());

Graphics::BdfFont *font = Graphics::BdfFont::loadFont(*stream);

delete stream;

Common::String fontName = (*it)->getName();

// Trim the .bdf extension
for (int i = fontName.size() - 1; i >= 0; --i) {
if (fontName[i] == '.') {
while ((uint)i < fontName.size()) {
fontName.deleteLastChar();
}
break;
}
}

FontMan.assignFontToName(fontName, font);

debug(2, " %s", fontName.c_str());
}

_builtInFonts = false;

delete dat;
}

} // End of namespace Wage
3 changes: 3 additions & 0 deletions engines/wage/gui.h
Expand Up @@ -73,6 +73,7 @@ class Gui {
void renderConsole(Graphics::Surface *g, int x, int y, int width, int height);
void drawBox(Graphics::Surface *g, int x, int y, int w, int h);
void fillRect(Graphics::Surface *g, int x, int y, int w, int h);
void loadFonts();

private:
Graphics::Surface _screen;
Expand All @@ -83,6 +84,8 @@ class Gui {
Common::StringArray _out;
Common::StringArray _lines;
uint _scrollPos;

bool _builtInFonts;
};

} // End of namespace Wage
Expand Down

0 comments on commit dad200e

Please sign in to comment.