[Scummvm-cvs-logs] SF.net SVN: scummvm: [25260] residual/trunk
aquadran at users.sourceforge.net
aquadran at users.sourceforge.net
Mon Jan 29 19:42:58 CET 2007
Revision: 25260
http://scummvm.svn.sourceforge.net/scummvm/?rev=25260&view=rev
Author: aquadran
Date: 2007-01-29 10:42:58 -0800 (Mon, 29 Jan 2007)
Log Message:
-----------
corrected fonts rendering
Modified Paths:
--------------
residual/trunk/font.cpp
residual/trunk/font.h
residual/trunk/textobject.cpp
residual/trunk/textobject.h
Modified: residual/trunk/font.cpp
===================================================================
--- residual/trunk/font.cpp 2007-01-29 18:36:27 UTC (rev 25259)
+++ residual/trunk/font.cpp 2007-01-29 18:42:58 UTC (rev 25260)
@@ -33,15 +33,11 @@
_numChars = READ_LE_UINT32(data);
_dataSize = READ_LE_UINT32(data + 4);
- _maxCharWidth = READ_LE_UINT32(data + 8);
- _maxCharHeight= READ_LE_UINT32(data + 12);
- _unknownHeader1 = READ_LE_UINT32(data + 16);
- _unknownHeader2 = READ_LE_UINT32(data + 20); // 8 unknown bytes are skipped
+ _height = READ_LE_UINT32(data + 8);
+ _baseOffsetY = READ_LE_UINT32(data + 12);
_firstChar = READ_LE_UINT32(data + 24);
_lastChar = READ_LE_UINT32(data + 28);
- //printf("unknown1: %#02x. unknown2: %#02x.\n", _unknownHeader1, _unknownHeader2);
-
data += 32;
// Read character indexes - are the key/value reversed?
@@ -60,18 +56,13 @@
error("Could not load font %s. Out of memory\n", filename);
for (uint i = 0; i < _numChars; ++i) {
_charHeaders[i].offset = READ_LE_UINT32(data);
- // 1 unknown byte before the startingLine, and 2 afterwards are skipped
- _charHeaders[i].unknown = READ_LE_UINT32(data + 4);
- _charHeaders[i].logicalWidth = *(uint8 *)(data + 4);
- _charHeaders[i].startingCol = *(uint8 *)(data + 5);
- _charHeaders[i].startingLine = (*(uint8 *)(data + 6)) & 0x0F;
- _charHeaders[i].width = READ_LE_UINT32(data + 8);
- _charHeaders[i].height = READ_LE_UINT32(data + 12);
+ _charHeaders[i].width = *(int8 *)(data + 4);
+ _charHeaders[i].startingCol = *(int8 *)(data + 5);
+ _charHeaders[i].startingLine = *(int8 *)(data + 6);
+ _charHeaders[i].dataWidth = READ_LE_UINT32(data + 8);
+ _charHeaders[i].dataHeight = READ_LE_UINT32(data + 12);
data += 16;
- _charHeaders[i].logicalWidth = MAX((int32) _charHeaders[i].logicalWidth, _charHeaders[i].width);
- //printf("%c. width: %d. logical width: %d. startCol: %d\n", i, _charHeaders[i].width, _charHeaders[i].logicalWidth, _charHeaders[i].startingCol);
}
-
// Read font data
_fontData = (byte *)malloc(_dataSize);
if (!_fontData)
@@ -86,8 +77,7 @@
free(_fontData);
}
-uint16 Font::getCharIndex(unsigned char c)
-{
+uint16 Font::getCharIndex(unsigned char c) {
uint16 c2 = uint16(c);
// In order to ensure the correct character codes for
Modified: residual/trunk/font.h
===================================================================
--- residual/trunk/font.h 2007-01-29 18:36:27 UTC (rev 25259)
+++ residual/trunk/font.h 2007-01-29 18:42:58 UTC (rev 25260)
@@ -33,9 +33,11 @@
Font(const char *filename, const char *data, int len);
~Font();
+ int32 getHeight() { return _height; }
+ int32 getBaseOffsetY() { return _baseOffsetY; }
+ int32 getCharDataWidth(unsigned char c) { return _charHeaders[getCharIndex(c)].dataWidth; }
+ int32 getCharDataHeight(unsigned char c) { return _charHeaders[getCharIndex(c)].dataHeight; }
int32 getCharWidth(unsigned char c) { return _charHeaders[getCharIndex(c)].width; }
- int32 getCharHeight(unsigned char c) { return _charHeaders[getCharIndex(c)].height; }
- int32 getCharLogicalWidth(unsigned char c) { return _charHeaders[getCharIndex(c)].logicalWidth; }
int32 getCharStartingCol(unsigned char c) { return _charHeaders[getCharIndex(c)].startingCol; }
int32 getCharStartingLine(unsigned char c) { return _charHeaders[getCharIndex(c)].startingLine; }
const byte *getCharData(unsigned char c) { return _fontData + (_charHeaders[getCharIndex(c)].offset); }
@@ -46,18 +48,16 @@
uint16 getCharIndex(unsigned char c);
struct CharHeader {
int32 offset;
- int32 unknown;
- int8 logicalWidth;
+ int8 width;
int8 startingCol;
int8 startingLine;
- int32 width;
- int32 height;
+ int32 dataWidth;
+ int32 dataHeight;
};
uint32 _numChars;
uint32 _dataSize;
- uint32 _maxCharWidth, _maxCharHeight;
- uint32 _unknownHeader1, _unknownHeader2;
+ uint32 _height, _baseOffsetY;
uint32 _firstChar, _lastChar;
uint16 *_charIndex;
CharHeader *_charHeaders;
Modified: residual/trunk/textobject.cpp
===================================================================
--- residual/trunk/textobject.cpp 2007-01-29 18:36:27 UTC (rev 25259)
+++ residual/trunk/textobject.cpp 2007-01-29 18:42:58 UTC (rev 25260)
@@ -35,7 +35,7 @@
TextObject::TextObject() :
_created(false), _x(0), _y(0), _width(0), _height(0), _justify(0),
_numberLines(1), _disabled(false), _font(NULL), _textBitmap(NULL),
- _bitmapWidthPtr(NULL), _bitmapHeightPtr(NULL), _textObjectHandle(NULL) {
+ _bitmapWidthPtr(NULL), _textObjectHandle(NULL) {
memset(_textID, 0, sizeof(_textID));
_fgColor._vals[0] = 0;
_fgColor._vals[1] = 0;
@@ -81,13 +81,10 @@
}
int TextObject::getBitmapHeight() {
- if (_bitmapHeightPtr == NULL)
- return 0;
-
uint height = 0;
for (int i = 0; i < _numberLines; i++) {
- height += _bitmapHeightPtr[i];
+ height += _font->getHeight();
}
return height;
}
@@ -96,9 +93,8 @@
int width = 0;
std::string msg = parseMsgText(_textID, NULL);
for (int i = 0; (msg[i] != '\0') && (i < pos); ++i) {
- width += _font->getCharLogicalWidth(msg[i]);
+ width += _font->getCharWidth(msg[i]);
}
-
return width;
}
@@ -127,7 +123,7 @@
_numberLines = 1;
lineWidth = 0;
for (int i = 0; msg[i] != '\0'; ++i) {
- lineWidth += _font->getCharLogicalWidth(msg[i]);
+ lineWidth += MAX(_font->getCharWidth(msg[i]), _font->getCharDataWidth(msg[i]));
if ((_width != 0 && lineWidth > (_width - _x))
|| (_justify == CENTER && (_x - lineWidth / 2 < 0 || _x + lineWidth / 2 > 640))
|| (_justify == LJUSTIFY && (_x + lineWidth > 640))
@@ -141,48 +137,47 @@
}
message += msg[i];
}
- _textObjectHandle = (Driver::TextObjectHandle **) malloc(sizeof(long) * _numberLines);
+ _textObjectHandle = (Driver::TextObjectHandle **)malloc(sizeof(long) * _numberLines);
_bitmapWidthPtr = (int *)malloc(sizeof(int) * _numberLines);
- _bitmapHeightPtr = (int *)malloc(sizeof(int) * _numberLines);
for (int j = 0; j < _numberLines; j++) {
int nextLinePos = message.find_first_of('\n');
std::string currentLine = message.substr(0, nextLinePos);
_bitmapWidthPtr[j] = 0;
- _bitmapHeightPtr[j] = 0;
for (int i = 0; currentLine[i] != '\0'; ++i) {
- _bitmapWidthPtr[j] += _font->getCharLogicalWidth(currentLine[i]);
- int h = _font->getCharHeight(currentLine[i]) + _font->getCharStartingLine(currentLine[i]);
- if (h > _bitmapHeightPtr[j])
- _bitmapHeightPtr[j] = h;
+ _bitmapWidthPtr[j] += MAX(_font->getCharWidth(currentLine[i]),
+ _font->getCharDataWidth(currentLine[i]));
}
- //printf("creating textobject: %s\nheight: %d\nwidth: %d\n", currentLine.c_str(), _bitmapHeight[j], _bitmapWidth[j]);
- // Due to the size of charWidth we need to allocate one more byte than we plan on using
- _textBitmap = new uint8[_bitmapHeightPtr[j] * _bitmapWidthPtr[j] + 1];
- memset(_textBitmap, 0, _bitmapHeightPtr[j] * _bitmapWidthPtr[j] + 1);
+ _textBitmap = new uint8[_font->getHeight() * (_bitmapWidthPtr[j] + 1)];
+ memset(_textBitmap, 0, _font->getHeight() * (_bitmapWidthPtr[j] + 1));
// Fill bitmap
- int offset = 0;
- for (int line = 0; line < _bitmapHeightPtr[j]; ++line) {
- for (int c = 0; currentLine[c] != '\0'; ++c) {
- int32 charWidth = _font->getCharWidth(currentLine[c]);
- int32 charLogicalWidth = _font->getCharLogicalWidth(currentLine[c]);
- int8 startingCol = _font->getCharStartingCol(currentLine[c]);
- int8 startingLine = _font->getCharStartingLine(currentLine[c]);
-
- if (startingLine < line + 1 && _font->getCharHeight(currentLine[c]) + startingLine > line) {
- memcpy(&_textBitmap[offset + startingCol],
- _font->getCharData(currentLine[c]) + charWidth * (line - startingLine), charWidth);
+ int startOffset = 0;
+ for (int c = 0; currentLine[c] != '\0'; c++) {
+ int ch = currentLine[c];
+ int8 startingLine = _font->getCharStartingLine(ch) + _font->getBaseOffsetY();
+ int32 charDataWidth = _font->getCharDataWidth(ch);
+ int32 charWidth = _font->getCharWidth(ch);
+ int8 startingCol = _font->getCharStartingCol(ch);
+ for (int line = 0; line < _font->getCharDataHeight(ch); line++) {
+ int offset = startOffset + ((_bitmapWidthPtr[j] + 1) * (line + startingLine));
+ for (int r = 0; r < charDataWidth; r++) {
+ const byte pixel = *(_font->getCharData(ch) + r + (charDataWidth * line));
+ byte *dst = _textBitmap + offset + startingCol + r;
+ if ((*dst == 0) && (pixel != 0))
+ _textBitmap[offset + startingCol + r] = pixel;
}
-
- offset += charLogicalWidth;
+ if (line + startingLine >= _font->getHeight())
+ break;
}
+ startOffset += charWidth;
}
- _textObjectHandle[j] = g_driver->createTextBitmap(_textBitmap, _bitmapWidthPtr[j], _bitmapHeightPtr[j], _fgColor);
+
+ _textObjectHandle[j] = g_driver->createTextBitmap(_textBitmap, _bitmapWidthPtr[j] + 1, _font->getHeight(), _fgColor);
delete[] _textBitmap;
- message = message.substr(nextLinePos+1, message.length()-(nextLinePos+1));
+ message = message.substr(nextLinePos + 1, message.length() - (nextLinePos + 1));
}
_created = true;
}
@@ -201,10 +196,6 @@
free(_bitmapWidthPtr);
_bitmapWidthPtr = NULL;
}
- if (_bitmapHeightPtr) {
- free(_bitmapHeightPtr);
- _bitmapHeightPtr = NULL;
- }
}
void TextObject::draw() {
@@ -217,29 +208,29 @@
int y;
if (_height != 0)
- y = (int) (_y - _bitmapHeightPtr[i] / 2.0);
+ y = _y - (_font->getHeight() / 2);
else
- y = _y;
+ y = _y + 5;
if (y < 0)
y = 0;
if (_justify == LJUSTIFY || _justify == NONE)
g_driver->drawTextBitmap(_x, height + y, _textObjectHandle[i]);
else if (_justify == CENTER) {
- int x = (int) (_x - (1 / 2.0) * _bitmapWidthPtr[i]);
+ int x = _x - (_bitmapWidthPtr[i] / 2);
if (x < 0)
x = 0;
g_driver->drawTextBitmap(x, height + y, _textObjectHandle[i]);
} else if (_justify == RJUSTIFY) {
- int x = _x - getBitmapWidth();
+ int x = (_x - getBitmapWidth());
if (x < 0)
x = 0;
- g_driver->drawTextBitmap(x, height + _y, _textObjectHandle[i]);
+ g_driver->drawTextBitmap(x, height + y, _textObjectHandle[i]);
} else if (debugLevel == DEBUG_WARN || debugLevel == DEBUG_ALL)
warning("TextObject::draw: Unknown justification code (%d)!", _justify);
- height += _bitmapHeightPtr[i];
+ height += _font->getHeight();
}
}
Modified: residual/trunk/textobject.h
===================================================================
--- residual/trunk/textobject.h 2007-01-29 18:36:27 UTC (rev 25259)
+++ residual/trunk/textobject.h 2007-01-29 18:42:58 UTC (rev 25260)
@@ -85,7 +85,7 @@
Font *_font;
char _textID[256];
uint8 *_textBitmap;
- int *_bitmapWidthPtr, *_bitmapHeightPtr;
+ int *_bitmapWidthPtr;
Driver::TextObjectHandle **_textObjectHandle;
};
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