[Scummvm-cvs-logs] SF.net SVN: scummvm:[41471] scummvm/branches/gsoc2009-draci/engines/draci

dkasak13 at users.sourceforge.net dkasak13 at users.sourceforge.net
Fri Jun 12 12:22:43 CEST 2009


Revision: 41471
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41471&view=rev
Author:   dkasak13
Date:     2009-06-12 10:22:43 +0000 (Fri, 12 Jun 2009)

Log Message:
-----------
Removed overflow/underflow checks from DraciFont::drawChar(). Instead, we now calculate the number of pixels that can be drawn without overflowing beforehand. Also added asserts to catch any negative value passed for the coordinates.

Modified Paths:
--------------
    scummvm/branches/gsoc2009-draci/engines/draci/draci.cpp
    scummvm/branches/gsoc2009-draci/engines/draci/font.cpp

Modified: scummvm/branches/gsoc2009-draci/engines/draci/draci.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/draci.cpp	2009-06-12 09:56:07 UTC (rev 41470)
+++ scummvm/branches/gsoc2009-draci/engines/draci/draci.cpp	2009-06-12 10:22:43 UTC (rev 41471)
@@ -133,7 +133,7 @@
 	// Draw small string
 	path = "Small.fon";
 	font.setFont(path);
-	testString = "I'm smaller than the font above me";
+	testString = "I'm smaller than the font above me.";
 	font.drawString(surf, testString, 
 		(320 - font.getStringWidth(testString, 1)) / 2, 150, 1);
 	_system->unlockScreen();

Modified: scummvm/branches/gsoc2009-draci/engines/draci/font.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/font.cpp	2009-06-12 09:56:07 UTC (rev 41470)
+++ scummvm/branches/gsoc2009-draci/engines/draci/font.cpp	2009-06-12 10:22:43 UTC (rev 41471)
@@ -117,27 +117,27 @@
 
 void DraciFont::drawChar(Graphics::Surface *dst, uint8 chr, int tx, int ty) const {
 	assert(dst != NULL);
+	assert(tx >= 0);
+	assert(ty >= 0);
+
 	byte *ptr = (byte *)dst->getBasePtr(tx, ty);
 	uint8 charIndex = chr - kCharIndexOffset;
 	int charOffset = charIndex * _fontHeight * _maxCharWidth;
 	uint8 currentWidth = _charWidths[charIndex];
 
-	for (uint8 y = 0; y < _fontHeight; ++y) {
+	// Determine how many pixels to draw horizontally (to prevent overflow)
+	int xSpaceLeft = dst->w - tx - 1;	
+	int xPixelsToDraw = (currentWidth < xSpaceLeft) ? currentWidth : xSpaceLeft;
 
-		// Check for vertical overflow
-		if (ty + y < 0 || ty + y >= dst->h) {
-			continue;
-		}
+	// Determine how many pixels to draw vertically
+	int ySpaceLeft = dst->h - ty - 1;	
+	int yPixelsToDraw = (_fontHeight < ySpaceLeft) ? _fontHeight : ySpaceLeft;
 
-		for (uint8 x = 0; x <= currentWidth; ++x) {
-			
-			// Check for horizontal overflow
-			if (tx + x < 0 || tx + x >= dst->w) {
-				continue;
-			}
-			
+	for (int y = 0; y < yPixelsToDraw; ++y) {
+		for (int x = 0; x <= xPixelsToDraw; ++x) {
+
 			// Paint pixel
-			int curr = ((int)y) * _maxCharWidth + x;
+			int curr = y * _maxCharWidth + x;
 			ptr[x] = _charData[charOffset + curr];
 		}
 
@@ -158,9 +158,13 @@
 
 void DraciFont::drawString(Graphics::Surface *dst, Common::String str, 
 							int x, int y, int spacing) const {
-	assert(dst != NULL);	
+	assert(dst != NULL);
+	assert(x >= 0);
+	assert(y >= 0);
+
 	int curx = x;
 	uint len = str.size();
+
 	for (unsigned int i = 0; i < len; ++i) {
 		drawChar(dst, str[i], curx, y);
 		curx += getCharWidth(str[i]) + spacing;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list