[Scummvm-git-logs] scummvm master -> f1ddc4b346fb3d2cea5d9ae380a80b69d5264cd7

djsrv dservilla at gmail.com
Mon Jul 12 04:41:18 UTC 2021


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

Summary:
6cfed5099e DIRECTOR: Remove Cast::getString
6408f6023a DIRECTOR: Rename FontInfo to FontMapEntry
b7c40b3d37 GRAPHICS: MACGUI: Create font info dictionary
f39e6eaac7 GRAPHICS: MACGUI: Add Japanese font info
fcb4649b14 DEVTOOLS: Add script to extract Japanese Mac fonts
b57f6d8b7f GRAPHICS: MACGUI: Allow fonts to be registered to a preferred ID
e1d375a6d1 DIRECTOR: Register fonts to original ID if possible
53f600846b GRAPHICS: MACGUI: Fix fallback of Japanese fonts to Osaka
50cec75fd5 GRAPHICS: MACGUI: Remove changing font ID 3 to 1
ed406150c2 GRAPHICS: MACGUI: Add font name from Alan Kay demo
71d4127b8a GRAPHICS: MACGUI: Store font lang and encoding
acb3ace45e GRAPHICS: MACGUI: Detect Japanese fonts from preferred ID
2e3b08017f GRAPHICS: MACGUI: Whitespace cleanup
f4d2b75342 GRAPHICS: MACGUI: Set default encodings in registerFontName
5bc3ad06c0 GRAPHICS: MACGUI: Move encoding tracking to MacFontRun
63b69aa91e DIRECTOR: Create function to detect encoding from font
f1ddc4b346 DIRECTOR: Handle STXT encoding


Commit: 6cfed5099ef812d67318b0e9987f895afe61c211
    https://github.com/scummvm/scummvm/commit/6cfed5099ef812d67318b0e9987f895afe61c211
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-12T00:38:05-04:00

Commit Message:
DIRECTOR: Remove Cast::getString

This is no longer used for loading cast info.

Changed paths:
    engines/director/cast.cpp
    engines/director/cast.h


diff --git a/engines/director/cast.cpp b/engines/director/cast.cpp
index 6cfae51ad9..0b7e93649c 100644
--- a/engines/director/cast.cpp
+++ b/engines/director/cast.cpp
@@ -181,29 +181,6 @@ void Cast::setCastMemberModified(int castId) {
 	cast->setModified(true);
 }
 
-Common::String Cast::getString(Common::String str) {
-	if (str.size() == 0) {
-		return str;
-	}
-
-	uint8 f = static_cast<uint8>(str.firstChar());
-
-	if (f == 0) {
-		return "";
-	}
-
-	//TODO: check if all versions need to cut off the first character.
-	if (_version >= kFileVer400) {
-		str.deleteChar(0);
-	}
-
-	if (str.lastChar() == '\x00') {
-		str.deleteLastChar();
-	}
-
-	return str;
-}
-
 void Cast::setArchive(Archive *archive) {
 	_castArchive = archive;
 
diff --git a/engines/director/cast.h b/engines/director/cast.h
index 08d9249536..b38d936784 100644
--- a/engines/director/cast.h
+++ b/engines/director/cast.h
@@ -105,7 +105,6 @@ private:
 	void loadFontMapV4(Common::SeekableReadStreamEndian &stream);
 	void loadFXmp(Common::SeekableReadStreamEndian &stream);
 	bool readFXmpLine(Common::SeekableReadStreamEndian &stream);
-	Common::String getString(Common::String str);
 
 public:
 	Archive *_castArchive;


Commit: 6408f6023ab9ac8f22e58eec9090616b92ffbc92
    https://github.com/scummvm/scummvm/commit/6408f6023ab9ac8f22e58eec9090616b92ffbc92
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-12T00:38:05-04:00

Commit Message:
DIRECTOR: Rename FontInfo to FontMapEntry

Changed paths:
    engines/director/cast.h
    engines/director/fonts.cpp
    engines/director/stxt.cpp


diff --git a/engines/director/cast.h b/engines/director/cast.h
index b38d936784..543121e8a2 100644
--- a/engines/director/cast.h
+++ b/engines/director/cast.h
@@ -57,14 +57,14 @@ struct FontXPlatformInfo {
 };
 typedef Common::HashMap<Common::String, FontXPlatformInfo *> FontXPlatformMap;
 
-struct FontInfo {
+struct FontMapEntry {
 	uint16 toFont;
 	bool remapChars;
 	FontSizeMap sizeMap;
 
-	FontInfo() : toFont(0), remapChars(false) {}
+	FontMapEntry() : toFont(0), remapChars(false) {}
 };
-typedef Common::HashMap<uint16, FontInfo *> FontMap;
+typedef Common::HashMap<uint16, FontMapEntry *> FontMap;
 
 class Cast {
 public:
diff --git a/engines/director/fonts.cpp b/engines/director/fonts.cpp
index f56654ed19..4fd847c84f 100644
--- a/engines/director/fonts.cpp
+++ b/engines/director/fonts.cpp
@@ -55,9 +55,9 @@ void Cast::loadFontMap(Common::SeekableReadStreamEndian &stream) {
 		}
 
 		// Map cast font ID to window manager font ID
-		FontInfo *info = new FontInfo;
-		info->toFont = _vm->_wm->_fontMan->registerFontName(font);
-		_fontMap[id] = info;
+		FontMapEntry *entry = new FontMapEntry;
+		entry->toFont = _vm->_wm->_fontMan->registerFontName(font);
+		_fontMap[id] = entry;
 
 		debugC(3, kDebugLoading, "Cast::loadFontMap: Mapping font %d (%s) to %d", id, font.c_str(), _fontMap[id]->toFont);
 		currentRawPosition = stream.pos();
@@ -94,16 +94,16 @@ void Cast::loadFontMapV4(Common::SeekableReadStreamEndian &stream) {
 		uint16 id = stream.readUint16();
 
 		// Map cast font ID to window manager font ID
-		FontInfo *info = new FontInfo;
+		FontMapEntry *entry = new FontMapEntry;
 		if (platform == Common::kPlatformWindows && _fontXPlatformMap.contains(name)) {
 			FontXPlatformInfo *xinfo = _fontXPlatformMap[name];
-			info->toFont = _vm->_wm->_fontMan->registerFontName(xinfo->toFont);
-			info->remapChars = xinfo->remapChars;
-			info->sizeMap = xinfo->sizeMap;
+			entry->toFont = _vm->_wm->_fontMan->registerFontName(xinfo->toFont);
+			entry->remapChars = xinfo->remapChars;
+			entry->sizeMap = xinfo->sizeMap;
 		} else {
-			info->toFont = _vm->_wm->_fontMan->registerFontName(name);
+			entry->toFont = _vm->_wm->_fontMan->registerFontName(name);
 		}
-		_fontMap[id] = info;
+		_fontMap[id] = entry;
 
 		debugC(3, kDebugLoading, "Cast::loadFontMapV4: Mapping %s font %d (%s) to %d", getPlatformAbbrev(platform), id, name.c_str(), _fontMap[id]->toFont);
 	}
diff --git a/engines/director/stxt.cpp b/engines/director/stxt.cpp
index bef7e6e1ae..9ffd5a7060 100644
--- a/engines/director/stxt.cpp
+++ b/engines/director/stxt.cpp
@@ -130,7 +130,7 @@ void FontStyle::read(Common::ReadStreamEndian &stream, Cast *cast) {
 	b = stream.readUint16();
 
 	if (cast->_fontMap.contains(originalFontId)) {
-		FontInfo *info = cast->_fontMap[originalFontId];
+		FontMapEntry *info = cast->_fontMap[originalFontId];
 		fontId = info->toFont;
 		if (info->sizeMap.contains(originalHeight)) {
 			height = info->sizeMap[height];


Commit: b7c40b3d378293a517ee00a6acc0fab2b936e4fc
    https://github.com/scummvm/scummvm/commit/b7c40b3d378293a517ee00a6acc0fab2b936e4fc
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-12T00:38:05-04:00

Commit Message:
GRAPHICS: MACGUI: Create font info dictionary

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


diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index f8a827aa3b..7c8bd62b9f 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -34,46 +34,39 @@ namespace Graphics {
 
 // Source: Apple IIGS Technical Note #41, "Font Family Numbers"
 // http://apple2.boldt.ca/?page=til/tn.iigs.041
-static const char *const defaultFontNames[] = {
-	"Chicago",	// system font
-	"Geneva",	// application font
-	"New York",
-	NULL, // FIXME: "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"
+static struct FontProto {
+	int id;
+	FontCharSet charset;
+	int fallbackId;
+	const char *name;
+} defaultFonts[] = {
+	// Latin
+	{ 0,		kCharsLatin,	-1,		"Chicago" }, // system font
+	{ 1,		kCharsLatin,	-1,		"Geneva" }, // application font
+	{ 2,		kCharsLatin,	-1,		"New York" },
+	{ 3,		kCharsLatin,	-1,		"Geneva" },
+	{ 4,		kCharsLatin,	-1,		"Monaco" },
+	{ 5,		kCharsLatin,	-1,		"Venice" },
+	{ 6,		kCharsLatin,	-1,		"London" },
+	{ 7,		kCharsLatin,	-1,		"Athens" },
+	{ 8,		kCharsLatin,	-1,		"San Francisco" },
+	{ 9,		kCharsLatin,	-1,		"Toronto" },
+	{ 11,		kCharsLatin,	-1,		"Cairo" },
+	{ 12,		kCharsLatin,	-1,		"Los Angeles" },
+	{ 13,		kCharsLatin,	-1,		"Zapf Dingbats" },
+	{ 14,		kCharsLatin,	-1,		"Bookman" },
+	{ 15,		kCharsLatin,	-1,		"Helvetica Narrow" },
+	{ 16,		kCharsLatin,	-1,		"Palatino" },
+	{ 18,		kCharsLatin,	-1,		"Zapf Chancery" },
+	{ 20,		kCharsLatin,	-1,		"Times" }, // 20
+	{ 21,		kCharsLatin,	-1,		"Helvetica" },
+	{ 22,		kCharsLatin,	-1,		"Courier" },
+	{ 23,		kCharsLatin,	-1,		"Symbol" },
+	{ 24,		kCharsLatin,	-1,		"Taliesin" }, // mobile?
+	{ 33,		kCharsLatin,	-1,		"Avant Garde" },
+	{ 34,		kCharsLatin,	-1,		"New Century Schoolbook" },
+
+	{ -1,		kCharsUnknown,	-1,		NULL }
 };
 
 static const char *const fontStyleSuffixes[] = {
@@ -110,22 +103,30 @@ Common::String cleanFontName(const Common::String fontname) {
 }
 
 MacFontManager::MacFontManager(uint32 mode) : _mode(mode) {
-	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());
+	for (FontProto *font = defaultFonts; font->name; font++) {
+		if (!_fontInfo.contains(font->id)) {
+			FontInfo *info = new FontInfo;
+			info->charset = font->charset;
+			info->fallbackId = font->fallbackId;
+			info->name = font->name;
+			_fontInfo[font->id] = info;
 		}
+		if (!_fontIds.contains(font->name)) {
+			_fontIds[font->name] = font->id;
+		}
+	}
 
 	if (_mode & MacGUIConstants::kWMModeForceBuiltinFonts) {
 		_builtInFonts = true;
 	} else {
 		loadFonts();
 	}
+	_nextFontId = 100;
 }
 
 MacFontManager::~MacFontManager() {
+	for (Common::HashMap<int, FontInfo *>::iterator it = _fontInfo.begin(); it != _fontInfo.end(); it++)
+		delete it->_value;
 	for (Common::HashMap<int, const Graphics::Font *>::iterator it = _uniFonts.begin(); it != _uniFonts.end(); it++)
 		delete it->_value;
 	for (Common::HashMap<int, Common::SeekableReadStream *>::iterator it = _ttfData.begin(); it != _ttfData.end(); it++)
@@ -216,6 +217,49 @@ void MacFontManager::loadFonts() {
 	delete dat;
 }
 
+void MacFontManager::loadJapaneseFonts() {
+	if (_japaneseFontsLoaded)
+		return;
+
+#ifdef USE_FREETYPE2
+	Common::Archive *dat;
+
+	dat = Common::makeZipArchive("japanesemacfonts.dat");
+
+	if (!dat) {
+		warning("Could not find japanesemacfonts.dat");
+		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());
+		Common::String fontName = (*it)->getName();
+
+		// Trim the .ttf extension
+		for (int i = fontName.size() - 1; i >= 0; --i) {
+			if (fontName[i] == '.') {
+				while ((uint)i < fontName.size()) {
+					fontName.deleteLastChar();
+				}
+				break;
+			}
+		}
+
+		_ttfData[_fontIds.getValOrDefault(fontName, kMacFontNonStandard)] = stream;
+	}
+
+	delete dat;
+#else
+	warning("Japanese fonts require FreeType");
+#endif
+
+	// Set this to true even if we don't have FreeType so we don't spam warnings.
+	_japaneseFontsLoaded = true;
+}
+
 void MacFontManager::loadFonts(Common::SeekableReadStream *stream) {
 	Common::MacResManager fontFile;
 
@@ -412,35 +456,30 @@ int MacFontManager::registerFontName(Common::String name) {
 	if (_fontIds.contains(name))
 		return _fontIds[name];
 
-	_fontNames.push_back(name);
-	_fontIds[name] = _fontNames.size() - 1;
-	return _fontNames.size() - 1;
+	FontInfo *info = new FontInfo;
+	info->name = name;
+	_fontInfo[_nextFontId] = info;
+	_fontIds[name] = _nextFontId;
+	return _nextFontId++;
 }
 void MacFont::setName(const char *name) {
 	_name = name;
 }
 
 const Common::String MacFontManager::getFontName(uint16 id, int size, int slant, bool tryGen) {
-	Common::String n;
-
-	if (id == 3) // This is Geneva
-		id = 1;
+	if (_fontInfo[id]->fallbackId > -1)
+		id = _fontInfo[id]->fallbackId ;
 
-	int extraSlant = 0;
-
-	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(_fontNames[id]);
-	}
+	Common::String rawName = _fontInfo[id]->name;
+	Common::String n = cleanFontName(rawName);
+	int extraSlant = parseFontSlant(rawName);
+	// let's try parse slant from name
+	if (!extraSlant)
+		extraSlant = parseSlantFromName(rawName);
 
 	if (n.empty()) {
 		warning("MacFontManager: Requested font ID %d not found. Falling back to Geneva", id);
-		n = _fontNames[1]; // Fallback to Geneva
+		n = "Geneva";
 	}
 
 	return Common::String::format("%s-%d-%d", n.c_str(), slant | extraSlant, size);
diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
index 0eac4ee4f0..8df9098c00 100644
--- a/graphics/macgui/macfontmanager.h
+++ b/graphics/macgui/macfontmanager.h
@@ -64,8 +64,22 @@ enum {
 	kMacFontExtend = 64
 };
 
+enum FontCharSet {
+	kCharsUnknown,
+	kCharsLatin,
+	kCharsJapanese
+};
+
 class Font;
 
+struct FontInfo {
+	FontCharSet charset;
+	int fallbackId;
+	Common::String name;
+
+	FontInfo() : charset(kCharsUnknown), fallbackId(-1) {}
+};
+
 class MacFont {
 public:
 	MacFont(int id = kMacFontChicago, int size = 12, int slant = kMacFontRegular, FontManager::FontUsage fallback = Graphics::FontManager::kBigGUIFont) {
@@ -161,8 +175,9 @@ private:
 	uint32 _mode;
 	Common::HashMap<Common::String, MacFont *> _fontRegistry;
 
-	Common::Array<Common::String> _fontNames;
-	Common::HashMap<Common::String, uint16> _fontIds;
+	uint16 _nextFontId;
+	Common::HashMap<int, FontInfo *> _fontInfo;
+	Common::HashMap<Common::String, int> _fontIds;
 
 	int parseFontSlant(Common::String slant);
 


Commit: f39e6eaac714f567ecd10846e21710b955058e0c
    https://github.com/scummvm/scummvm/commit/f39e6eaac714f567ecd10846e21710b955058e0c
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-12T00:38:05-04:00

Commit Message:
GRAPHICS: MACGUI: Add Japanese font info

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


diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 7c8bd62b9f..75f91f35e1 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -66,6 +66,17 @@ static struct FontProto {
 	{ 33,		kCharsLatin,	-1,		"Avant Garde" },
 	{ 34,		kCharsLatin,	-1,		"New Century Schoolbook" },
 
+	// Japanese (names are Shift JIS encoded)
+	{ 16384,	kCharsJapanese,	-1,		"Osaka" },
+	{ 16433,	kCharsJapanese,	16436,	"\x93\x99\x95\x9D\x83\x53\x83\x56\x83\x62\x83\x4E" }, // Mono Gothic
+	{ 16435,	kCharsJapanese,	16436,	"\x93\x99\x95\x9D\x96\xBE\x92\xA9" }, // Mono Ming
+	{ 16436,	kCharsJapanese,	-1,		"Osaka\x81\x7C\x93\x99\x95\x9D" }, // Osaka Mono
+	{ 16436,	kCharsJapanese,	-1,		"OsakaMono" }, // redundant entry is to register English name
+	{ 16640,	kCharsJapanese,	16384,	"\x92\x86\x83\x53\x83\x56\x83\x62\x83\x4E\x91\xCC" }, // Medium Gothic
+	{ 16641,	kCharsJapanese,	16384,	"\x8D\xD7\x96\xBE\x92\xA9\x91\xCC" }, // Ming
+	{ 16700,	kCharsJapanese,	16384,	"\x95\xBD\x90\xAC\x96\xBE\x92\xA9" }, // Heisi Mincho
+	{ 16701,	kCharsJapanese,	16384,	"\x95\xBD\x90\xAC\x8A\x70\x83\x53\x83\x56\x83\x62\x83\x4E" }, // Heisei Kaku Gothic
+
 	{ -1,		kCharsUnknown,	-1,		NULL }
 };
 
@@ -121,6 +132,7 @@ MacFontManager::MacFontManager(uint32 mode) : _mode(mode) {
 	} else {
 		loadFonts();
 	}
+	_japaneseFontsLoaded = false;
 	_nextFontId = 100;
 }
 
@@ -362,6 +374,14 @@ const Font *MacFontManager::getFont(MacFont macFont) {
 	const Font *font = 0;
 
 	if (!_builtInFonts) {
+		if (_fontInfo.contains(macFont.getId())) {
+			if (_fontInfo[macFont.getId()]->charset == kCharsJapanese && !_japaneseFontsLoaded) {
+				loadJapaneseFonts();
+			}
+		} else {
+			warning("MacFontManager::getFont: No _fontInfo entry for font %d", macFont.getId());
+		}
+
 		if (macFont.getName().empty()) {
 			name = getFontName(macFont.getId(), macFont.getSize(), macFont.getSlant());
 			macFont.setName(name);
diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
index 8df9098c00..87469548a5 100644
--- a/graphics/macgui/macfontmanager.h
+++ b/graphics/macgui/macfontmanager.h
@@ -162,6 +162,7 @@ public:
 private:
 	void loadFontsBDF();
 	void loadFonts();
+	void loadJapaneseFonts();
 
 	void generateFontSubstitute(MacFont &macFont);
 	void generateFONTFont(MacFont &toFont, MacFont &fromFont);
@@ -172,6 +173,7 @@ private:
 
 private:
 	bool _builtInFonts;
+	bool _japaneseFontsLoaded;
 	uint32 _mode;
 	Common::HashMap<Common::String, MacFont *> _fontRegistry;
 


Commit: fcb4649b14341579965f812fd02000b98a4b5e15
    https://github.com/scummvm/scummvm/commit/fcb4649b14341579965f812fd02000b98a4b5e15
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-12T00:38:05-04:00

Commit Message:
DEVTOOLS: Add script to extract Japanese Mac fonts

Changed paths:
  A devtools/create_japanesemacfonts.sh


diff --git a/devtools/create_japanesemacfonts.sh b/devtools/create_japanesemacfonts.sh
new file mode 100644
index 0000000000..f3046ea543
--- /dev/null
+++ b/devtools/create_japanesemacfonts.sh
@@ -0,0 +1,94 @@
+#!/bin/bash
+#
+# This script downloads Mac OS X Lion installer from Apple and extracts fonts
+# from it. Mac only, unfortunately.
+
+echo_n() {
+	printf "$@"
+}
+
+if test `uname` != "Darwin"; then
+	echo This script is Mac OS X-only
+	exit
+fi
+
+echo "Downloading InstallMacOSX.dmg..."
+if test ! -f InstallMacOSX.dmg; then
+	curl https://updates.cdn-apple.com/2021/macos/041-7683-20210614-E610947E-C7CE-46EB-8860-D26D71F0D3EA/InstallMacOSX.dmg -o InstallMacOSX.dmg
+fi
+
+if test ! -f InstallMacOSX.dmg; then
+	echo "Cannot download InstallMacOSX.dmg"
+	exit
+fi
+
+echo "...Done"
+
+echo_n "Mounting InstallMacOSX.dmg..."
+
+hdiutil attach -quiet InstallMacOSX.dmg
+
+if test ! -f "/Volumes/Install Mac OS X/InstallMacOSX.pkg"; then
+	echo "Failed to attach InstallMacOSX.dmg"
+	exit
+fi
+
+echo done
+
+echo_n "Extracting InstallMacOSX.pkg..."
+
+pkgutil --expand "/Volumes/Install Mac OS X/InstallMacOSX.pkg" InstallMacOSX
+hdiutil detach -quiet `hdiutil info|grep "/Volumes/Install Mac OS X"|cut -f 1`
+
+if test ! -f InstallMacOSX/InstallMacOSX.pkg/InstallESD.dmg; then
+	echo "Failed to extract InstallMacOSX.pkg;"
+	exit
+fi
+
+echo done
+
+echo_n "Mounting InstallESD.dmg..."
+
+hdiutil attach -quiet -nobrowse InstallMacOSX/InstallMacOSX.pkg/InstallESD.dmg
+
+if test ! -f "/Volumes/Mac OS X Install ESD/Packages/Essentials.pkg"; then
+	echo "Failed to attach InstallESD.dmg"
+	exit
+fi
+
+echo done
+
+echo_n "Extracting Essentials.pkg..."
+
+pkgutil --expand-full "/Volumes/Mac OS X Install ESD/Packages/Essentials.pkg" Essentials
+hdiutil detach -quiet `hdiutil info|grep "/Volumes/Mac OS X Install ESD"|cut -f 1`
+
+if test ! -f Essentials/Payload/Library/Fonts/Osaka.ttf; then
+	echo "Failed to extract Essentials.pkg;"
+	exit
+fi
+
+echo done
+
+echo_n "Copying fonts..."
+
+for i in Osaka OsakaMono
+do
+	echo $i
+	cp "Essentials/Payload/Library/Fonts/$i.ttf" .
+done
+
+echo ...Done
+
+hdiutil detach -quiet `hdiutil info|grep "/Volumes/Fonts"|cut -f 1`
+
+zip -9 japanesemacfonts *.ttf
+mv japanesemacfonts.zip japanesemacfonts.dat
+
+echo_n "Cleaning up..."
+rm *.ttf
+rm -rf InstallMacOSX
+rm -rf Essentials
+echo done
+
+ls -l japanesemacfonts.dat


Commit: b57f6d8b7ff2de15d84e7ec7f7c1a591f8449b25
    https://github.com/scummvm/scummvm/commit/b57f6d8b7ff2de15d84e7ec7f7c1a591f8449b25
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-12T00:38:05-04:00

Commit Message:
GRAPHICS: MACGUI: Allow fonts to be registered to a preferred ID

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


diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 75f91f35e1..5072a06d03 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -133,7 +133,6 @@ MacFontManager::MacFontManager(uint32 mode) : _mode(mode) {
 		loadFonts();
 	}
 	_japaneseFontsLoaded = false;
-	_nextFontId = 100;
 }
 
 MacFontManager::~MacFontManager() {
@@ -468,7 +467,7 @@ int MacFontManager::parseSlantFromName(const Common::String &name) {
 	return slantVal;
 }
 
-int MacFontManager::registerFontName(Common::String name) {
+int MacFontManager::registerFontName(Common::String name, int preferredId) {
 	// Don't register an empty font name, just return Geneva's ID.
 	if (name.empty())
 		return 1;
@@ -476,11 +475,21 @@ int MacFontManager::registerFontName(Common::String name) {
 	if (_fontIds.contains(name))
 		return _fontIds[name];
 
+	int id;
+	if (preferredId > -1 && !_fontInfo.contains(id)) {
+		id = preferredId;
+	} else {
+		// Preferred ID is already registered, find an unused one.
+		id = 0;
+		while (_fontInfo.contains(id))
+			id++;
+	}
+
 	FontInfo *info = new FontInfo;
 	info->name = name;
-	_fontInfo[_nextFontId] = info;
-	_fontIds[name] = _nextFontId;
-	return _nextFontId++;
+	_fontInfo[id] = info;
+	_fontIds[name] = id;
+	return id;
 }
 void MacFont::setName(const char *name) {
 	_name = name;
diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
index 87469548a5..52061fb993 100644
--- a/graphics/macgui/macfontmanager.h
+++ b/graphics/macgui/macfontmanager.h
@@ -154,7 +154,7 @@ public:
 	 * @param name name of the font
 	 * @return the font's ID
 	 */
-	int registerFontName(Common::String name);
+	int registerFontName(Common::String name, int preferredId = -1);
 
 	void forceBuiltinFonts() { _builtInFonts = true; }
 	int parseSlantFromName(const Common::String &name);
@@ -177,7 +177,6 @@ private:
 	uint32 _mode;
 	Common::HashMap<Common::String, MacFont *> _fontRegistry;
 
-	uint16 _nextFontId;
 	Common::HashMap<int, FontInfo *> _fontInfo;
 	Common::HashMap<Common::String, int> _fontIds;
 


Commit: e1d375a6d1ce189da5081f82f459cfc06c583754
    https://github.com/scummvm/scummvm/commit/e1d375a6d1ce189da5081f82f459cfc06c583754
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-12T00:38:05-04:00

Commit Message:
DIRECTOR: Register fonts to original ID if possible

Changed paths:
    engines/director/fonts.cpp


diff --git a/engines/director/fonts.cpp b/engines/director/fonts.cpp
index 4fd847c84f..083cbc6e5d 100644
--- a/engines/director/fonts.cpp
+++ b/engines/director/fonts.cpp
@@ -56,7 +56,7 @@ void Cast::loadFontMap(Common::SeekableReadStreamEndian &stream) {
 
 		// Map cast font ID to window manager font ID
 		FontMapEntry *entry = new FontMapEntry;
-		entry->toFont = _vm->_wm->_fontMan->registerFontName(font);
+		entry->toFont = _vm->_wm->_fontMan->registerFontName(font, id);
 		_fontMap[id] = entry;
 
 		debugC(3, kDebugLoading, "Cast::loadFontMap: Mapping font %d (%s) to %d", id, font.c_str(), _fontMap[id]->toFont);
@@ -97,11 +97,11 @@ void Cast::loadFontMapV4(Common::SeekableReadStreamEndian &stream) {
 		FontMapEntry *entry = new FontMapEntry;
 		if (platform == Common::kPlatformWindows && _fontXPlatformMap.contains(name)) {
 			FontXPlatformInfo *xinfo = _fontXPlatformMap[name];
-			entry->toFont = _vm->_wm->_fontMan->registerFontName(xinfo->toFont);
+			entry->toFont = _vm->_wm->_fontMan->registerFontName(xinfo->toFont, id);
 			entry->remapChars = xinfo->remapChars;
 			entry->sizeMap = xinfo->sizeMap;
 		} else {
-			entry->toFont = _vm->_wm->_fontMan->registerFontName(name);
+			entry->toFont = _vm->_wm->_fontMan->registerFontName(name, id);
 		}
 		_fontMap[id] = entry;
 


Commit: 53f600846be1dbb90c84162a18c5064c1d3a9137
    https://github.com/scummvm/scummvm/commit/53f600846be1dbb90c84162a18c5064c1d3a9137
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-12T00:38:05-04:00

Commit Message:
GRAPHICS: MACGUI: Fix fallback of Japanese fonts to Osaka

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


diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 5072a06d03..887b4772cd 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -372,6 +372,14 @@ const Font *MacFontManager::getFont(MacFont macFont) {
 	Common::String name;
 	const Font *font = 0;
 
+	if (_fontInfo.contains(macFont.getId())) {
+		if (_fontInfo[macFont.getId()]->fallbackId > -1) {
+			macFont.setId(_fontInfo[macFont.getId()]->fallbackId);
+		}
+	} else {
+		warning("MacFontManager::getFont: No _fontInfo entry for font %d", macFont.getId());
+	}
+
 	if (!_builtInFonts) {
 		if (_fontInfo.contains(macFont.getId())) {
 			if (_fontInfo[macFont.getId()]->charset == kCharsJapanese && !_japaneseFontsLoaded) {
@@ -496,9 +504,6 @@ void MacFont::setName(const char *name) {
 }
 
 const Common::String MacFontManager::getFontName(uint16 id, int size, int slant, bool tryGen) {
-	if (_fontInfo[id]->fallbackId > -1)
-		id = _fontInfo[id]->fallbackId ;
-
 	Common::String rawName = _fontInfo[id]->name;
 	Common::String n = cleanFontName(rawName);
 	int extraSlant = parseFontSlant(rawName);
diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
index 52061fb993..e96634d2bb 100644
--- a/graphics/macgui/macfontmanager.h
+++ b/graphics/macgui/macfontmanager.h
@@ -93,6 +93,7 @@ public:
 	}
 
 	int getId() const { return _id; };
+	void setId(int id) { _id = id; }
 	int getSize() const { return _size; }
 	int getSlant() const { return _slant; }
 	Common::String getName() { return _name; }


Commit: 50cec75fd5e612afbaf59294dd0396ae778bd965
    https://github.com/scummvm/scummvm/commit/50cec75fd5e612afbaf59294dd0396ae778bd965
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-12T00:38:05-04:00

Commit Message:
GRAPHICS: MACGUI: Remove changing font ID 3 to 1

We register font ID 3 now.

Changed paths:
    graphics/macgui/macfontmanager.h


diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
index e96634d2bb..a11ee40fb6 100644
--- a/graphics/macgui/macfontmanager.h
+++ b/graphics/macgui/macfontmanager.h
@@ -83,7 +83,7 @@ struct FontInfo {
 class MacFont {
 public:
 	MacFont(int id = kMacFontChicago, int size = 12, int slant = kMacFontRegular, FontManager::FontUsage fallback = Graphics::FontManager::kBigGUIFont) {
-		_id = id == 3 ? 1 : id;	// Substitude duplicate "Geneva"
+		_id = id;
 		_size = size ? size : 12;
 		_slant = slant;
 		_fallback = fallback;


Commit: ed406150c26d0aa21f6454d6e16e4dd48ea7dbf7
    https://github.com/scummvm/scummvm/commit/ed406150c26d0aa21f6454d6e16e4dd48ea7dbf7
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-12T00:38:05-04:00

Commit Message:
GRAPHICS: MACGUI: Add font name from Alan Kay demo

Changed paths:
    graphics/macgui/macfontmanager.cpp


diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 887b4772cd..27b2ad5ad1 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -68,6 +68,7 @@ static struct FontProto {
 
 	// Japanese (names are Shift JIS encoded)
 	{ 16384,	kCharsJapanese,	-1,		"Osaka" },
+	{ 16396,	kCharsJapanese,	16384,	"\x96\x7B\x96\xBE\x92\xA9\x81\x7C\x82\x6C" }, // Book Mincho - M
 	{ 16433,	kCharsJapanese,	16436,	"\x93\x99\x95\x9D\x83\x53\x83\x56\x83\x62\x83\x4E" }, // Mono Gothic
 	{ 16435,	kCharsJapanese,	16436,	"\x93\x99\x95\x9D\x96\xBE\x92\xA9" }, // Mono Ming
 	{ 16436,	kCharsJapanese,	-1,		"Osaka\x81\x7C\x93\x99\x95\x9D" }, // Osaka Mono


Commit: 71d4127b8a0c2ca3a9a00274ff6af72d7c6e169d
    https://github.com/scummvm/scummvm/commit/71d4127b8a0c2ca3a9a00274ff6af72d7c6e169d
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-12T00:38:05-04:00

Commit Message:
GRAPHICS: MACGUI: Store font lang and encoding

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


diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 27b2ad5ad1..bc99ca2f1c 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -36,49 +36,50 @@ namespace Graphics {
 // http://apple2.boldt.ca/?page=til/tn.iigs.041
 static struct FontProto {
 	int id;
-	FontCharSet charset;
+	Common::Language lang;
+	Common::CodePage encoding;
 	int fallbackId;
 	const char *name;
 } defaultFonts[] = {
 	// Latin
-	{ 0,		kCharsLatin,	-1,		"Chicago" }, // system font
-	{ 1,		kCharsLatin,	-1,		"Geneva" }, // application font
-	{ 2,		kCharsLatin,	-1,		"New York" },
-	{ 3,		kCharsLatin,	-1,		"Geneva" },
-	{ 4,		kCharsLatin,	-1,		"Monaco" },
-	{ 5,		kCharsLatin,	-1,		"Venice" },
-	{ 6,		kCharsLatin,	-1,		"London" },
-	{ 7,		kCharsLatin,	-1,		"Athens" },
-	{ 8,		kCharsLatin,	-1,		"San Francisco" },
-	{ 9,		kCharsLatin,	-1,		"Toronto" },
-	{ 11,		kCharsLatin,	-1,		"Cairo" },
-	{ 12,		kCharsLatin,	-1,		"Los Angeles" },
-	{ 13,		kCharsLatin,	-1,		"Zapf Dingbats" },
-	{ 14,		kCharsLatin,	-1,		"Bookman" },
-	{ 15,		kCharsLatin,	-1,		"Helvetica Narrow" },
-	{ 16,		kCharsLatin,	-1,		"Palatino" },
-	{ 18,		kCharsLatin,	-1,		"Zapf Chancery" },
-	{ 20,		kCharsLatin,	-1,		"Times" }, // 20
-	{ 21,		kCharsLatin,	-1,		"Helvetica" },
-	{ 22,		kCharsLatin,	-1,		"Courier" },
-	{ 23,		kCharsLatin,	-1,		"Symbol" },
-	{ 24,		kCharsLatin,	-1,		"Taliesin" }, // mobile?
-	{ 33,		kCharsLatin,	-1,		"Avant Garde" },
-	{ 34,		kCharsLatin,	-1,		"New Century Schoolbook" },
+	{ 0,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Chicago" }, // system font
+	{ 1,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Geneva" }, // application font
+	{ 2,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"New York" },
+	{ 3,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Geneva" },
+	{ 4,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Monaco" },
+	{ 5,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Venice" },
+	{ 6,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"London" },
+	{ 7,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Athens" },
+	{ 8,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"San Francisco" },
+	{ 9,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Toronto" },
+	{ 11,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Cairo" },
+	{ 12,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Los Angeles" },
+	{ 13,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Zapf Dingbats" },
+	{ 14,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Bookman" },
+	{ 15,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Helvetica Narrow" },
+	{ 16,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Palatino" },
+	{ 18,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Zapf Chancery" },
+	{ 20,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Times" }, // 20
+	{ 21,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Helvetica" },
+	{ 22,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Courier" },
+	{ 23,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Symbol" },
+	{ 24,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Taliesin" }, // mobile?
+	{ 33,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"Avant Garde" },
+	{ 34,		Common::UNK_LANG,	Common::kMacCentralEurope,	-1,		"New Century Schoolbook" },
 
 	// Japanese (names are Shift JIS encoded)
-	{ 16384,	kCharsJapanese,	-1,		"Osaka" },
-	{ 16396,	kCharsJapanese,	16384,	"\x96\x7B\x96\xBE\x92\xA9\x81\x7C\x82\x6C" }, // Book Mincho - M
-	{ 16433,	kCharsJapanese,	16436,	"\x93\x99\x95\x9D\x83\x53\x83\x56\x83\x62\x83\x4E" }, // Mono Gothic
-	{ 16435,	kCharsJapanese,	16436,	"\x93\x99\x95\x9D\x96\xBE\x92\xA9" }, // Mono Ming
-	{ 16436,	kCharsJapanese,	-1,		"Osaka\x81\x7C\x93\x99\x95\x9D" }, // Osaka Mono
-	{ 16436,	kCharsJapanese,	-1,		"OsakaMono" }, // redundant entry is to register English name
-	{ 16640,	kCharsJapanese,	16384,	"\x92\x86\x83\x53\x83\x56\x83\x62\x83\x4E\x91\xCC" }, // Medium Gothic
-	{ 16641,	kCharsJapanese,	16384,	"\x8D\xD7\x96\xBE\x92\xA9\x91\xCC" }, // Ming
-	{ 16700,	kCharsJapanese,	16384,	"\x95\xBD\x90\xAC\x96\xBE\x92\xA9" }, // Heisi Mincho
-	{ 16701,	kCharsJapanese,	16384,	"\x95\xBD\x90\xAC\x8A\x70\x83\x53\x83\x56\x83\x62\x83\x4E" }, // Heisei Kaku Gothic
-
-	{ -1,		kCharsUnknown,	-1,		NULL }
+	{ 16384,	Common::JA_JPN,		Common::kUtf8,				-1,		"Osaka" },
+	{ 16396,	Common::JA_JPN,		Common::kUtf8,				16384,	"\x96\x7B\x96\xBE\x92\xA9\x81\x7C\x82\x6C" }, // Book Mincho - M
+	{ 16433,	Common::JA_JPN,		Common::kUtf8,				16436,	"\x93\x99\x95\x9D\x83\x53\x83\x56\x83\x62\x83\x4E" }, // Mono Gothic
+	{ 16435,	Common::JA_JPN,		Common::kUtf8,				16436,	"\x93\x99\x95\x9D\x96\xBE\x92\xA9" }, // Mono Ming
+	{ 16436,	Common::JA_JPN,		Common::kUtf8,				-1,		"Osaka\x81\x7C\x93\x99\x95\x9D" }, // Osaka Mono
+	{ 16436,	Common::JA_JPN,		Common::kUtf8,				-1,		"OsakaMono" }, // redundant entry is to register English name
+	{ 16640,	Common::JA_JPN,		Common::kUtf8,				16384,	"\x92\x86\x83\x53\x83\x56\x83\x62\x83\x4E\x91\xCC" }, // Medium Gothic
+	{ 16641,	Common::JA_JPN,		Common::kUtf8,				16384,	"\x8D\xD7\x96\xBE\x92\xA9\x91\xCC" }, // Ming
+	{ 16700,	Common::JA_JPN,		Common::kUtf8,				16384,	"\x95\xBD\x90\xAC\x96\xBE\x92\xA9" }, // Heisi Mincho
+	{ 16701,	Common::JA_JPN,		Common::kUtf8,				16384,	"\x95\xBD\x90\xAC\x8A\x70\x83\x53\x83\x56\x83\x62\x83\x4E" }, // Heisei Kaku Gothic
+
+	{ -1,		Common::UNK_LANG,	Common::kCodePageInvalid,	-1,		NULL }
 };
 
 static const char *const fontStyleSuffixes[] = {
@@ -118,7 +119,8 @@ MacFontManager::MacFontManager(uint32 mode) : _mode(mode) {
 	for (FontProto *font = defaultFonts; font->name; font++) {
 		if (!_fontInfo.contains(font->id)) {
 			FontInfo *info = new FontInfo;
-			info->charset = font->charset;
+			info->lang = font->lang;
+			info->encoding = font->encoding;
 			info->fallbackId = font->fallbackId;
 			info->name = font->name;
 			_fontInfo[font->id] = info;
@@ -383,7 +385,7 @@ const Font *MacFontManager::getFont(MacFont macFont) {
 
 	if (!_builtInFonts) {
 		if (_fontInfo.contains(macFont.getId())) {
-			if (_fontInfo[macFont.getId()]->charset == kCharsJapanese && !_japaneseFontsLoaded) {
+			if (_fontInfo[macFont.getId()]->lang == Common::JA_JPN && !_japaneseFontsLoaded) {
 				loadJapaneseFonts();
 			}
 		} else {
diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
index a11ee40fb6..82f7c94e61 100644
--- a/graphics/macgui/macfontmanager.h
+++ b/graphics/macgui/macfontmanager.h
@@ -23,6 +23,8 @@
 #ifndef GRAPHICS_MACGUI_MACFONTMANAGER_H
 #define GRAPHICS_MACGUI_MACFONTMANAGER_H
 
+#include "common/language.h"
+
 #include "graphics/fontman.h"
 
 namespace Common {
@@ -64,20 +66,15 @@ enum {
 	kMacFontExtend = 64
 };
 
-enum FontCharSet {
-	kCharsUnknown,
-	kCharsLatin,
-	kCharsJapanese
-};
-
 class Font;
 
 struct FontInfo {
-	FontCharSet charset;
+	Common::Language lang;
+	Common::CodePage encoding;
 	int fallbackId;
 	Common::String name;
 
-	FontInfo() : charset(kCharsUnknown), fallbackId(-1) {}
+	FontInfo() : lang(Common::UNK_LANG), encoding(Common::kCodePageInvalid), fallbackId(-1) {}
 };
 
 class MacFont {


Commit: acb3ace45e96ff04f105c8a352960d00c7bbce81
    https://github.com/scummvm/scummvm/commit/acb3ace45e96ff04f105c8a352960d00c7bbce81
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-12T00:38:05-04:00

Commit Message:
GRAPHICS: MACGUI: Detect Japanese fonts from preferred ID

Changed paths:
    graphics/macgui/macfontmanager.cpp


diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index bc99ca2f1c..270db1204e 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -498,6 +498,9 @@ int MacFontManager::registerFontName(Common::String name, int preferredId) {
 
 	FontInfo *info = new FontInfo;
 	info->name = name;
+	if (preferredId >= 16000) {
+		info->lang = Common::JA_JPN;
+	}
 	_fontInfo[id] = info;
 	_fontIds[name] = id;
 	return id;


Commit: 2e3b08017ff190726f64f3701c3a5a97fd319ff9
    https://github.com/scummvm/scummvm/commit/2e3b08017ff190726f64f3701c3a5a97fd319ff9
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-12T00:38:05-04:00

Commit Message:
GRAPHICS: MACGUI: Whitespace cleanup

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


diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 270db1204e..7d5334f8e8 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -375,21 +375,15 @@ const Font *MacFontManager::getFont(MacFont macFont) {
 	Common::String name;
 	const Font *font = 0;
 
-	if (_fontInfo.contains(macFont.getId())) {
-		if (_fontInfo[macFont.getId()]->fallbackId > -1) {
-			macFont.setId(_fontInfo[macFont.getId()]->fallbackId);
-		}
-	} else {
-		warning("MacFontManager::getFont: No _fontInfo entry for font %d", macFont.getId());
+	int fallbackId = getFontFallbackId(macFont.getId());
+	if (fallbackId > -1) {
+		macFont.setId(fallbackId);
 	}
 
 	if (!_builtInFonts) {
-		if (_fontInfo.contains(macFont.getId())) {
-			if (_fontInfo[macFont.getId()]->lang == Common::JA_JPN && !_japaneseFontsLoaded) {
-				loadJapaneseFonts();
-			}
-		} else {
-			warning("MacFontManager::getFont: No _fontInfo entry for font %d", macFont.getId());
+		Common::Language lang = getFontLanguage(macFont.getId());
+		if (lang == Common::JA_JPN && !_japaneseFontsLoaded) {
+			loadJapaneseFonts();
 		}
 
 		if (macFont.getName().empty()) {
@@ -505,6 +499,7 @@ int MacFontManager::registerFontName(Common::String name, int preferredId) {
 	_fontIds[name] = id;
 	return id;
 }
+
 void MacFont::setName(const char *name) {
 	_name = name;
 }
@@ -536,6 +531,30 @@ int MacFontManager::getFontIdByName(Common::String name) {
 	return 1;
 }
 
+Common::Language MacFontManager::getFontLanguage(uint16 id) {
+	if (!_fontInfo.contains(id)) {
+		warning("MacFontManager::getFontLanguage: No _fontInfo entry for font %d", id);
+		return Common::UNK_LANG;
+	}
+	return _fontInfo[id]->lang;
+}
+
+Common::CodePage MacFontManager::getFontEncoding(uint16 id) {
+	if (!_fontInfo.contains(id)) {
+		warning("MacFontManager::getFontEncoding: No _fontInfo entry for font %d", id);
+		return Common::kCodePageInvalid;
+	}
+	return _fontInfo[id]->encoding;
+}
+
+int MacFontManager::getFontFallbackId(uint16 id) {
+	if (!_fontInfo.contains(id)) {
+		warning("MacFontManager::getFontFallbackId: No _fontInfo entry for font %d", id);
+		return -1;
+	}
+	return _fontInfo[id]->fallbackId;
+}
+
 void MacFontManager::generateFontSubstitute(MacFont &macFont) {
 	Common::String name;
 
@@ -550,7 +569,6 @@ void MacFontManager::generateFontSubstitute(MacFont &macFont) {
 		}
 	}
 
-
 #ifdef USE_FREETYPE2
 	// Checking if it's a TTF font. Restrict it only to regular fonts now
 	if (_ttfData.contains(macFont.getId()) && macFont.getSlant() == kMacFontRegular) {
diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
index 82f7c94e61..a9002d9993 100644
--- a/graphics/macgui/macfontmanager.h
+++ b/graphics/macgui/macfontmanager.h
@@ -143,6 +143,10 @@ public:
 	const Common::String getFontName(MacFont &font);
 	int getFontIdByName(Common::String name);
 
+	Common::Language getFontLanguage(uint16 id);
+	Common::CodePage getFontEncoding(uint16 id);
+	int getFontFallbackId(uint16 id);
+
 	void loadFonts(Common::SeekableReadStream *stream);
 	void loadFonts(const Common::String &fileName);
 	void loadFonts(Common::MacResManager *fontFile);


Commit: f4d2b753426d5c0debccee2cd1ac804f90a1bfd2
    https://github.com/scummvm/scummvm/commit/f4d2b753426d5c0debccee2cd1ac804f90a1bfd2
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-12T00:38:05-04:00

Commit Message:
GRAPHICS: MACGUI: Set default encodings in registerFontName

Changed paths:
    graphics/macgui/macfontmanager.cpp


diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 7d5334f8e8..44c35340d9 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -494,6 +494,9 @@ int MacFontManager::registerFontName(Common::String name, int preferredId) {
 	info->name = name;
 	if (preferredId >= 16000) {
 		info->lang = Common::JA_JPN;
+		info->encoding = Common::kWindows932; // default to Shift JIS
+	} else {
+		info->encoding = Common::kMacCentralEurope;
 	}
 	_fontInfo[id] = info;
 	_fontIds[name] = id;


Commit: 5bc3ad06c0159c9119195ed5119402748e74b3aa
    https://github.com/scummvm/scummvm/commit/5bc3ad06c0159c9119195ed5119402748e74b3aa
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-12T00:38:05-04:00

Commit Message:
GRAPHICS: MACGUI: Move encoding tracking to MacFontRun

Font is basically the only way to determine a piece of text's encoding
in Director. Since MacFontRun tracks fonts, it's the nicest place to
handle encoding too.

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


diff --git a/graphics/macgui/mactext.cpp b/graphics/macgui/mactext.cpp
index 3f6be5657c..f123259ecf 100644
--- a/graphics/macgui/mactext.cpp
+++ b/graphics/macgui/mactext.cpp
@@ -71,6 +71,20 @@ bool MacFontRun::equals(MacFontRun &to) {
 		&& palinfo2 == to.palinfo2 && palinfo3 == to.palinfo3);
 }
 
+Common::CodePage MacFontRun::getEncoding() {
+	return wm->_fontMan->getFontEncoding(fontId);
+}
+
+bool MacFontRun::plainByteMode() {
+	Common::CodePage encoding = getEncoding();
+	return encoding != Common::kUtf8 && encoding != Common::kCodePageInvalid;
+}
+
+Common::String MacFontRun::getEncodedText() {
+	Common::CodePage encoding = getEncoding();
+	return Common::convertFromU32String(text, encoding);
+}
+
 uint MacTextLine::getChunkNum(int *col) {
 	int pos = *col;
 	uint i;
@@ -107,33 +121,6 @@ MacText::MacText(MacWidget *parent, int x, int y, int w, int h, MacWindowManager
 	_bgcolor = bgcolor;
 	_textShadow = textShadow;
 	_macFontMode = true;
-	_encodeType = Common::kUtf8;
-	_plainByteMode = false;
-
-	if (macFont) {
-		_defaultFormatting = MacFontRun(_wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
-		_defaultFormatting.font = wm->_fontMan->getFont(*macFont);
-	} else {
-		_defaultFormatting.font = NULL;
-	}
-
-	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) :
-	MacWidget(parent, x, y, w, h, wm, true, border, gutter, boxShadow),
-	_macFont(macFont), _maxWidth(maxWidth), _textAlignment(textAlignment), _interLinear(interlinear) {
-
-	_str = Common::U32String(s, encodeType);
-
-	_fixedDims = fixedDims;
-	_wm = wm;
-	_fgcolor = fgcolor;
-	_bgcolor = bgcolor;
-	_textShadow = textShadow;
-	_macFontMode = true;
-	_encodeType = encodeType;
-	_plainByteMode = true;
 
 	if (macFont) {
 		_defaultFormatting = MacFontRun(_wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
@@ -158,33 +145,6 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const MacFont
 	_bgcolor = bgcolor;
 	_textShadow = 0;
 	_macFontMode = true;
-	_encodeType = Common::kUtf8;
-	_plainByteMode = false;
-
-	if (macFont) {
-		_defaultFormatting = MacFontRun(_wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
-		_defaultFormatting.font = wm->_fontMan->getFont(*macFont);
-	} else {
-		_defaultFormatting.font = NULL;
-	}
-
-	init();
-}
-
-MacText::MacText(const Common::String &s, MacWindowManager *wm, const MacFont *macFont, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear, Common::CodePage encodeType, bool fixedDims) :
-	MacWidget(nullptr, 0, 0, 0, 0, wm, false, 0, 0, 0),
-	_macFont(macFont), _maxWidth(maxWidth), _textAlignment(textAlignment), _interLinear(interlinear) {
-
-	_str = Common::U32String(s, encodeType);
-
-	_fixedDims = fixedDims;
-	_wm = wm;
-	_fgcolor = fgcolor;
-	_bgcolor = bgcolor;
-	_textShadow = 0;
-	_macFontMode = true;
-	_encodeType = encodeType;
-	_plainByteMode = true;
 
 	if (macFont) {
 		_defaultFormatting = MacFontRun(_wm, macFont->getId(), macFont->getSlant(), macFont->getSize(), 0, 0, 0);
@@ -209,8 +169,6 @@ MacText::MacText(const Common::U32String &s, MacWindowManager *wm, const Font *f
 	_bgcolor = bgcolor;
 	_textShadow = 0;
 	_macFontMode = false;
-	_encodeType = Common::kUtf8;
-	_plainByteMode = false;
 
 	if (font) {
 		_defaultFormatting = MacFontRun(_wm, font, 0, font->getFontHeight(), 0, 0, 0);
@@ -316,11 +274,11 @@ MacFontRun MacText::getFgColor() {
 
 // we are doing this because we may need to dealing with the plain byte. See ctor of mactext which contains String str instead of U32String str
 // thus, if we are passing the str, meaning we are using plainByteMode. And when we calculating the string width. we need to convert it to it's orignal state first;
-int MacText::getStringWidth(const Font *font, const Common::U32String &str) {
-	if (_plainByteMode)
-		return font->getStringWidth(Common::convertFromU32String(str, _encodeType));
+int MacText::getStringWidth(MacFontRun &format, const Common::U32String &str) {
+	if (format.plainByteMode())
+		return format.getFont()->getStringWidth(Common::convertFromU32String(str, format.getEncoding()));
 	else
-		return font->getStringWidth(str);
+		return format.getFont()->getStringWidth(str);
 }
 
 void MacText::setMaxWidth(int maxWidth) {
@@ -752,7 +710,7 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
 				continue;
 			}
 			// calc word_width, the trick we define here is we don`t count the space
-			int word_width = getStringWidth(current_format.getFont(), tmp);
+			int word_width = getStringWidth(current_format, tmp);
 			// add all spaces left
 			while (*s == ' ') {
 				tmp += *s;
@@ -771,7 +729,7 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
 			}
 
 			for (int i = 1; i < (int)word.size(); i++) {
-				word_width += getStringWidth(word[i].getFont(), word[i].text);
+				word_width += getStringWidth(word[i], word[i].text);
 				D(9, "** word \"%s\" textslant [%d]", Common::toPrintable(word[i].text.encode()).c_str(), word[i].textSlant);
 			}
 
@@ -813,8 +771,8 @@ void MacText::splitString(const Common::U32String &str, int curLine) {
 
 						// here, if we are in the plainByteMode, then we need to get the original text width, because current font may not resolve that u32string
 						int char_width = 0;
-						if (_plainByteMode) {
-							char_width = word[i].getFont()->getCharWidth(Common::convertFromU32String(Common::U32String(it, 1), _encodeType)[0]);
+						if (word[i].plainByteMode()) {
+							char_width = word[i].getFont()->getCharWidth(Common::convertFromU32String(Common::U32String(it, 1), word[i].getEncoding())[0]);
 						} else {
 							char_width = word[i].getFont()->getCharWidth(c);
 						}
@@ -946,8 +904,8 @@ void MacText::render(int from, int to) {
 				yOffset = maxAscentForRow - _textLines[i].chunks[j].font->getFontAscent();
 			}
 
-			if (_plainByteMode) {
-				Common::String str = Common::convertFromU32String(_textLines[i].chunks[j].text, _encodeType);
+			if (_textLines[i].chunks[j].plainByteMode()) {
+				Common::String str = _textLines[i].chunks[j].getEncodedText();
 				_textLines[i].chunks[j].getFont()->drawString(_surface, str, xOffset, _textLines[i].y + yOffset, w, _textLines[i].chunks[j].fgcolor);
 				xOffset += _textLines[i].chunks[j].getFont()->getStringWidth(str);
 			} else {
@@ -990,14 +948,14 @@ int MacText::getLineWidth(int line, bool enforce, int col) {
 			} else {
 				Common::U32String tmp = _textLines[line].chunks[i].text.substr(0, col);
 
-				width += getStringWidth(_textLines[line].chunks[i].getFont(), tmp);
+				width += getStringWidth(_textLines[line].chunks[i], tmp);
 
 				return width;
 			}
 		}
 
 		if (!_textLines[line].chunks[i].text.empty()) {
-			width += getStringWidth(_textLines[line].chunks[i].getFont(), _textLines[line].chunks[i].text);
+			width += getStringWidth(_textLines[line].chunks[i], _textLines[line].chunks[i].text);
 			charwidth += _textLines[line].chunks[i].text.size();
 			hastext = true;
 		}
@@ -1237,10 +1195,6 @@ void MacText::appendText_(const Common::U32String &strWithFont, uint oldLen) {
 	}
 }
 
-void MacText::appendText(const Common::String &str, int fontId, int fontSize, int fontSlant, bool skipAdd) {
-	appendText(Common::U32String(str, _encodeType), fontId, fontSize, fontSlant, skipAdd);
-}
-
 void MacText::appendTextDefault(const Common::U32String &str, bool skipAdd) {
 	uint oldLen = _textLines.size();
 
@@ -1557,12 +1511,12 @@ void MacText::setSelection(int pos, bool start) {
 			if (pos < getLineCharWidth(row)) {
 				for (uint i = 0; i < _textLines[row].chunks.size(); i++) {
 					if ((uint)pos < _textLines[row].chunks[i].text.size()) {
-						colX += getStringWidth(_textLines[row].chunks[i].getFont(), _textLines[row].chunks[i].text.substr(0, pos));
+						colX += getStringWidth(_textLines[row].chunks[i], _textLines[row].chunks[i].text.substr(0, pos));
 						col += pos;
 						pos = 0;
 						break;
 					} else {
-						colX += getStringWidth(_textLines[row].chunks[i].getFont(), _textLines[row].chunks[i].text);
+						colX += getStringWidth(_textLines[row].chunks[i], _textLines[row].chunks[i].text);
 						pos -= _textLines[row].chunks[i].text.size();
 						col += _textLines[row].chunks[i].text.size();
 					}
@@ -1938,7 +1892,7 @@ void MacText::getRowCol(int x, int y, int *sx, int *sy, int *row, int *col) {
 		pwidth = width;
 		pmcol = mcol;
 		if (!_textLines[nrow].chunks[chunk].text.empty()) {
-			width += getStringWidth(_textLines[nrow].chunks[chunk].getFont(), _textLines[nrow].chunks[chunk].text);
+			width += getStringWidth(_textLines[nrow].chunks[chunk], _textLines[nrow].chunks[chunk].text);
 			mcol += _textLines[nrow].chunks[chunk].text.size();
 		}
 
@@ -1955,7 +1909,7 @@ void MacText::getRowCol(int x, int y, int *sx, int *sy, int *row, int *col) {
 	nsx = pwidth;
 
 	for (int i = str.size(); i >= 0; i--) {
-		int strw = getStringWidth(_textLines[nrow].chunks[chunk].getFont(), str);
+		int strw = getStringWidth(_textLines[nrow].chunks[chunk], str);
 		if (strw + pwidth + alignOffset <= x) {
 			ncol = pmcol + i;
 			nsx = strw + pwidth;
@@ -2144,10 +2098,6 @@ void MacText::setText(const Common::U32String &str) {
 	_contentIsDirty = true;
 }
 
-void MacText::setText(const Common::String &str) {
-	setText(Common::U32String(str, _encodeType));
-}
-
 //////////////////
 // Text editing
 void MacText::insertChar(byte c, int *row, int *col) {
@@ -2162,14 +2112,14 @@ void MacText::insertChar(byte c, int *row, int *col) {
 	int pos = *col;
 	uint ch = line->getChunkNum(&pos);
 
-	Common::U32String newchunk(line->chunks[ch].text, _encodeType);
+	Common::U32String newchunk = line->chunks[ch].text;
 
 	if (pos >= (int)newchunk.size())
 		newchunk += c;
 	else
 		newchunk.insertChar(c, pos);
-	int chunkw = getStringWidth(line->chunks[ch].getFont(), newchunk);
-	int oldw = getStringWidth(line->chunks[ch].getFont(), line->chunks[ch].text);
+	int chunkw = getStringWidth(line->chunks[ch], newchunk);
+	int oldw = getStringWidth(line->chunks[ch], line->chunks[ch].text);
 
 	line->chunks[ch].text = newchunk;
 	line->width = -1;	// Force recalc
diff --git a/graphics/macgui/mactext.h b/graphics/macgui/mactext.h
index 21d6134f78..2c5f28ea7d 100644
--- a/graphics/macgui/mactext.h
+++ b/graphics/macgui/mactext.h
@@ -94,6 +94,10 @@ struct MacFontRun {
 
 	const Common::String toString();
 	bool equals(MacFontRun &to);
+
+	Common::CodePage getEncoding();
+	bool plainByteMode();
+	Common::String getEncodedText();
 };
 
 struct MacTextLine {
@@ -146,11 +150,9 @@ 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);
 	// 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);
-	MacText(const Common::String &s, MacWindowManager *wm, const MacFont *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear = 0, Common::CodePage encodeType = Common::kMacCentralEurope, bool fixedDims = true);
 
 	MacText(const Common::U32String &s, MacWindowManager *wm, const Font *font, int fgcolor, int bgcolor, int maxWidth, TextAlign textAlignment, int interlinear = 0, bool fixedDims = true);
 
@@ -189,7 +191,6 @@ public:
 	void setTextColor(uint32 color, uint32 start, uint32 end);
 
 	void appendText(const Common::U32String &str, int fontId = kMacFontChicago, int fontSize = 12, int fontSlant = kMacFontRegular, bool skipAdd = false);
-	void appendText(const Common::String &str, int fontId = kMacFontChicago, int fontSize = 12, int fontSlant = kMacFontRegular, bool skipAdd = false);
 	void appendText(const Common::U32String &str, int fontId = kMacFontChicago, int fontSize = 12, int fontSlant = kMacFontRegular, uint16 r = 0, uint16 g = 0, uint16 b = 0, bool skipAdd = false);
 	void appendText(const Common::U32String &str, const Font *font, uint16 r = 0, uint16 g = 0, uint16 b = 0, bool skipAdd = false);
 
@@ -219,7 +220,7 @@ private:
 	void deletePreviousCharInternal(int *row, int *col);
 	void insertTextFromClipboard();
 	// getStringWidth for mactext version, because we may have the plain bytes mode
-	int getStringWidth(const Font *font, const Common::U32String &str);
+	int getStringWidth(MacFontRun &format, const Common::U32String &str);
 	int getAlignOffset(int row);
 	MacFontRun getFgColor();
 
@@ -236,7 +237,6 @@ public:
 	int getTextMaxWidth() { return _textMaxWidth; }
 
 	void setText(const Common::U32String &str);
-	void setText(const Common::String &str);
 
 	void setFixDims(bool fixed) { _fixedDims = fixed; }
 	bool getFixDims() { return _fixedDims; }
@@ -347,10 +347,6 @@ protected:
 
 	bool _macFontMode;
 
-	bool _plainByteMode;
-
-	Common::CodePage _encodeType;
-
 private:
 	ManagedSurface *_cursorSurface;
 	ManagedSurface *_cursorSurface2;
diff --git a/graphics/macgui/mactextwindow.cpp b/graphics/macgui/mactextwindow.cpp
index b139c05648..6808f7f8e5 100644
--- a/graphics/macgui/mactextwindow.cpp
+++ b/graphics/macgui/mactextwindow.cpp
@@ -47,7 +47,7 @@ MacTextWindow::MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgco
 		MacWindow(wm->getLastId(), true, true, true, wm), _bgcolor(bgcolor), _maxWidth(maxWidth), _menu(menu) {
 
 	_font = font;
-	_mactext = new MacText("", _wm, font, fgcolor, bgcolor, maxWidth, textAlignment);
+	_mactext = new MacText(Common::U32String(""), _wm, font, fgcolor, bgcolor, maxWidth, textAlignment);
 
 	_fontRef = wm->_fontMan->getFont(*font);
 


Commit: 63b69aa91e1b2729c7b62db65c5392d30f2a2d3d
    https://github.com/scummvm/scummvm/commit/63b69aa91e1b2729c7b62db65c5392d30f2a2d3d
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-12T00:38:05-04:00

Commit Message:
DIRECTOR: Create function to detect encoding from font

Changed paths:
    engines/director/util.cpp
    engines/director/util.h


diff --git a/engines/director/util.cpp b/engines/director/util.cpp
index 8bacce0781..2782a8fbab 100644
--- a/engines/director/util.cpp
+++ b/engines/director/util.cpp
@@ -25,6 +25,9 @@
 #include "common/memstream.h"
 #include "common/zlib.h"
 
+#include "graphics/macgui/macwindowmanager.h"
+#include "graphics/macgui/macfontmanager.h"
+
 #include "director/director.h"
 #include "director/movie.h"
 #include "director/util.h"
@@ -750,4 +753,17 @@ Common::Platform platformFromID(uint16 id) {
 	return Common::kPlatformUnknown;
 }
 
+Common::CodePage detectEncoding(Common::Platform platform, uint16 fontId) {
+	Common::Language lang = g_director->_wm->_fontMan->getFontLanguage(fontId);
+	switch (lang) {
+	case Common::JA_JPN:
+		return Common::kWindows932; // Shift JIS
+	default:
+		break;
+	}
+	return (platform == Common::kPlatformWindows)
+				? Common::kWindows1252
+				: Common::kMacCentralEurope;
+}
+
 } // End of namespace Director
diff --git a/engines/director/util.h b/engines/director/util.h
index ae823d987c..509de8a3bc 100644
--- a/engines/director/util.h
+++ b/engines/director/util.h
@@ -84,6 +84,8 @@ uint16 humanVersion(uint16 ver);
 
 Common::Platform platformFromID(uint16 id);
 
+Common::CodePage detectEncoding(Common::Platform platform, uint16 fontId);
+
 } // End of namespace Director
 
 #endif


Commit: f1ddc4b346fb3d2cea5d9ae380a80b69d5264cd7
    https://github.com/scummvm/scummvm/commit/f1ddc4b346fb3d2cea5d9ae380a80b69d5264cd7
Author: djsrv (dservilla at gmail.com)
Date: 2021-07-12T00:38:05-04:00

Commit Message:
DIRECTOR: Handle STXT encoding

Changed paths:
    engines/director/castmember.cpp
    engines/director/castmember.h
    engines/director/lingo/lingo-builtins.cpp
    engines/director/lingo/lingo-object.cpp
    engines/director/lingo/lingo.cpp
    engines/director/stxt.cpp
    engines/director/stxt.h


diff --git a/engines/director/castmember.cpp b/engines/director/castmember.cpp
index 3201d87395..58539ff811 100644
--- a/engines/director/castmember.cpp
+++ b/engines/director/castmember.cpp
@@ -730,7 +730,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, _textType == kTextTypeFixed);
 		((Graphics::MacText *)widget)->setSelRange(g_director->getCurrentMovie()->_selStart, g_director->getCurrentMovie()->_selEnd);
 		((Graphics::MacText *)widget)->setEditable(_editable);
 		((Graphics::MacText *)widget)->draw();
@@ -772,13 +772,13 @@ void TextCastMember::importRTE(byte *text) {
 	//child2 is positional?
 }
 
-void TextCastMember::setText(const char *text) {
+void TextCastMember::setText(const Common::U32String &text) {
 	// Do nothing if text did not change
 	if (_ptext.equals(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::U32String formatting = Common::U32String::format("\001\016%04x%02x%04x%04x%04x%04x", _fontId, _textSlant, _fontSize, _fgpalinfo1, _fgpalinfo2, _fgpalinfo3);
 	_ptext = text;
 	_ftext = formatting + text;
 
@@ -811,7 +811,7 @@ int TextCastMember::getTextSize() {
 	return 0;
 }
 
-Common::String TextCastMember::getText() {
+Common::U32String TextCastMember::getText() {
 	return _ptext;
 }
 
@@ -838,7 +838,7 @@ void TextCastMember::setEditable(bool editable) {
 
 void TextCastMember::updateFromWidget(Graphics::MacWidget *widget) {
 	if (widget && _type == kCastText) {
-		_ptext = ((Graphics::MacText *)widget)->getEditedString().encode();
+		_ptext = ((Graphics::MacText *)widget)->getEditedString();
 	}
 }
 
diff --git a/engines/director/castmember.h b/engines/director/castmember.h
index 618231d608..e2e7245865 100644
--- a/engines/director/castmember.h
+++ b/engines/director/castmember.h
@@ -219,7 +219,7 @@ public:
 	TextCastMember(Cast *cast, uint16 castId, Common::SeekableReadStreamEndian &stream, uint16 version, uint8 flags1 = 0, bool asButton = false);
 	virtual void setColors(uint32 *fgcolor, uint32 *bgcolor) override;
 
-	void setText(const char *text);
+	void setText(const Common::U32String &text);
 	virtual Graphics::MacWidget *createWidget(Common::Rect &bbox, Channel *channel) override;
 
 	virtual bool isEditable() override;
@@ -263,12 +263,12 @@ public:
 	bool _editable;
 	int _lineSpacing;
 
-	Common::String _ftext;
-	Common::String _ptext;
+	Common::U32String _ftext;
+	Common::U32String _ptext;
 	void importStxt(const Stxt *stxt);
 	void importRTE(byte *text);
 
-	Common::String getText();
+	Common::U32String getText();
 
 private:
 	uint32 _bgcolor;
diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index 9d8007605b..1f3665815b 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -1670,7 +1670,7 @@ void LB::b_installMenu(int nargs) {
 	}
 	TextCastMember *field = static_cast<TextCastMember *>(member);
 
-	Common::String menuStxt = g_lingo->_compiler->codePreprocessor(field->getText().c_str(), field->getCast()->_lingoArchive, kNoneScript, memberID, true);
+	Common::String menuStxt = g_lingo->_compiler->codePreprocessor(field->getText().encode(Common::kMacCentralEurope).c_str(), field->getCast()->_lingoArchive, kNoneScript, memberID, true); // FIXME: Properly handle encoding
 	Common::String line;
 	int linenum = -1; // We increment it before processing
 
diff --git a/engines/director/lingo/lingo-object.cpp b/engines/director/lingo/lingo-object.cpp
index 58cc3a9d94..04668c6c9a 100644
--- a/engines/director/lingo/lingo-object.cpp
+++ b/engines/director/lingo/lingo-object.cpp
@@ -883,7 +883,7 @@ Datum TextCastMember::getField(int field) {
 		d = _hilite;
 		break;
 	case kTheText:
-		d = getText();
+		d = getText().encode(Common::kMacCentralEurope); // FIXME: Properly handle encoding
 		break;
 	case kTheTextAlign:
 		d.type = STRING;
@@ -944,7 +944,7 @@ bool TextCastMember::setField(int field, const Datum &d) {
 		}
 		break;
 	case kTheText:
-		setText(d.asString().c_str());
+		setText(Common::U32String(d.asString(), Common::kMacCentralEurope)); // FIXME: Properly handle encoding
 		return true;
 	case kTheTextAlign:
 		{
diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp
index 755a7a405f..4e7938c24c 100644
--- a/engines/director/lingo/lingo.cpp
+++ b/engines/director/lingo/lingo.cpp
@@ -1166,7 +1166,7 @@ void Lingo::varAssign(const Datum &var, const Datum &value) {
 			}
 			switch (member->_type) {
 			case kCastText:
-				((TextCastMember *)member)->setText(value.asString().c_str());
+				((TextCastMember *)member)->setText(Common::U32String(value.asString(), Common::kMacCentralEurope)); // FIXME: Properly handle encoding
 				break;
 			default:
 				warning("varAssign: Unhandled cast type %d", member->_type);
@@ -1287,7 +1287,7 @@ Datum Lingo::varFetch(const Datum &var, bool silent) {
 			switch (member->_type) {
 			case kCastText:
 				result.type = STRING;
-				result.u.s = new Common::String(((TextCastMember *)member)->getText());
+				result.u.s = new Common::String(((TextCastMember *)member)->getText().encode(Common::kMacCentralEurope)); // FIXME: Properly handle encoding
 				break;
 			default:
 				warning("varFetch: Unhandled cast type %d", member->_type);
diff --git a/engines/director/stxt.cpp b/engines/director/stxt.cpp
index 9ffd5a7060..9925a455f1 100644
--- a/engines/director/stxt.cpp
+++ b/engines/director/stxt.cpp
@@ -59,47 +59,52 @@ Stxt::Stxt(Cast *cast, Common::SeekableReadStreamEndian &textStream) : _cast(cas
 		text += ch;
 	}
 	debugC(3, kDebugText, "Stxt init: offset: %d strLen: %d dataLen: %d textlen: %u", offset, strLen, dataLen, text.size());
-	if (strLen < 200)
-		debugC(3, kDebugText, "text: '%s'", Common::toPrintable(text).c_str());
-
-	_ptext = text;
 
 	uint16 formattingCount = textStream.readUint16();
 	uint32 prevPos = 0;
 
+	debugC(3, kDebugText, "Stxt init: formattingCount: %u", formattingCount);
+
+	Common::U32String logText;
+
 	while (formattingCount) {
-		debugC(3, kDebugText, "Stxt init: formattingCount: %u", formattingCount);
-		_style.read(textStream, _cast);
+		FontStyle nextStyle;
+		nextStyle.read(textStream, _cast);
 
 		assert(prevPos <= _style.formatStartOffset);  // If this is triggered, we have to implement sorting
 
+		Common::String textPart;
 		while (prevPos != _style.formatStartOffset) {
-			// We should theoretically handle the cross-platform character mappings stored in _cast->_charMap here.
-			// However, Director 4 seems to ignore these mappings despite storing them.
-			// Maybe they're handled in a later version?
-
 			char f = text.firstChar();
-			_ftext += text.firstChar();
+			textPart += f;
 			text.deleteChar(0);
 
 			if (f == '\001')	// Insert two \001s as a replacement
 				_ftext += '\001';
 
 			prevPos++;
-
-			debugCN(4, kDebugText, "%c", f);
 		}
+		Common::CodePage encoding = detectEncoding(cast->_platform, _style.fontId);
+		Common::U32String u32TextPart(textPart, encoding);
+		_ptext += u32TextPart;
+		_ftext += u32TextPart;
+		logText += u32TextPart;
 
-		debugCN(4, kDebugText, "*");
-
-		_ftext += Common::String::format("\001\016%04x%02x%04x%04x%04x%04x", _style.fontId, _style.textSlant, _style.fontSize, _style.r, _style.g, _style.b);
+		_style = nextStyle;
+		Common::String format = Common::String::format("\001\016%04x%02x%04x%04x%04x%04x", _style.fontId, _style.textSlant, _style.fontSize, _style.r, _style.g, _style.b);
+		_ftext += format;
+		logText += Common::toPrintable(format);
 
 		formattingCount--;
 	}
 
-	_ftext += text;
+	Common::CodePage encoding = detectEncoding(cast->_platform, _style.fontId);
+	Common::U32String u32Text(text, encoding);
+	_ptext += u32Text;
+	_ftext += u32Text;
+	logText += u32Text;
 
-	debugC(4, kDebugText, "#### text:\n%s\n####", Common::toPrintable(_ftext).c_str());
+	debugC(4, kDebugText, "#### text:\n%s\n####", logText.encode().c_str());
 }
 
 FontStyle::FontStyle() {
diff --git a/engines/director/stxt.h b/engines/director/stxt.h
index 0a2b2278ca..5ca9b3b3e0 100644
--- a/engines/director/stxt.h
+++ b/engines/director/stxt.h
@@ -53,8 +53,8 @@ public:
 
 public:
 	Cast *_cast;
-	Common::String _ftext;
-	Common::String _ptext;
+	Common::U32String _ftext;
+	Common::U32String _ptext;
 	TextType _textType;
 	TextAlignType _textAlign;
 	SizeType _textShadow;




More information about the Scummvm-git-logs mailing list