[Scummvm-git-logs] scummvm master -> 2cb0e45c630e568ef7a4c7b5f0f195f0d67f92ce

sev- sev at scummvm.org
Wed Oct 12 19:17:52 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:
2cb0e45c63 GRAPHICS: Further work on BDF font scaling


Commit: 2cb0e45c630e568ef7a4c7b5f0f195f0d67f92ce
    https://github.com/scummvm/scummvm/commit/2cb0e45c630e568ef7a4c7b5f0f195f0d67f92ce
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2016-10-12T19:17:29+02:00

Commit Message:
GRAPHICS: Further work on BDF font scaling

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



diff --git a/graphics/fonts/bdf.cpp b/graphics/fonts/bdf.cpp
index a783a22..34155fc 100644
--- a/graphics/fonts/bdf.cpp
+++ b/graphics/fonts/bdf.cpp
@@ -701,6 +701,11 @@ BdfFont *BdfFont::loadFromCache(Common::SeekableReadStream &stream) {
 }
 
 BdfFont *BdfFont::scaleFont(BdfFont *src, int newSize) {
+	if (!src) {
+		warning("Emtpy font reference in scale font");
+		return NULL;
+	}
+
 	if (src->getFontSize()) {
 		warning("Requested to scale 0 size font");
 		return NULL;
@@ -720,6 +725,8 @@ BdfFont *BdfFont::scaleFont(BdfFont *src, int newSize) {
 	data.firstCharacter = src->_data.firstCharacter;
 	data.defaultCharacter = src->_data.defaultCharacter;
 	data.numCharacters = src->_data.numCharacters;
+	data.familyName = strdup(src->_data.familyName);
+	data.slant = strdup(src->_data.slant);
 
 	BdfBoundingBox *boxes = new BdfBoundingBox[data.numCharacters];
 	for (int i = 0; i < data.numCharacters; ++i) {
diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index ce94935..52e8258 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -127,6 +127,7 @@ void MacFontManager::loadFonts() {
 		}
 
 		FontMan.assignFontToName(fontName, font);
+		macfont->setBdfFont(font);
 		_fontRegistry.setVal(fontName, macfont);
 
 		debug(2, " %s", fontName.c_str());
@@ -150,7 +151,7 @@ const Font *MacFontManager::getFont(MacFont macFont) {
 		font = FontMan.getFontByName(macFont.getName());
 
 		if (!font) {
-			warning("Cannot load font %s", macFont.getName().c_str());
+			warning("Cannot load font '%s'", macFont.getName().c_str());
 
 			font = FontMan.getFontByName(MacFont(kMacFontChicago, 12).getName());
 		}
@@ -219,7 +220,7 @@ void MacFontManager::generateFontSubstitute(MacFont &macFont) {
 
 	// Now half size
 	name = getFontName(macFont.getId(), macFont.getSize() / 2, macFont.getSlant());
-	if (_fontRegistry.contains(name)) {
+	if (_fontRegistry.contains(name) && !_fontRegistry[name]->isGenerated()) {
 		generateFont(macFont, *_fontRegistry[name]);
 
 		return;
@@ -230,7 +231,7 @@ void MacFontManager::generateFontSubstitute(MacFont &macFont) {
 	// 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())
+		if (i->_value->getId() == macFont.getId() && i->_value->getSlant() == macFont.getSlant() && !i->_value->isGenerated())
 			sizes.push_back(i->_value->getSize());
 	}
 
@@ -251,7 +252,7 @@ void MacFontManager::generateFontSubstitute(MacFont &macFont) {
 	}
 
 	if (candidate != 1000) {
-		generateFont(macFont, MacFont(macFont.getId(), candidate, macFont.getSlant()));
+		generateFont(macFont, *_fontRegistry[getFontName(macFont.getId(), candidate, macFont.getSlant())]);
 		return;
 	}
 
@@ -260,17 +261,18 @@ void MacFontManager::generateFontSubstitute(MacFont &macFont) {
 }
 
 void MacFontManager::generateFont(MacFont toFont, MacFont fromFont) {
-	debugN("Found font substitute for font %s ", getFontName(fromFont));
-	debug("as %s", getFontName(toFont));
-
-	Graphics::BdfFont *bdfFont = (Graphics::BdfFont *)getFont(fromFont);
+	debugN("Found font substitute for font '%s' ", getFontName(toFont));
+	debug("as '%s'", getFontName(fromFont));
 
-	Graphics::BdfFont *font = Graphics::BdfFont::scaleFont(bdfFont, toFont.getSize());
+	Graphics::BdfFont *font = Graphics::BdfFont::scaleFont(fromFont.getBdfFont(), toFont.getSize());
 
 	toFont.setGenerated(true);
+	toFont.setBdfFont(font);
 
 	FontMan.assignFontToName(getFontName(toFont), font);
-	_fontRegistry.setVal(getFontName(toFont), &toFont);
+	_fontRegistry.setVal(getFontName(toFont), new MacFont(toFont));
+
+	debug("Generated font '%s'", getFontName(toFont));
 }
 
 } // End of namespace Graphics
diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
index e09e1dc..3e90818 100644
--- a/graphics/macgui/macfontmanager.h
+++ b/graphics/macgui/macfontmanager.h
@@ -48,6 +48,7 @@ public:
 		_slant = slant;
 		_fallback = fallback;
 		_generated = false;
+		_bdfFont = NULL;
 	}
 
 	int getId() { return _id; };
@@ -59,6 +60,8 @@ public:
 	FontManager::FontUsage getFallback() { return _fallback; }
 	bool isGenerated() { return _generated; }
 	void setGenerated(bool gen) { _generated = gen; }
+	BdfFont *getBdfFont() { return _bdfFont; }
+	void setBdfFont(BdfFont *bdfFont) { _bdfFont = bdfFont; }
 
 private:
 	int _id;
@@ -68,6 +71,7 @@ private:
 	FontManager::FontUsage _fallback;
 
 	bool _generated;
+	BdfFont *_bdfFont;
 };
 
 class MacFontManager {
@@ -100,7 +104,7 @@ private:
 	const char *getFontName(MacFont &font);
 
 	void generateFontSubstitute(MacFont &macFont);
-	void generateFont(MacFont fromFont, MacFont toFont);
+	void generateFont(MacFont toFont, MacFont fromFont);
 
 private:
 	bool _builtInFonts;





More information about the Scummvm-git-logs mailing list