xoreos  0.0.5
font.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_FONT_H
26 #define GRAPHICS_FONT_H
27 
28 #include <vector>
29 
30 #include "glm/mat4x4.hpp"
31 
32 #include "src/common/ustring.h"
33 
34 #include "src/graphics/types.h"
35 
36 namespace Graphics {
37 
39 class Font {
40 public:
41  Font();
42  virtual ~Font();
43 
45  virtual float getWidth (uint32 c) const = 0;
47  virtual float getHeight() const = 0;
48 
50  virtual float getLineSpacing() const;
51 
53  size_t getLineCount(const Common::UString &text, float maxWidth = 0.0f, float maxHeight = 0.0f) const;
54 
56  float getWidth (const Common::UString &text, float maxWidth = 0.0f) const;
58  float getHeight(const Common::UString &text, float maxWidth = 0.0f, float maxHeight = 0.0f) const;
60  float getLineWidth(const Common::UString &text) const;
61 
63  virtual void buildChars(const Common::UString &str);
64 
66  virtual void draw(uint32 c) const = 0;
67 
68  virtual void renderBind(const glm::mat4 &UNUSED(transform)) const {}
69  virtual void render(uint32 UNUSED(c), float &UNUSED(x), float &UNUSED(y), float *UNUSED(rgba)) const {}
70  virtual void renderUnbind() const {}
71 
72  float split(const Common::UString &line, std::vector<Common::UString> &lines,
73  float maxWidth = 0.0f, float maxHeight = 0.0f, bool trim = true) const;
74  float split(Common::UString &line, float maxWidth, float maxHeight = 0.0f, bool trim = true) const;
75  float split(const Common::UString &line, Common::UString &lines, float maxWidth, float maxHeight = 0.0f, bool trim = true) const;
76 
77 private:
78  bool addLine(std::vector<Common::UString> &lines, const Common::UString &newLine, float maxHeight) const;
79 };
80 
81 } // End of namespace Graphics
82 
83 #endif // GRAPHICS_FONT_H
virtual ~Font()
Definition: font.cpp:36
A class holding an UTF-8 string.
Definition: ustring.h:48
virtual void draw(uint32 c) const =0
Draw this character.
float getLineWidth(const Common::UString &text) const
Return the width of this string.
Definition: font.cpp:257
virtual float getLineSpacing() const
Return the size of space between lines.
Definition: font.cpp:39
size_t getLineCount(const Common::UString &text, float maxWidth=0.0f, float maxHeight=0.0f) const
Return the number of lines this text spans.
Definition: font.cpp:43
float split(const Common::UString &line, std::vector< Common::UString > &lines, float maxWidth=0.0f, float maxHeight=0.0f, bool trim=true) const
Definition: font.cpp:69
Basic graphics types.
bool addLine(std::vector< Common::UString > &lines, const Common::UString &newLine, float maxHeight) const
Definition: font.cpp:266
#define UNUSED(x)
Definition: system.h:170
An abstract font.
Definition: font.h:39
Unicode string handling.
uint32_t uint32
Definition: types.h:204
virtual void renderBind(const glm::mat4 &transform) const
Definition: font.h:68
virtual void buildChars(const Common::UString &str)
Build all necessary characters to display this string.
Definition: font.cpp:66
virtual float getHeight() const =0
Return the height of a character.
virtual float getWidth(uint32 c) const =0
Return the width of a character.
virtual void renderUnbind() const
Definition: font.h:70
virtual void render(uint32 c, float &x, float &y, float *rgba) const
Definition: font.h:69