Sceneview
 All Classes Functions Variables Enumerations Enumerator Groups Pages
font_resource.hpp
1 // Copyright [2015] Albert Huang
2 
3 #ifndef SCENEVIEW_FONT_RESOURCE_HPP__
4 #define SCENEVIEW_FONT_RESOURCE_HPP__
5 
6 #include <memory>
7 
8 #include <QFont>
9 
10 class QOpenGLTexture;
11 
12 namespace sv {
13 
25 class FontResource {
26  public:
55  struct CharData {
56  // Texture left coordinate
57  float u0;
58 
59  // Texture top coordinate
60  float v0;
61 
62  // Texture right coordinate
63  float u1;
64 
65  // Texture bottom coordinate
66  float v1;
67 
68  // Character width, relative to line height
69  float width_to_height;
70 
71  // Vertex left offset (relative to line height)
72  float x0;
73 
74  // Vertex top offset (relative to line height)
75  float y0;
76 
77  // Vertex right offset (relative to line height)
78  float x1;
79 
80  // Vertex bottom offset (relative to line height)
81  float y1;
82  };
83 
84  public:
85  typedef std::shared_ptr<FontResource> Ptr;
86 
90  const std::shared_ptr<QOpenGLTexture>& Texture() { return texture_; }
91 
95  const CharData& GetCharData(int c) {
96  return char_data_[c];
97  }
98 
99  private:
100  friend class ResourceManager;
101 
102  static Ptr Create(const QFont& font);
103 
104  explicit FontResource(const QFont& font);
105 
106  void Build(const QFont& font);
107 
108  int num_rows_;
109  int num_cols_;
110  int block_size_;
111 
112  CharData char_data_[256];
113 
114  std::shared_ptr<QOpenGLTexture> texture_;
115 };
116 
117 } // namespace sv
118 
119 #endif // SCENEVIEW_FONT_RESOURCE_HPP__
Describes how to draw a character from the font texture map.
Definition: font_resource.hpp:55
const CharData & GetCharData(int c)
Retrieve parameters on how to draw the specified character.
Definition: font_resource.hpp:95
Central repository for resources.
Definition: resource_manager.hpp:36
const std::shared_ptr< QOpenGLTexture > & Texture()
Retrieve the texture.
Definition: font_resource.hpp:90
A font texture map, suitable for rendering fonts using texture-mapped quads.
Definition: font_resource.hpp:25