GOB: Check font index for kFontCount

svn-id: r55547
This commit is contained in:
Sven Hesse 2011-01-26 19:03:13 +00:00
parent 2c2476b203
commit a2afc0f4d1
5 changed files with 38 additions and 18 deletions

View File

@ -371,10 +371,15 @@ void Draw::adjustCoords(char adjust, int16 *coord1, int16 *coord2) {
}
}
int Draw::stringLength(const char *str, int16 fontIndex) {
int Draw::stringLength(const char *str, uint16 fontIndex) {
static const int8 japaneseExtraCharLen[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
if ((fontIndex < 0) || (fontIndex > 7) || !_fonts[fontIndex])
if (fontIndex >= kFontCount) {
warning("Draw::stringLength(): Font %d > Count %d", fontIndex, kFontCount);
return 0;
}
if (!_fonts[fontIndex])
return 0;
Font &font = *_fonts[fontIndex];
@ -442,6 +447,14 @@ void Draw::printTextCentered(int16 id, int16 left, int16 top, int16 right,
if (str[0] == '\0')
return;
if (fontIndex >= kFontCount) {
warning("Draw::printTextCentered(): Font %d > Count %d", fontIndex, kFontCount);
return;
}
if (!_fonts[fontIndex])
return;
_transparency = 1;
_destSpriteX = left;
_destSpriteY = top;
@ -503,6 +516,14 @@ void Draw::oPlaytoons_sub_F_1B(uint16 id, int16 left, int16 top, int16 right, in
strcpy(paramStr, tmpStr);
if (fontIndex >= kFontCount) {
warning("Draw::oPlaytoons_sub_F_1B(): Font %d > Count %d", fontIndex, kFontCount);
return;
}
if (!_fonts[fontIndex])
return;
if (*paramStr) {
_transparency = 1;
_fontIndex = fontIndex;
@ -673,9 +694,11 @@ Font *Draw::loadFont(const char *path) const {
return new Font(data);
}
bool Draw::loadFont(int fontIndex, const char *path) {
if ((fontIndex < 0) || (fontIndex >= kFontCount))
bool Draw::loadFont(uint16 fontIndex, const char *path) {
if (fontIndex >= kFontCount) {
warning("Draw::loadFont(): Font %d > Count %d (\"%s\")", fontIndex, kFontCount, path);
return false;
}
delete _fonts[fontIndex];

View File

@ -71,7 +71,7 @@ public:
int16 _renderFlags;
int16 _fontIndex;
uint16 _fontIndex;
int16 _spriteLeft;
int16 _spriteTop;
int16 _spriteRight;
@ -184,7 +184,7 @@ public:
void adjustCoords(char adjust, uint16 *coord1, uint16 *coord2) {
adjustCoords(adjust, (int16 *)coord1, (int16 *)coord2);
}
int stringLength(const char *str, int16 fontIndex);
int stringLength(const char *str, uint16 fontIndex);
void drawString(const char *str, int16 x, int16 y, int16 color1, int16 color2,
int16 transp, Surface &dest, const Font &font);
void printTextCentered(int16 id, int16 left, int16 top, int16 right,
@ -198,7 +198,7 @@ public:
void wobble(Surface &surfDesc);
Font *loadFont(const char *path) const;
bool loadFont(int fontIndex, const char *path);
bool loadFont(uint16 fontIndex, const char *path);
virtual void initScreen() = 0;
virtual void closeScreen() = 0;

View File

@ -247,8 +247,7 @@ void Draw_v1::printTotText(int16 id) {
if (*ptr != 0xBA) {
_letterToPrint = (char) *ptr;
spriteOperation(DRAW_DRAWLETTER);
_destSpriteX +=
_fonts[_fontIndex]->getCharWidth();
_destSpriteX += _fonts[_fontIndex]->getCharWidth();
ptr++;
} else {
cmd = ptrEnd[17] & 0x7F;
@ -401,12 +400,12 @@ void Draw_v1::spriteOperation(int16 operation) {
break;
case DRAW_PRINTTEXT:
font = _fonts[_fontIndex];
if (!font) {
if ((_fontIndex >= kFontCount) || !_fonts[_fontIndex]) {
warning("Trying to print \"%s\" with undefined font %d", _textToPrint, _fontIndex);
break;
}
font = _fonts[_fontIndex];
len = strlen(_textToPrint);
dirtiedRect(_destSurface, _destSpriteX, _destSpriteY,
_destSpriteX + len * font->getCharWidth() - 1,
@ -453,12 +452,12 @@ void Draw_v1::spriteOperation(int16 operation) {
break;
case DRAW_DRAWLETTER:
font = _fonts[_fontIndex];
if (!font) {
if ((_fontIndex >= kFontCount) || !_fonts[_fontIndex]) {
warning("Trying to print \'%c\' with undefined font %d", _letterToPrint, _fontIndex);
break;
}
font = _fonts[_fontIndex];
if (_fontToSprite[_fontIndex].sprite == -1) {
dirtiedRect(_destSurface, _destSpriteX, _destSpriteY,
_destSpriteX + font->getCharWidth() - 1,

View File

@ -788,12 +788,12 @@ void Draw_v2::spriteOperation(int16 operation) {
left = _destSpriteX;
if ((_fontIndex >= 4) || (_fontToSprite[_fontIndex].sprite == -1)) {
Font *font = _fonts[_fontIndex];
if (!font) {
if ((_fontIndex >= kFontCount) || !_fonts[_fontIndex]) {
warning("Trying to print \"%s\" with undefined font %d", _textToPrint, _fontIndex);
break;
}
Font *font = _fonts[_fontIndex];
if (font->isMonospaced()) {
if (((int8) _textToPrint[0]) == -1) {
_vm->validateLanguage();

View File

@ -1746,10 +1746,8 @@ bool Inter_v1::o1_blitCursor(OpFuncParams &params) {
}
bool Inter_v1::o1_loadFont(OpFuncParams &params) {
int16 index;
_vm->_game->_script->evalExpr(0);
index = _vm->_game->_script->readInt16();
uint16 index = _vm->_game->_script->readInt16();
_vm->_draw->animateCursor(4);