diff --git a/doomsday/client/include/dd_main.h b/doomsday/client/include/dd_main.h index 7cf8f75f8e..af9a5371e1 100644 --- a/doomsday/client/include/dd_main.h +++ b/doomsday/client/include/dd_main.h @@ -142,7 +142,7 @@ namespace de * @param name Symbolic name of the type. * @return FileType associated with @a name. May return a null-object. */ -de::FileType& DD_FileTypeByName(de::String name); +de::FileType &DD_FileTypeByName(de::String name); /** * Attempts to determine which "type" should be attributed to a resource, solely @@ -150,7 +150,7 @@ de::FileType& DD_FileTypeByName(de::String name); * * @return Type determined for this resource. May return a null-object. */ -de::FileType& DD_GuessFileTypeFromFileName(de::String name); +de::FileType &DD_GuessFileTypeFromFileName(de::String name); /// Returns the registered file types for efficient traversal. de::FileTypes const& DD_FileTypes(); diff --git a/doomsday/client/include/resource/compositebitmapfont.h b/doomsday/client/include/resource/compositebitmapfont.h index 70c888eebb..d40c5e02ec 100644 --- a/doomsday/client/include/resource/compositebitmapfont.h +++ b/doomsday/client/include/resource/compositebitmapfont.h @@ -60,7 +60,7 @@ class CompositeBitmapFont : public AbstractFont * * @todo Should observe engine reset. */ - void rebuildFromDef(ded_compositefont_t *def); + void rebuildFromDef(ded_compositefont_t const &def); int ascent(); int descent(); diff --git a/doomsday/client/include/resource/fonts.h b/doomsday/client/include/resource/fonts.h index 3702cd9aa5..480b014696 100644 --- a/doomsday/client/include/resource/fonts.h +++ b/doomsday/client/include/resource/fonts.h @@ -21,11 +21,7 @@ #ifndef DENG_RESOURCE_FONTS_H #define DENG_RESOURCE_FONTS_H -#include "dd_share.h" // fontschemeid_t -#include "def_data.h" #include "AbstractFont" -#include "BitmapFont" -#include "CompositeBitmapFont" #include "uri.hh" #include #include diff --git a/doomsday/client/include/resource/resourcesystem.h b/doomsday/client/include/resource/resourcesystem.h index 9001f3670f..1c6de54bc7 100644 --- a/doomsday/client/include/resource/resourcesystem.h +++ b/doomsday/client/include/resource/resourcesystem.h @@ -19,13 +19,15 @@ #ifndef DENG_RESOURCESYSTEM_H #define DENG_RESOURCESYSTEM_H +#include "def_data.h" #include "resourceclass.h" #include "Textures" #ifdef __CLIENT__ # include "Fonts" #endif -#include #include +#include +#include /** * Logical resources; materials, packages, textures, etc... @ingroup resource @@ -89,7 +91,7 @@ class ResourceSystem : public de::System void clearSystemFontSchemes(); AbstractFont *createFontFromDef(ded_compositefont_t const &def); - AbstractFont *createFontFromFile(de::Uri const &uri, char const *resourcePath); + AbstractFont *createFontFromFile(de::Uri const &uri, de::String filePath); #endif diff --git a/doomsday/client/src/def_main.cpp b/doomsday/client/src/def_main.cpp index 0b07a0bb64..2429606136 100644 --- a/doomsday/client/src/def_main.cpp +++ b/doomsday/client/src/def_main.cpp @@ -1460,7 +1460,7 @@ void Def_Read() // Composite fonts. for(int i = 0; i < defs.count.compositeFonts.num; ++i) { - App_ResourceSystem().createFontFromDef(defs.compositeFonts + i); + App_ResourceSystem().createFontFromDef(defs.compositeFonts[i]); } #endif diff --git a/doomsday/client/src/resource/compositebitmapfont.cpp b/doomsday/client/src/resource/compositebitmapfont.cpp index f7a87979e5..55cf0a8937 100644 --- a/doomsday/client/src/resource/compositebitmapfont.cpp +++ b/doomsday/client/src/resource/compositebitmapfont.cpp @@ -231,21 +231,21 @@ void CompositeBitmapFont::setDefinition(ded_compositefont_t *newDef) d->def = newDef; } -void CompositeBitmapFont::rebuildFromDef(ded_compositefont_t *newDef) +void CompositeBitmapFont::rebuildFromDef(ded_compositefont_t const &newDef) { LOG_AS("CompositeBitmapFont::rebuildFromDef"); - setDefinition(newDef); - if(!newDef) return; + setDefinition(const_cast(&newDef)); + if(!d->def) return; - for(int i = 0; i < newDef->charMapCount.num; ++i) + for(int i = 0; i < d->def->charMapCount.num; ++i) { - if(!newDef->charMap[i].path) continue; + if(!d->def->charMap[i].path) continue; try { - QByteArray path = reinterpret_cast(*newDef->charMap[i].path).resolved().toUtf8(); - glyphSetPatch(newDef->charMap[i].ch, path.constData()); + String glyphPatchPath = reinterpret_cast(*d->def->charMap[i].path).resolved(); + glyphSetPatch(d->def->charMap[i].ch, glyphPatchPath); } catch(de::Uri::ResolveError const& er) { diff --git a/doomsday/client/src/resource/fonts.cpp b/doomsday/client/src/resource/fonts.cpp index 4f6fccc4d5..5bf5250c8c 100644 --- a/doomsday/client/src/resource/fonts.cpp +++ b/doomsday/client/src/resource/fonts.cpp @@ -210,7 +210,7 @@ bool FontManifest::setUniqueId(int newUniqueId) _uniqueId = newUniqueId; // Notify interested parties that the uniqueId has changed. - DENG2_FOR_AUDIENCE(UniqueIdChanged, i) i->fontManifestUniqueIdChanged(*this); + DENG2_FOR_AUDIENCE(UniqueIdChanged, i) i->manifestUniqueIdChanged(*this); return true; } diff --git a/doomsday/client/src/resource/resourcesystem.cpp b/doomsday/client/src/resource/resourcesystem.cpp index 00ee6e8c64..e874bb9c45 100644 --- a/doomsday/client/src/resource/resourcesystem.cpp +++ b/doomsday/client/src/resource/resourcesystem.cpp @@ -104,10 +104,12 @@ DENG2_PIMPL(ResourceSystem) textures.createScheme("Lightmaps"); textures.createScheme("Flaremaps"); +#ifdef __CLIENT__ LOG_VERBOSE("Initializing Font collection..."); /// @note Order here defines the ambigious-URI search order. fonts.createScheme("System"); fonts.createScheme("Game"); +#endif } ~Instance() @@ -1003,13 +1005,11 @@ AbstractFont *ResourceSystem::createFontFromDef(ded_compositefont_t const &def) /// @todo Do not update fonts here (not enough knowledge). We should /// instead return an invalid reference/signal and force the caller /// to implement the necessary update logic. -#ifdef DENG_DEBUG LOG_DEBUG("A Font with uri \"%s\" already exists, returning existing.") << manifest.composeUri(); -#endif + compFont->rebuildFromDef(def); } - return &manifest.font(); } @@ -1019,7 +1019,8 @@ AbstractFont *ResourceSystem::createFontFromDef(ded_compositefont_t const &def) { if(verbose >= 1) { - LOG_VERBOSE("New font \"%s\"") << manifest.composeUri(id); + LOG_VERBOSE("New font \"%s\"") + << manifest.composeUri(); } return &manifest.font(); } @@ -1042,92 +1043,62 @@ AbstractFont *ResourceSystem::createFontFromDef(ded_compositefont_t const &def) } AbstractFont *ResourceSystem::createFontFromFile(de::Uri const &uri, - char const *resourcePath) + String filePath) { LOG_AS("ResourceSystem::createFontFromFile"); - if(!resourcePath || !resourcePath[0] || - !App_FileSystem().accessFile(de::Uri::fromNativePath(resourcePath))) + if(!App_FileSystem().accessFile(de::Uri::fromNativePath(filePath))) { - LOG_WARNING("Invalid ResourcePath reference, ignoring."); + LOG_WARNING("Invalid resourcePath reference, ignoring."); return 0; } - fontschemeid_t schemeId = parseScheme(uri.schemeCStr()); - if(!VALID_FONTSCHEMEID(schemeId)) + try { - LOG_WARNING("Invalid font scheme in Font Uri \"%s\", ignoring.") - << NativePath(uri.asText()).pretty(); - return 0; - } - - FontScheme &fs = scheme(uri.scheme()); - int uniqueId = fs.count() + 1; // 1-based index. - fontid_t id = fs.declare(uri.path(), uniqueId); - if(id == NOFONTID) return 0; // Invalid URI? + FontManifest &manifest = d->fonts.scheme(uri.scheme()).declare(uri.path()); - // Have we already encountered this name? - AbstractFont *font = toFont(id); - if(font) - { - if(BitmapFont *bmapFont = font->maybeAs()) + if(manifest.hasFont()) { - bmapFont->setFilePath(resourcePath); - } - - return font; - } - - // A new font. - FontManifest *manifest = findDirectoryNodeForBindId(id); - if(!manifest) - { - LOG_WARNING("Failed creating Font #%u (invalid id), ignoring.") << id; - return 0; - } + if(BitmapFont *bmapFont = manifest.font().maybeAs()) + { + /// @todo Do not update fonts here (not enough knowledge). We should + /// instead return an invalid reference/signal and force the caller + /// to implement the necessary update logic. + LOG_DEBUG("A Font with uri \"%s\" already exists, returning existing.") + << manifest.composeUri(); - if(!resourcePath || !resourcePath[0]) - { - LOG_WARNING("Failed creating Font #%u (resourcePath = NULL), ignoring.") << id; - return 0; - } + bmapFont->setFilePath(filePath); + } + return &manifest.font(); + } - if(manifest->hasFont()) - { - if(BitmapFont *bmapFont = manifest->font().maybeAs()) + // A new font. + manifest.setFont(BitmapFont::fromFile(manifest, filePath)); + if(manifest.hasFont()) { - /// @todo Do not update fonts here (not enough knowledge). We should - /// instead return an invalid reference/signal and force the caller - /// to implement the necessary update logic. -#ifdef DENG_DEBUG - LOG_DEBUG("A Font with uri \"%s\" already exists, returning existing.") - << manifest->composeUri(id); -#endif - bmapFont->setFilePath(resourcePath); + if(verbose >= 1) + { + LOG_VERBOSE("New font \"%s\"") + << manifest.composeUri(); + } + return &manifest.font(); } - return &manifest->font(); + LOG_WARNING("Failed defining new Font for \"%s\", ignoring.") + << NativePath(uri.asText()).pretty(); } - - // A new font. - manifest->setFont(BitmapFont::fromFile(id, resourcePath)); - if(manifest->hasFont()) + catch(Fonts::UnknownSchemeError const &er) { - if(verbose >= 1) - { - LOG_VERBOSE("New font \"%s\"") << manifest->composeUri(id); - } - - return &manifest->font(); + LOG_WARNING(er.asText() + ". Failed declaring font \"%s\", ignoring.") + << NativePath(uri.asText()).pretty(); } - - if(!font) + catch(FontScheme::InvalidPathError const &er) { - LOG_WARNING("Failed defining new Font for \"%s\", ignoring.") + LOG_WARNING(er.asText() + ". Failed declaring font \"%s\", ignoring.") << NativePath(uri.asText()).pretty(); } - return font; + return 0; } #endif // __CLIENT__