FastUIDraw
glyph_sequence.hpp
Go to the documentation of this file.
1 /*!
2  * \file glyph_sequence.hpp
3  * \brief file glyph_sequence.hpp
4  *
5  * Copyright 2018 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 #ifndef FASTUIDRAW_GLYPH_SEQUENCE_HPP
20 #define FASTUIDRAW_GLYPH_SEQUENCE_HPP
21 
24 #include <fastuidraw/util/rect.hpp>
25 #include <fastuidraw/text/font.hpp>
32 
33 namespace fastuidraw
34 {
35 /*!\addtogroup PainterAttribute
36  * @{
37  */
38 
39  /*!
40  * \brief
41  * A GlyphSequence represents a sequence of glyph codes with positions.
42  * A GlyphSequence provides an interface to grab the glyph-codes realized
43  * as different renderers for the purpose of rendering text in response
44  * to the transformation that a Painter currently has. A GlyphSequence
45  * maintains a hierarchy so that Painter can quickly cull glyphs that
46  * are not visible. The methods of GlyphSequence are re-entrant but not
47  * thread safe, i.e. if an application uses the same GlyphSequence from
48  * multiple threads it needs to explicitely handle locking itself when
49  * using it.
50  */
52  {
53  public:
54  /*!
55  * A \ref Subset represents a subset of the glyphs
56  * of a \ref GlyphSequence for the purpose of culling
57  * when rendering. Different Subset values from the
58  * same \ref GlyphSequence are guaranteed to have disjoint
59  * glyphs.
60  */
61  class Subset
62  {
63  public:
64  /*!
65  * Given a \ref GlyphRenderer, returns \ref PainterAttribute
66  * and \ref PainterIndex data for specified \ref GlyphRenderer
67  * value. The attribute data and index is generated by the
68  * \ref GlyphAttributePacker as returned by parents \ref
69  * GlyphSequence::attribute_packer(). The data is constructed
70  * lazily on demand.
71  * \param render GlyphRenderer how to render the glyphs of this
72  * \ref Subset
73  * \param out_attributes location to which to write the array
74  * of the attributes to render the glyphs
75  * \param out_indices location to which to write the array
76  * of the indices to render the glyphs
77  */
78  void
80  c_array<const PainterAttribute> *out_attributes,
81  c_array<const PainterIndex> *out_indices);
82 
83  /*!
84  * Returns an array of index values to pass to GlyphSequence::add_glyph()
85  * of the glyphs of this \ref Subset.
86  */
88  glyphs(void);
89 
90  /*!
91  * Gives the bounding box of the glyphs of this
92  * Subset object. A return value of false indicates
93  * that the bounding box is empty.
94  * \param out_bb_box location to which to write the
95  * bounding box
96  */
97  bool
98  bounding_box(Rect *out_bb_box);
99 
100  /*!
101  * Returns the \ref Path made from the bounding
102  * box of the Subset.
103  */
104  const Path&
105  path(void);
106 
107  private:
108  friend class GlyphSequence;
109  explicit
110  Subset(void *d);
111  void *m_d;
112  };
113 
114  /*!
115  * \brief
116  * Opaque object to hold work room needed for functions
117  * of GlyphSequence that require scratch space.
118  */
120  {
121  public:
122  ScratchSpace(void);
123  ~ScratchSpace();
124  private:
125  friend class GlyphSequence;
126  void *m_d;
127  };
128 
129  /*!
130  * Ctor that sets the \ref GlyphAttributePacker to come from
131  * \ref GlyphAttributePacker::standard_packer().
132  * \param format_size format size at which glyphs added via
133  * add_glyphs() or add_glyph() are formatted
134  * \param orientation screen orientation at which glyphs added by
135  * add_glyphs() or add_glyph() are formatted
136  * \param cache \ref GlyphCache used to fetch \ref Glyph values
137  * \param layout specifies if glyphs added by add_glyphs()
138  * or add_glyph() will be layed out horizontally
139  * or vertically
140  */
141  explicit
143  enum PainterEnums::screen_orientation orientation,
144  GlyphCache &cache,
147 
148  /*!
149  * Ctor.
150  * \param format_size format size at which glyphs added via
151  * \param cache \ref GlyphCache used to fetch \ref Glyph values
152  * \param packer specifies how the \ref Glyph values
153  * will be realized as attribute and index data.
154  */
155  explicit
156  GlyphSequence(float format_size, GlyphCache &cache,
158 
159  ~GlyphSequence();
160 
161  /*!
162  * Add \ref GlyphSource values and positions; values are -copied-.
163  * \param glyph_sources specifies what glyphs to add
164  * \param positions specifies the positions of each glyph added
165  */
166  void
168  c_array<const vec2> positions);
169 
170  /*!
171  * Add a single \ref GlyphSource and position
172  * \param glyph_source specifies what glyph to add
173  * \param position specifies the position of the glyph added
174  */
175  void
176  add_glyph(const GlyphSource &glyph_source, const vec2 &position)
177  {
178  c_array<const GlyphSource> glyph_sources(&glyph_source, 1);
179  c_array<const vec2> positions(&position, 1);
180  add_glyphs(glyph_sources, positions);
181  }
182 
183  /*!
184  * Returns the number of \ref GlyphSource values added via
185  * add_glyph() and add_glyphs().
186  */
187  unsigned int
188  number_glyphs(void) const;
189 
190  /*!
191  * Returns the \ref GlyphMetrics and position value for
192  * the i'th glyph added via add_glyph() or add_glyphs().
193  * \param I index to select which glyph, must be that
194  * 0 <= I < number_glyphs()
195  * \param *out_glyph_metrics location to which to write
196  * the \ref GlyphMetrics value
197  * describing the glyph
198  * \param *out_position location to which to write the
199  * position of the glyph
200  */
201  void
202  added_glyph(unsigned int I,
203  GlyphMetrics *out_glyph_metrics,
204  vec2 *out_position) const;
205 
206  /*!
207  * Return the \ref GlyphCache used by this GlyphSequence
208  * to fetch \ref Glyph values.
209  */
210  GlyphCache&
211  glyph_cache(void) const;
212 
213  /*!
214  * Format size with which glyph sequences added by
215  * add_glyphs() and add_glyph() are formatted.
216  */
217  float
218  format_size(void) const;
219 
220  /*!
221  * Returns the \ref GlyphAttributePacker that is used to
222  * create the attribute and index data.
223  */
224  const GlyphAttributePacker&
225  attribute_packer(void) const;
226 
227  /*!
228  * Returns the total number of \ref Subset objects of this
229  * \ref GlyphSequence. This value can change when add_glyph()
230  * or add_glyphs() is called.
231  */
232  unsigned int
233  number_subsets(void) const;
234 
235  /*!
236  * Fetch a \ref Subset of this \ref GlyphSequence. The
237  * returned object may no longer be valid if add_glyph()
238  * or add_glyphs() is called. In addition, any returned
239  * object is no longer valid if the owning \ref GlyphSequence
240  * goes out of scope.
241  * \param I which Subset to fetch with 0 <= I < number_subsets()
242  */
243  Subset
244  subset(unsigned int I) const;
245 
246  /*!
247  * Fetch those Subset objects that intersect a region
248  * specified by clip equations.
249  * \param scratch_space scratch space for computations.
250  * \param clip_equations array of clip equations
251  * \param clip_matrix_local 3x3 transformation from local (x, y, 1)
252  * coordinates to clip coordinates.
253  * \param[out] dst location to which to write the \ref Subset
254  * ID values
255  * \returns the number of Subset object ID's written to dst, that
256  * number is guaranteed to be no more than number_subsets().
257  */
258  unsigned int
259  select_subsets(ScratchSpace &scratch_space,
260  c_array<const vec3> clip_equations,
261  const float3x3 &clip_matrix_local,
262  c_array<unsigned int> dst) const;
263 
264  private:
265  void *m_d;
266  };
267 
268 /*! @} */
269 }
270 
271 #endif
A GlyphSequence represents a sequence of glyph codes with positions. A GlyphSequence provides an inte...
file glyph_cache.hpp
screen_orientation
Enumeration to indicate in what direction the y-coordinate increases.
file glyph_attribute_packer.hpp
file matrix.hpp
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
A wrapper over a pointer to implement reference counting.
A GlyphCache represents a cache of glyphs and manages the uploading of the data to a GlyphAtlas...
Definition: glyph_cache.hpp:43
void attributes_and_indices(GlyphRenderer render, c_array< const PainterAttribute > *out_attributes, c_array< const PainterIndex > *out_indices)
const GlyphAttributePacker & attribute_packer(void) const
file c_array.hpp
unsigned int number_glyphs(void) const
GlyphCache & glyph_cache(void) const
void add_glyphs(c_array< const GlyphSource > glyph_sources, c_array< const vec2 > positions)
file painter_attribute_data.hpp
unsigned int number_subsets(void) const
unsigned int select_subsets(ScratchSpace &scratch_space, c_array< const vec3 > clip_equations, const float3x3 &clip_matrix_local, c_array< unsigned int > dst) 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
glyph_layout_type
Enumeration to indicate if glyph layout is horizontal or vertical.
file painter_enums.hpp
void added_glyph(unsigned int I, GlyphMetrics *out_glyph_metrics, vec2 *out_position) const
file glyph_source.hpp
A GlyphMetrics provides information on the metrics of a glyph, all the values are in units of the fon...
Subset subset(unsigned int I) const
Opaque object to hold work room needed for functions of GlyphSequence that require scratch space...
A Path represents a collection of PathContour objects.
Definition: path.hpp:668
file glyph.hpp
void add_glyph(const GlyphSource &glyph_source, const vec2 &position)
A GlyphAttributePacker provides an interface to customize how glyph attribute and index data is reali...
bool bounding_box(Rect *out_bb_box)
Class for which copy ctor and assignment operator are private functions.
Definition: util.hpp:505
float format_size(void) const
Specifies how to render a glyph.
c_array< const unsigned int > glyphs(void)
file font.hpp