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

sev- sev at scummvm.org
Sat Oct 8 14:47:51 CEST 2016


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

Summary:
c0b76581d8 GRAPHICS: Detect substitute for Mac fonts


Commit: c0b76581d8e4c1938c3f2f617edf553105dc6fdc
    https://github.com/scummvm/scummvm/commit/c0b76581d8e4c1938c3f2f617edf553105dc6fdc
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2016-10-08T14:47:38+02:00

Commit Message:
GRAPHICS: Detect substitute for Mac fonts

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



diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 97da1a6..bf3532d 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -28,7 +28,55 @@
 
 namespace Graphics {
 
+// Source: Apple IIGS Technical Note #41, "Font Family Numbers"
+// http://apple2.boldt.ca/?page=til/tn.iigs.041
+static const char *const fontNames[] = {
+	"Chicago",	// system font
+	"Geneva",	// application font
+	"New York",
+	"Geneva",
+
+	"Monaco",
+	"Venice",
+	"London",
+	"Athens",
+
+	"San Francisco",
+	"Toronto",
+	NULL,
+	"Cairo",
+	"Los Angeles", // 12
+
+	"Zapf Dingbats",
+	"Bookman",
+	"Helvetica Narrow",
+	"Palatino",
+	NULL,
+	"Zapf Chancery",
+	NULL,
+
+	"Times", // 20
+	"Helvetica",
+	"Courier",
+	"Symbol",
+	"Taliesin", // mobile?
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL, // 30
+	NULL,
+	NULL,
+	"Avant Garde",
+	"New Century Schoolbook"
+};
+
 MacFontManager::MacFontManager() {
+	for (uint i = 0; i < ARRAYSIZE(fontNames); i++)
+		if (fontNames[i])
+			_fontNames.setVal(fontNames[i], i);
+
 	loadFonts();
 }
 
@@ -55,8 +103,12 @@ void MacFontManager::loadFonts() {
 		delete stream;
 
 		Common::String fontName;
+		MacFont *macfont;
+
 		if (font->getFamilyName() && *font->getFamilyName()) {
 			fontName = Common::String::format("%s-%s-%d", font->getFamilyName(), font->getFontSlant(), font->getFontSize());
+
+			macfont = new MacFont(_fontNames.getVal(font->getFamilyName(), kMacFontNonStandard), font->getFontSize(), parseFontSlant(font->getFontSlant()));
 		} else { // Get it from the file name
 			fontName = (*it)->getName();
 
@@ -69,10 +121,13 @@ void MacFontManager::loadFonts() {
 					break;
 				}
 			}
+
+			macfont = new MacFont(kMacFontNonStandard);
+			macfont->setName(fontName);
 		}
 
 		FontMan.assignFontToName(fontName, font);
-		_fontRegistry.setVal(fontName, font);
+		_fontRegistry.setVal(fontName, macfont);
 
 		debug(2, " %s", fontName.c_str());
 	}
@@ -107,49 +162,20 @@ const Font *MacFontManager::getFont(MacFont macFont) {
 	return font;
 }
 
-// Source: Apple IIGS Technical Note #41, "Font Family Numbers"
-// http://apple2.boldt.ca/?page=til/tn.iigs.041
-static const char *const fontNames[] = {
-	"Chicago",	// system font
-	"Geneva",	// application font
-	"New York",
-	"Geneva",
+int MacFontManager::parseFontSlant(Common::String slant) {
+	slant.toUppercase();
 
-	"Monaco",
-	"Venice",
-	"London",
-	"Athens",
-
-	"San Francisco",
-	"Toronto",
-	NULL,
-	"Cairo",
-	"Los Angeles", // 12
+	if (slant == "I")
+		return kMacFontItalic;
+	if (slant == "B")
+		return kMacFontBold;
+	if (slant == "R")
+		return kMacFontRegular;
 
-	"Zapf Dingbats",
-	"Bookman",
-	"Helvetica Narrow",
-	"Palatino",
-	NULL,
-	"Zapf Chancery",
-	NULL,
+	warning("Unknown font slant '%s'", slant.c_str());
 
-	"Times", // 20
-	"Helvetica",
-	"Courier",
-	"Symbol",
-	"Taliesin", // mobile?
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	NULL, // 30
-	NULL,
-	NULL,
-	"Avant Garde",
-	"New Century Schoolbook"
-};
+	return kMacFontRegular;
+}
 
 const char *MacFontManager::getFontName(int id, int size, int slant) {
 	static char name[128];
@@ -181,21 +207,61 @@ const char *MacFontManager::getFontName(MacFont &font) {
 }
 
 void MacFontManager::generateFontSubstitute(MacFont &macFont) {
-	if (_fontRegistry.contains(getFontName(macFont.getId(), macFont.getSize() * 2, macFont.getSlant()))) {
-		generateFont(macFont, MacFont(macFont.getId(), macFont.getSize() * 2, macFont.getSlant()));
+	Common::String name;
+
+	// First we try twice size
+	name = getFontName(macFont.getId(), macFont.getSize() * 2, macFont.getSlant());
+	if (_fontRegistry.contains(name) && !_fontRegistry[name]->isGenerated()) {
+		generateFont(macFont, *_fontRegistry[name]);
 
 		return;
 	}
 
-	if (_fontRegistry.contains(getFontName(macFont.getId(), macFont.getSize() / 2, macFont.getSlant()))) {
-		generateFont(macFont, MacFont(macFont.getId(), macFont.getSize() / 2, macFont.getSlant()));
+	// Now half size
+	name = getFontName(macFont.getId(), macFont.getSize() / 2, macFont.getSlant());
+	if (_fontRegistry.contains(name)) {
+		generateFont(macFont, *_fontRegistry[name]);
 
 		return;
 	}
+
+	// No simple substitute was found. Looking for neighborhood fonts
+
+	// First we gather all font sizes for this font
+	Common::Array<int> sizes;
+	for (Common::HashMap<Common::String, MacFont *>::iterator i = _fontRegistry.begin(); i != _fontRegistry.end(); ++i) {
+		if (i->_value->getId() == macFont.getId() && i->_value->getSlant() == macFont.getSlant())
+			sizes.push_back(i->_value->getSize());
+	}
+
+	if (sizes.empty()) {
+		warning("No viable substitute found for font %s", getFontName(macFont));
+		return;
+	}
+
+	// Now looking next larger font, and store the largest one for next check
+	int candidate = 1000;
+	int maxSize = sizes[0];
+	for (uint i = 0; i < sizes.size(); i++) {
+		if (sizes[i] > macFont.getSize() && sizes[i] < candidate)
+			candidate = sizes[i];
+
+		if (sizes[i] > maxSize)
+			maxSize = sizes[i];
+	}
+
+	if (candidate != 1000) {
+		generateFont(macFont, MacFont(macFont.getId(), candidate, macFont.getSlant()));
+		return;
+	}
+
+	// Now next smaller font, which is the biggest we have
+	generateFont(macFont, MacFont(macFont.getId(), maxSize, macFont.getSlant()));
 }
 
 void MacFontManager::generateFont(MacFont fromFont, MacFont toFont) {
-	warning("Found font substitute from font %s to %s", getFontName(fromFont), getFontName(toFont));
+	debugN("Found font substitute for font %s ", getFontName(fromFont));
+	debug("as %s", getFontName(toFont));
 }
 
 } // End of namespace Graphics
diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
index a263ab5..e09e1dc 100644
--- a/graphics/macgui/macfontmanager.h
+++ b/graphics/macgui/macfontmanager.h
@@ -28,6 +28,7 @@
 namespace Graphics {
 
 enum {
+	kMacFontNonStandard = -1,
 	kMacFontChicago = 0
 };
 
@@ -46,6 +47,7 @@ public:
 		_size = size;
 		_slant = slant;
 		_fallback = fallback;
+		_generated = false;
 	}
 
 	int getId() { return _id; };
@@ -55,6 +57,8 @@ public:
 	void setName(Common::String &name) { _name = name; }
 	void setName(const char *name) { _name = name; }
 	FontManager::FontUsage getFallback() { return _fallback; }
+	bool isGenerated() { return _generated; }
+	void setGenerated(bool gen) { _generated = gen; }
 
 private:
 	int _id;
@@ -62,6 +66,8 @@ private:
 	int _slant;
 	Common::String _name;
 	FontManager::FontUsage _fallback;
+
+	bool _generated;
 };
 
 class MacFontManager {
@@ -98,7 +104,11 @@ private:
 
 private:
 	bool _builtInFonts;
-	Common::HashMap<Common::String, BdfFont *> _fontRegistry;
+	Common::HashMap<Common::String, MacFont *> _fontRegistry;
+
+	Common::HashMap<Common::String, int> _fontNames;
+
+	int parseFontSlant(Common::String slant);
 };
 
 } // End of namespace Graphics





More information about the Scummvm-git-logs mailing list