[Scummvm-cvs-logs] SF.net SVN: scummvm: [21952] scummvm/trunk/gui
lordhoto at users.sourceforge.net
lordhoto at users.sourceforge.net
Sun Apr 16 12:55:00 CEST 2006
Revision: 21952
Author: lordhoto
Date: 2006-04-16 12:54:39 -0700 (Sun, 16 Apr 2006)
ViewCVS: http://svn.sourceforge.net/scummvm/?rev=21952&view=rev
Log Message:
-----------
- Moves Graphics::loadFont to Graphics::NewFont::loadFont
- adds code for caching of fonts (just for Graphics::NewFont)
- implements cache using in the modern theme for custom fonts
- adds cache file for current normal font in the theme zip file
Modified Paths:
--------------
scummvm/trunk/graphics/font.cpp
scummvm/trunk/graphics/font.h
scummvm/trunk/gui/ThemeNew.cpp
scummvm/trunk/gui/theme.h
scummvm/trunk/gui/themes/modern.zip
Modified: scummvm/trunk/graphics/font.cpp
===================================================================
--- scummvm/trunk/graphics/font.cpp 2006-04-16 19:23:14 UTC (rev 21951)
+++ scummvm/trunk/graphics/font.cpp 2006-04-16 19:54:39 UTC (rev 21952)
@@ -21,6 +21,8 @@
#include "common/stdafx.h"
#include "common/stream.h"
+#include "common/file.h"
+#include "common/endian.h"
#include "graphics/font.h"
namespace Graphics {
@@ -538,7 +540,7 @@
return val;
}
-NewFont *loadFont(Common::SeekableReadStream &stream) {
+NewFont *NewFont::loadFont(Common::SeekableReadStream &stream) {
NewFontData *data = bdf_read_font(stream);
if (!data)
return 0;
@@ -559,13 +561,101 @@
return new NewFont(desc, data);
}
-NewFont *loadFont(const byte *src, uint32 size) {
- Common::MemoryReadStream stream(src, size);
+bool NewFont::cacheFontData(const NewFont &font, const Common::String &filename) {
+ Common::File cacheFile;
+ if (!cacheFile.open(filename, Common::File::kFileWriteMode)) {
+ warning("Couldn't open file '%s' for writing", filename.c_str());
+ return false;
+ }
- NewFontData *data = bdf_read_font(stream);
- if (!data)
+ cacheFile.writeUint16BE(font.desc.maxwidth);
+ cacheFile.writeUint16BE(font.desc.height);
+ cacheFile.writeUint16BE(font.desc.ascent);
+ cacheFile.writeUint16BE(font.desc.firstchar);
+ cacheFile.writeUint16BE(font.desc.size);
+ cacheFile.writeUint16BE(font.desc.defaultchar);
+ cacheFile.writeUint32BE(font.desc.bits_size);
+
+ for (long i = 0; i < font.desc.bits_size; ++i) {
+ cacheFile.writeUint16BE(font.desc.bits[i]);
+ }
+
+ if (font.desc.offset) {
+ cacheFile.writeByte(1);
+ for (int i = 0; i < font.desc.size; ++i) {
+ cacheFile.writeUint32BE(font.desc.offset[i]);
+ }
+ } else {
+ cacheFile.writeByte(0);
+ }
+
+ if (font.desc.width) {
+ cacheFile.writeByte(1);
+ for (int i = 0; i < font.desc.size; ++i) {
+ cacheFile.writeByte(font.desc.width[i]);
+ }
+ } else {
+ cacheFile.writeByte(0);
+ }
+
+ return !cacheFile.ioFailed();
+}
+
+NewFont *NewFont::loadFromCache(Common::SeekableReadStream &stream) {
+ NewFont *font = 0;
+
+ NewFontData *data = (NewFontData *)malloc(sizeof(NewFontData));
+ if (!data) return 0;
+
+ memset(data, 0, sizeof(NewFontData));
+
+ data->maxwidth = stream.readUint16BE();
+ data->height = stream.readUint16BE();
+ data->ascent = stream.readUint16BE();
+ data->firstchar = stream.readUint16BE();
+ data->size = stream.readUint16BE();
+ data->defaultchar = stream.readUint16BE();
+ data->bits_size = stream.readUint32BE();
+
+ data->bits = (bitmap_t*)malloc(sizeof(bitmap_t)*data->bits_size);
+ if (!data->bits) {
+ free(data);
return 0;
+ }
+ for (long i = 0; i < data->bits_size; ++i) {
+ data->bits[i] = stream.readUint16BE();
+ }
+
+ bool hasOffsetTable = stream.readByte();
+ if (hasOffsetTable) {
+ data->offset = (unsigned long*)malloc(sizeof(unsigned long)*data->size);
+ if (!data->offset) {
+ free(data->bits);
+ free(data);
+ return 0;
+ }
+
+ for (int i = 0; i < data->size; ++i) {
+ data->offset[i] = stream.readUint32BE();
+ }
+ }
+
+ bool hasWidthTable = stream.readByte();
+ if (hasWidthTable) {
+ data->width = (unsigned char*)malloc(sizeof(unsigned char)*data->size);
+ if (!data->width) {
+ free(data->bits);
+ free(data->offset);
+ free(data);
+ return 0;
+ }
+
+ for (int i = 0; i < data->size; ++i) {
+ data->width[i] = stream.readByte();
+ }
+ }
+
FontDesc desc;
desc.name = data->name;
desc.maxwidth = data->maxwidth;
@@ -579,7 +669,16 @@
desc.defaultchar = data->defaultchar;
desc.bits_size = data->bits_size;
- return new NewFont(desc, data);
+ font = new NewFont(desc, data);
+ if (!font || stream.ioFailed()) {
+ free(data->bits);
+ free(data->offset);
+ free(data->width);
+ free(data);
+ return 0;
+ }
+
+ return font;
}
#pragma mark -
Modified: scummvm/trunk/graphics/font.h
===================================================================
--- scummvm/trunk/graphics/font.h 2006-04-16 19:23:14 UTC (rev 21951)
+++ scummvm/trunk/graphics/font.h 2006-04-16 19:54:39 UTC (rev 21952)
@@ -123,11 +123,12 @@
virtual int getCharWidth(byte chr) const;
virtual void drawChar(Surface *dst, byte chr, int x, int y, uint32 color) const;
+
+ static NewFont *loadFont(Common::SeekableReadStream &stream);
+ static bool cacheFontData(const NewFont &font, const Common::String &filename);
+ static NewFont *loadFromCache(Common::SeekableReadStream &stream);
};
-NewFont *loadFont(Common::SeekableReadStream &stream);
-NewFont *loadFont(const byte *src, uint32 size);
-
#if (defined(PALMOS_ARM) || defined(PALMOS_DEBUG) || defined(__GP32__))
# define DEFINE_FONT(n) \
const NewFont *n; \
Modified: scummvm/trunk/gui/ThemeNew.cpp
===================================================================
--- scummvm/trunk/gui/ThemeNew.cpp 2006-04-16 19:23:14 UTC (rev 21951)
+++ scummvm/trunk/gui/ThemeNew.cpp 2006-04-16 19:54:39 UTC (rev 21952)
@@ -1341,38 +1341,98 @@
}
const Graphics::Font *ThemeNew::loadFont(const char *filename) {
- const Graphics::Font *font = 0;
+ const Graphics::NewFont *font = 0;
+ Common::String cacheFilename = genCacheFilename(filename);
+ Common::File fontFile;
- Common::File fontFile;
- if (fontFile.open(filename)) {
- font = Graphics::loadFont(fontFile);
+ if (cacheFilename != "") {
+ if (fontFile.open(cacheFilename))
+ font = Graphics::NewFont::loadFromCache(fontFile);
if (font)
return font;
- }
#ifdef USE_ZLIB
- unzFile zipFile = unzOpen((_stylefile + ".zip").c_str());
- if (zipFile && unzLocateFile(zipFile, filename, 2) == UNZ_OK) {
- unz_file_info fileInfo;
- unzOpenCurrentFile(zipFile);
- unzGetCurrentFileInfo(zipFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
- uint8 *buffer = new uint8[fileInfo.uncompressed_size+1];
- assert(buffer);
- memset(buffer, 0, (fileInfo.uncompressed_size+1)*sizeof(uint8));
- unzReadCurrentFile(zipFile, buffer, fileInfo.uncompressed_size);
- unzCloseCurrentFile(zipFile);
- Common::MemoryReadStream stream(buffer, fileInfo.uncompressed_size+1);
+ unzFile zipFile = unzOpen((_stylefile + ".zip").c_str());
+ if (zipFile && unzLocateFile(zipFile, cacheFilename.c_str(), 2) == UNZ_OK) {
+ unz_file_info fileInfo;
+ unzOpenCurrentFile(zipFile);
+ unzGetCurrentFileInfo(zipFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
+ uint8 *buffer = new uint8[fileInfo.uncompressed_size+1];
+ assert(buffer);
+ memset(buffer, 0, (fileInfo.uncompressed_size+1)*sizeof(uint8));
+ unzReadCurrentFile(zipFile, buffer, fileInfo.uncompressed_size);
+ unzCloseCurrentFile(zipFile);
+ Common::MemoryReadStream stream(buffer, fileInfo.uncompressed_size+1);
+
+ font = Graphics::NewFont::loadFromCache(stream);
+
+ delete [] buffer;
+ buffer = 0;
+ }
+ unzClose(zipFile);
+#endif
+ if (font)
+ return font;
+ }
- font = Graphics::loadFont(stream);
+ printf("normal font open!\n");
+ fflush(stdout);
- delete [] buffer;
- buffer = 0;
+ // normal open
+ if (fontFile.open(filename)) {
+ font = Graphics::NewFont::loadFont(fontFile);
}
- unzClose(zipFile);
+
+#ifdef USE_ZLIB
+ if (!font) {
+ unzFile zipFile = unzOpen((_stylefile + ".zip").c_str());
+ if (zipFile && unzLocateFile(zipFile, filename, 2) == UNZ_OK) {
+ unz_file_info fileInfo;
+ unzOpenCurrentFile(zipFile);
+ unzGetCurrentFileInfo(zipFile, &fileInfo, NULL, 0, NULL, 0, NULL, 0);
+ uint8 *buffer = new uint8[fileInfo.uncompressed_size+1];
+ assert(buffer);
+ memset(buffer, 0, (fileInfo.uncompressed_size+1)*sizeof(uint8));
+ unzReadCurrentFile(zipFile, buffer, fileInfo.uncompressed_size);
+ unzCloseCurrentFile(zipFile);
+ Common::MemoryReadStream stream(buffer, fileInfo.uncompressed_size+1);
+
+ font = Graphics::NewFont::loadFont(stream);
+
+ delete [] buffer;
+ buffer = 0;
+ }
+ unzClose(zipFile);
+ }
#endif
+
+ if (font) {
+ if (cacheFilename != "") {
+ if (!Graphics::NewFont::cacheFontData(*font, cacheFilename)) {
+ warning("Couldn't create cache file for font '%s'", filename);
+ }
+ }
+ }
+
return font;
}
+Common::String ThemeNew::genCacheFilename(const char *filename) {
+ Common::String cacheName = filename;
+ for (int i = cacheName.size() - 1; i >= 0; --i) {
+ if (cacheName[i] == '.') {
+ while ((uint)i < cacheName.size() - 1) {
+ cacheName.deleteLastChar();
+ }
+
+ cacheName += "fcc";
+ return cacheName;
+ }
+ }
+
+ return "";
+}
+
#pragma mark -
OverlayColor ThemeNew::calcLuminance(OverlayColor col) {
Modified: scummvm/trunk/gui/theme.h
===================================================================
--- scummvm/trunk/gui/theme.h 2006-04-16 19:23:14 UTC (rev 21951)
+++ scummvm/trunk/gui/theme.h 2006-04-16 19:54:39 UTC (rev 21952)
@@ -364,6 +364,7 @@
void setupFonts();
void deleteFonts();
const Graphics::Font *loadFont(const char *filename);
+ Common::String genCacheFilename(const char *filename);
const Graphics::Font *_fonts[kFontStyleMax];
public:
Modified: scummvm/trunk/gui/themes/modern.zip
===================================================================
(Binary files differ)
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