[Scummvm-cvs-logs] SF.net SVN: scummvm:[48462] scummvm/trunk/engines/draci/font.cpp
spalek at users.sourceforge.net
spalek at users.sourceforge.net
Fri Apr 2 03:00:36 CEST 2010
Revision: 48462
http://scummvm.svn.sourceforge.net/scummvm/?rev=48462&view=rev
Author: spalek
Date: 2010-04-02 01:00:35 +0000 (Fri, 02 Apr 2010)
Log Message:
-----------
Fixed bug 2976767 on corrupted char glyphs.
After unfinished translation of the game, several inaccessible characters
have been left in the game files. Since the font does not contain all 256
characters, trying to draw them brings them random jump. I now properly
skip these characters.
Modified Paths:
--------------
scummvm/trunk/engines/draci/font.cpp
Modified: scummvm/trunk/engines/draci/font.cpp
===================================================================
--- scummvm/trunk/engines/draci/font.cpp 2010-04-01 23:33:34 UTC (rev 48461)
+++ scummvm/trunk/engines/draci/font.cpp 2010-04-02 01:00:35 UTC (rev 48462)
@@ -108,7 +108,12 @@
}
uint8 Font::getCharWidth(uint8 chr) const {
- return _charWidths[chr - kCharIndexOffset];
+ // Safe-guard against incorrect strings containing localized characters
+ // with inaccessible codes. These strings do not exist in the original
+ // Czech version, but they do in the (never properly reviewed) English
+ // version.
+ return chr >= kCharIndexOffset && chr < kCharIndexOffset + kCharNum
+ ? _charWidths[chr - kCharIndexOffset] : 0;
}
/**
@@ -126,10 +131,14 @@
assert(ty >= 0);
byte *ptr = (byte *)dst->getBasePtr(tx, ty);
- uint8 charIndex = chr - kCharIndexOffset;
- int charOffset = charIndex * _fontHeight * _maxCharWidth;
- uint8 currentWidth = _charWidths[charIndex];
+ const uint8 currentWidth = getCharWidth(chr);
+ if (currentWidth == 0) {
+ return;
+ }
+ const uint8 charIndex = chr - kCharIndexOffset;
+ const int charOffset = charIndex * _fontHeight * _maxCharWidth;
+
// Determine how many pixels to draw horizontally (to prevent overflow)
int xSpaceLeft = dst->w - tx - 1;
int xPixelsToDraw = (currentWidth < xSpaceLeft) ? currentWidth : xSpaceLeft;
@@ -256,9 +265,7 @@
for (uint i = 0, tmp = 0; i < len; ++i) {
if (str[i] != '|') {
- uint8 charIndex = str[i] - kCharIndexOffset;
- tmp += _charWidths[charIndex];
- tmp += spacing;
+ tmp += getCharWidth(str[i]) + spacing;
}
// Newline char encountered, skip it and store the new length if it is greater.
@@ -291,9 +298,7 @@
break;
// Add width of the current char
- uint8 charIndex = str[i] - kCharIndexOffset;
- width += _charWidths[charIndex];
- width += spacing;
+ width += getCharWidth(str[i]) + spacing;
}
return width;
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