Skip to content

Commit

Permalink
GRAPHICS: Move font-related MacGUI code to MacFontManager
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Oct 6, 2016
1 parent 59a7993 commit b2dcd1b
Show file tree
Hide file tree
Showing 15 changed files with 296 additions and 189 deletions.
11 changes: 5 additions & 6 deletions engines/director/frame.cpp
Expand Up @@ -22,6 +22,7 @@

#include "common/system.h"
#include "graphics/font.h"
#include "graphics/macgui/macfontmanager.h"
#include "graphics/macgui/macwindowmanager.h"
#include "image/bmp.h"

Expand Down Expand Up @@ -606,16 +607,14 @@ void Frame::renderText(Graphics::ManagedSurface &surface, uint16 spriteID) {
int height = _sprites[spriteID]->_height;
int width = _sprites[spriteID]->_width;

const char *fontName;
Graphics::MacFont macFont(textCast->fontId, textCast->fontSize);

if (_vm->_currentScore->_fontMap.contains(textCast->fontId)) {
fontName = _vm->_currentScore->_fontMap[textCast->fontId].c_str();
} else if ((fontName = _vm->_wm->getFontName(textCast->fontId, textCast->fontSize)) == NULL) {
warning("Unknown font id %d, falling back to default", textCast->fontId);
fontName = _vm->_wm->getFontName(0, 12);
// Override
macFont.setName(_vm->_currentScore->_fontMap[textCast->fontId]);
}

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

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

Expand Down
3 changes: 2 additions & 1 deletion engines/macventure/gui.cpp
Expand Up @@ -33,6 +33,7 @@
#include "common/debug-channels.h"
#include "common/debug.h"
#include "image/bmp.h"
#include "graphics/macgui/macfontmanager.h"

#include "macventure/gui.h"
#include "macventure/dialog.h"
Expand Down Expand Up @@ -266,7 +267,7 @@ const WindowData &Gui::getWindowData(WindowReference reference) {
}

const Graphics::Font &Gui::getCurrentFont() {
return *_wm.getFont("Chicago-12", Graphics::FontManager::kBigGUIFont);
return *_wm._fontMan->getFont(Graphics::MacFont(Graphics::kMacFontChicago, 12));
}

void Gui::bringToFront(WindowReference winID) {
Expand Down
3 changes: 2 additions & 1 deletion engines/wage/dialog.cpp
Expand Up @@ -48,6 +48,7 @@
#include "common/system.h"
#include "common/events.h"

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

#include "wage/wage.h"
Expand Down Expand Up @@ -92,7 +93,7 @@ Dialog::~Dialog() {
}

const Graphics::Font *Dialog::getDialogFont() {
return _gui->_wm.getFont(_gui->_wm.getFontName(0, 12), Graphics::FontManager::kBigGUIFont); // Default is Chicago
return _gui->_wm._fontMan->getFont(Graphics::MacFont(Graphics::kMacFontChicago, 12));
}

void Dialog::paint() {
Expand Down
17 changes: 4 additions & 13 deletions engines/wage/entities.cpp
Expand Up @@ -54,6 +54,7 @@

#include "common/memstream.h"
#include "graphics/managed_surface.h"
#include "graphics/macgui/macfontmanager.h"

namespace Wage {

Expand Down Expand Up @@ -86,8 +87,7 @@ Scene::Scene() {
_script = NULL;
_design = NULL;
_textBounds = NULL;
_fontSize = 0;
_fontType = 0;
_font = NULL;

for (int i = 0; i < 4; i++)
_blocked[i] = false;
Expand All @@ -111,8 +111,7 @@ Scene::Scene(Common::String name, Common::SeekableReadStream *data) {

_script = NULL;
_textBounds = NULL;
_fontSize = 0;
_fontType = 0;
_font = NULL;

setDesignBounds(readRect(data));
_worldY = data->readSint16BE();
Expand All @@ -138,6 +137,7 @@ Scene::Scene(Common::String name, Common::SeekableReadStream *data) {
Scene::~Scene() {
delete _script;
delete _textBounds;
delete _font;
}

void Scene::paint(Graphics::ManagedSurface *surface, int x, int y) {
Expand All @@ -157,15 +157,6 @@ void Scene::paint(Graphics::ManagedSurface *surface, int x, int y) {
}
}

const char *Scene::getFontName() {
const char *name = ((WageEngine *)g_engine)->_gui->_wm.getFontName(_fontType, _fontSize);

if (!name)
return "Unknown";

return name;
}

Designed *Scene::lookUpEntity(int x, int y) {
for (ObjList::const_iterator it = _objs.end(); it != _objs.begin(); ) {
it--;
Expand Down
6 changes: 3 additions & 3 deletions engines/wage/entities.h
Expand Up @@ -50,6 +50,7 @@

namespace Graphics {
class ManagedSurface;
class MacFont;
}

namespace Wage {
Expand Down Expand Up @@ -308,8 +309,7 @@ class Scene : public Designed {
Script *_script;
Common::String _text;
Common::Rect *_textBounds;
int _fontSize;
int _fontType; // 3 => Geneva, 22 => Courier, param to TextFont() function
Graphics::MacFont *_font;
bool _blocked[4];
Common::String _messages[4];
int _soundFrequency; // times a minute, max 3600
Expand All @@ -334,7 +334,7 @@ class Scene : public Designed {

void paint(Graphics::ManagedSurface *screen, int x, int y);

const char *getFontName();
const Graphics::MacFont *getFont() { return _font; }
};

} // End of namespace Wage
Expand Down
3 changes: 2 additions & 1 deletion engines/wage/gui-console.cpp
Expand Up @@ -51,6 +51,7 @@
#include "graphics/cursorman.h"
#include "graphics/fonts/bdf.h"
#include "graphics/palette.h"
#include "graphics/macgui/macfontmanager.h"
#include "graphics/macgui/macwindow.h"
#include "graphics/macgui/macmenu.h"

Expand All @@ -65,7 +66,7 @@ namespace Wage {
const Graphics::Font *Gui::getConsoleFont() {
Scene *scene = _engine->_world->_player->_currentScene;

return _wm.getFont(scene->getFontName(), Graphics::FontManager::kConsoleFont);
return _wm._fontMan->getFont(*scene->getFont());
}

void Gui::clearOutput() {
Expand Down
6 changes: 4 additions & 2 deletions engines/wage/world.cpp
Expand Up @@ -46,6 +46,7 @@
*/

#include "common/file.h"
#include "graphics/macgui/macfontmanager.h"

#include "wage/wage.h"
#include "wage/entities.h"
Expand Down Expand Up @@ -203,8 +204,9 @@ bool World::loadWorld(Common::MacResManager *resMan) {
res = resMan->getResource(MKTAG('A','T','X','T'), *iter);
if (res != NULL) {
scene->_textBounds = readRect(res);
scene->_fontType = res->readUint16BE();
scene->_fontSize = res->readUint16BE();
int fontType = res->readUint16BE();
int fontSize = res->readUint16BE();
scene->_font = new Graphics::MacFont(fontType, fontSize, Graphics::FontManager::kConsoleFont);

Common::String text;
while (res->pos() < res->size()) {
Expand Down
161 changes: 161 additions & 0 deletions graphics/macgui/macfontmanager.cpp
@@ -0,0 +1,161 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include "common/archive.h"
#include "common/stream.h"
#include "common/unzip.h"
#include "graphics/fonts/bdf.h"

#include "graphics/macgui/macfontmanager.h"

namespace Graphics {

MacFontManager::MacFontManager() {
loadFonts();
}

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

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

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

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;
if (font->getFamilyName() && *font->getFamilyName()) {
fontName = Common::String::format("%s-%d", font->getFamilyName(), font->getFontSize());
} else { // Get it from the file name
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;
}

const Font *MacFontManager::getFont(MacFont macFont) {
const Font *font = 0;

if (!_builtInFonts) {
if (macFont.getName().empty())
macFont.setName(getFontName(macFont.getId(), macFont.getSize()));

font = FontMan.getFontByName(macFont.getName());

if (!font) {
warning("Cannot load font %s", macFont.getName().c_str());

font = FontMan.getFontByName(MacFont(kMacFontChicago, 12).getName());
}
}

if (_builtInFonts || !font)
font = FontMan.getFontByUsage(macFont.getFallback());

return font;
}

// Source: Apple IIGS Technical Note #41, "Font Family Numbers"
// http://apple2.boldt.ca/?page=til/tn.iigs.041
static const char *const fontNames[] = {
"Chicago", // system font
"Geneva", // application font
"New York",
"Geneva",

"Monaco",
"Venice",
"London",
"Athens",

"San Francisco",
"Toronto",
NULL,
"Cairo",
"Los Angeles", // 12

"Zapf Dingbats",
"Bookman",
"Helvetica Narrow",
"Palatino",
NULL,
"Zapf Chancery",
NULL,

"Times", // 20
"Helvetica",
"Courier",
"Symbol",
"Taliesin", // mobile?
NULL,
NULL,
NULL,
NULL,
NULL,
NULL, // 30
NULL,
NULL,
"Avant Garde",
"New Century Schoolbook"
};

const char *MacFontManager::getFontName(int id, int size) {
static char name[128];

if (id > ARRAYSIZE(fontNames))
return NULL;

snprintf(name, 128, "%s-%d", fontNames[id], size);

return name;
}

} // End of namespace Graphics

0 comments on commit b2dcd1b

Please sign in to comment.