aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kurushin2010-10-20 21:23:02 +0000
committerAndrew Kurushin2010-10-20 21:23:02 +0000
commit1bd1a253f0bdc063b4795a68fab52e2d98d2f181 (patch)
treeb66bab1484068d40c50dc7763aa2c1b343c1c447
parente797fdc0d9508a200e28c297ab350ca3dda33751 (diff)
downloadscummvm-rg350-1bd1a253f0bdc063b4795a68fab52e2d98d2f181.tar.gz
scummvm-rg350-1bd1a253f0bdc063b4795a68fab52e2d98d2f181.tar.bz2
scummvm-rg350-1bd1a253f0bdc063b4795a68fab52e2d98d2f181.zip
SAGA: replace Font "::*alloc" & "::free" with Common::Array
svn-id: r53656
-rw-r--r--engines/saga/font.cpp61
-rw-r--r--engines/saga/font.h11
2 files changed, 25 insertions, 47 deletions
diff --git a/engines/saga/font.cpp b/engines/saga/font.cpp
index 47f1a122c0..05f22d685f 100644
--- a/engines/saga/font.cpp
+++ b/engines/saga/font.cpp
@@ -41,11 +41,9 @@ Font::Font(SagaEngine *vm) : _vm(vm) {
assert(_vm->getFontsCount() > 0);
- _fonts = (FontData **)calloc(_vm->getFontsCount(), sizeof(*_fonts));
- _loadedFonts = 0;
-
+ _fonts.resize(_vm->getFontsCount());
for (i = 0; i < _vm->getFontsCount(); i++) {
- loadFont(_vm->getFontDescription(i)->fontResourceId);
+ loadFont(&_fonts[i], _vm->getFontDescription(i)->fontResourceId);
}
_fontMapping = 0;
@@ -53,23 +51,10 @@ Font::Font(SagaEngine *vm) : _vm(vm) {
Font::~Font() {
debug(8, "Font::~Font(): Freeing fonts.");
- int i;
-
- for (i = 0 ; i < _loadedFonts ; i++) {
- if (_fonts[i] != NULL) {
- free(_fonts[i]->normal.font);
- free(_fonts[i]->outline.font);
- }
-
- free(_fonts[i]);
- }
-
- free(_fonts);
}
-void Font::loadFont(uint32 fontResourceId) {
- FontData *font;
+void Font::loadFont(FontData *font, uint32 fontResourceId) {
byte *fontResourcePointer;
size_t fontResourceLength;
int numBits;
@@ -92,9 +77,6 @@ void Font::loadFont(uint32 fontResourceId) {
MemoryReadStreamEndian readS(fontResourcePointer, fontResourceLength, fontContext->isBigEndian());
- // Create new font structure
- font = (FontData *)malloc(sizeof(*font));
-
// Read font header
font->normal.header.charHeight = readS.readUint16();
font->normal.header.charWidth = readS.readUint16();
@@ -126,17 +108,14 @@ void Font::loadFont(uint32 fontResourceId) {
error("Invalid font resource size");
}
- font->normal.font = (byte*)malloc(fontResourceLength - FONT_DESCSIZE);
- memcpy(font->normal.font, fontResourcePointer + FONT_DESCSIZE, fontResourceLength - FONT_DESCSIZE);
+ font->normal.font.resize(fontResourceLength - FONT_DESCSIZE);
+ memcpy(&font->normal.font.front(), fontResourcePointer + FONT_DESCSIZE, fontResourceLength - FONT_DESCSIZE);
free(fontResourcePointer);
// Create outline font style
createOutline(font);
-
- // Set font data
- _fonts[_loadedFonts++] = font;
}
void Font::createOutline(FontData *font) {
@@ -145,12 +124,12 @@ void Font::createOutline(FontData *font) {
int newByteWidth;
int newRowLength = 0;
int currentByte;
- unsigned char *basePointer;
- unsigned char *srcPointer;
- unsigned char *destPointer1;
- unsigned char *destPointer2;
- unsigned char *destPointer3;
- unsigned char charRep;
+ byte *basePointer;
+ byte *srcPointer;
+ byte *destPointer1;
+ byte *destPointer2;
+ byte *destPointer3;
+ byte charRep;
// Populate new font style character data
for (i = 0; i < FONT_CHARCOUNT; i++) {
@@ -177,20 +156,20 @@ void Font::createOutline(FontData *font) {
font->outline.header.rowLength = newRowLength;
// Allocate new font representation storage
- font->outline.font = (unsigned char *)calloc(newRowLength, font->outline.header.charHeight);
+ font->outline.font.resize(newRowLength * font->outline.header.charHeight);
// Generate outline font representation
for (i = 0; i < FONT_CHARCOUNT; i++) {
for (row = 0; row < font->normal.header.charHeight; row++) {
for (currentByte = 0; currentByte < font->outline.fontCharEntry[i].byteWidth; currentByte++) {
- basePointer = font->outline.font + font->outline.fontCharEntry[i].index + currentByte;
+ basePointer = &font->outline.font[font->outline.fontCharEntry[i].index + currentByte];
destPointer1 = basePointer + newRowLength * row;
destPointer2 = basePointer + newRowLength * (row + 1);
destPointer3 = basePointer + newRowLength * (row + 2);
if (currentByte > 0) {
// Get last two columns from previous byte
- srcPointer = font->normal.font + font->normal.header.rowLength * row + font->normal.fontCharEntry[i].index + (currentByte - 1);
+ srcPointer = &font->normal.font[font->normal.header.rowLength * row + font->normal.fontCharEntry[i].index + (currentByte - 1)];
charRep = *srcPointer;
*destPointer1 |= ((charRep << 6) | (charRep << 7));
*destPointer2 |= ((charRep << 6) | (charRep << 7));
@@ -198,7 +177,7 @@ void Font::createOutline(FontData *font) {
}
if (currentByte < font->normal.fontCharEntry[i].byteWidth) {
- srcPointer = font->normal.font + font->normal.header.rowLength * row + font->normal.fontCharEntry[i].index + currentByte;
+ srcPointer = &font->normal.font[font->normal.header.rowLength * row + font->normal.fontCharEntry[i].index + currentByte];
charRep = *srcPointer;
*destPointer1 |= charRep | (charRep >> 1) | (charRep >> 2);
*destPointer2 |= charRep | (charRep >> 1) | (charRep >> 2);
@@ -210,15 +189,15 @@ void Font::createOutline(FontData *font) {
// "Hollow out" character to prevent overdraw
for (row = 0; row < font->normal.header.charHeight; row++) {
for (currentByte = 0; currentByte < font->outline.fontCharEntry[i].byteWidth; currentByte++) {
- destPointer2 = font->outline.font + font->outline.header.rowLength * (row + 1) + font->outline.fontCharEntry[i].index + currentByte;
+ destPointer2 = &font->outline.font[font->outline.header.rowLength * (row + 1) + font->outline.fontCharEntry[i].index + currentByte];
if (currentByte > 0) {
// Get last two columns from previous byte
- srcPointer = font->normal.font + font->normal.header.rowLength * row + font->normal.fontCharEntry[i].index + (currentByte - 1);
+ srcPointer = &font->normal.font[font->normal.header.rowLength * row + font->normal.fontCharEntry[i].index + (currentByte - 1)];
*destPointer2 &= ((*srcPointer << 7) ^ 0xFFU);
}
if (currentByte < font->normal.fontCharEntry[i].byteWidth) {
- srcPointer = font->normal.font + font->normal.header.rowLength * row + font->normal.fontCharEntry[i].index + currentByte;
+ srcPointer = &font->normal.font[font->normal.header.rowLength * row + font->normal.fontCharEntry[i].index + currentByte];
*destPointer2 &= ((*srcPointer >> 1) ^ 0xFFU);
}
}
@@ -289,7 +268,7 @@ void Font::draw(FontId fontId, const char *text, size_t count, const Common::Poi
void Font::outFont(const FontStyle &drawFont, const char *text, size_t count, const Common::Point &point, int color, FontEffectFlags flags) {
const byte *textPointer;
- byte *c_dataPointer;
+ const byte *c_dataPointer;
int c_code;
int charRow = 0;
Point textPoint(point);
@@ -384,7 +363,7 @@ void Font::outFont(const FontStyle &drawFont, const char *text, size_t count, co
break;
}
- c_dataPointer = drawFont.font + charRow * drawFont.header.rowLength + drawFont.fontCharEntry[c_code].index;
+ c_dataPointer = &drawFont.font[charRow * drawFont.header.rowLength + drawFont.fontCharEntry[c_code].index];
for (c_byte = 0; c_byte < c_byte_len; c_byte++, c_dataPointer++) {
// Check each bit, draw pixel if bit is set
diff --git a/engines/saga/font.h b/engines/saga/font.h
index 1b9f290a1b..a85906c799 100644
--- a/engines/saga/font.h
+++ b/engines/saga/font.h
@@ -120,7 +120,7 @@ struct FontCharEntry {
struct FontStyle {
FontHeader header;
FontCharEntry fontCharEntry[256];
- byte *font;
+ Common::Array<byte> font;
};
struct FontData {
@@ -170,14 +170,14 @@ class Font {
void textDrawRect(FontId fontId, const char *text, const Common::Rect &rect, int color, int effectColor, FontEffectFlags flags);
void textDraw(FontId fontId, const char *string, const Common::Point &point, int color, int effectColor, FontEffectFlags flags);
- void loadFont(uint32 fontResourceId);
+ void loadFont(FontData *font, uint32 fontResourceId);
void createOutline(FontData *font);
void draw(FontId fontId, const char *text, size_t count, const Common::Point &point, int color, int effectColor, FontEffectFlags flags);
void outFont(const FontStyle &drawFont, const char *text, size_t count, const Common::Point &point, int color, FontEffectFlags flags);
FontData *getFont(FontId fontId) {
validate(fontId);
- return _fonts[fontId];
+ return &_fonts[fontId];
}
int getHeight(FontId fontId) {
@@ -190,7 +190,7 @@ class Font {
}
}
bool valid(FontId fontId) {
- return (fontId < _loadedFonts);
+ return (uint(fontId) < _fonts.size());
}
int getByteLen(int numBits) const {
int byteLength = numBits / 8;
@@ -207,8 +207,7 @@ class Font {
int _fontMapping;
- int _loadedFonts;
- FontData **_fonts;
+ Common::Array<FontData> _fonts;
};
} // End of namespace Saga