[Scummvm-git-logs] scummvm master -> 2097c33b57d1a105b7f72637cd4a6cf2be3fc39e

bluegr bluegr at gmail.com
Sun Dec 23 14:57:23 CET 2018


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:
2097c33b57 GRAPHICS: MACGUI: Make use of Common::String::format (#1454)


Commit: 2097c33b57d1a105b7f72637cd4a6cf2be3fc39e
    https://github.com/scummvm/scummvm/commit/2097c33b57d1a105b7f72637cd4a6cf2be3fc39e
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2018-12-23T15:57:20+02:00

Commit Message:
GRAPHICS: MACGUI: Make use of Common::String::format (#1454)

Changed paths:
    engines/director/frame.cpp
    graphics/macgui/macfontmanager.cpp
    graphics/macgui/macfontmanager.h
    graphics/macgui/macmenu.cpp
    graphics/macgui/macmenu.h


diff --git a/engines/director/frame.cpp b/engines/director/frame.cpp
index 231a2ea..fe0f256 100644
--- a/engines/director/frame.cpp
+++ b/engines/director/frame.cpp
@@ -772,7 +772,7 @@ void Frame::renderText(Graphics::ManagedSurface &surface, uint16 spriteId, Commo
 
 	Graphics::MacFont *macFont = new Graphics::MacFont(textCast->fontId, textCast->fontSize, textCast->textSlant);
 
-	debugC(3, kDebugText, "renderText: x: %d y: %d w: %d h: %d font: '%s'", x, y, width, height, _vm->_wm->_fontMan->getFontName(*macFont));
+	debugC(3, kDebugText, "renderText: x: %d y: %d w: %d h: %d font: '%s'", x, y, width, height, _vm->_wm->_fontMan->getFontName(*macFont).c_str());
 
 	uint16 boxShadow = (uint16)textCast->boxShadow;
 	uint16 borderSize = (uint16)textCast->borderSize;
diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index c3a96dc..05bdddc 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -249,16 +249,21 @@ void MacFontManager::loadFonts(Common::MacResManager *fontFile) {
 }
 
 const Font *MacFontManager::getFont(MacFont macFont) {
+	Common::String name;
 	const Font *font = 0;
 
 	if (!_builtInFonts) {
-		if (macFont.getName().empty())
-			macFont.setName(getFontName(macFont.getId(), macFont.getSize(), macFont.getSlant()));
+		if (macFont.getName().empty()) {
+			name = getFontName(macFont.getId(), macFont.getSize(), macFont.getSlant());
+			macFont.setName(name);
+		}
 
 		if (!_fontRegistry.contains(macFont.getName())) {
 			// Let's try to generate name
-			if (macFont.getSlant() != kMacFontRegular)
-				macFont.setName(getFontName(macFont.getId(), macFont.getSize(), macFont.getSlant(), true));
+			if (macFont.getSlant() != kMacFontRegular) {
+				name = getFontName(macFont.getId(), macFont.getSize(), macFont.getSlant(), true);
+				macFont.setName(name);
+			}
 
 			if (!_fontRegistry.contains(macFont.getName()))
 				generateFontSubstitute(macFont);
@@ -303,8 +308,7 @@ void MacFontManager::clearFontMapping() {
 	_extraFontIds.clear();
 }
 
-const char *MacFontManager::getFontName(int id, int size, int slant, bool tryGen) {
-	static char name[128];
+const Common::String MacFontManager::getFontName(int id, int size, int slant, bool tryGen) {
 	Common::String n;
 
 	if (_extraFontNames.contains(id)) {
@@ -327,12 +331,10 @@ const char *MacFontManager::getFontName(int id, int size, int slant, bool tryGen
 		slant = 0;
 	}
 
-	snprintf(name, 128, "%s-%d-%d", n.c_str(), slant, size);
-
-	return name;
+	return Common::String::format("%s-%d-%d", n.c_str(), slant, size);
 }
 
-const char *MacFontManager::getFontName(MacFont &font) {
+const Common::String MacFontManager::getFontName(MacFont &font) {
 	return getFontName(font.getId(), font.getSize(), font.getSlant());
 }
 
@@ -375,7 +377,7 @@ void MacFontManager::generateFontSubstitute(MacFont &macFont) {
 	}
 
 	if (sizes.empty()) {
-		debug(1, "No viable substitute found for font %s", getFontName(macFont));
+		debug(1, "No viable substitute found for font %s", getFontName(macFont).c_str());
 		return;
 	}
 
@@ -400,13 +402,13 @@ void MacFontManager::generateFontSubstitute(MacFont &macFont) {
 }
 
 void MacFontManager::generateFont(MacFont &toFont, MacFont &fromFont) {
-	debugN("Found font substitute for font '%s' ", getFontName(toFont));
-	debug("as '%s'", getFontName(fromFont));
+	debugN("Found font substitute for font '%s' ", getFontName(toFont).c_str());
+	debug("as '%s'", getFontName(fromFont).c_str());
 
 	MacFONTFont *font = Graphics::MacFONTFont::scaleFont(fromFont.getFont(), toFont.getSize());
 
 	if (!font) {
-		warning("Failed to generate font '%s'", getFontName(toFont));
+		warning("Failed to generate font '%s'", getFontName(toFont).c_str());
 	}
 
 	toFont.setGenerated(true);
@@ -415,7 +417,7 @@ void MacFontManager::generateFont(MacFont &toFont, MacFont &fromFont) {
 	FontMan.assignFontToName(getFontName(toFont), font);
 	_fontRegistry.setVal(getFontName(toFont), new MacFont(toFont));
 
-	debug("Generated font '%s'", getFontName(toFont));
+	debug("Generated font '%s'", getFontName(toFont).c_str());
 }
 
 } // End of namespace Graphics
diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
index 0fb92ac..ddd9282 100644
--- a/graphics/macgui/macfontmanager.h
+++ b/graphics/macgui/macfontmanager.h
@@ -123,8 +123,8 @@ public:
 	 * @param size size of the font
 	 * @return the font name or NULL if ID goes beyond the mapping
 	 */
-	const char *getFontName(int id, int size, int slant = kMacFontRegular, bool tryGen = false);
-	const char *getFontName(MacFont &font);
+	const Common::String getFontName(int id, int size, int slant = kMacFontRegular, bool tryGen = false);
+	const Common::String getFontName(MacFont &font);
 	int getFontIdByName(Common::String name);
 
 	void loadFonts(Common::SeekableReadStream *stream);
diff --git a/graphics/macgui/macmenu.cpp b/graphics/macgui/macmenu.cpp
index ac64f0c..45e05c5 100644
--- a/graphics/macgui/macmenu.cpp
+++ b/graphics/macgui/macmenu.cpp
@@ -391,14 +391,11 @@ const Font *MacMenu::getMenuFont() {
 	return _wm->_fontMan->getFont(Graphics::MacFont(kMacFontChicago, 12));
 }
 
-const char *MacMenu::getAcceleratorString(MacMenuSubItem *item, const char *prefix) {
-	static char res[20];
-	*res = 0;
+const Common::String MacMenu::getAcceleratorString(MacMenuSubItem *item, const char *prefix) {
+	if (item->shortcut == 0)
+		return Common::String();
 
-	if (item->shortcut != 0)
-		sprintf(res, "%s%c%c", prefix, (_wm->_fontMan->hasBuiltInFonts() ? '^' : '\x11'), item->shortcut);
-
-	return res;
+	return Common::String::format("%s%c%c", prefix, (_wm->_fontMan->hasBuiltInFonts() ? '^' : '\x11'), item->shortcut);
 }
 
 int MacMenu::calculateMenuWidth(MacMenuItem *menu) {
diff --git a/graphics/macgui/macmenu.h b/graphics/macgui/macmenu.h
index 36cd06a..717a0ce 100644
--- a/graphics/macgui/macmenu.h
+++ b/graphics/macgui/macmenu.h
@@ -86,7 +86,7 @@ private:
 
 private:
 	const Font *getMenuFont();
-	const char *getAcceleratorString(MacMenuSubItem *item, const char *prefix);
+	const Common::String getAcceleratorString(MacMenuSubItem *item, const char *prefix);
 	int calculateMenuWidth(MacMenuItem *menu);
 	void calcMenuBounds(MacMenuItem *menu);
 	void renderSubmenu(MacMenuItem *menu);





More information about the Scummvm-git-logs mailing list