Skip to content

Commit

Permalink
Refactor|Fonts|Resources|Client: Split up fonts.cpp/h; added convenie…
Browse files Browse the repository at this point in the history
…nce headers
  • Loading branch information
danij-deng committed Nov 15, 2013
1 parent 2740cbb commit 6978d77
Show file tree
Hide file tree
Showing 9 changed files with 670 additions and 536 deletions.
6 changes: 6 additions & 0 deletions doomsday/client/client.pro
Expand Up @@ -131,7 +131,9 @@ DENG_CONVENIENCE_HEADERS += \
include/EntityDatabase \
include/Face \
include/FontLineWrapping \
include/FontManifest \
include/Fonts \
include/FontScheme \
include/Game \
include/Games \
include/GLTextComposer \
Expand Down Expand Up @@ -335,7 +337,9 @@ DENG_HEADERS += \
include/resource/colorpalettes.h \
include/resource/compositebitmapfont.h \
include/resource/compositetexture.h \
include/resource/fontmanifest.h \
include/resource/fonts.h \
include/resource/fontscheme.h \
include/resource/hq2x.h \
include/resource/image.h \
include/resource/lumpcache.h \
Expand Down Expand Up @@ -693,7 +697,9 @@ SOURCES += \
src/resource/colorpalettes.cpp \
src/resource/compositebitmapfont.cpp \
src/resource/compositetexture.cpp \
src/resource/fontmanifest.cpp \
src/resource/fonts.cpp \
src/resource/fontscheme.cpp \
src/resource/hq2x.cpp \
src/resource/image.cpp \
src/resource/material.cpp \
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/include/FontManifest
@@ -0,0 +1 @@
#include "resource/fontmanifest.h"
1 change: 1 addition & 0 deletions doomsday/client/include/FontScheme
@@ -0,0 +1 @@
#include "resource/fontscheme.h"
152 changes: 152 additions & 0 deletions doomsday/client/include/resource/fontmanifest.h
@@ -0,0 +1,152 @@
/** @file fontmanifest.h Font resource manifest.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/

#ifndef DENG_RESOURCE_FONTMANIFEST_H
#define DENG_RESOURCE_FONTMANIFEST_H

#include "AbstractFont"
#include "uri.hh"
#include <de/Error>
#include <de/PathTree>
#include <de/String>

namespace de {

class Fonts;
class FontScheme;

/**
* FontManifest. Stores metadata for a unique Font in the collection.
*/
class FontManifest : public PathTree::Node,
DENG2_OBSERVES(AbstractFont, Deletion)
{
public:
/// Required Font instance is missing. @ingroup errors
DENG2_ERROR(MissingFontError);

DENG2_DEFINE_AUDIENCE(Deletion, void manifestBeingDeleted(FontManifest const &manifest))
DENG2_DEFINE_AUDIENCE(UniqueIdChanged, void manifestUniqueIdChanged(FontManifest &manifest))

public:
/// Scheme-unique identifier chosen by the owner of the collection.
int _uniqueId;

/// The defined font instance (if any).
QScopedPointer<AbstractFont>(_font);

public:
FontManifest(PathTree::NodeArgs const &args);
~FontManifest();

/**
* Returns the owning scheme of the manifest.
*/
FontScheme &scheme() const;

/// Convenience method for returning the name of the owning scheme.
String const &schemeName() const;

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

/**
* Compose a URN of the form "urn:scheme:uniqueid" for the font
* FontRecord.
*
* 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.
*
* @see uniqueId(), setUniqueId()
*/
inline Uri composeUrn() const
{
return Uri("urn", String("%1:%2").arg(schemeName()).arg(uniqueId(), 0, 10));
}

/**
* Returns a textual description of the manifest.
*
* @return Human-friendly description the manifest.
*/
String description(Uri::ComposeAsTextFlags uriCompositionFlags = Uri::DefaultComposeAsTextFlags) const;

/**
* Returns the scheme-unique identifier for the manifest.
*/
int uniqueId() const;

/**
* Change the unique identifier property of the manifest.
*
* @return @c true iff @a newUniqueId differed to the existing unique
* identifier, which was subsequently changed.
*/
bool setUniqueId(int newUniqueId);

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

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

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

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

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

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

} // namespace de

#endif // DENG_RESOURCE_FONTMANIFEST_H

0 comments on commit 6978d77

Please sign in to comment.