[Scummvm-cvs-logs] SF.net SVN: scummvm:[53656] scummvm/trunk/engines/saga

h00ligan at users.sourceforge.net h00ligan at users.sourceforge.net
Wed Oct 20 23:23:03 CEST 2010


Revision: 53656
          http://scummvm.svn.sourceforge.net/scummvm/?rev=53656&view=rev
Author:   h00ligan
Date:     2010-10-20 21:23:02 +0000 (Wed, 20 Oct 2010)

Log Message:
-----------
SAGA: replace Font "::*alloc" & "::free" with Common::Array

Modified Paths:
--------------
    scummvm/trunk/engines/saga/font.cpp
    scummvm/trunk/engines/saga/font.h

Modified: scummvm/trunk/engines/saga/font.cpp
===================================================================
--- scummvm/trunk/engines/saga/font.cpp	2010-10-20 21:06:45 UTC (rev 53655)
+++ scummvm/trunk/engines/saga/font.cpp	2010-10-20 21:23:02 UTC (rev 53656)
@@ -41,11 +41,9 @@
 
 	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() {
 	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 @@
 
 	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 @@
 		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 @@
 	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 @@
 	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 @@
 				}
 
 				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 @@
 		// "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::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 @@
 				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

Modified: scummvm/trunk/engines/saga/font.h
===================================================================
--- scummvm/trunk/engines/saga/font.h	2010-10-20 21:06:45 UTC (rev 53655)
+++ scummvm/trunk/engines/saga/font.h	2010-10-20 21:23:02 UTC (rev 53656)
@@ -120,7 +120,7 @@
 struct FontStyle {
 	FontHeader header;
 	FontCharEntry fontCharEntry[256];
-	byte *font;
+	Common::Array<byte> font;
 };
 
 struct FontData {
@@ -170,14 +170,14 @@
 	 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 @@
 		 }
 	 }
 	 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 @@
 
 	int _fontMapping;
 
-	int _loadedFonts;
-	FontData **_fonts;
+	Common::Array<FontData> _fonts;
 };
 
 } // End of namespace Saga


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