Unofficial OpenGL Software Development Kit  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Font.h
Go to the documentation of this file.
1 
2 #ifndef FONT_UTIL_H
3 #define FONT_UTIL_H
4 
10 #include <exception>
11 #include <stdexcept>
12 #include <utility>
13 #include <vector>
14 #include <boost/utility/string_ref.hpp>
15 #include <glm/glm.hpp>
16 
17 namespace glutil
18 {
21 
22  namespace detail
23  {
24  class FontImpl;
25  }
26 
27  class Font;
28 
34  enum FontSizes
35  {
40  };
41 
71  Font *GenerateFont(FontSizes eSize);
72 
80  class GlyphQuad
81  {
82  public:
86  GlyphQuad(glm::vec2 ptBottomLeft, glm::vec2 tcBottomLeft,
87  glm::vec2 ptTopRight, glm::vec2 tcTopRight)
88  : m_ptBottomLeft(ptBottomLeft)
89  , m_tcBottomLeft(tcBottomLeft)
90  , m_ptTopRight(ptTopRight)
91  , m_tcTopRight(tcTopRight)
92  {}
93 
108  std::vector<glm::vec2> GetPositions() const;
109 
118  std::vector<glm::vec2> GetTexCoords() const;
119 
120  private:
121  glm::vec2 m_ptBottomLeft;
122  glm::vec2 m_tcBottomLeft;
123  glm::vec2 m_ptTopRight;
124  glm::vec2 m_tcTopRight;
125  };
126 
138  {
142  };
143 
147  class InvalidEncodingException : public std::runtime_error
148  {
149  public:
150  InvalidEncodingException() : std::runtime_error("UTF-8 text is not valid.") {}
151  };
152 
153  //Deletion of this object must happen while OpenGL is still active.
175  class Font
176  {
177  public:
178  ~Font();
179 
190  GLuint GetTexture() const;
191 
206  std::pair<GlyphQuad, bool> GetSingleGlyph(unsigned int codepoint, const glm::vec2 &ptReference,
207  PointReference eRef = REF_BASELINE) const;
208 
223  std::vector<GlyphQuad> LayoutLine(boost::string_ref text, const glm::vec2 &ptReference,
224  PointReference eRef = REF_BASELINE) const;
225 
227  int GetLinePixelHeight() const;
228 
230  int GetGlyphAdvanceWidth() const;
231 
232  private:
233  detail::FontImpl *m_pImpl;
234 
235  explicit Font(detail::FontImpl *pImpl);
236 
237  friend Font *GenerateFont(FontSizes eSize);
238 
239  //Prevent copying
240  Font(const Font &);
241  Font &operator=(const Font &);
242  };
243 
245 }
246 
247 #endif //FONT_UTIL_H