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

sev- noreply at scummvm.org
Fri May 3 22:14:35 UTC 2024


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

Summary:
e70ea93149 GRAPHICS: MACGUI: Add support for TTF font maps
bd867b109a GUI: Switch HelpDialog to TTF fonts
cea8312c35 GUI: load ttf from archive in Unicode branch


Commit: e70ea93149acc1dc8f419821f4fc07d0b585b925
    https://github.com/scummvm/scummvm/commit/e70ea93149acc1dc8f419821f4fc07d0b585b925
Author: InariInDream (inariindream at 163.com)
Date: 2024-05-04T00:14:31+02:00

Commit Message:
GRAPHICS: MACGUI: Add support for TTF font maps

Changed paths:
    graphics/macgui/macfontmanager.cpp
    graphics/macgui/macfontmanager.h
    gui/widgets/richtext.cpp


diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 3e92c92b84f..04e2bf4a309 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -534,6 +534,11 @@ const Font *MacFontManager::getFont(MacFont *macFont) {
 				font = Graphics::loadTTFFontFromArchive("FreeSans.ttf", macFont->getSize(), Graphics::kTTFSizeModeCharacter, 0, 0, Graphics::kTTFRenderModeMonochrome);
 				_uniFonts[macFont->getSize()] = font;
 			}
+		} else {
+			int newId = macFont->getId();
+			int newSlant = macFont->getSlant();
+			int familyId = getFamilyId(newId, newSlant);
+			font = Graphics::loadTTFFontFromArchive(_fontInfo[familyId]->name, macFont->getSize(), Graphics::kTTFSizeModeCharacter, 0, 0, Graphics::kTTFRenderModeMonochrome);
 		}
 	}
 #endif
@@ -658,6 +663,47 @@ int MacFontManager::registerFontName(Common::String name, int preferredId) {
 	return id;
 }
 
+int MacFontManager::registerTTFFont(const Common::Array<TTFMap>& ttfList) {
+	int defaultValue = 1;
+
+	for (auto &&i : ttfList) {
+		int id = 1000;
+		Common::String name = i.ttfName;
+
+		if (name.empty()) {
+			if (defaultValue == 1)
+				defaultValue = id;
+			continue;
+		}
+
+		if (_fontIds.contains(name)){
+			if (defaultValue == 1)
+				defaultValue = id;
+			continue;
+		}
+
+		int slant = 0;
+
+		id += slant | i.slant;
+
+		FontInfo *info = new FontInfo;
+		info->name = name;
+		_fontInfo[id] = info;
+		_fontIds[name] = id;
+		if (defaultValue == 1)
+			defaultValue = id;
+	}
+	return defaultValue;
+}
+
+int MacFontManager::getFamilyId(int newId, int newSlant){
+	if (_fontInfo.contains(newId + newSlant)) {
+		return newId + newSlant;
+	}
+	warning("MacFontManager::getFamilyId(): No font with slant %d found, setting to kMacFontBold | kMacFontItalic", newSlant);
+	return newId + (kMacFontBold | kMacFontItalic);
+}
+
 void MacFont::setName(const char *name) {
 	_name = name;
 }
diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
index 48ea9d8a220..83c73def721 100644
--- a/graphics/macgui/macfontmanager.h
+++ b/graphics/macgui/macfontmanager.h
@@ -33,6 +33,11 @@ namespace Common {
 
 namespace Graphics {
 
+struct TTFMap {
+	const char *ttfName;
+	uint16 slant;
+};
+
 class MacFONTFont;
 class MacFontFamily;
 
@@ -174,6 +179,10 @@ public:
 
 	void printFontRegistry(int debugLevel, uint32 channel);
 
+	int registerTTFFont(const Common::Array<Graphics::TTFMap> &ttfList);
+
+	int getFamilyId(int newId, int newSlant);
+
 private:
 	void loadFontsBDF();
 	void loadFonts();
diff --git a/gui/widgets/richtext.cpp b/gui/widgets/richtext.cpp
index 9b11b9d5aeb..48f1a536e5a 100644
--- a/gui/widgets/richtext.cpp
+++ b/gui/widgets/richtext.cpp
@@ -34,6 +34,13 @@
 
 namespace GUI {
 
+Common::Array<Graphics::TTFMap> ttfFamily = {
+	{"NotoSans-Regular.ttf", Graphics::kMacFontRegular},
+	{"NotoSans-Bold.ttf", Graphics::kMacFontBold},
+	{"NotoSerif-Italic.ttf", Graphics::kMacFontItalic},
+	{"NotoSerif-Bold-Italic.ttf", Graphics::kMacFontBold | Graphics::kMacFontItalic},
+};
+
 RichTextWidget::RichTextWidget(GuiObject *boss, int x, int y, int w, int h, bool scale, const Common::U32String &text, const Common::U32String &tooltip)
 	: Widget(boss, x, y, w, h, scale, tooltip), CommandSender(nullptr)  {
 
@@ -189,7 +196,8 @@ void RichTextWidget::createWidget() {
 
 	const int fontHeight = g_gui.xmlEval()->getVar("Globals.Font.Height", 25);
 
-	Graphics::MacFont macFont(Graphics::kMacFontNewYork, fontHeight, Graphics::kMacFontRegular);
+	int newId = wm->_fontMan->registerTTFFont(ttfFamily);
+	Graphics::MacFont macFont(newId, fontHeight, Graphics::kMacFontRegular);
 
 	_txtWnd = new Graphics::MacText(Common::U32String(), wm, &macFont, fg, bg, _textWidth, Graphics::kTextAlignLeft);
 


Commit: bd867b109a09c84db62d89f1029bee53b6386f3c
    https://github.com/scummvm/scummvm/commit/bd867b109a09c84db62d89f1029bee53b6386f3c
Author: InariInDream (inariindream at 163.com)
Date: 2024-05-04T00:14:31+02:00

Commit Message:
GUI: Switch HelpDialog to TTF fonts

Changed paths:
    graphics/macgui/macfontmanager.cpp


diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 04e2bf4a309..1371688a95c 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -663,11 +663,23 @@ int MacFontManager::registerFontName(Common::String name, int preferredId) {
 	return id;
 }
 
-int MacFontManager::registerTTFFont(const Common::Array<TTFMap>& ttfList) {
+int MacFontManager::registerTTFFont(const Common::Array<TTFMap> &ttfList) {
 	int defaultValue = 1;
+	int realId = 100;
+	auto checkId = [&](int id) {
+		for (auto &&i : ttfList) {
+			if (_fontInfo.contains(id + i.slant)) {
+				return true;
+			}
+		}
+		return false;
+	};
+
+	while (checkId(realId))
+		realId++;
 
 	for (auto &&i : ttfList) {
-		int id = 1000;
+		int id = realId;
 		Common::String name = i.ttfName;
 
 		if (name.empty()) {
@@ -676,9 +688,9 @@ int MacFontManager::registerTTFFont(const Common::Array<TTFMap>& ttfList) {
 			continue;
 		}
 
-		if (_fontIds.contains(name)){
+		if (_fontIds.contains(name)) {
 			if (defaultValue == 1)
-				defaultValue = id;
+				defaultValue = _fontIds[name];
 			continue;
 		}
 
@@ -696,12 +708,12 @@ int MacFontManager::registerTTFFont(const Common::Array<TTFMap>& ttfList) {
 	return defaultValue;
 }
 
-int MacFontManager::getFamilyId(int newId, int newSlant){
+int MacFontManager::getFamilyId(int newId, int newSlant) {
 	if (_fontInfo.contains(newId + newSlant)) {
 		return newId + newSlant;
 	}
-	warning("MacFontManager::getFamilyId(): No font with slant %d found, setting to kMacFontBold | kMacFontItalic", newSlant);
-	return newId + (kMacFontBold | kMacFontItalic);
+	warning("MacFontManager::getFamilyId(): No font with slant %d found, setting to kMacFontRegular", newSlant);
+	return newId;
 }
 
 void MacFont::setName(const char *name) {


Commit: cea8312c35935c9774d13d778bf6c03f081867ad
    https://github.com/scummvm/scummvm/commit/cea8312c35935c9774d13d778bf6c03f081867ad
Author: InariInDream (inariindream at 163.com)
Date: 2024-05-04T00:14:31+02:00

Commit Message:
GUI: load ttf from archive in Unicode branch

Changed paths:
    graphics/macgui/macfontmanager.cpp


diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 1371688a95c..2531dc607da 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -531,14 +531,23 @@ const Font *MacFontManager::getFont(MacFont *macFont) {
 			if (pFont != _uniFonts.end()) {
 				font = pFont->_value;
 			} else {
-				font = Graphics::loadTTFFontFromArchive("FreeSans.ttf", macFont->getSize(), Graphics::kTTFSizeModeCharacter, 0, 0, Graphics::kTTFRenderModeMonochrome);
-				_uniFonts[macFont->getSize()] = font;
+				int newId = macFont->getId();
+				int newSlant = macFont->getSlant();
+				int familyId = getFamilyId(newId, newSlant);
+				if (_fontInfo.contains(familyId)) {
+					font = Graphics::loadTTFFontFromArchive(_fontInfo[familyId]->name, macFont->getSize(), Graphics::kTTFSizeModeCharacter, 0, 0, Graphics::kTTFRenderModeMonochrome);
+					_uniFonts[macFont->getSize()] = font;
+				} else {
+					font = Graphics::loadTTFFontFromArchive("FreeSans.ttf", macFont->getSize(), Graphics::kTTFSizeModeCharacter, 0, 0, Graphics::kTTFRenderModeMonochrome);
+					_uniFonts[macFont->getSize()] = font;
+				}
 			}
 		} else {
 			int newId = macFont->getId();
 			int newSlant = macFont->getSlant();
 			int familyId = getFamilyId(newId, newSlant);
 			font = Graphics::loadTTFFontFromArchive(_fontInfo[familyId]->name, macFont->getSize(), Graphics::kTTFSizeModeCharacter, 0, 0, Graphics::kTTFRenderModeMonochrome);
+			_uniFonts[macFont->getSize()] = font;
 		}
 	}
 #endif




More information about the Scummvm-git-logs mailing list