[Scummvm-git-logs] scummvm master -> 4dabee7e8b26a6fd170e27ff6dd4bfdf67faec67

djsrv dservilla at gmail.com
Tue Jul 6 02:54:37 UTC 2021


This automated email contains information about 4 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
b3b55e59e9 GRAPHICS: MACGUI: Add parent to MacFontRun
831c014f9e DIRECTOR: Make FXmp available to MacText
3fda461d5f GRAPHICS: MACGUI: Handle FontXPlatformMap in MacFontManager::getFont
4dabee7e8b DIRECTOR: Clean up char/font mapping registration


Commit: b3b55e59e9ce4caab668b58e4173a8dd102b9c54
    https://github.com/scummvm/scummvm/commit/b3b55e59e9ce4caab668b58e4173a8dd102b9c54
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-05T22:53:35-04:00

Commit Message:
GRAPHICS: MACGUI: Add parent to MacFontRun

Changed paths:
    graphics/macgui/mactext.cpp
    graphics/macgui/mactext.h


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 98e382cdab..581c7ad2f6 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -111,7 +111,7 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
 	_plainByteMode = false;
 
 	if (macFont) {
-		_defaultFormatting = MacFontRun(_wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
+		_defaultFormatting = MacFontRun(this, _wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
 		_defaultFormatting.font = wm->_fontMan->getFont(*macFont);
 	} else {
 		_defaultFormatting.font = NULL;
@@ -136,7 +136,7 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
 	_plainByteMode = true;
 
 	if (macFont) {
-		_defaultFormatting = MacFontRun(_wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
+		_defaultFormatting = MacFontRun(this, _wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
 		_defaultFormatting.font = wm->_fontMan->getFont(*macFont);
 	} else {
 		_defaultFormatting.font = NULL;
@@ -162,7 +162,7 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont
 	_plainByteMode = false;
 
 	if (macFont) {
-		_defaultFormatting = MacFontRun(_wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
+		_defaultFormatting = MacFontRun(this, _wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
 		_defaultFormatting.font = wm->_fontMan->getFont(*macFont);
 	} else {
 		_defaultFormatting.font = NULL;
@@ -187,7 +187,7 @@ MacText::MacText(const Common::String &s, MacWindowManager *wm, const MacFont *m
 	_plainByteMode = true;
 
 	if (macFont) {
-		_defaultFormatting = MacFontRun(_wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
+		_defaultFormatting = MacFontRun(this, _wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
 		_defaultFormatting.font = wm->_fontMan->getFont(*macFont);
 	} else {
 		_defaultFormatting.font = NULL;
@@ -213,7 +213,7 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const Font *f
 	_plainByteMode = false;
 
 	if (font) {
-		_defaultFormatting = MacFontRun(_wm, font, 0, font->getFontHeight(), 0, 0, 0);
+		_defaultFormatting = MacFontRun(this, _wm, font, 0, font->getFontHeight(), 0, 0, 0);
 		_defaultFormatting.font = font;
 	} else {
 		_defaultFormatting.font = NULL;
@@ -443,7 +443,7 @@ void MacText::setTextColor(uint32 color, uint32 start, uint32 end) {
 
 void MacText::setDefaultFormatting(uint16 fontId, byte textSlant, uint16 fontSize,
 		uint16 palinfo1, uint16 palinfo2, uint16 palinfo3) {
-	_defaultFormatting.setValues(_defaultFormatting.wm, fontId, textSlant, fontSize, palinfo1, palinfo2, palinfo3);
+	_defaultFormatting.setValues(this, _defaultFormatting.wm, fontId, textSlant, fontSize, palinfo1, palinfo2, palinfo3);
 
 	MacFont macFont = MacFont(fontId, fontSize, textSlant);
 
@@ -612,7 +612,7 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
 				D(9, "** splitString: fontId: %d, textSlant: %d, fontSize: %d, p0: %x p1: %x p2: %x",
 						fontId, textSlant, fontSize, palinfo1, palinfo2, palinfo3);
 
-				current_format.setValues(_wm, fontId, textSlant, fontSize, palinfo1, palinfo2, palinfo3);
+				current_format.setValues(this, _wm, fontId, textSlant, fontSize, palinfo1, palinfo2, palinfo3);
 
 				if (!_macFontMode)
 					current_format.font = _defaultFormatting.font;
@@ -631,7 +631,7 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
 				D(9, "** splitString: fontId: %d, textSlant: %d, fontSize: %d, p0: %x p1: %x p2: %x",
 						fontId, textSlant, fontSize, palinfo1, palinfo2, palinfo3);
 
-				current_format.setValues(_wm, fontId, textSlant, fontSize, palinfo1, palinfo2, palinfo3);
+				current_format.setValues(this, _wm, fontId, textSlant, fontSize, palinfo1, palinfo2, palinfo3);
 
 				// So far, we enforce single font here, though in the future, font size could be altered
 				if (!_macFontMode)
@@ -1068,7 +1068,7 @@ void MacText::appendText(const Common::U32String &str, int fontId, int fontSize,
 void MacText::appendText(const Common::U32String &str, int fontId, int fontSize, int fontSlant, uint16 r, uint16 g, uint16 b, bool skipAdd) {
 	uint oldLen = _textLines.size();
 
-	MacFontRun fontRun = MacFontRun(_wm, fontId, fontSlant, fontSize, r, g, b);
+	MacFontRun fontRun = MacFontRun(this, _wm, fontId, fontSlant, fontSize, r, g, b);
 
 	_currentFormatting = fontRun;
 
@@ -1094,7 +1094,7 @@ void MacText::appendText(const Common::U32String &str, int fontId, int fontSize,
 void MacText::appendText(const Common::U32String &str, const Font *font, uint16 r, uint16 g, uint16 b, bool skipAdd) {
 	uint oldLen = _textLines.size();
 
-	MacFontRun fontRun = MacFontRun(_wm, font, 0, font->getFontHeight(), r, g, b);
+	MacFontRun fontRun = MacFontRun(this, _wm, font, 0, font->getFontHeight(), r, g, b);
 
 	_currentFormatting = fontRun;
 
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index ee5dd133d6..d34cdce688 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -53,9 +53,11 @@ struct MacFontRun {
 	// to determine whether the next word is part of this one
 	bool wordContinuation;
 	const Font *font;
+	MacText *parent;
 	MacWindowManager *wm;
 
 	MacFontRun() {
+		parent = nullptr;
 		wm = nullptr;
 		fontId = textSlant = fontSize = 0;
 		palinfo1 = palinfo2 = palinfo3 = 0;
@@ -64,21 +66,22 @@ struct MacFontRun {
 		wordContinuation = false;
 	}
 
-	MacFontRun(MacWindowManager *wm_, uint16 fontId_, byte textSlant_, uint16 fontSize_,
+	MacFontRun(MacText *parent_, MacWindowManager *wm_, uint16 fontId_, byte textSlant_, uint16 fontSize_,
 			uint16 palinfo1_, uint16 palinfo2_, uint16 palinfo3_) {
-		setValues(wm_, fontId_, textSlant_, fontSize_, palinfo1_, palinfo2_, palinfo3_);
+		setValues(parent_, wm_, fontId_, textSlant_, fontSize_, palinfo1_, palinfo2_, palinfo3_);
 		wordContinuation = false;
 	}
 
-	MacFontRun(MacWindowManager *wm_, const Font *font_, byte textSlant_, uint16 fontSize_,
+	MacFontRun(MacText *parent_, MacWindowManager *wm_, const Font *font_, byte textSlant_, uint16 fontSize_,
 			uint16 palinfo1_, uint16 palinfo2_, uint16 palinfo3_) {
-		setValues(wm_, 0, textSlant_, fontSize_, palinfo1_, palinfo2_, palinfo3_);
+		setValues(parent_, wm_, 0, textSlant_, fontSize_, palinfo1_, palinfo2_, palinfo3_);
 		font = font_;
 		wordContinuation = false;
 	}
 
-	void setValues(MacWindowManager *wm_, uint16 fontId_, byte textSlant_, uint16 fontSize_,
+	void setValues(MacText *parent_, MacWindowManager *wm_, uint16 fontId_, byte textSlant_, uint16 fontSize_,
 			uint16 palinfo1_, uint16 palinfo2_, uint16 palinfo3_) {
+		parent    = parent_;
 		wm        = wm_;
 		fontId    = fontId_;
 		textSlant = textSlant_;


Commit: 831c014f9eb4205b47c815c5598d30c94de551d0
    https://github.com/scummvm/scummvm/commit/831c014f9eb4205b47c815c5598d30c94de551d0
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-05T22:53:35-04:00

Commit Message:
DIRECTOR: Make FXmp available to MacText

Changed paths:
    engines/director/cast.cpp
    engines/director/cast.h
    engines/director/castmember.cpp
    engines/director/fonts.cpp
    graphics/macgui/macfontmanager.h
    graphics/macgui/mactext.cpp
    graphics/macgui/mactext.h


diff --git a/engines/director/cast.cpp b/engines/director/cast.cpp
index bb53e8008f..25e7fb5ed6 100644
--- a/engines/director/cast.cpp
+++ b/engines/director/cast.cpp
@@ -102,10 +102,7 @@ Cast::~Cast() {
 	for (Common::HashMap<uint16, CastMemberInfo *>::iterator it = _castsInfo.begin(); it != _castsInfo.end(); ++it)
 		delete it->_value;
 
-	for (FontXPlatformMap::iterator it = _macFontsToWin.begin(); it != _macFontsToWin.end(); ++it)
-		delete it->_value;
-
-	for (FontXPlatformMap::iterator it = _winFontsToMac.begin(); it != _winFontsToMac.end(); ++it)
+	for (Graphics::FontXPlatformMap::iterator it = _fontXPlatformMap.begin(); it != _fontXPlatformMap.end(); ++it)
 		delete it->_value;
 
 	delete _loadedStxts;
diff --git a/engines/director/cast.h b/engines/director/cast.h
index 32236bbf90..d692558f9f 100644
--- a/engines/director/cast.h
+++ b/engines/director/cast.h
@@ -31,6 +31,12 @@ namespace Common {
 	class SeekableReadStreamEndian;
 }
 
+namespace Graphics {
+	struct FontXPlatformInfo;
+	typedef Common::HashMap<byte, byte> CharMap;
+	typedef Common::HashMap<uint16, FontXPlatformInfo *> FontXPlatformMap;
+}
+
 namespace Director {
 
 class Archive;
@@ -46,15 +52,6 @@ class ScriptCastMember;
 class ShapeCastMember;
 class TextCastMember;
 
-typedef Common::HashMap<byte, byte> CharMap;
-typedef Common::HashMap<uint16, uint16> FontSizeMap;
-struct FontXPlatformInfo {
-	Common::String toFont;
-	bool remapChars;
-	FontSizeMap sizeMap;
-};
-typedef Common::HashMap<Common::String, FontXPlatformInfo *> FontXPlatformMap;
-
 class Cast {
 public:
 	Cast(Movie *movie, uint16 castLibID, bool shared = false);
@@ -104,10 +101,8 @@ public:
 	uint16 _castLibID;
 
 	Common::HashMap<uint16, uint16> _fontMap;
-	CharMap _macCharsToWin;
-	CharMap _winCharsToMac;
-	FontXPlatformMap _macFontsToWin;
-	FontXPlatformMap _winFontsToMac;
+	Graphics::CharMap _charMap;
+	Graphics::FontXPlatformMap _fontXPlatformMap;
 
 	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..2deba1142b 100644
--- a/engines/director/castmember.cpp
+++ b/engines/director/castmember.cpp
@@ -701,7 +701,7 @@ Graphics::MacWidget *TextCastMember::createWidget(Common::Rect &bbox, Channel *c
 			dims.right = MIN<int>(dims.right, dims.left + _initialRect.width());
 			dims.bottom = MIN<int>(dims.bottom, dims.top + _initialRect.height());
 		}
-		widget = new Graphics::MacText(g_director->getCurrentWindow(), bbox.left, bbox.top, dims.width(), dims.height(), g_director->_wm, _ftext, macFont, getForeColor(), getBackColor(), _initialRect.width(), getAlignment(), 0, _borderSize, _gutterSize, _boxShadow, _textShadow, Common::kMacCentralEurope, _textType == kTextTypeFixed);
+		widget = new Graphics::MacText(g_director->getCurrentWindow(), bbox.left, bbox.top, dims.width(), dims.height(), g_director->_wm, _ftext, macFont, getForeColor(), getBackColor(), _initialRect.width(), getAlignment(), 0, _borderSize, _gutterSize, _boxShadow, _textShadow, Common::kMacCentralEurope, _textType == kTextTypeFixed, &_cast->_charMap, &_cast->_fontXPlatformMap);
 		((Graphics::MacText *)widget)->setSelRange(g_director->getCurrentMovie()->_selStart, g_director->getCurrentMovie()->_selEnd);
 		((Graphics::MacText *)widget)->setEditable(_editable);
 		((Graphics::MacText *)widget)->draw();
diff --git a/engines/director/fonts.cpp b/engines/director/fonts.cpp
index 8b43de1363..0d9bfec1d3 100644
--- a/engines/director/fonts.cpp
+++ b/engines/director/fonts.cpp
@@ -276,9 +276,11 @@ bool Cast::readFXmpLine(Common::SeekableReadStreamEndian &stream) {
 	}
 
 	Common::String fromFont;
+	uint16 fromFontId;
 	tok = readFXmpToken(stream);
 	if (tok.type == FXMP_TOKEN_WORD || tok.type == FXMP_TOKEN_STRING) {
 		fromFont = tok.str;
+		fromFontId = _vm->_wm->_fontMan->registerFontName(fromFont);
 		tok = readFXmpToken(stream);
 	}
 
@@ -332,11 +334,12 @@ bool Cast::readFXmpLine(Common::SeekableReadStreamEndian &stream) {
 			}
 			byte toChar = atoi(tok.str.c_str());
 
+			// TODO: We should fill _charMap with mappings matching the current platform.
+			// We only have Mac fonts right now, though, so we'll always use the Win => Mac mappings.
 			if (fromPlatform == Common::kPlatformMacintosh) {
-				_macCharsToWin[fromChar] = toChar;
 				debugC(3, kDebugLoading, "Cast::readFXmpLine: Mapping Mac char %d to Win char %d", fromChar, toChar);
 			} else {
-				_winCharsToMac[fromChar] = toChar;
+				_charMap[fromChar] = toChar;
 				debugC(3, kDebugLoading, "Cast::readFXmpLine: Mapping Win char %d to Mac char %d", fromChar, toChar);
 			}
 
@@ -344,7 +347,7 @@ bool Cast::readFXmpLine(Common::SeekableReadStreamEndian &stream) {
 		}
 	} else {
 		// font mapping
-		FontXPlatformInfo *info = new FontXPlatformInfo;
+		Graphics::FontXPlatformInfo *info = new Graphics::FontXPlatformInfo;
 
 		// to font
 		tok = readFXmpToken(stream);
@@ -353,7 +356,9 @@ bool Cast::readFXmpLine(Common::SeekableReadStreamEndian &stream) {
 			delete info;
 			return false;
 		}
-		info->toFont = tok.str;
+		Common::String toFont = tok.str;
+		uint16 toFontId = _vm->_wm->_fontMan->registerFontName(toFont);
+		info->toFont = toFontId;
 
 		tok = readFXmpToken(stream);
 
@@ -409,15 +414,16 @@ bool Cast::readFXmpLine(Common::SeekableReadStreamEndian &stream) {
 			tok = readFXmpToken(stream);
 		}
 
+		// TODO: We should fill _fontXPlatformMap with mappings matching the current platform.
+		// We only have Mac fonts right now, though, so we'll always use the Win => Mac mappings.
 		if (fromPlatform == Common::kPlatformMacintosh) {
-			_macFontsToWin[fromFont] = info;
-			debugC(3, kDebugLoading, "Cast::readFXmpLine: Mapping Mac font '%s' to Win font '%s'", fromFont.c_str(), info->toFont.c_str());
+			debugC(3, kDebugLoading, "Cast::readFXmpLine: Mapping Mac font '%s' (%d) to Win font '%s' (%d)", fromFont.c_str(), fromFontId, toFont.c_str(), toFontId);
 		} else {
-			_winFontsToMac[fromFont] = info;
-			debugC(3, kDebugLoading, "Cast::readFXmpLine: Mapping Win font '%s' to Mac font '%s'", fromFont.c_str(), info->toFont.c_str());
+			_fontXPlatformMap[fromFontId] = info;
+			debugC(3, kDebugLoading, "Cast::readFXmpLine: Mapping Win font '%s' (%d) to Mac font '%s' (%d)", fromFont.c_str(), fromFontId, toFont.c_str(), toFontId);
 		}
 		debugC(4, kDebugLoading, "  Remap characters: %d", info->remapChars);
-		for (FontSizeMap::iterator it = info->sizeMap.begin(); it != info->sizeMap.end(); ++it) {
+		for (Graphics::FontSizeMap::iterator it = info->sizeMap.begin(); it != info->sizeMap.end(); ++it) {
 			debugC(4, kDebugLoading, "  Mapping size %d to %d", it->_key, it->_value);
 		}
 	}
diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
index 0eac4ee4f0..6ebf6f0383 100644
--- a/graphics/macgui/macfontmanager.h
+++ b/graphics/macgui/macfontmanager.h
@@ -66,6 +66,15 @@ enum {
 
 class Font;
 
+typedef Common::HashMap<byte, byte> CharMap;
+typedef Common::HashMap<uint16, uint16> FontSizeMap;
+struct FontXPlatformInfo {
+	uint16 toFont;
+	bool remapChars;
+	FontSizeMap sizeMap;
+};
+typedef Common::HashMap<uint16, FontXPlatformInfo *> FontXPlatformMap;
+
 class MacFont {
 public:
 	MacFont(int id = kMacFontChicago, int size = 12, int slant = kMacFontRegular, FontManager::FontUsage fallback = Graphics::FontManager::kBigGUIFont) {
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 581c7ad2f6..2c1fcbd99d 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -94,7 +94,7 @@ uint MacTextLine::getChunkNum(int *col) {
 }
 
 
-MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::U32String &s, const MacFont *macFont, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, uint16 border, uint16 gutter, uint16 boxShadow, uint16 textShadow, bool fixedDims) :
+MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::U32String &s, const MacFont *macFont, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, uint16 border, uint16 gutter, uint16 boxShadow, uint16 textShadow, bool fixedDims, CharMap *charMap, FontXPlatformMap *fontXPlatformMap) :
 	MacWidget(parent, x, y, w, h, wm, true, border, gutter, boxShadow),
 	_macFont(macFont), _maxWidth(maxWidth), _textAlignment(textAlignment), _interLinear(interlinear) {
 
@@ -110,6 +110,9 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
 	_encodeType = Common::kUtf8;
 	_plainByteMode = false;
 
+	_charMap = charMap;
+	_fontXPlatformMap = fontXPlatformMap;
+
 	if (macFont) {
 		_defaultFormatting = MacFontRun(this, _wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
 		_defaultFormatting.font = wm->_fontMan->getFont(*macFont);
@@ -120,7 +123,7 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
 	init();
 }
 
-MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::String &s, const MacFont *macFont, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, uint16 border, uint16 gutter, uint16 boxShadow, uint16 textShadow, Common::CodePage encodeType, bool fixedDims) :
+MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::String &s, const MacFont *macFont, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, uint16 border, uint16 gutter, uint16 boxShadow, uint16 textShadow, Common::CodePage encodeType, bool fixedDims, CharMap *charMap, FontXPlatformMap *fontXPlatformMap) :
 	MacWidget(parent, x, y, w, h, wm, true, border, gutter, boxShadow),
 	_macFont(macFont), _maxWidth(maxWidth), _textAlignment(textAlignment), _interLinear(interlinear) {
 
@@ -135,6 +138,9 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
 	_encodeType = encodeType;
 	_plainByteMode = true;
 
+	_charMap = charMap;
+	_fontXPlatformMap = fontXPlatformMap;
+
 	if (macFont) {
 		_defaultFormatting = MacFontRun(this, _wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
 		_defaultFormatting.font = wm->_fontMan->getFont(*macFont);
@@ -161,6 +167,9 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont
 	_encodeType = Common::kUtf8;
 	_plainByteMode = false;
 
+	_charMap = nullptr;
+	_fontXPlatformMap = nullptr;
+
 	if (macFont) {
 		_defaultFormatting = MacFontRun(this, _wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
 		_defaultFormatting.font = wm->_fontMan->getFont(*macFont);
@@ -186,6 +195,9 @@ MacText::MacText(const Common::String &s, MacWindowManager *wm, const MacFont *m
 	_encodeType = encodeType;
 	_plainByteMode = true;
 
+	_charMap = nullptr;
+	_fontXPlatformMap = nullptr;
+
 	if (macFont) {
 		_defaultFormatting = MacFontRun(this, _wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
 		_defaultFormatting.font = wm->_fontMan->getFont(*macFont);
@@ -212,6 +224,9 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const Font *f
 	_encodeType = Common::kUtf8;
 	_plainByteMode = false;
 
+	_charMap = nullptr;
+	_fontXPlatformMap = nullptr;
+
 	if (font) {
 		_defaultFormatting = MacFontRun(this, _wm, font, 0, font->getFontHeight(), 0, 0, 0);
 		_defaultFormatting.font = font;
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index d34cdce688..e92c998294 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -39,6 +39,10 @@ class MacText;
 class MacWidget;
 class MacWindow;
 class MacWindowManager;
+struct FontXPlatformInfo;
+
+typedef Common::HashMap<byte, byte> CharMap;
+typedef Common::HashMap<uint16, FontXPlatformInfo *> FontXPlatformMap;
 
 struct MacFontRun {
 	Common::U32String text;
@@ -148,8 +152,8 @@ struct SelectedText {
 
 class MacText : public MacWidget {
 public:
-	MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::U32String &s, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment = kTextAlignLeft, int interlinear = 0, uint16 border = 0, uint16 gutter = 0, uint16 boxShadow = 0, uint16 textShadow = 0, bool fixedDims = true);
-	MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::String &s, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment = kTextAlignLeft, int interlinear = 0, uint16 border = 0, uint16 gutter = 0, uint16 boxShadow = 0, uint16 textShadow = 0, Common::CodePage encodeType = Common::kMacCentralEurope, bool fixedDims = true);
+	MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::U32String &s, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment = kTextAlignLeft, int interlinear = 0, uint16 border = 0, uint16 gutter = 0, uint16 boxShadow = 0, uint16 textShadow = 0, bool fixedDims = true, CharMap *charMap = nullptr, FontXPlatformMap *fontXPlatformMap = nullptr);
+	MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager *wm, const Common::String &s, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment = kTextAlignLeft, int interlinear = 0, uint16 border = 0, uint16 gutter = 0, uint16 boxShadow = 0, uint16 textShadow = 0, Common::CodePage encodeType = Common::kMacCentralEurope, bool fixedDims = true, CharMap *charMap = nullptr, FontXPlatformMap *fontXPlatformMap = nullptr);
 	// 0 pixels between the lines by default
 
 	MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear = 0, bool fixedDims = true);
@@ -300,6 +304,9 @@ public:
 
 	bool _fullRefresh;
 
+	CharMap *_charMap;
+	FontXPlatformMap *_fontXPlatformMap;
+
 protected:
 	Common::U32String _str;
 	const MacFont *_macFont;


Commit: 3fda461d5f961f6d9ae347a39767dbfa70c54e82
    https://github.com/scummvm/scummvm/commit/3fda461d5f961f6d9ae347a39767dbfa70c54e82
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-05T22:54:14-04:00

Commit Message:
GRAPHICS: MACGUI: Handle FontXPlatformMap in MacFontManager::getFont

Changed paths:
    graphics/macgui/macfontmanager.cpp
    graphics/macgui/macfontmanager.h
    graphics/macgui/mactext.cpp


diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index f8a827aa3b..504a5cd248 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -313,20 +313,30 @@ void MacFontManager::loadFonts(Common::MacResManager *fontFile) {
 	}
 }
 
-const Font *MacFontManager::getFont(MacFont macFont) {
+const Font *MacFontManager::getFont(MacFont macFont, FontXPlatformMap *fontXPlatformMap) {
+	int id = macFont.getId();
+	int size = macFont.getSize();
+	if (fontXPlatformMap && fontXPlatformMap->contains(id)) {
+		FontXPlatformInfo *info = (*fontXPlatformMap)[id];
+		id = info->toFont;
+		if (info->sizeMap.contains(size)) {
+			size = info->sizeMap[size];
+		}
+	}
+
 	Common::String name;
 	const Font *font = 0;
 
 	if (!_builtInFonts) {
 		if (macFont.getName().empty()) {
-			name = getFontName(macFont.getId(), macFont.getSize(), macFont.getSlant());
+			name = getFontName(id, size, macFont.getSlant());
 			macFont.setName(name);
 		}
 
 		if (!_fontRegistry.contains(macFont.getName())) {
 			// Let's try to generate name
 			if (macFont.getSlant() != kMacFontRegular) {
-				name = getFontName(macFont.getId(), macFont.getSize(), macFont.getSlant(), true);
+				name = getFontName(id, size, macFont.getSlant(), true);
 				macFont.setName(name);
 			}
 
@@ -346,16 +356,16 @@ const Font *MacFontManager::getFont(MacFont macFont) {
 #ifdef USE_FREETYPE2
 	if (!font) {
 		if (_mode & kWMModeUnicode) {
-			if (macFont.getSize() <= 0) {
+			if (size <= 0) {
 				debug(1, "MacFontManager::getFont() - Font size <= 0!");
 			}
-			Common::HashMap<int, const Graphics::Font *>::iterator pFont = _uniFonts.find(macFont.getSize());
+			Common::HashMap<int, const Graphics::Font *>::iterator pFont = _uniFonts.find(size);
 
 			if (pFont != _uniFonts.end()) {
 				font = pFont->_value;
 			} else {
-				font = Graphics::loadTTFFontFromArchive("FreeSans.ttf", macFont.getSize(), Graphics::kTTFSizeModeCharacter, 0, Graphics::kTTFRenderModeMonochrome);
-				_uniFonts[macFont.getSize()] = font;
+				font = Graphics::loadTTFFontFromArchive("FreeSans.ttf", size, Graphics::kTTFSizeModeCharacter, 0, Graphics::kTTFRenderModeMonochrome);
+				_uniFonts[size] = font;
 			}
 		}
 	}
diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
index 6ebf6f0383..21976175ec 100644
--- a/graphics/macgui/macfontmanager.h
+++ b/graphics/macgui/macfontmanager.h
@@ -126,9 +126,10 @@ public:
 	 * 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.
+	 * @param fontXPlatformMap an optional map from Windows fonts to Mac fonts or vice versa
 	 * @return The requested font or the fallback.
 	 */
-	const Font *getFont(MacFont macFont);
+	const Font *getFont(MacFont macFont, FontXPlatformMap *fontXPlatformMap = nullptr);
 
 	/**
 	 * Return font name from standard ID
diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 2c1fcbd99d..84bce45a83 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -56,7 +56,7 @@ const Font *MacFontRun::getFont() {
 
 	MacFont macFont = MacFont(fontId, fontSize, textSlant);
 
-	font = wm->_fontMan->getFont(macFont);
+	font = wm->_fontMan->getFont(macFont, parent->_fontXPlatformMap);
 
 	return font;
 }
@@ -115,7 +115,7 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
 
 	if (macFont) {
 		_defaultFormatting = MacFontRun(this, _wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
-		_defaultFormatting.font = wm->_fontMan->getFont(*macFont);
+		_defaultFormatting.font = wm->_fontMan->getFont(*macFont, _fontXPlatformMap);
 	} else {
 		_defaultFormatting.font = NULL;
 	}
@@ -143,7 +143,7 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
 
 	if (macFont) {
 		_defaultFormatting = MacFontRun(this, _wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
-		_defaultFormatting.font = wm->_fontMan->getFont(*macFont);
+		_defaultFormatting.font = wm->_fontMan->getFont(*macFont, _fontXPlatformMap);
 	} else {
 		_defaultFormatting.font = NULL;
 	}
@@ -172,7 +172,7 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont
 
 	if (macFont) {
 		_defaultFormatting = MacFontRun(this, _wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
-		_defaultFormatting.font = wm->_fontMan->getFont(*macFont);
+		_defaultFormatting.font = wm->_fontMan->getFont(*macFont, _fontXPlatformMap);
 	} else {
 		_defaultFormatting.font = NULL;
 	}
@@ -200,7 +200,7 @@ MacText::MacText(const Common::String &s, MacWindowManager *wm, const MacFont *m
 
 	if (macFont) {
 		_defaultFormatting = MacFontRun(this, _wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
-		_defaultFormatting.font = wm->_fontMan->getFont(*macFont);
+		_defaultFormatting.font = wm->_fontMan->getFont(*macFont, _fontXPlatformMap);
 	} else {
 		_defaultFormatting.font = NULL;
 	}
@@ -462,7 +462,7 @@ void MacText::setDefaultFormatting(uint16 fontId, byte textSlant, uint16 fontSiz
 
 	MacFont macFont = MacFont(fontId, fontSize, textSlant);
 
-	_defaultFormatting.font = _wm->_fontMan->getFont(macFont);
+	_defaultFormatting.font = _wm->_fontMan->getFont(macFont, _fontXPlatformMap);
 }
 
 static const Common::U32String::value_type *readHex(uint16 *res, const Common::U32String::value_type *s, int len) {


Commit: 4dabee7e8b26a6fd170e27ff6dd4bfdf67faec67
    https://github.com/scummvm/scummvm/commit/4dabee7e8b26a6fd170e27ff6dd4bfdf67faec67
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-05T22:54:18-04:00

Commit Message:
DIRECTOR: Clean up char/font mapping registration

Changed paths:
    engines/director/fonts.cpp


diff --git a/engines/director/fonts.cpp b/engines/director/fonts.cpp
index 0d9bfec1d3..f18c4dbee4 100644
--- a/engines/director/fonts.cpp
+++ b/engines/director/fonts.cpp
@@ -336,9 +336,7 @@ bool Cast::readFXmpLine(Common::SeekableReadStreamEndian &stream) {
 
 			// TODO: We should fill _charMap with mappings matching the current platform.
 			// We only have Mac fonts right now, though, so we'll always use the Win => Mac mappings.
-			if (fromPlatform == Common::kPlatformMacintosh) {
-				debugC(3, kDebugLoading, "Cast::readFXmpLine: Mapping Mac char %d to Win char %d", fromChar, toChar);
-			} else {
+			if (fromPlatform == Common::kPlatformWindows) {
 				_charMap[fromChar] = toChar;
 				debugC(3, kDebugLoading, "Cast::readFXmpLine: Mapping Win char %d to Mac char %d", fromChar, toChar);
 			}
@@ -416,15 +414,15 @@ bool Cast::readFXmpLine(Common::SeekableReadStreamEndian &stream) {
 
 		// TODO: We should fill _fontXPlatformMap with mappings matching the current platform.
 		// We only have Mac fonts right now, though, so we'll always use the Win => Mac mappings.
-		if (fromPlatform == Common::kPlatformMacintosh) {
-			debugC(3, kDebugLoading, "Cast::readFXmpLine: Mapping Mac font '%s' (%d) to Win font '%s' (%d)", fromFont.c_str(), fromFontId, toFont.c_str(), toFontId);
-		} else {
+		if (fromPlatform == Common::kPlatformWindows) {
 			_fontXPlatformMap[fromFontId] = info;
 			debugC(3, kDebugLoading, "Cast::readFXmpLine: Mapping Win font '%s' (%d) to Mac font '%s' (%d)", fromFont.c_str(), fromFontId, toFont.c_str(), toFontId);
-		}
-		debugC(4, kDebugLoading, "  Remap characters: %d", info->remapChars);
-		for (Graphics::FontSizeMap::iterator it = info->sizeMap.begin(); it != info->sizeMap.end(); ++it) {
-			debugC(4, kDebugLoading, "  Mapping size %d to %d", it->_key, it->_value);
+			debugC(4, kDebugLoading, "  Remap characters: %d", info->remapChars);
+			for (Graphics::FontSizeMap::iterator it = info->sizeMap.begin(); it != info->sizeMap.end(); ++it) {
+				debugC(4, kDebugLoading, "  Mapping size %d to %d", it->_key, it->_value);
+			}
+		} else {
+			delete info;
 		}
 	}
 




More information about the Scummvm-git-logs mailing list