From 46b036ab6aea23319ac4a3fdfb0faa13bc3cc3dd Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Sat, 18 Oct 2008 01:27:33 +0000 Subject: ImageManager: Added support for generic archives (zips and folders). Theme Font Loading: Added support for generic archives. ThemeEngine: Removed dependency on Common::File and File::AddDefaultPath for image and font loading. svn-id: r34815 --- graphics/imageman.cpp | 28 +++++++++++++++++-------- gui/ThemeEngine.cpp | 13 +++--------- gui/theme.cpp | 57 +++++++++++++++++++++++++++++++++------------------ gui/theme.h | 1 + 4 files changed, 61 insertions(+), 38 deletions(-) diff --git a/graphics/imageman.cpp b/graphics/imageman.cpp index 44ac7c9e75..1a7bcdefd1 100644 --- a/graphics/imageman.cpp +++ b/graphics/imageman.cpp @@ -46,19 +46,33 @@ ImageManager::~ImageManager() { } bool ImageManager::addArchive(const Common::String &name) { + Common::Archive *arch = 0; + + if (name.hasSuffix(".zip")) { #ifdef USE_ZLIB - Common::ZipArchive *arch = new Common::ZipArchive(name); - if (!arch || !arch->isOpen()) + Common::ZipArchive *zip = new Common::ZipArchive(name); + if (!zip || !zip->isOpen()) + return false; + + arch = zip; +#else return false; - _archives.add(name, Common::ArchivePtr(arch)); #endif + } else { + Common::FSDirectory *dir = new Common::FSDirectory(name); + if (!dir || !dir->getFSNode().isDirectory()) + return false; + + arch = dir; + } + + _archives.add(name, Common::ArchivePtr(arch)); return true; } void ImageManager::removeArchive(const Common::String &name) { -#ifdef USE_ZLIB - _archives.remove(name); -#endif + if (_archives.hasArchive(name)) + _archives.remove(name); } bool ImageManager::registerSurface(const Common::String &name, Surface *surf) { @@ -73,7 +87,6 @@ bool ImageManager::registerSurface(const Common::String &name, Surface *surf) { if (!surf) surf = ImageDecoder::loadFile(name); -#ifdef USE_ZLIB if (!surf) { Common::SeekableReadStream *stream = _archives.openFile(name); if (stream) { @@ -81,7 +94,6 @@ bool ImageManager::registerSurface(const Common::String &name, Surface *surf) { delete stream; } } -#endif if (!surf) return false; diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index f26d35ba58..9c49bfdeb8 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -251,10 +251,7 @@ void ThemeEngine::unloadTheme() { for (ImagesMap::iterator i = _bitmaps.begin(); i != _bitmaps.end(); ++i) ImageMan.unregisterSurface(i->_key); - if (_themeFileName.hasSuffix(".zip")) - ImageMan.removeArchive(_themeFileName); - - Common::File::resetDefaultDirectories(); + ImageMan.removeArchive(_themeFileName); _themeEval->reset(); _themeOk = false; @@ -463,12 +460,8 @@ bool ThemeEngine::addDrawData(const Common::String &data, bool cached) { bool ThemeEngine::loadTheme(Common::String fileName) { unloadTheme(); - if (fileName != "builtin") { - if (fileName.hasSuffix(".zip")) - ImageMan.addArchive(fileName); - else - Common::File::addDefaultDirectory(fileName); - } + if (fileName != "builtin") + ImageMan.addArchive(fileName); if (fileName == "builtin") { if (!loadDefaultXML()) diff --git a/gui/theme.cpp b/gui/theme.cpp index 8e05ca8479..2d21339f4c 100644 --- a/gui/theme.cpp +++ b/gui/theme.cpp @@ -33,26 +33,51 @@ Theme::Theme() : _loadedThemeX(0), _loadedThemeY(0) {} Theme::~Theme() {} -const Graphics::Font *Theme::loadFont(const Common::String &filename) { +const Graphics::Font *Theme::loadFontFromArchive(const Common::String &filename) { + Common::Archive *arch = 0; const Graphics::NewFont *font = 0; + + if (getThemeFileName().hasSuffix(".zip")) { +#ifdef USE_ZLIB + Common::ZipArchive *zip = new Common::ZipArchive(getThemeFileName()); + if (!zip || !zip->isOpen()) + return 0; + + arch = zip; +#else + return 0; +#endif + } else { + Common::FSDirectory *dir = new Common::FSDirectory(getThemeFileName()); + if (!dir || !dir->getFSNode().isDirectory()) + return 0; + + arch = dir; + } + + Common::SeekableReadStream *stream(arch->openFile(filename)); + if (stream) { + font = Graphics::NewFont::loadFromCache(*stream); + delete stream; + } + + delete arch; + return font; +} + +const Graphics::Font *Theme::loadFont(const Common::String &filename) { + const Graphics::Font *font = 0; Common::String cacheFilename = genCacheFilename(filename.c_str()); Common::File fontFile; if (!cacheFilename.empty()) { if (fontFile.open(cacheFilename)) font = Graphics::NewFont::loadFromCache(fontFile); + if (font) return font; -#ifdef USE_ZLIB - Common::ZipArchive zipArchive(getThemeFileName()); - Common::SeekableReadStream *stream(zipArchive.openFile(cacheFilename)); - if (stream) { - font = Graphics::NewFont::loadFromCache(*stream); - delete stream; - } -#endif - if (font) + if ((font = loadFontFromArchive(cacheFilename))) return font; } @@ -61,21 +86,13 @@ const Graphics::Font *Theme::loadFont(const Common::String &filename) { font = Graphics::NewFont::loadFont(fontFile); } -#ifdef USE_ZLIB if (!font) { - Common::ZipArchive zipArchive(getThemeFileName()); - - Common::SeekableReadStream *stream(zipArchive.openFile(filename)); - if (stream) { - font = Graphics::NewFont::loadFont(*stream); - delete stream; - } + font = loadFontFromArchive(filename); } -#endif if (font) { if (!cacheFilename.empty()) { - if (!Graphics::NewFont::cacheFontData(*font, cacheFilename)) { + if (!Graphics::NewFont::cacheFontData(*(Graphics::NewFont*)font, cacheFilename)) { warning("Couldn't create cache file for font '%s'", filename.c_str()); } } diff --git a/gui/theme.h b/gui/theme.h index 3d114ae207..45c81a06cf 100644 --- a/gui/theme.h +++ b/gui/theme.h @@ -337,6 +337,7 @@ public: protected: const Graphics::Font *loadFont(const Common::String &filename); + const Graphics::Font *loadFontFromArchive(const Common::String &filename); Common::String genCacheFilename(const char *filename); public: -- cgit v1.2.3