[Scummvm-git-logs] scummvm master -> 86dcef45ea6f1a9eb93f21c43ccbdf4d0679e47c
djsrv
dservilla at gmail.com
Fri Jul 2 22:10:41 UTC 2021
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
58ab956d72 GRAPHICS: MACGUI: Don't allow font IDs to be overridden
86dcef45ea DIRECTOR: Fix per-cast font mappings
Commit: 58ab956d72d3703247510d781e0f22948b6c87a8
https://github.com/scummvm/scummvm/commit/58ab956d72d3703247510d781e0f22948b6c87a8
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-02T18:08:21-04:00
Commit Message:
GRAPHICS: MACGUI: Don't allow font IDs to be overridden
New fonts are automatically assigned a unique ID.
Changed paths:
graphics/macgui/macfontmanager.cpp
graphics/macgui/macfontmanager.h
diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 3230edc974..f8a827aa3b 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -34,7 +34,7 @@ namespace Graphics {
// Source: Apple IIGS Technical Note #41, "Font Family Numbers"
// http://apple2.boldt.ca/?page=til/tn.iigs.041
-static const char *const fontNames[] = {
+static const char *const defaultFontNames[] = {
"Chicago", // system font
"Geneva", // application font
"New York",
@@ -110,9 +110,13 @@ Common::String cleanFontName(const Common::String fontname) {
}
MacFontManager::MacFontManager(uint32 mode) : _mode(mode) {
- for (uint i = 0; i < ARRAYSIZE(fontNames); i++)
- if (fontNames[i])
- _fontIds.setVal(fontNames[i], i);
+ for (uint i = 0; i < ARRAYSIZE(defaultFontNames); i++)
+ if (defaultFontNames[i]) {
+ _fontNames.push_back(defaultFontNames[i]);
+ _fontIds.setVal(defaultFontNames[i], i);
+ } else {
+ _fontNames.push_back(Common::String());
+ }
if (_mode & MacGUIConstants::kWMModeForceBuiltinFonts) {
_builtInFonts = true;
@@ -243,6 +247,8 @@ void MacFontManager::loadFonts(Common::MacResManager *fontFile) {
familyName = cleanFontName(familyName);
}
+ registerFontName(familyName);
+
Graphics::MacFontFamily *fontFamily = new MacFontFamily();
fontFamily->load(*fond);
@@ -398,21 +404,23 @@ int MacFontManager::parseSlantFromName(const Common::String &name) {
return slantVal;
}
-void MacFontManager::registerFontMapping(uint16 id, Common::String name) {
- _extraFontNames[id] = name;
- _extraFontIds[name] = id;
-}
+int MacFontManager::registerFontName(Common::String name) {
+ // Don't register an empty font name, just return Geneva's ID.
+ if (name.empty())
+ return 1;
-void MacFontManager::clearFontMapping() {
- _extraFontNames.clear();
- _extraFontIds.clear();
-}
+ if (_fontIds.contains(name))
+ return _fontIds[name];
+ _fontNames.push_back(name);
+ _fontIds[name] = _fontNames.size() - 1;
+ return _fontNames.size() - 1;
+}
void MacFont::setName(const char *name) {
_name = name;
}
-const Common::String MacFontManager::getFontName(int id, int size, int slant, bool tryGen) {
+const Common::String MacFontManager::getFontName(uint16 id, int size, int slant, bool tryGen) {
Common::String n;
if (id == 3) // This is Geneva
@@ -420,20 +428,19 @@ const Common::String MacFontManager::getFontName(int id, int size, int slant, bo
int extraSlant = 0;
- if (_extraFontNames.contains(id)) {
- n = cleanFontName(_extraFontNames[id]);
- extraSlant = parseFontSlant(_extraFontNames[id]);
+ if (id < ARRAYSIZE(defaultFontNames)) {
+ n = _fontNames[id];
+ } else if (id < _fontNames.size()) {
+ n = cleanFontName(_fontNames[id]);
+ extraSlant = parseFontSlant(_fontNames[id]);
// let's try parse slant from name
if (!extraSlant)
- extraSlant = parseSlantFromName(_extraFontNames[id]);
- } else if (id < ARRAYSIZE(fontNames)) {
- if (fontNames[id])
- n = fontNames[id];
+ extraSlant = parseSlantFromName(_fontNames[id]);
}
if (n.empty()) {
warning("MacFontManager: Requested font ID %d not found. Falling back to Geneva", id);
- n = fontNames[1]; // Fallback to Geneva
+ n = _fontNames[1]; // Fallback to Geneva
}
return Common::String::format("%s-%d-%d", n.c_str(), slant | extraSlant, size);
@@ -444,12 +451,9 @@ const Common::String MacFontManager::getFontName(MacFont &font) {
}
int MacFontManager::getFontIdByName(Common::String name) {
- if (_extraFontIds.contains(name))
- return _extraFontIds[name];
+ if (_fontIds.contains(name))
+ return _fontIds[name];
- for (int f = 0; f < ARRAYSIZE(fontNames); f++)
- if (fontNames[f] != NULL && strcmp(fontNames[f], name.c_str()) == 0)
- return f;
return 1;
}
diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
index 75418dd64f..0eac4ee4f0 100644
--- a/graphics/macgui/macfontmanager.h
+++ b/graphics/macgui/macfontmanager.h
@@ -127,7 +127,7 @@ public:
* @param size size of the font
* @return the font name or NULL if ID goes beyond the mapping
*/
- const Common::String getFontName(int id, int size, int slant = kMacFontRegular, bool tryGen = false);
+ const Common::String getFontName(uint16 id, int size, int slant = kMacFontRegular, bool tryGen = false);
const Common::String getFontName(MacFont &font);
int getFontIdByName(Common::String name);
@@ -135,8 +135,12 @@ public:
void loadFonts(const Common::String &fileName);
void loadFonts(Common::MacResManager *fontFile);
- void registerFontMapping(uint16 id, Common::String name);
- void clearFontMapping();
+ /**
+ * Register a font name if it doesn't already exist.
+ * @param name name of the font
+ * @return the font's ID
+ */
+ int registerFontName(Common::String name);
void forceBuiltinFonts() { _builtInFonts = true; }
int parseSlantFromName(const Common::String &name);
@@ -157,10 +161,8 @@ private:
uint32 _mode;
Common::HashMap<Common::String, MacFont *> _fontRegistry;
- Common::HashMap<Common::String, int> _fontIds;
-
- Common::HashMap<uint16, Common::String> _extraFontNames;
- Common::HashMap<Common::String, int> _extraFontIds;
+ Common::Array<Common::String> _fontNames;
+ Common::HashMap<Common::String, uint16> _fontIds;
int parseFontSlant(Common::String slant);
Commit: 86dcef45ea6f1a9eb93f21c43ccbdf4d0679e47c
https://github.com/scummvm/scummvm/commit/86dcef45ea6f1a9eb93f21c43ccbdf4d0679e47c
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-02T18:08:21-04:00
Commit Message:
DIRECTOR: Fix per-cast font mappings
Font mappings are per-cast, so we can't override the WM's font IDs,
which are universal.
Now a TextCastMember's _fontId uses the per-cast font IDs, and the
Cast's _fontMap gives the corresponding WM font ID.
Changed paths:
engines/director/cast.cpp
engines/director/cast.h
engines/director/castmember.cpp
diff --git a/engines/director/cast.cpp b/engines/director/cast.cpp
index 88801db5ad..c218fcce17 100644
--- a/engines/director/cast.cpp
+++ b/engines/director/cast.cpp
@@ -328,8 +328,6 @@ void Cast::loadCast() {
// Font Mapping
if (_castArchive->hasResource(MKTAG('V', 'W', 'F', 'M'), -1)) {
- _vm->_wm->_fontMan->clearFontMapping();
-
loadFontMap(*(r = _castArchive->getFirstResource(MKTAG('V', 'W', 'F', 'M'))));
delete r;
}
@@ -1193,8 +1191,8 @@ void Cast::loadFontMap(Common::SeekableReadStreamEndian &stream) {
font += stream.readByte();
}
- _fontMap[id] = font;
- _vm->_wm->_fontMan->registerFontMapping(id, font);
+ // Map cast font ID to window manager font ID
+ _fontMap[id] = _vm->_wm->_fontMan->registerFontName(font);
debugC(3, kDebugLoading, "Fontmap. ID %d Font %s", id, font.c_str());
currentRawPosition = stream.pos();
diff --git a/engines/director/cast.h b/engines/director/cast.h
index 367dabd1cf..2c892ace0e 100644
--- a/engines/director/cast.h
+++ b/engines/director/cast.h
@@ -89,7 +89,7 @@ public:
uint16 _version;
uint16 _castLibID;
- Common::HashMap<uint16, Common::String> _fontMap;
+ Common::HashMap<uint16, uint16> _fontMap;
Common::HashMap<int, CastMember *> *_loadedCast;
Common::HashMap<int, const Stxt *> *_loadedStxts;
diff --git a/engines/director/castmember.cpp b/engines/director/castmember.cpp
index 68ec6ec93c..7c7c47e1f0 100644
--- a/engines/director/castmember.cpp
+++ b/engines/director/castmember.cpp
@@ -690,7 +690,7 @@ void TextCastMember::importStxt(const Stxt *stxt) {
}
Graphics::MacWidget *TextCastMember::createWidget(Common::Rect &bbox, Channel *channel) {
- Graphics::MacFont *macFont = new Graphics::MacFont(_fontId, _fontSize, _textSlant);
+ Graphics::MacFont *macFont = new Graphics::MacFont(_cast->_fontMap[_fontId], _fontSize, _textSlant);
Graphics::MacWidget *widget = nullptr;
Common::Rect dims(bbox);
@@ -749,7 +749,7 @@ void TextCastMember::setText(const char *text) {
return;
// If text has changed, use the cached formatting from first STXT in this castmember.
- Common::String formatting = Common::String::format("\001\016%04x%02x%04x%04x%04x%04x", _fontId, _textSlant, _fontSize, _fgpalinfo1, _fgpalinfo2, _fgpalinfo3);
+ Common::String formatting = Common::String::format("\001\016%04x%02x%04x%04x%04x%04x", _cast->_fontMap[_fontId], _textSlant, _fontSize, _fgpalinfo1, _fgpalinfo2, _fgpalinfo3);
_ptext = text;
_ftext = formatting + text;
More information about the Scummvm-git-logs
mailing list