zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Font.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
44 #ifndef ZENI_FONT_H
45 #define ZENI_FONT_H
46 
47 #include <Zeni/Color.h>
48 #include <Zeni/Coordinate.h>
49 #include <Zeni/Core.h>
50 #include <Zeni/Image.h>
51 #include <Zeni/String.h>
52 
53 #include <memory>
54 
55 #include <Zeni/Define.h>
56 
57 typedef struct FT_FaceRec_* FT_Face;
58 
59 namespace Zeni {
60 
61  struct Color;
62  class ZENI_GRAPHICS_DLL Video;
63  class ZENI_GRAPHICS_DLL Video_GL_Fixed;
64  class ZENI_GRAPHICS_DLL Video_GL_Shader;
65  class ZENI_GRAPHICS_DLL Video_DX9;
66  class ZENI_GRAPHICS_DLL Texture;
67 
68  enum JUSTIFY {ZENI_LEFT = 0, ZENI_CENTER = 1, ZENI_RIGHT = 2};
69 
70  class ZENI_GRAPHICS_DLL Font {
71  Font(const Font &);
72  Font & operator=(const Font &);
73 
74  public:
75  Font();
76  Font(const float &glyph_height,
77  const float &virtual_screen_height,
78  const String &font_name = "Untitled Font");
79  virtual ~Font() {}
80 
81  inline const String & get_name() const;
82  inline float get_text_height() const;
83  virtual float get_text_width(const String &text) const = 0;
84  inline float get_virtual_screen_height() const;
85 
87  virtual void render_text(const String &text, const Point2f &position,
88  const Color &color, const JUSTIFY &justify = ZENI_DEFAULT_JUSTIFY) const = 0;
90  virtual void render_text(const String &text, const Point3f &position, const Vector3f &right, const Vector3f &down,
91  const Color &color, const JUSTIFY &justify = ZENI_DEFAULT_JUSTIFY) const = 0;
92 
93  private:
94  float m_glyph_height;
95  float m_virtual_screen_height;
96  String m_font_name;
97  };
98 
99  class ZENI_GRAPHICS_DLL Font_FT : public Font {
100  Font_FT(const Font_FT &);
101  Font_FT & operator=(const Font_FT &);
102 
103  struct ZENI_GRAPHICS_DLL Glyph {
104  Glyph();
105  Glyph(FT_Face &face,
106  const char &c,
107  const int &ascent,
108  const float &vratio,
109  const Point2i &position,
110  const Point2i &total_size
111  );
112 
113  inline float get_glyph_width() const;
114 
115  inline void render(Video &vr, const Point2f &position, const float &vratio) const;
116  inline void render(Video &vr, const Point3f &position, const Vector3f &right, const Vector3f &down) const;
117 
118  private:
119  float m_glyph_width;
120  Point2f m_upper_left_point, m_lower_right_point;
121  Point2f m_upper_left_texel, m_lower_right_texel;
122  };
123 
124  public:
125  Font_FT();
126  Font_FT(const String &filepath,
127  const float &glyph_height,
128  const float &virtual_screen_height);
129 
130  virtual float get_text_width(const String &text) const;
131 
132  virtual void render_text(const String &text, const Point2f &position,
133  const Color &color, const JUSTIFY &justify = ZENI_LEFT) const;
134  virtual void render_text(const String &text, const Point3f &position, const Vector3f &right, const Vector3f &down,
135  const Color &color, const JUSTIFY &justify = ZENI_DEFAULT_JUSTIFY) const;
136 
137  private:
138  void init(const String &filepath);
139 
140  int next_power_of_two(const int &value);
141  Image gen_glyph(FT_Face &face, const char &ch);
142 
143 #ifdef _WINDOWS
144 #pragma warning( push )
145 #pragma warning( disable : 4251 )
146 #endif
147  std::vector<Glyph> m_glyph;
148  std::auto_ptr<Texture> m_texture;
149 #ifdef _WINDOWS
150 #pragma warning( pop )
151 #endif
152  int m_ascent;
153 
154  float m_font_height;
155  float m_vratio;
156  };
157 
158  struct ZENI_GRAPHICS_DLL Font_Type_Unsupported : Error {
159  Font_Type_Unsupported(const String &filename) : Error("Unsupported Font Type: ")
160  {msg += filename;}
161  };
162 
163  struct ZENI_GRAPHICS_DLL Font_Init_Failure : Error {
164  Font_Init_Failure() : Error("Zeni Font Initialization Failure!") {}
165  };
166 
167 }
168 
169 #include <Zeni/Undefine.h>
170 
171 #endif
#define ZENI_DEFAULT_JUSTIFY
Definition: Define.h:65
GLuint color
Definition: glew.h:7185
static void init(struct bs2b *bs2b)
Definition: bs2b.c:46
static void render(const Vertex_Buffer_Macrorenderer &macrorenderer, std::vector< Vertex_Buffer::Vertex_Buffer_Range * > &descriptors)
JUSTIFY
Definition: Font.h:68
Image.
Definition: Image.h:52
A 3D Point represented with floats.
Definition: Coordinate.h:133
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
Font_Type_Unsupported(const String &filename)
Definition: Font.h:159
GLenum face
Definition: gl2ext.h:1490
const GLfloat * c
Definition: glew.h:14913
struct FT_FaceRec_ * FT_Face
Definition: freetype.h:399
virtual ~Font()
Definition: Font.h:79
Font Abstraction.
Definition: Font.h:70
EGLSurface EGLint void ** value
Definition: eglext.h:301
The Error Class.
Definition: Error.h:52
GLfloat right
Definition: glew.h:13816
A 2D Point represented with floats.
Definition: Coordinate.h:98
Color.
Definition: Color.h:41
A 2D Point represented with integers.
Definition: Coordinate.h:85