Skip to content

Commit

Permalink
Refactor|Fonts|Client: Superficial generalization of Fonts resource c…
Browse files Browse the repository at this point in the history
…ollection components

These components are (now) very similar to those used by the other
resource collections (i.e., Materials and Textures). At some point
they should be refactored to share a common base implementation.
  • Loading branch information
danij-deng committed Nov 15, 2013
1 parent 8df8fd3 commit 0c5991a
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 75 deletions.
40 changes: 20 additions & 20 deletions doomsday/client/include/resource/fontmanifest.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "AbstractFont"
#include "uri.hh"
#include <de/Error>
#include <de/Observers>
#include <de/PathTree>
#include <de/String>

Expand All @@ -33,7 +34,7 @@ class Fonts;
class FontScheme;

/**
* FontManifest. Stores metadata for a unique Font in the collection.
* FontManifest. Stores metadata for would-be Font resource.
*/
class FontManifest : public PathTree::Node,
DENG2_OBSERVES(AbstractFont, Deletion)
Expand All @@ -58,28 +59,27 @@ DENG2_OBSERVES(AbstractFont, Deletion)
String const &schemeName() const;

/**
* Compose a URI of the form "scheme:path" for the FontRecord.
* Compose a URI of the form "scheme:path" for the manifest.
*
* The scheme component of the URI will contain the symbolic name of
* the scheme for the FontRecord.
* the scheme for the manifest.
*
* The path component of the URI will contain the percent-encoded path
* of the FontRecord.
* of the manifest.
*/
inline Uri composeUri(QChar sep = '/') const
{
return Uri(schemeName(), path(sep));
}

/**
* Compose a URN of the form "urn:scheme:uniqueid" for the font
* FontRecord.
* Compose a URN of the form "urn:scheme:uniqueid" for the manifest.
*
* The scheme component of the URI will contain the identifier 'urn'.
*
* The path component of the URI is a string which contains both the
* symbolic name of the scheme followed by the unique id of the font
* FontRecord, separated with a colon.
* manifest, separated with a colon.
*
* @see uniqueId(), setUniqueId()
*/
Expand Down Expand Up @@ -109,35 +109,35 @@ DENG2_OBSERVES(AbstractFont, Deletion)
bool setUniqueId(int newUniqueId);

/**
* Returns @c true if a Font is presently associated with the manifest.
* Returns @c true if a resource is presently associated with the manifest.
*/
bool hasFont() const;
bool hasResource() const;

/**
* Returns the logical Font associated with the manifest.
* Returns the logical resource associated with the manifest.
*/
AbstractFont &font() const;
AbstractFont &resource() const;

/**
* Change the logical Font associated with the manifest.
* Change the logical resource associated with the manifest.
*
* @param newFont New logical Font to associate.
* @param newFont New resource to associate.
*/
void setFont(AbstractFont *newFont);
void setResource(AbstractFont *newResource);

/**
* Clear the logical Font associated with the manifest.
* Clear the logical resource associated with the manifest.
*
* Same as @c setFont(0)
* Same as @c setResource(0)
*/
inline void clearFont() { setFont(0); }
inline void clearResource() { setResource(0); }

/// Returns a reference to the application's font collection.
static Fonts &fonts();
/// Returns a reference to the owning collection.
static Fonts &collection();

protected:
// Observes AbstractFont::Deletion.
void fontBeingDeleted(AbstractFont const &font);
void fontBeingDeleted(AbstractFont const &resource);

private:
DENG2_PRIVATE(d)
Expand Down
24 changes: 12 additions & 12 deletions doomsday/client/include/resource/fonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ DENG2_OBSERVES(AbstractFont, Deletion)
typedef class FontScheme Scheme;

public:
/// The referenced font/manifest was not found. @ingroup errors
/// The referenced rsource/manifest was not found. @ingroup errors
DENG2_ERROR(NotFoundError);

/// An unknown scheme was referenced. @ingroup errors
Expand All @@ -70,7 +70,7 @@ DENG2_OBSERVES(AbstractFont, Deletion)

public:
/**
* Constructs a new font resource collection.
* Constructs a new Font resource collection.
*/
Fonts();

Expand All @@ -80,25 +80,25 @@ DENG2_OBSERVES(AbstractFont, Deletion)
static void consoleRegister();

/**
* Returns the total number of unique fonts in the collection.
* Returns the total number of resource manifests in the collection.
*/
uint count() const { return all().count(); }

/**
* Returns the total number of unique fonts in the collection.
* Returns the total number of resource manifests in the collection.
*
* Same as size()
*/
inline uint size() const { return count(); }

/**
* Determines if a manifest exists for a declared font on @a path.
* Determines if a manifest exists for a resource on @a path.
* @return @c true, if a manifest exists; otherwise @a false.
*/
bool has(Uri const &path) const;

/**
* Find the manifest for a declared font.
* Find a resource manifest.
*
* @param search The search term.
* @return Found unique identifier.
Expand Down Expand Up @@ -153,7 +153,7 @@ DENG2_OBSERVES(AbstractFont, Deletion)
inline int schemeCount() const { return allSchemes().count(); }

/**
* Clear all fonts in all schemes.
* Clear all resources in all schemes.
*
* @see allSchemes(), Scheme::clear().
*/
Expand All @@ -166,21 +166,21 @@ DENG2_OBSERVES(AbstractFont, Deletion)
}

/**
* Declare a font in the collection, producing a manifest for a logical
* AbstractFont which will be defined later. If a manifest with the specified
* Declare a resource in the collection, producing a (possibly new) manifest
* for a resource which may be defined later. If a manifest with the specified
* @a uri already exists the existing manifest will be returned.
*
* @param uri Uri representing a path to the font in the virtual hierarchy.
* @param uri Uri representing a path to the resource in the virtual hierarchy.
*
* @return Manifest for this URI.
* @return The associated manifest for this URI.
*/
inline Manifest &declare(Uri const &uri)
{
return scheme(uri.scheme()).declare(uri.path());
}

/**
* Returns a list of all the unique texture instances in the collection,
* Returns a list of pointers to all the concrete resources in the collection,
* from all schemes.
*/
All const &all() const;
Expand Down
24 changes: 12 additions & 12 deletions doomsday/client/include/resource/fontscheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,40 +53,40 @@ DENG2_OBSERVES(FontManifest, Deletion)

public:
/**
* Construct a new (empty) texture subspace scheme.
* Construct a new (empty) resource subspace scheme.
*
* @param symbolicName Symbolic name of the new subspace scheme. Must
* have at least @ref min_name_length characters.
* @param symbolicName Symbolic name of the new subspace scheme. Must have
* at least @ref min_name_length characters.
*/
FontScheme(String symbolicName);

/// @return Symbolic name of this scheme (e.g., "System").
String const &name() const;

/// @return Total number of records in the scheme.
/// @return Total number of manifests in the scheme.
inline int size() const { return index().size(); }

/// @return Total number of records in the scheme. Same as @ref size().
/// @return Total number of manifests in the scheme. Same as @ref size().
inline int count() const { return size(); }

/**
* Clear all records in the scheme (any GL textures which have been
* acquired for associated font textures will be released).
* Destroys all manifests (and any associated resources) in the scheme.
*/
void clear();

/**
* Insert a new manifest at the given @a path into the scheme.
* If a manifest already exists at this path, the existing manifest is
* returned and the call is a no-op.
* Insert a new manifest at the given @a path into the scheme. If a manifest
* already exists at this path, the existing manifest is returned.
*
* @param path Virtual path for the resultant manifest.
*
* @return The (possibly newly created) manifest at @a path.
*/
Manifest &declare(Path const &path);

/**
* Determines if a manifest exists on the given @a path.
*
* @return @c true if a manifest exists; otherwise @a false.
*/
bool has(Path const &path) const;
Expand All @@ -102,8 +102,8 @@ DENG2_OBSERVES(FontManifest, Deletion)
Manifest &find(Path const &path);

/**
* Search the scheme for a manifest whose associated unique
* identifier matches @a uniqueId.
* Search the scheme for a manifest whose associated unique identifier
* matches @a uniqueId.
*
* @return Found manifest.
*/
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/gl/gl_texmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,9 +1119,9 @@ void GL_ReleaseFontTexturesByScheme(char const *schemeName)
while(iter.hasNext())
{
FontManifest &manifest = iter.next();
if(manifest.hasFont())
if(manifest.hasResource())
{
manifest.font().glDeinit();
manifest.resource().glDeinit();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/render/r_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static void loadFontIfNeeded(char const *uri, fontid_t *fid)
try
{
FontManifest &manifest = App_ResourceSystem().fonts().find(de::Uri(uri, RC_NULL));
if(manifest.hasFont())
if(manifest.hasResource())
{
*fid = fontid_t(manifest.uniqueId());
}
Expand Down
14 changes: 7 additions & 7 deletions doomsday/client/src/render/rend_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ void FR_CharSize(Size2Raw *size, uchar ch)
errorIfNotInited("FR_CharSize");
if(size)
{
Vector2ui dimensions = App_Fonts().toManifest(fr.fontNum).font().glyphPosCoords(ch).size();
Vector2ui dimensions = App_Fonts().toManifest(fr.fontNum).resource().glyphPosCoords(ch).size();
size->width = dimensions.x;
size->height = dimensions.y;
}
Expand All @@ -435,7 +435,7 @@ int FR_CharWidth(uchar ch)
{
errorIfNotInited("FR_CharWidth");
if(fr.fontNum != 0)
return App_Fonts().toManifest(fr.fontNum).font().glyphPosCoords(ch).width();
return App_Fonts().toManifest(fr.fontNum).resource().glyphPosCoords(ch).width();
return 0;
}

Expand All @@ -444,7 +444,7 @@ int FR_CharHeight(uchar ch)
{
errorIfNotInited("FR_CharHeight");
if(fr.fontNum != 0)
return App_Fonts().toManifest(fr.fontNum).font().glyphPosCoords(ch).height();
return App_Fonts().toManifest(fr.fontNum).resource().glyphPosCoords(ch).height();
return 0;
}

Expand All @@ -453,7 +453,7 @@ int FR_SingleLineHeight(char const *text)
errorIfNotInited("FR_SingleLineHeight");
if(fr.fontNum == 0 || !text)
return 0;
AbstractFont &font = App_Fonts().toManifest(fr.fontNum).font();
AbstractFont &font = App_Fonts().toManifest(fr.fontNum).resource();
int ascent = font.ascent();
if(ascent != 0)
return ascent;
Expand All @@ -465,7 +465,7 @@ int FR_GlyphTopToAscent(char const *text)
errorIfNotInited("FR_GlyphTopToAscent");
if(fr.fontNum == 0 || !text)
return 0;
AbstractFont &font = App_Fonts().toManifest(fr.fontNum).font();
AbstractFont &font = App_Fonts().toManifest(fr.fontNum).resource();
int lineHeight = font.lineSpacing();
if(lineHeight == 0)
return 0;
Expand Down Expand Up @@ -519,7 +519,7 @@ static int textFragmentHeight(char const *fragment)
height = de::max(height, FR_CharHeight(c));
}

return topToAscent(&App_Fonts().toManifest(fr.fontNum).font()) + height;
return topToAscent(&App_Fonts().toManifest(fr.fontNum).resource()) + height;
}

/*
Expand All @@ -535,7 +535,7 @@ static void textFragmentDrawer(const char* fragment, int x, int y, int alignFlag
{
DENG2_ASSERT(fragment != 0 && fragment[0]);

AbstractFont *font = &App_Fonts().toManifest(fr.fontNum).font();
AbstractFont *font = &App_Fonts().toManifest(fr.fontNum).resource();
fr_state_attributes_t* sat = currentAttribs();
boolean noTypein = (textFlags & DTF_NO_TYPEIN) != 0;
boolean noGlitter = (sat->glitterStrength <= 0 || (textFlags & DTF_NO_GLITTER) != 0);
Expand Down
12 changes: 6 additions & 6 deletions doomsday/client/src/resource/fontmanifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ FontManifest::~FontManifest()
DENG2_FOR_AUDIENCE(Deletion, i) i->manifestBeingDeleted(*this);
}

Fonts &FontManifest::fonts()
Fonts &FontManifest::collection()
{
return App_Fonts();
}
Expand All @@ -52,7 +52,7 @@ FontScheme &FontManifest::scheme() const
{
LOG_AS("FontManifest::scheme");
/// @todo Optimize: FontManifest should contain a link to the owning FontScheme.
foreach(FontScheme *scheme, fonts().allSchemes())
foreach(FontScheme *scheme, collection().allSchemes())
{
if(&scheme->index() == &tree()) return *scheme;
}
Expand Down Expand Up @@ -88,22 +88,22 @@ bool FontManifest::setUniqueId(int newUniqueId)
return true;
}

bool FontManifest::hasFont() const
bool FontManifest::hasResource() const
{
return !d->resource.isNull();
}

AbstractFont &FontManifest::font() const
AbstractFont &FontManifest::resource() const
{
if(hasFont())
if(hasResource())
{
return *d->resource.data();
}
/// @throw MissingFontError No resource is associated with the manifest.
throw MissingFontError("FontManifest::font", "No resource is associated");
}

void FontManifest::setFont(AbstractFont *newResource)
void FontManifest::setResource(AbstractFont *newResource)
{
if(d->resource.data() != newResource)
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/resource/fonts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ static int printIndex2(FontScheme *scheme, Path const &like,
String info = String(" %1: ").arg(idx, numFoundDigits)
+ manifest->description(composeUriFlags);

Con_FPrintf(!manifest->hasFont()? CPF_LIGHT : CPF_WHITE, "%s\n", info.toUtf8().constData());
Con_FPrintf(!manifest->hasResource()? CPF_LIGHT : CPF_WHITE, "%s\n", info.toUtf8().constData());
idx++;
}

Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/resource/fontscheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ DENG2_PIMPL(FontScheme)

void deindex(Manifest &manifest)
{
/// @todo Only destroy the font if this is the last remaining reference.
manifest.clearFont();
/// @todo Only destroy the resource if this is the last remaining reference.
manifest.clearResource();

unlinkInUniqueIdLut(manifest);
}
Expand Down
Loading

0 comments on commit 0c5991a

Please sign in to comment.