Skip to content

Commit

Permalink
DIRECTOR: Switch Mac font loading to the common code
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Aug 3, 2016
1 parent 8618cbb commit 59ebb0c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 46 deletions.
5 changes: 5 additions & 0 deletions engines/director/director.cpp
Expand Up @@ -36,6 +36,7 @@
#include "engines/util.h"

#include "graphics/surface.h"
#include "graphics/macgui/macwindowmanager.h"

#include "director/director.h"
#include "director/dib.h"
Expand Down Expand Up @@ -65,6 +66,8 @@ DirectorEngine::DirectorEngine(OSystem *syst, const DirectorGameDescription *gam

_movies = nullptr;

_wm = nullptr;

const Common::FSNode gameDataDir(ConfMan.get("path"));
SearchMan.addSubDirectoryMatching(gameDataDir, "data");
SearchMan.addSubDirectoryMatching(gameDataDir, "install");
Expand Down Expand Up @@ -97,6 +100,8 @@ Common::Error DirectorEngine::run() {
_macBinary = nullptr;
_soundManager = nullptr;

_wm = new Graphics::MacWindowManager;

_lingo = new Lingo(this);
_soundManager = new DirectorSound();

Expand Down
5 changes: 5 additions & 0 deletions engines/director/director.h
Expand Up @@ -36,6 +36,10 @@ namespace Common {
class MacResManager;
}

namespace Graphics {
class MacWindowManager;
}

namespace Director {

enum DirectorGameID {
Expand Down Expand Up @@ -79,6 +83,7 @@ class DirectorEngine : public ::Engine {
Score *_currentScore;

Common::RandomSource _rnd;
Graphics::MacWindowManager *_wm;

protected:
virtual Common::Error run();
Expand Down
54 changes: 9 additions & 45 deletions engines/director/score.cpp
Expand Up @@ -38,6 +38,7 @@
#include "common/events.h"
#include "engines/util.h"
#include "graphics/managed_surface.h"
#include "graphics/macgui/macwindowmanager.h"
#include "image/bmp.h"
#include "graphics/fontman.h"
#include "graphics/fonts/bdf.h"
Expand Down Expand Up @@ -111,7 +112,6 @@ static byte defaultPalette[768] = {
255, 255, 102, 255, 255, 153, 255, 255, 204, 255, 255, 255 };

Score::Score(DirectorEngine *vm) {
loadMacFonts();
_vm = vm;
_surface = new Graphics::ManagedSurface;
_trailSurface = new Graphics::ManagedSurface;
Expand Down Expand Up @@ -663,47 +663,6 @@ void Score::loadFontMap(Common::SeekableSubReadStreamEndian &stream) {
}
}

void Score::loadMacFonts() {
//Copy from Wage
Common::Archive *dat;

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

if (!dat) {
warning("Could not find classicmacfonts.dat. Falling back to built-in fonts");
return;
}

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(" %s", fontName.c_str());
}

delete dat;
}

BitmapCast::BitmapCast(Common::SeekableSubReadStreamEndian &stream) {
/*byte flags = */ stream.readByte();
uint16 someFlaggyThing = stream.readUint16();
Expand Down Expand Up @@ -1432,12 +1391,17 @@ void Frame::renderText(Graphics::ManagedSurface &surface, uint16 spriteID) {
int height = _sprites[spriteID]->_height;
int width = _sprites[spriteID]->_width;

const Graphics::Font *font = FontMan.getFontByName(_vm->_currentScore->_fontMap[textCast->fontId]);
const char *fontName;

if (!font) {
error("Cannot load font '%s', id %d", _vm->_currentScore->_fontMap[textCast->fontId].c_str(), textCast->fontId);
if (_vm->_currentScore->_fontMap.contains(textCast->fontId)) {
fontName = _vm->_currentScore->_fontMap[textCast->fontId].c_str();
} else if ((fontName = _vm->_wm->getFontName(textCast->fontId)) == NULL) {
warning("Unknown font id %d, falling back to default", textCast->fontId);
fontName = _vm->_wm->getFontName(0);
}

const Graphics::Font *font = _vm->_wm->getFont(fontName, Graphics::FontManager::kBigGUIFont);

font->drawString(&surface, text, x, y, width, 0);

if (textCast->borderSize != kSizeNone) {
Expand Down
1 change: 0 additions & 1 deletion engines/director/score.h
Expand Up @@ -402,7 +402,6 @@ class Score {
void update();
void readVersion(uint32 rid);
void loadConfig(Common::SeekableSubReadStreamEndian &stream);
void loadMacFonts();
void loadPalette(Common::SeekableSubReadStreamEndian &stream);
void loadFrames(Common::SeekableSubReadStreamEndian &stream);
void loadLabels(Common::SeekableSubReadStreamEndian &stream);
Expand Down

0 comments on commit 59ebb0c

Please sign in to comment.