diff options
| author | Denis Kasak | 2009-06-12 10:22:43 +0000 | 
|---|---|---|
| committer | Denis Kasak | 2009-06-12 10:22:43 +0000 | 
| commit | 32d12e90e3624e57d5f0eb1176f542ec44bd9ef8 (patch) | |
| tree | 2251366042bdc849109ca35b9219486c1eeac068 | |
| parent | 2308748f01e5ef80c22bd489a218aeee85250aa3 (diff) | |
| download | scummvm-rg350-32d12e90e3624e57d5f0eb1176f542ec44bd9ef8.tar.gz scummvm-rg350-32d12e90e3624e57d5f0eb1176f542ec44bd9ef8.tar.bz2 scummvm-rg350-32d12e90e3624e57d5f0eb1176f542ec44bd9ef8.zip | |
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.
svn-id: r41471
| -rw-r--r-- | engines/draci/draci.cpp | 2 | ||||
| -rw-r--r-- | engines/draci/font.cpp | 32 | 
2 files changed, 19 insertions, 15 deletions
| diff --git a/engines/draci/draci.cpp b/engines/draci/draci.cpp index 69460029d3..58f5261193 100644 --- a/engines/draci/draci.cpp +++ b/engines/draci/draci.cpp @@ -133,7 +133,7 @@ int DraciEngine::go() {  	// 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(); diff --git a/engines/draci/font.cpp b/engines/draci/font.cpp index a99dd06a58..808feb7d3c 100644 --- a/engines/draci/font.cpp +++ b/engines/draci/font.cpp @@ -117,27 +117,27 @@ uint8 DraciFont::getCharWidth(uint8 chr) const {  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 (int y = 0; y < yPixelsToDraw; ++y) { +		for (int x = 0; x <= xPixelsToDraw; ++x) { -		for (uint8 x = 0; x <= currentWidth; ++x) { -			 -			// Check for horizontal overflow -			if (tx + x < 0 || tx + x >= dst->w) { -				continue; -			} -			  			// Paint pixel -			int curr = ((int)y) * _maxCharWidth + x; +			int curr = y * _maxCharWidth + x;  			ptr[x] = _charData[charOffset + curr];  		} @@ -158,9 +158,13 @@ void DraciFont::drawChar(Graphics::Surface *dst, uint8 chr, int tx, int ty) cons  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; | 
