[Scummvm-git-logs] scummvm master -> 122acc39b5b00a4fdb6c7544fe619b0193f0737e

dreammaster dreammaster at scummvm.org
Thu Aug 26 04:31:54 UTC 2021


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:
122acc39b5 AGS: Fix font outlines not drawing correctly


Commit: 122acc39b5b00a4fdb6c7544fe619b0193f0737e
    https://github.com/scummvm/scummvm/commit/122acc39b5b00a4fdb6c7544fe619b0193f0737e
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-08-25T21:31:40-07:00

Commit Message:
AGS: Fix font outlines not drawing correctly

Changed paths:
    engines/ags/lib/alfont/alfont.cpp
    engines/ags/lib/alfont/alfont.h
    engines/ags/shared/font/fonts.cpp
    engines/ags/shared/font/fonts.h
    engines/ags/shared/font/ttf_font_renderer.cpp


diff --git a/engines/ags/lib/alfont/alfont.cpp b/engines/ags/lib/alfont/alfont.cpp
index 2efe207a04..99fec416e6 100644
--- a/engines/ags/lib/alfont/alfont.cpp
+++ b/engines/ags/lib/alfont/alfont.cpp
@@ -65,14 +65,33 @@ size_t alfont_text_height(ALFONT_FONT *font) {
 	return font->_size;
 }
 
-void alfont_textout(BITMAP *bmp, ALFONT_FONT *font, const char *text, int x, int y, uint32 color) {
+void alfont_textout(BITMAP *bmp, ALFONT_FONT *font, ALFONT_FONT *refFont, const char *text, int x, int y, uint32 color) {
 	// Note: the original does not use antialiasing when drawing on 8 bit bmp
 	// if (bitmap_color_depth(bmp) > 8) do not use AA in getFont()...
 	// The original alfont changes the y based on the font height and ascent.
 	y += (font->_size - font->getFont()->getFontAscent());
 	Graphics::ManagedSurface &surf = **bmp;
-	font->getFont()->drawString(&surf, text, x, y, bmp->w - x,
-		(color == surf.getTransparentColor()) ? color - 1 : color);
+	Graphics::Font *fnt = font->getFont();
+	uint32 col = (color == surf.getTransparentColor()) ? color - 1 : color;
+
+	if (!refFont) {
+		// Standard string draw
+		fnt->drawString(&surf, text, x, y, bmp->w - x, col);
+
+	} else {
+		// Drawing an outline prior to standard font drawing on top.
+		// We use the font's character widths to ensure the two match up
+		refFont->_size = font->_size;
+		Graphics::Font *srcFnt = refFont->getFont();
+
+		for (int w = bmp->w - x; *text && w > 0; ++text) {
+			fnt->drawChar(&surf, *text, x, y, col);
+
+			int charWidth = srcFnt->getCharWidth(*text);
+			x += charWidth;
+			w -= charWidth;
+		}
+	}
 }
 
 void alfont_set_font_size(ALFONT_FONT *font, int size) {
diff --git a/engines/ags/lib/alfont/alfont.h b/engines/ags/lib/alfont/alfont.h
index b63a9562d9..61b80f488e 100644
--- a/engines/ags/lib/alfont/alfont.h
+++ b/engines/ags/lib/alfont/alfont.h
@@ -55,7 +55,7 @@ extern void alfont_destroy_font(ALFONT_FONT *font);
 
 extern size_t alfont_text_length(ALFONT_FONT *font, const char *text);
 extern size_t alfont_text_height(ALFONT_FONT *font);
-extern void alfont_textout(BITMAP *bmp, ALFONT_FONT *font, const char *text, int x, int y, uint32 color);
+extern void alfont_textout(BITMAP *bmp, ALFONT_FONT *font, ALFONT_FONT *refFont, const char *text, int x, int y, uint32 color);
 extern const char *alfont_get_name(ALFONT_FONT *font);
 extern void alfont_set_font_size(ALFONT_FONT *font, int size);
 
diff --git a/engines/ags/shared/font/fonts.cpp b/engines/ags/shared/font/fonts.cpp
index 56f5009f04..7f16cf5635 100644
--- a/engines/ags/shared/font/fonts.cpp
+++ b/engines/ags/shared/font/fonts.cpp
@@ -138,6 +138,15 @@ int get_font_outline(size_t font_number) {
 	return _GP(fonts)[font_number].Info.Outline;
 }
 
+int get_outline_font(size_t font_number) {
+	for (size_t fontNum = 0; fontNum < _GP(fonts).size(); ++fontNum) {
+		if (_GP(fonts)[fontNum].Info.Outline == (int)font_number)
+			return fontNum;
+	}
+
+	return FONT_OUTLINE_NONE;
+}
+
 void set_font_outline(size_t font_number, int outline_type) {
 	if (font_number >= _GP(fonts).size())
 		return;
diff --git a/engines/ags/shared/font/fonts.h b/engines/ags/shared/font/fonts.h
index c5ab4c4914..5636c02624 100644
--- a/engines/ags/shared/font/fonts.h
+++ b/engines/ags/shared/font/fonts.h
@@ -84,6 +84,7 @@ int getfontlinespacing(size_t fontNumber);
 // Get is font is meant to use default line spacing
 bool use_default_linespacing(size_t fontNumber);
 int  get_font_outline(size_t font_number);
+int  get_outline_font(size_t font_number);
 void set_font_outline(size_t font_number, int outline_type);
 // Outputs a single line of text on the defined position on bitmap, using defined font, color and parameters
 int getfontlinespacing(size_t fontNumber);
diff --git a/engines/ags/shared/font/ttf_font_renderer.cpp b/engines/ags/shared/font/ttf_font_renderer.cpp
index 052576273d..dd616d0ffc 100644
--- a/engines/ags/shared/font/ttf_font_renderer.cpp
+++ b/engines/ags/shared/font/ttf_font_renderer.cpp
@@ -68,8 +68,16 @@ void TTFFontRenderer::RenderText(const char *text, int fontNumber, BITMAP *desti
 	if (y > destination->cb)  // optimisation
 		return;
 
+	int srcFontNum = get_outline_font(fontNumber);
+	ALFONT_FONT *srcFont = nullptr;
+	if (srcFontNum != FONT_OUTLINE_NONE) {
+		srcFont = _fontData[srcFontNum].AlFont;
+		assert(srcFont);
+	}
+
 	// Y - 1 because it seems to get drawn down a bit
-	alfont_textout(destination, _fontData[fontNumber].AlFont, text, x, y - 1, colour);
+	alfont_textout(destination, _fontData[fontNumber].AlFont,
+		srcFont, text, x, y - 1, colour);
 }
 
 bool TTFFontRenderer::LoadFromDisk(int fontNumber, int fontSize) {




More information about the Scummvm-git-logs mailing list