xoreos  0.0.5
fontman.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef GRAPHICS_AURORA_FONTMAN_H
26 #define GRAPHICS_AURORA_FONTMAN_H
27 
28 #include <map>
29 
30 #include "src/common/types.h"
31 #include "src/common/singleton.h"
32 #include "src/common/mutex.h"
33 #include "src/common/ustring.h"
34 
36 
37 namespace Graphics {
38 
39 namespace Aurora {
40 
42 extern const char *kSystemFontMono;
43 
45 enum FontFormat {
51 };
52 
54 class FontManager : public Common::Singleton<FontManager> {
55 public:
56  FontManager();
57  ~FontManager();
58 
60  void setFormat(FontFormat format);
61 
63  void addAlias(const Common::UString &alias, const Common::UString &realName);
64 
66  void clear();
67 
69  bool hasFont(const Common::UString &name, int height = 0);
70 
72  FontHandle add(Font *font, const Common::UString &name);
74  FontHandle get(FontFormat format, const Common::UString &name, int height = 0);
76  FontHandle get(const Common::UString &name, int height = 0);
78  FontHandle getIfExist(const Common::UString &name, int height = 0);
79 
80 private:
82 
83  std::map<Common::UString, Common::UString> _aliases;
84 
86 
88 
91 
92  void assign(FontHandle &font, const FontHandle &from);
93  void release(FontHandle &handle);
94 
95  static ManagedFont *createFont(FontFormat format, const Common::UString &name, int height);
96 
97  friend class FontHandle;
98 };
99 
100 } // End of namespace Aurora
101 
102 } // End of namespace Graphics
103 
105 #define FontMan Graphics::Aurora::FontManager::instance()
106 
107 #endif // GRAPHICS_AURORA_FONTMAN_H
static ManagedFont * createFont(FontFormat format, const Common::UString &name, int height)
Definition: fontman.cpp:168
ABC/SBM font, used by Jade Empire.
Definition: fontman.h:48
A managed font, storing how often it&#39;s referenced.
Definition: fonthandle.h:42
Class and macro for implementing singletons.
NFTR font, used by Sonic.
Definition: fontman.h:50
A class holding an UTF-8 string.
Definition: ustring.h:48
TTF font, used by NWN2.
Definition: fontman.h:49
FontHandle getIfExist(const Common::UString &name, int height=0)
Retrieve this named font, returning an empty handle if it&#39;s not managed.
Definition: fontman.cpp:118
A handle to a font.
Definition: fonthandle.h:52
std::map< Common::UString, Common::UString > _aliases
Definition: fontman.h:83
bool hasFont(const Common::UString &name, int height=0)
Does this named managed font exist?
Definition: fontman.cpp:71
Generic template base class for implementing the singleton design pattern.
Definition: singleton.h:61
A mutex.
Definition: mutex.h:40
FontFormat
The format of a font.
Definition: fontman.h:45
void addAlias(const Common::UString &alias, const Common::UString &realName)
Add an alias for a specific font name.
Definition: fontman.cpp:65
const char * kSystemFontMono
Identifier used for the monospaced system font.
Definition: fontman.cpp:41
A handle to an Aurora font.
void release(FontHandle &handle)
Definition: fontman.cpp:157
Low-level type definitions to handle fixed width types portably.
Common::UString getIndexName(Common::UString name, int height)
Definition: fontman.cpp:136
An abstract font.
Definition: font.h:39
void clear()
Remove and delete all managed fonts.
Definition: fontman.cpp:50
void assign(FontHandle &font, const FontHandle &from)
Definition: fontman.cpp:147
Textured font, used by NWN and KotOR/KotOR2.
Definition: fontman.h:47
The global Aurora font manager.
Definition: fontman.h:54
Unicode string handling.
Thread mutex classes.
Common::UString getAliasName(const Common::UString &name)
Definition: fontman.cpp:128
void setFormat(FontFormat format)
Load fonts in this format by default.
Definition: fontman.cpp:59
Unknown font format.
Definition: fontman.h:46
FontHandle add(Font *font, const Common::UString &name)
Add this font to the FontManager.
Definition: fontman.cpp:79