FastUIDraw
glyph.hpp
Go to the documentation of this file.
1 /*!
2  * \file glyph.hpp
3  * \brief file glyph.hpp
4  *
5  * Copyright 2016 by Intel.
6  *
7  * Contact: kevin.rogovin@gmail.com
8  *
9  * This Source Code Form is subject to the
10  * terms of the Mozilla Public License, v. 2.0.
11  * If a copy of the MPL was not distributed with
12  * this file, You can obtain one at
13  * http://mozilla.org/MPL/2.0/.
14  *
15  * \author Kevin Rogovin <kevin.rogovin@gmail.com>
16  *
17  */
18 
19 
20 #ifndef FASTUIDRAW_GLYPH_HPP
21 #define FASTUIDRAW_GLYPH_HPP
22 
24 #include <fastuidraw/util/util.hpp>
25 #include <fastuidraw/util/vecN.hpp>
27 #include <fastuidraw/path.hpp>
33 
34 namespace fastuidraw
35 {
36 /*!\addtogroup Glyph
37  * @{
38  */
39 
40  class GlyphCache;
41 
42  /*!
43  * \brief
44  * A Glyph is essentially an opaque pointer to
45  * data for rendering and performing layout of a
46  * glyph.
47  */
48  class Glyph
49  {
50  public:
51  /*!
52  * Ctor. Initializes the Glyph to be invalid,
53  * i.e. essentially a nullptr pointer
54  */
55  Glyph(void):
56  m_opaque(nullptr)
57  {}
58 
59  /*!
60  * Returns true if the Glyph refers to actual
61  * glyph data
62  */
63  bool
64  valid(void) const
65  {
66  return m_opaque != nullptr;
67  }
68 
69  /*!
70  * Returns the glyph's rendering type, valid()
71  * must return true. If not, debug builds FASTUIDRAWassert
72  * and release builds crash.
73  */
74  enum glyph_type
75  type(void) const;
76 
77  /*!
78  * Returns the glyph's renderer, valid() must
79  * return true. If not, debug builds FASTUIDRAWassert
80  * and release builds crash.
81  */
83  renderer(void) const;
84 
85  /*!
86  * Returns ths rendering size of the glyph (in
87  * font coordinates). This value is similair in
88  * value to GlyphMetrics:size() but not necessarily
89  * idential (differnces come from discretization to
90  * pixels for example).
91  */
92  vec2
93  render_size(void) const;
94 
95  /*!
96  * Returns the glyph's layout data, valid()
97  * must return true. If not, debug builds FASTUIDRAWassert
98  * and release builds crash.
99  */
101  metrics(void) const;
102 
103  /*!
104  * Returns the glyph's per-corner attribute data.
105  */
107  attributes(void) const;
108 
109  /*!
110  * Returns the GlyphCache on which the glyph
111  * resides. The return value of valid() must be
112  * true. If not, debug builds FASTUIDRAWassert
113  * and release builds crash.
114  */
115  GlyphCache*
116  cache(void) const;
117 
118  /*!
119  * Returns the index location into the GlyphCache
120  * of the glyph. The return value of valid() must be
121  * true. If not, debug builds FASTUIDRAWassert and release
122  * builds crash.
123  */
124  unsigned int
125  cache_location(void) const;
126 
127  /*!
128  * If returns \ref routine_fail, then the GlyphCache
129  * on which the glyph resides needs to be cleared
130  * first. If the glyph is already uploaded returns
131  * immediately with \ref routine_success.
132  */
133  enum return_code
134  upload_to_atlas(void) const;
135 
136  /*!
137  * Returns true if and only if the Glyph is
138  * already uploaded to a GlyphAtlas.
139  */
140  bool
141  uploaded_to_atlas(void) const;
142 
143  /*!
144  * Returns the path of the Glyph; the path is in
145  * coordinates of the glyph with the convention
146  * that the y-coordinate increases upwards. If one
147  * is rendering the path (for example stroking it),
148  * together with drawing of glyphs via a \ref Painter,
149  * then one needs to reverse the y-coordinate (for
150  * example by Painter::shear(1.0, -1.0)) if the
151  * glyphs are rendered with data packed by
152  * pack_glyph() with PainterEnums::y_increases_downwards.
153  */
154  const Path&
155  path(void) const;
156 
157  /*!
158  * Create a Glyph WITHOUT placing it on a \ref GlyphCache.
159  * Such a Glyph needs to be destroyed manually with
160  * delete_glyph() or placed on a GlyphCache (via GlyphCache::add_glyph()).
161  * Glyph values that are NOT on a GlyphCache will always fail
162  * in their call to upload_to_atlas().
163  * \param render the nature of the render data to give to the Glyph
164  * \param font the font used to generate the Glyph
165  * \param glyph_code the glyph code to generate the Glyph
166  */
167  static
168  Glyph
171  uint32_t glyph_code);
172 
173  /*!
174  * Destroy a Glyph that is NOT in a \ref GlyphCache,
175  * i.e. cache() returns a nullptr. On success the underlying
176  * data of the passed Glyph is no longer valid and the
177  * Glyph value passed should be discarded (i.e. like a freed
178  * pointer).
179  * \param G Glyph to delete
180  */
181  static
182  enum return_code
183  delete_glyph(Glyph G);
184 
185  /*!
186  * Given an index into an array of \ref GlyphAttribute values,
187  * as used by pack_raw() or returned by \ref attributes()),
188  * return the point to member variable of which attribute is
189  * written to from the glyph attribute value and what component
190  * of it.
191  * \param glyph_attribute_index into an array of \ref GlyphAttribute
192  * values, for example the array returned
193  * by \ref attributes().
194  * \param out_attribute location to which to write the pointer
195  * member of \ref PainterAttribute that
196  * the glyph attribute value is written to
197  * in pack_raw() and/or pack_glyph().
198  * \param out_index_into_attribute location to which to write the
199  * array-index element of the
200  * member of \ref PainterAttribute
201  * that the glyph attribute value
202  * is written to in pack_raw()
203  * and/or pack_glyph().
204  */
205  static
206  void
207  glyph_attribute_dst_write(int glyph_attribute_index,
208  PainterAttribute::pointer_to_field *out_attribute,
209  int *out_index_into_attribute);
210 
211  /*!
212  * Provides information on the rendering cost of the Glyph,
213  * entirely dependent on the \ref GlyphRenderData that generated
214  * the data.
215  */
217  render_cost(void) const;
218 
219  private:
220  friend class GlyphCache;
221 
222  explicit
223  Glyph(void *p):
224  m_opaque(p)
225  {}
226 
227  void *m_opaque;
228  };
229 /*! @} */
230 }
231 
232 #endif
GlyphRenderer renderer(void) const
bool uploaded_to_atlas(void) const
file glyph_render_data.hpp
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
GlyphCache * cache(void) const
A wrapper over a pointer to implement reference counting.
c_array< const GlyphAttribute > attributes(void) const
GlyphMetrics metrics(void) const
return_code
Enumeration for simple return codes for functions for success or failure.
Definition: util.hpp:142
A GlyphCache represents a cache of glyphs and manages the uploading of the data to a GlyphAtlas...
Definition: glyph_cache.hpp:43
vec2 render_size(void) const
static enum return_code delete_glyph(Glyph G)
file c_array.hpp
const Path & path(void) const
file path.hpp
file util.hpp
glyph_type
Provides an enumeration of the rendering data for a glyph.
static void glyph_attribute_dst_write(int glyph_attribute_index, PainterAttribute::pointer_to_field *out_attribute, int *out_index_into_attribute)
enum return_code upload_to_atlas(void) const
A c_array is a wrapper over a C pointer with a size parameter to facilitate bounds checking and provi...
Definition: c_array.hpp:43
file glyph_attribute.hpp
file painter_enums.hpp
bool valid(void) const
Definition: glyph.hpp:64
file vecN.hpp
uvec4 PainterAttribute::* pointer_to_field
A GlyphMetrics provides information on the metrics of a glyph, all the values are in units of the fon...
unsigned int cache_location(void) const
file painter_attribute.hpp
c_array< const GlyphRenderCostInfo > render_cost(void) const
A Glyph is essentially an opaque pointer to data for rendering and performing layout of a glyph...
Definition: glyph.hpp:48
A Path represents a collection of PathContour objects.
Definition: path.hpp:668
file glyph_metrics.hpp
enum glyph_type type(void) const
static Glyph create_glyph(GlyphRenderer render, const reference_counted_ptr< const FontBase > &font, uint32_t glyph_code)
Specifies how to render a glyph.
file reference_counted.hpp