From e9cbf5fcbd1af19d1936593d1de736c0e0e91f89 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 16 Apr 2006 19:54:39 +0000 Subject: - 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 svn-id: r21952 --- gui/ThemeNew.cpp | 102 +++++++++++++++++++++++++++++++++++++++----------- gui/theme.h | 1 + gui/themes/modern.zip | Bin 32709 -> 34689 bytes 3 files changed, 82 insertions(+), 21 deletions(-) (limited to 'gui') diff --git a/gui/ThemeNew.cpp b/gui/ThemeNew.cpp index 1a225c3ab8..11b737ffb1 100644 --- a/gui/ThemeNew.cpp +++ b/gui/ThemeNew.cpp @@ -1341,38 +1341,98 @@ void ThemeNew::deleteFonts() { } 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; - 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, 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; + } + + printf("normal font open!\n"); + fflush(stdout); + + // normal open + if (fontFile.open(filename)) { + font = Graphics::NewFont::loadFont(fontFile); } #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); - - font = Graphics::loadFont(stream); - - delete [] buffer; - buffer = 0; + 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); } - 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) { diff --git a/gui/theme.h b/gui/theme.h index 734ff3c37a..8b0e59a6de 100644 --- a/gui/theme.h +++ b/gui/theme.h @@ -364,6 +364,7 @@ private: void setupFonts(); void deleteFonts(); const Graphics::Font *loadFont(const char *filename); + Common::String genCacheFilename(const char *filename); const Graphics::Font *_fonts[kFontStyleMax]; public: diff --git a/gui/themes/modern.zip b/gui/themes/modern.zip index 8c44d3e16f..1817123542 100644 Binary files a/gui/themes/modern.zip and b/gui/themes/modern.zip differ -- cgit v1.2.3