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

eriktorbjorn eriktorbjorn at telia.com
Sun Apr 4 08:27:33 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:
2fb992ed4e GRAPHICS: Clip Mac font glyphs to the destination surface


Commit: 2fb992ed4eef8dc8a33ac91ac288ffd0a36c7913
    https://github.com/scummvm/scummvm/commit/2fb992ed4eef8dc8a33ac91ac288ffd0a36c7913
Author: Torbjörn Andersson (eriktorbjorn at users.sourceforge.net)
Date: 2021-04-04T10:23:20+02:00

Commit Message:
GRAPHICS: Clip Mac font glyphs to the destination surface

This was probably causing instabilities in the MacVenture engine. The
engine is pretty broken at the moment, and the command window is so
small that text doesn't fit in it at all. Hopefully this will make the
remaining errors easier to debug... some day.

Changed paths:
    graphics/fonts/macfont.cpp


diff --git a/graphics/fonts/macfont.cpp b/graphics/fonts/macfont.cpp
index 7677a460bd..d0c3c6d36c 100644
--- a/graphics/fonts/macfont.cpp
+++ b/graphics/fonts/macfont.cpp
@@ -355,14 +355,31 @@ void MacFONTFont::drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color)
 	assert(dst != 0);
 	assert(dst->format.bytesPerPixel == 1 || dst->format.bytesPerPixel == 2 || dst->format.bytesPerPixel == 4);
 
+	if (x > dst->w || y > dst->h)
+		return;
+
 	const MacGlyph *glyph = findGlyph(chr);
 	if (!glyph || glyph->width == 0)
 		return;
 
-	for (uint16 i = 0; i < _data._fRectHeight; i++) {
+	if (x + glyph->bitmapWidth < 0 || y + _data._fRectHeight < 0)
+		return;
+
+	// Make sure we do not draw outside the surface
+	uint16 yStart = (y < 0) ? -y : 0;
+	uint16 yStop = _data._fRectHeight;
+	uint16 xStart = (x < 0) ? -x : 0;
+	uint16 xStop = glyph->bitmapWidth;
+
+	if (y + _data._fRectHeight >= dst->h)
+		yStop = dst->h - y;
+	if (x + glyph->bitmapWidth >= dst->w)
+		xStop = dst->w - x;
+
+	for (uint16 i = yStart; i < yStop; i++) {
 		byte *srcRow = _data._bitImage + i * _data._rowWords;
 
-		for (uint16 j = 0; j < glyph->bitmapWidth; j++) {
+		for (uint16 j = xStart; j < xStop; j++) {
 			uint16 bitmapOffset = glyph->bitmapOffset + j;
 
 			if (srcRow[bitmapOffset / 8] & (1 << (7 - (bitmapOffset % 8)))) {




More information about the Scummvm-git-logs mailing list