/
fontmanifest.cpp
133 lines (110 loc) · 3.76 KB
/
fontmanifest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/** @file fontmanifest.cpp 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>
*/
#include "resource/fontmanifest.h"
#include "dd_main.h" // App_Fonts(), remove me
#include "FontScheme"
#include <de/Log>
using namespace de;
DENG2_PIMPL_NOREF(FontManifest)
{
int uniqueId;
QScopedPointer<AbstractFont>(resource); ///< Associated resource (if any).
Instance() : uniqueId(0)
{}
};
FontManifest::FontManifest(PathTree::NodeArgs const &args)
: Node(args), d(new Instance())
{}
FontManifest::~FontManifest()
{
DENG2_FOR_AUDIENCE(Deletion, i) i->manifestBeingDeleted(*this);
}
FontScheme &FontManifest::scheme() const
{
LOG_AS("FontManifest");
/// @todo Optimize: FontManifest should contain a link to the owning FontScheme.
foreach(FontScheme *scheme, collection().allSchemes())
{
if(&scheme->index() == &tree()) return *scheme;
}
/// @throw Error Failed to determine the scheme of the manifest (should never happen...).
throw Error("FontManifest::scheme", String("Failed to determine scheme for manifest [%1]").arg(de::dintptr(this)));
}
String const &FontManifest::schemeName() const
{
return scheme().name();
}
String FontManifest::description(de::Uri::ComposeAsTextFlags uriCompositionFlags) const
{
return String("%1").arg(composeUri().compose(uriCompositionFlags | Uri::DecodePath),
( uriCompositionFlags.testFlag(Uri::OmitScheme)? -14 : -22 ) );
}
int FontManifest::uniqueId() const
{
return d->uniqueId;
}
bool FontManifest::setUniqueId(int newUniqueId)
{
LOG_AS("FontManifest");
if(d->uniqueId == newUniqueId) return false;
d->uniqueId = newUniqueId;
// Notify interested parties that the uniqueId has changed.
DENG2_FOR_AUDIENCE(UniqueIdChange, i) i->manifestUniqueIdChanged(*this);
return true;
}
bool FontManifest::hasResource() const
{
return !d->resource.isNull();
}
AbstractFont &FontManifest::resource() const
{
if(hasResource())
{
return *d->resource.data();
}
/// @throw MissingFontError No resource is associated with the manifest.
throw MissingFontError("FontManifest::resource", "No resource is associated");
}
void FontManifest::setResource(AbstractFont *newResource)
{
LOG_AS("FontManifest");
if(d->resource.data() != newResource)
{
if(AbstractFont *curFont = d->resource.data())
{
// Cancel notifications about the existing resource.
curFont->audienceForDeletion -= this;
}
d->resource.reset(newResource);
if(AbstractFont *curFont = d->resource.data())
{
// We want notification when the new resource is about to be deleted.
curFont->audienceForDeletion += this;
}
}
}
void FontManifest::fontBeingDeleted(AbstractFont const & /*resource*/)
{
d->resource.reset();
}
Fonts &FontManifest::collection()
{
return App_Fonts();
}