[Scummvm-git-logs] scummvm master -> 672d216d113abcc11d3be1b0c76d2c251cfd8357

antoniou79 antoniou at cti.gr
Mon Mar 11 23:50:06 CET 2019


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:
672d216d11 GUI: Fix loading new (not already cached) localized fonts


Commit: 672d216d113abcc11d3be1b0c76d2c251cfd8357
    https://github.com/scummvm/scummvm/commit/672d216d113abcc11d3be1b0c76d2c251cfd8357
Author: Thanasis Antoniou (a.antoniou79 at gmail.com)
Date: 2019-03-12T00:42:58+02:00

Commit Message:
GUI: Fix loading new (not already cached) localized fonts

Changed paths:
    graphics/fonts/bdf.cpp
    gui/ThemeEngine.cpp


diff --git a/graphics/fonts/bdf.cpp b/graphics/fonts/bdf.cpp
index 8424e00..4374c36 100644
--- a/graphics/fonts/bdf.cpp
+++ b/graphics/fonts/bdf.cpp
@@ -203,6 +203,9 @@ byte *loadCharacter(Common::SeekableReadStream &stream, int &encoding, int &adva
 
 	while (true) {
 		line = stream.readLine();
+		line.trim(); 	// BDF files created from unifont tools (make hex)
+						// have a rogue space character after the "BITMAP" label
+
 		if (stream.err() || stream.eos()) {
 			warning("BdfFont::loadCharacter: Premature end of file");
 			delete[] bitmap;
@@ -412,7 +415,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) {
 			}
 		} else if (line.hasPrefix("FAMILY_NAME \"")) {
 			familyName = new char[line.size()];
-			Common::strlcpy(familyName, line.c_str() + 13, line.size() - 13);
+			Common::strlcpy(familyName, line.c_str() + 13, line.size() - 12);	// strlcpy() copies at most size-1 characters and then add a '\0'
 			char *p = &familyName[strlen(familyName)];
 			while (p != familyName && *p != '"')
 				p--;
@@ -429,7 +432,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) {
 			*p = '\0'; // Remove last quote
 		} else if (line.hasPrefix("SLANT \"")) {
 			slant = new char[line.size()];
-			Common::strlcpy(slant, line.c_str() + 7, line.size() - 7);
+			Common::strlcpy(slant, line.c_str() + 7, line.size() - 6);  // strlcpy() copies at most size-1 characters and then add a '\0'
 			char *p = &slant[strlen(slant)];
 			while (p != slant && *p != '"')
 				p--;
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp
index e57a1ef..e1438cd 100644
--- a/gui/ThemeEngine.cpp
+++ b/gui/ThemeEngine.cpp
@@ -526,17 +526,25 @@ bool ThemeEngine::addFont(TextData textId, const Common::String &file, const Com
 		_texts[textId]->_fontPtr = loadFont(localized, scalableFile, charset, pointsize, textId == kTextDataDefault);
 
 		if (!_texts[textId]->_fontPtr) {
+			warning("Failed to load localized font '%s'", localized.c_str());
 			// Try standard fonts
 			_texts[textId]->_fontPtr = loadFont(file, scalableFile, Common::String(), pointsize, textId == kTextDataDefault);
 
-			if (!_texts[textId]->_fontPtr)
+			if (!_texts[textId]->_fontPtr) {
 				error("Couldn't load font '%s'/'%s'", file.c_str(), scalableFile.c_str());
-
+#ifdef USE_TRANSLATION
+				TransMan.setLanguage("C");
+#endif
+				return false; // fall-back attempt failed
+			}
+			// Success in fall-back attempt to standard (non-localized) font.
+			// However, still returns false here, probably to avoid ugly / garbage glyphs side-effects
+			// FIXME If we return false anyway why would we attempt the fall-back in the first place?
 #ifdef USE_TRANSLATION
 			TransMan.setLanguage("C");
 #endif
-			warning("Failed to load localized font '%s'.", localized.c_str());
-
+			// Returning true here, would allow falling back to standard fonts for the missing ones,
+			// but that leads to "garbage" glyphs being displayed on screen for non-Latin languages
 			return false;
 		}
 	}





More information about the Scummvm-git-logs mailing list