[Scummvm-git-logs] scummvm master -> 96008586c6c89b4af482ad4ed4129b18a64596c7

sev- noreply at scummvm.org
Tue Jun 27 10:00:32 UTC 2023


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:
96008586c6 GRAPHICS: Add scaling for winfont


Commit: 96008586c6c89b4af482ad4ed4129b18a64596c7
    https://github.com/scummvm/scummvm/commit/96008586c6c89b4af482ad4ed4129b18a64596c7
Author: Harishankar Kumar (hari01584 at gmail.com)
Date: 2023-06-27T13:00:29+03:00

Commit Message:
GRAPHICS: Add scaling for winfont

Allow scaling of window font, ie FON, FNT. Internally this uses
same implementation as BDFScaling and MacFontScaling. Uses function
scaleSingleGlyph to scale each glyph.

Fonts in `mcluhan-win` used some of these fonts where the sizes
were different than parsed.

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


diff --git a/graphics/fonts/winfont.cpp b/graphics/fonts/winfont.cpp
index 6861a01893d..9427af0717a 100644
--- a/graphics/fonts/winfont.cpp
+++ b/graphics/fonts/winfont.cpp
@@ -337,4 +337,77 @@ int WinFont::getStyle() {
 	return style;
 }
 
+WinFont *WinFont::scaleFont(const WinFont *src, int newSize) {
+	if (!src) {
+		warning("WinFont::scaleFont(): Empty font reference in scale font");
+		return nullptr;
+	}
+
+	if (src->getFontHeight() == 0) {
+		warning("WinFont::scaleFont(): Requested to scale 0 size font");
+		return nullptr;
+	}
+
+	WinFont *scaledFont = new WinFont();
+
+	Graphics::Surface srcSurf;
+	srcSurf.create(MAX(src->getFontHeight() * 2, newSize * 2), MAX(src->getFontHeight() * 2, newSize * 2), PixelFormat::createFormatCLUT8());
+	int dstGraySize = newSize * 20 * newSize;
+	int *dstGray = (int *)malloc(dstGraySize * sizeof(int));
+
+	float scale = (float)newSize / (float)src->getFontHeight();
+
+	scaledFont->_pixHeight = (int)(roundf((float)src->_pixHeight * scale));
+	scaledFont->_maxWidth = (int)(roundf((float)src->_maxWidth * scale));
+	scaledFont->_ascent = src->_ascent;
+	scaledFont->_firstChar = src->_firstChar;
+	scaledFont->_lastChar = src->_lastChar;
+	scaledFont->_defaultChar = src->_defaultChar;
+	scaledFont->_italic = src->_italic;
+	scaledFont->_strikethrough = src->_strikethrough;
+	scaledFont->_underline = src->_underline;
+	scaledFont->_weight = src->_weight;
+	scaledFont->_name = Common::String(src->_name);
+
+	scaledFont->_glyphCount = src->_glyphCount;
+
+	GlyphEntry *glyphs = new GlyphEntry[src->_glyphCount];
+	for (int i = 0; i < src->_glyphCount; i++) {
+		glyphs[i].charWidth = (int)(roundf((float)src->_glyphs[i].charWidth * scale));
+		glyphs[i].offset = src->_glyphs[i].offset;
+
+		int boxWidth = glyphs[i].charWidth;
+		int boxHeight = scaledFont->_pixHeight;
+		int grayLevel = (boxWidth * boxHeight) / 3;
+
+		byte *bitmap = new byte[boxWidth * boxHeight];
+		memset(bitmap, 0, boxWidth * boxHeight);
+
+		// Scale single character
+		src->scaleSingleGlyph(&srcSurf, dstGray, dstGraySize, boxWidth, boxHeight, 0, 0, grayLevel, i + src->_firstChar,
+		                      src->_pixHeight, src->_glyphs[i].charWidth, scale);
+
+		// Convert back to bytes representation
+		byte *ptr = bitmap;
+		for (int y = 0; y < boxHeight; y++) {
+			byte *srcd = (byte *)srcSurf.getBasePtr(0, y);
+			byte *dst = ptr;
+
+			for (int x = 0; x < boxWidth; x++, srcd++) {
+				*dst++ = *srcd;
+			}
+
+			ptr += boxWidth;
+		}
+
+		glyphs[i].bitmap = bitmap;
+	}
+	scaledFont->_glyphs = glyphs;
+
+	free(dstGray);
+	srcSurf.free();
+
+	return (WinFont *)scaledFont;
+}
+
 } // End of namespace Graphics
diff --git a/graphics/fonts/winfont.h b/graphics/fonts/winfont.h
index aebefdc9a8d..9545e6e18e7 100644
--- a/graphics/fonts/winfont.h
+++ b/graphics/fonts/winfont.h
@@ -70,6 +70,7 @@ public:
 	void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const;
 	int getStyle();
 
+	static WinFont *scaleFont(const WinFont *src, int newSize);
 private:
 	bool loadFromEXE(Common::WinResources *exe, const Common::String &fileName, const WinFontDirEntry &dirEntry);
 
diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 0aec0141e9d..ec6c475f945 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -524,8 +524,10 @@ const Font *MacFontManager::getFont(MacFont *macFont) {
 			font = _winFontRegistry.getVal(_fontInfo.getVal(id)->name);
 			const Graphics::WinFont *winfont = (const Graphics::WinFont *)font;
 
-			if (winfont->getFontHeight() != macFont->getSize())
+			if (winfont->getFontHeight() != macFont->getSize()) {
 				debug(5, "MacFontManager::getFont(): For font '%s' windows font '%s' is used of a different size %d", macFont->getName().c_str(), winfont->getName().c_str(), winfont->getFontHeight());
+				font = WinFont::scaleFont(winfont, macFont->getSize());
+			}
 		}
 	}
 




More information about the Scummvm-git-logs mailing list