xoreos  0.0.5
ttffont.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_TTFFONT_H
26 #define GRAPHICS_AURORA_TTFFONT_H
27 
28 #include <vector>
29 #include <map>
30 
31 #include "src/common/types.h"
32 #include "src/common/scopedptr.h"
33 #include "src/common/ptrvector.h"
34 
35 #include "src/graphics/font.h"
36 
38 
39 namespace Common {
40  class UString;
41 }
42 
43 namespace Graphics {
44 
45 class Surface;
46 class TTFRenderer;
47 
48 namespace Aurora {
49 
50 class TTFFont : public Graphics::Font {
51 public:
52  TTFFont(Common::SeekableReadStream *ttf, int height);
53  TTFFont(const Common::UString &name, int height);
54  ~TTFFont();
55 
56  float getWidth (uint32 c) const;
57  float getHeight() const;
58 
59  void draw(uint32 c) const;
60 
61  void buildChars(const Common::UString &str);
62 
63 private:
65  struct Page {
68 
70 
73 
76 
77  Page();
78 
79  void rebuild();
80  };
81 
83  struct Char {
84  float width;
85 
86  float tX[4], tY[4];
87  float vX[4], vY[4];
88 
89  size_t page;
90  };
91 
92 
94 
96  std::map<uint32, Char> _chars;
97 
98  std::map<uint32, Char>::const_iterator _missingChar;
100 
102 
103  void load(Common::SeekableReadStream *ttf, int height);
104 
105  void rebuildPages();
106  void addChar(uint32 c);
107  void drawMissing() const;
108 };
109 
110 } // End of namespace Aurora
111 
112 } // End of namespace Graphics
113 
114 #endif // GRAPHICS_AURORA_TTFFONT_H
A texture page filled with characters.
Definition: ttffont.h:65
Definition: 2dafile.h:39
A class holding an UTF-8 string.
Definition: ustring.h:48
Common::ScopedPtr< TTFRenderer > _ttf
Definition: ttffont.h:93
void buildChars(const Common::UString &str)
Build all necessary characters to display this string.
Definition: ttffont.cpp:169
A handle to an Aurora texture.
float getHeight() const
Return the height of a character.
Definition: ttffont.cpp:124
A simple scoped smart pointer template.
A vector of pointer to objects, with automatic deletion.
Definition: ptrvector.h:44
float getWidth(uint32 c) const
Return the width of a character.
Definition: ttffont.cpp:116
void draw(uint32 c) const
Draw this character.
Definition: ttffont.cpp:143
Low-level type definitions to handle fixed width types portably.
An abstract font.
Definition: font.h:39
A vector storing pointer to objects, with automatic deletion.
A scoped plain pointer, allowing pointer-y access and normal deletion.
Definition: scopedptr.h:120
TTFFont(Common::SeekableReadStream *ttf, int height)
Definition: ttffont.cpp:67
void addChar(uint32 c)
Definition: ttffont.cpp:181
uint32_t uint32
Definition: types.h:204
void drawMissing() const
Definition: ttffont.cpp:128
std::map< uint32, Char >::const_iterator _missingChar
Definition: ttffont.h:98
A font character.
Definition: ttffont.h:83
Common::PtrVector< Page > _pages
Definition: ttffont.h:95
void load(Common::SeekableReadStream *ttf, int height)
Definition: ttffont.cpp:82
std::map< uint32, Char > _chars
Definition: ttffont.h:96
A handle to a texture.
Definition: texturehandle.h:51
Interface for a seekable & readable data stream.
Definition: readstream.h:265
A font.