aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sandulenko2016-10-06 23:48:50 +0200
committerEugene Sandulenko2016-10-06 23:49:39 +0200
commitb2dcd1bb1ef920e7723501c9500a8ef0348be03a (patch)
treeda8a53526126c8edc7195bcbbb7317cbc6ff0e81
parent59a7993951d80d2db651e773f3bb16b12e3f6f56 (diff)
downloadscummvm-rg350-b2dcd1bb1ef920e7723501c9500a8ef0348be03a.tar.gz
scummvm-rg350-b2dcd1bb1ef920e7723501c9500a8ef0348be03a.tar.bz2
scummvm-rg350-b2dcd1bb1ef920e7723501c9500a8ef0348be03a.zip
GRAPHICS: Move font-related MacGUI code to MacFontManager
-rw-r--r--engines/director/frame.cpp11
-rw-r--r--engines/macventure/gui.cpp3
-rw-r--r--engines/wage/dialog.cpp3
-rw-r--r--engines/wage/entities.cpp17
-rw-r--r--engines/wage/entities.h6
-rw-r--r--engines/wage/gui-console.cpp3
-rw-r--r--engines/wage/world.cpp6
-rw-r--r--graphics/macgui/macfontmanager.cpp161
-rw-r--r--graphics/macgui/macfontmanager.h90
-rw-r--r--graphics/macgui/macmenu.cpp13
-rw-r--r--graphics/macgui/macwindow.cpp5
-rw-r--r--graphics/macgui/macwindow.h2
-rw-r--r--graphics/macgui/macwindowmanager.cpp135
-rw-r--r--graphics/macgui/macwindowmanager.h29
-rw-r--r--graphics/module.mk1
15 files changed, 296 insertions, 189 deletions
diff --git a/engines/director/frame.cpp b/engines/director/frame.cpp
index d6f63a8584..2eaddc50f2 100644
--- a/engines/director/frame.cpp
+++ b/engines/director/frame.cpp
@@ -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"
@@ -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);
diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp
index 9e0a6e9f00..3b7c3a244b 100644
--- a/engines/macventure/gui.cpp
+++ b/engines/macventure/gui.cpp
@@ -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"
@@ -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) {
diff --git a/engines/wage/dialog.cpp b/engines/wage/dialog.cpp
index ffb4f9c93d..a8500a7ebe 100644
--- a/engines/wage/dialog.cpp
+++ b/engines/wage/dialog.cpp
@@ -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"
@@ -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() {
diff --git a/engines/wage/entities.cpp b/engines/wage/entities.cpp
index 5ec54493a7..90247a5b21 100644
--- a/engines/wage/entities.cpp
+++ b/engines/wage/entities.cpp
@@ -54,6 +54,7 @@
#include "common/memstream.h"
#include "graphics/managed_surface.h"
+#include "graphics/macgui/macfontmanager.h"
namespace Wage {
@@ -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;
@@ -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();
@@ -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) {
@@ -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--;
diff --git a/engines/wage/entities.h b/engines/wage/entities.h
index b7cafb2294..a755af5360 100644
--- a/engines/wage/entities.h
+++ b/engines/wage/entities.h
@@ -50,6 +50,7 @@
namespace Graphics {
class ManagedSurface;
+ class MacFont;
}
namespace Wage {
@@ -308,8 +309,7 @@ public:
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
@@ -334,7 +334,7 @@ public:
void paint(Graphics::ManagedSurface *screen, int x, int y);
- const char *getFontName();
+ const Graphics::MacFont *getFont() { return _font; }
};
} // End of namespace Wage
diff --git a/engines/wage/gui-console.cpp b/engines/wage/gui-console.cpp
index a5e71463f7..37031f0dd9 100644
--- a/engines/wage/gui-console.cpp
+++ b/engines/wage/gui-console.cpp
@@ -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"
@@ -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() {
diff --git a/engines/wage/world.cpp b/engines/wage/world.cpp
index 3e56c0daa7..100517b836 100644
--- a/engines/wage/world.cpp
+++ b/engines/wage/world.cpp
@@ -46,6 +46,7 @@
*/
#include "common/file.h"
+#include "graphics/macgui/macfontmanager.h"
#include "wage/wage.h"
#include "wage/entities.h"
@@ -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()) {
diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
new file mode 100644
index 0000000000..7bdb8a937e
--- /dev/null
+++ b/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
diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
new file mode 100644
index 0000000000..fab4ce9ea1
--- /dev/null
+++ b/graphics/macgui/macfontmanager.h
@@ -0,0 +1,90 @@
+/* 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.
+ *
+ */
+
+#ifndef GRAPHICS_MACGUI_MACFONTMANAGER_H
+#define GRAPHICS_MACGUI_MACFONTMANAGER_H
+
+#include "graphics/fontman.h"
+
+namespace Graphics {
+
+enum {
+ kMacFontChicago = 0
+};
+
+class MacFont {
+public:
+ MacFont(int id = kMacFontChicago, int size = 12, FontManager::FontUsage fallback = Graphics::FontManager::kBigGUIFont) {
+ _id = id;
+ _size = size;
+ _fallback = fallback;
+ }
+
+ int getId() { return _id; };
+ int getSize() { return _size; }
+ Common::String getName() { return _name; }
+ void setName(Common::String &name) { _name = name; }
+ void setName(const char *name) { _name = name; }
+ FontManager::FontUsage getFallback() { return _fallback; }
+
+private:
+ int _id;
+ int _size;
+ Common::String _name;
+ FontManager::FontUsage _fallback;
+};
+
+class MacFontManager {
+public:
+ MacFontManager();
+
+ /**
+ * Accessor method to check the presence of built-in fonts.
+ * @return True if there are bult-in fonts.
+ */
+ bool hasBuiltInFonts() { return _builtInFonts; }
+ /**
+ * Retrieve a font from the available ones.
+ * @param name Name of the desired font.
+ * @param fallback Fallback policy in case the desired font isn't there.
+ * @return The requested font or the fallback.
+ */
+ const Font *getFont(MacFont macFont);
+
+private:
+ void loadFonts();
+
+ /**
+ * Return font name from standard ID
+ * @param id ID of the font
+ * @param size size of the font
+ * @return the font name or NULL if ID goes beyond the mapping
+ */
+ const char *getFontName(int id, int size);
+
+private:
+ bool _builtInFonts;
+};
+
+} // End of namespace Graphics
+
+#endif
diff --git a/graphics/macgui/macmenu.cpp b/graphics/macgui/macmenu.cpp
index 4f8c6f32b9..449cf58335 100644
--- a/graphics/macgui/macmenu.cpp
+++ b/graphics/macgui/macmenu.cpp
@@ -25,6 +25,7 @@
#include "graphics/primitives.h"
#include "graphics/font.h"
+#include "graphics/macgui/macfontmanager.h"
#include "graphics/macgui/macwindowmanager.h"
#include "graphics/macgui/macwindow.h"
#include "graphics/macgui/macmenu.h"
@@ -112,7 +113,7 @@ Menu::~Menu() {
}
void Menu::addStaticMenus(const MenuData *data) {
- MenuItem *about = new MenuItem(_wm->hasBuiltInFonts() ? "\xa9" : "\xf0"); // (c) Symbol as the most resembling apple
+ MenuItem *about = new MenuItem(_wm->_fontMan->hasBuiltInFonts() ? "\xa9" : "\xf0"); // (c) Symbol as the most resembling apple
_items.push_back(about);
for (int i = 0; data[i].menunum; i++) {
@@ -154,7 +155,7 @@ void Menu::calcDimensions() {
_items[i]->bbox.left = x - kMenuLeftMargin;
_items[i]->bbox.top = y;
_items[i]->bbox.right = x + w + kMenuSpacing - kMenuLeftMargin;
- _items[i]->bbox.bottom = y + _font->getFontHeight() + (_wm->hasBuiltInFonts() ? 3 : 2);
+ _items[i]->bbox.bottom = y + _font->getFontHeight() + (_wm->_fontMan->hasBuiltInFonts() ? 3 : 2);
}
calcMenuBounds(_items[i]);
@@ -244,7 +245,7 @@ void Menu::createSubMenuFromString(int id, const char *str) {
}
const Font *Menu::getMenuFont() {
- return _wm->getFont("Chicago-12", FontManager::kBigGUIFont);
+ return _wm->_fontMan->getFont(Graphics::MacFont(kMacFontChicago, 12));
}
const char *Menu::getAcceleratorString(MenuSubItem *item, const char *prefix) {
@@ -252,7 +253,7 @@ const char *Menu::getAcceleratorString(MenuSubItem *item, const char *prefix) {
*res = 0;
if (item->shortcut != 0)
- sprintf(res, "%s%c%c", prefix, (_wm->hasBuiltInFonts() ? '^' : '\x11'), item->shortcut);
+ sprintf(res, "%s%c%c", prefix, (_wm->_fontMan->hasBuiltInFonts() ? '^' : '\x11'), item->shortcut);
return res;
}
@@ -339,7 +340,7 @@ bool Menu::draw(ManagedSurface *g, bool forceRedraw) {
renderSubmenu(it);
}
- _font->drawString(&_screen, it->name, it->bbox.left + kMenuLeftMargin, it->bbox.top + (_wm->hasBuiltInFonts() ? 2 : 1), it->bbox.width(), color);
+ _font->drawString(&_screen, it->name, it->bbox.left + kMenuLeftMargin, it->bbox.top + (_wm->_fontMan->hasBuiltInFonts() ? 2 : 1), it->bbox.width(), color);
}
g->transBlitFrom(_screen, kColorGreen);
@@ -372,7 +373,7 @@ void Menu::renderSubmenu(MenuItem *menu) {
int color = kColorBlack;
if (i == (uint)_activeSubItem && !text.empty() && menu->subitems[i]->enabled) {
color = kColorWhite;
- Common::Rect trect(r->left, y - (_wm->hasBuiltInFonts() ? 1 : 0), r->right, y + _font->getFontHeight());
+ Common::Rect trect(r->left, y - (_wm->_fontMan->hasBuiltInFonts() ? 1 : 0), r->right, y + _font->getFontHeight());
_screen.fillRect(trect, kColorBlack);
}
diff --git a/graphics/macgui/macwindow.cpp b/graphics/macgui/macwindow.cpp
index 2a6e191ded..0fce19e482 100644
--- a/graphics/macgui/macwindow.cpp
+++ b/graphics/macgui/macwindow.cpp
@@ -23,6 +23,7 @@
#include "graphics/font.h"
#include "graphics/primitives.h"
#include "common/events.h"
+#include "graphics/macgui/macfontmanager.h"
#include "graphics/macgui/macwindowmanager.h"
#include "graphics/macgui/macwindow.h"
#include "image/bmp.h"
@@ -67,7 +68,7 @@ MacWindow::~MacWindow() {
}
const Font *MacWindow::getTitleFont() {
- return _wm->getFont("Chicago-12", FontManager::kBigGUIFont);
+ return _wm->_fontMan->getFont(Graphics::MacFont(kMacFontChicago, 12));
}
void MacWindow::setActive(bool active) {
@@ -276,7 +277,7 @@ void MacWindow::drawSimpleBorder(ManagedSurface *g) {
if (drawTitle) {
const Graphics::Font *font = getTitleFont();
- int yOff = _wm->hasBuiltInFonts() ? 3 : 1;
+ int yOff = _wm->_fontMan->hasBuiltInFonts() ? 3 : 1;
int w = font->getStringWidth(_title) + 10;
int maxWidth = width - size * 2 - 7;
diff --git a/graphics/macgui/macwindow.h b/graphics/macgui/macwindow.h
index 5d06da383d..5446b65678 100644
--- a/graphics/macgui/macwindow.h
+++ b/graphics/macgui/macwindow.h
@@ -23,6 +23,8 @@
#ifndef GRAPHICS_MACGUI_MACWINDOW_H
#define GRAPHICS_MACGUI_MACWINDOW_H
+#include "common/stream.h"
+
#include "graphics/managed_surface.h"
#include "graphics/transparent_surface.h"
#include "graphics/nine_patch.h"
diff --git a/graphics/macgui/macwindowmanager.cpp b/graphics/macgui/macwindowmanager.cpp
index a6854663d6..42cab7cf8e 100644
--- a/graphics/macgui/macwindowmanager.cpp
+++ b/graphics/macgui/macwindowmanager.cpp
@@ -22,16 +22,14 @@
#include "common/array.h"
#include "common/events.h"
#include "common/list.h"
-#include "common/unzip.h"
#include "common/system.h"
-#include "common/stream.h"
#include "graphics/cursorman.h"
-#include "graphics/fonts/bdf.h"
#include "graphics/managed_surface.h"
#include "graphics/palette.h"
#include "graphics/primitives.h"
#include "graphics/macgui/macwindowmanager.h"
+#include "graphics/macgui/macfontmanager.h"
#include "graphics/macgui/macwindow.h"
#include "graphics/macgui/macmenu.h"
@@ -100,15 +98,13 @@ MacWindowManager::MacWindowManager() {
_fullRefresh = true;
- _builtInFonts = true;
-
for (int i = 0; i < ARRAYSIZE(fillPatterns); i++)
_patterns.push_back(fillPatterns[i]);
- loadFonts();
-
g_system->getPaletteManager()->setPalette(palette, 0, ARRAYSIZE(palette) / 3);
+ _fontMan = new MacFontManager();
+
CursorMan.replaceCursorPalette(palette, 0, ARRAYSIZE(palette) / 3);
CursorMan.replaceCursor(macCursorArrow, 11, 16, 1, 1, 3);
_cursorIsArrow = true;
@@ -118,6 +114,8 @@ MacWindowManager::MacWindowManager() {
MacWindowManager::~MacWindowManager() {
for (int i = 0; i < _lastId; i++)
delete _windows[i];
+
+ delete _fontMan;
}
MacWindow *MacWindowManager::addWindow(bool scrollable, bool resizable, bool editable) {
@@ -322,129 +320,6 @@ void MacWindowManager::removeFromWindowList(BaseMacWindow *target) {
_windows.remove_at(ndx);
}
-//////////////////////
-// Font stuff
-//////////////////////
-void MacWindowManager::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 = font->getFamilyName();
- } 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 Graphics::Font *MacWindowManager::getFont(const char *name, Graphics::FontManager::FontUsage fallback) {
- const Graphics::Font *font = 0;
-
- if (!_builtInFonts) {
- font = FontMan.getFontByName(name);
-
- if (!font)
- warning("Cannot load font %s", name);
- }
-
- if (_builtInFonts || !font)
- font = FontMan.getFontByUsage(fallback);
-
- 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 *MacWindowManager::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;
-}
-
/////////////////
// Cursor stuff
/////////////////
diff --git a/graphics/macgui/macwindowmanager.h b/graphics/macgui/macwindowmanager.h
index 96cc1e73a5..3449ab13c2 100644
--- a/graphics/macgui/macwindowmanager.h
+++ b/graphics/macgui/macwindowmanager.h
@@ -26,7 +26,6 @@
#include "common/array.h"
#include "common/list.h"
#include "common/events.h"
-#include "common/archive.h"
#include "graphics/fontman.h"
#include "graphics/macgui/macwindow.h"
@@ -62,6 +61,8 @@ class ManagedSurface;
class Menu;
+class MacFontManager;
+
typedef Common::Array<byte *> MacPatterns;
/**
@@ -80,27 +81,6 @@ public:
*/
void setScreen(ManagedSurface *screen) { _screen = screen; }
/**
- * Accessor method to check the presence of built-in fonts.
- * @return True if there are bult-in fonts.
- */
- bool hasBuiltInFonts() { return _builtInFonts; }
- /**
- * Retrieve a font from the available ones.
- * @param name Name of the desired font.
- * @param fallback Fallback policy in case the desired font isn't there.
- * @return The requested font or the fallback.
- */
- const Font *getFont(const char *name, FontManager::FontUsage fallback);
-
- /**
- * Return font name from standard ID
- * @param id ID of the font
- * @param size size of the font
- * @return the font name or NULL if ID goes beyond the mapping
- */
- const char *getFontName(int id, int size);
-
- /**
* Create a window with the given parameters.
* Note that this method allocates the necessary memory for the window.
* @param scrollable True if the window has to be scrollable.
@@ -168,9 +148,11 @@ public:
void pushArrowCursor();
void popCursor();
+public:
+ MacFontManager *_fontMan;
+
private:
void drawDesktop();
- void loadFonts();
void removeMarked();
void removeFromStack(BaseMacWindow *target);
@@ -194,7 +176,6 @@ private:
Menu *_menu;
- bool _builtInFonts;
bool _cursorIsArrow;
};
diff --git a/graphics/module.mk b/graphics/module.mk
index 1c87e74ba7..b6e704bc29 100644
--- a/graphics/module.mk
+++ b/graphics/module.mk
@@ -12,6 +12,7 @@ MODULE_OBJS := \
fonts/ttf.o \
fonts/winfont.o \
maccursor.o \
+ macgui/macfontmanager.o \
macgui/macmenu.o \
macgui/macwindow.o \
macgui/macwindowborder.o \