FastUIDraw
glyph_run.hpp
Go to the documentation of this file.
1 /*!
2  * \file glyph_run.hpp
3  * \brief file glyph_run.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_RUN_HPP
20 #define FASTUIDRAW_GLYPH_RUN_HPP
21 
24 #include <fastuidraw/text/font.hpp>
32 
33 namespace fastuidraw
34 {
35 /*!\addtogroup PainterAttribute
36  * @{
37  */
38 
39  /*!\brief
40  * A GlyphRun represents a sequence of glyph codes with positions.
41  * A GlyphRun provides an interface to grab the glyph-codes realized
42  * as different renderers for the purpose of rendering text in response
43  * to the transformation that a Painter currently has. In contrast to
44  * a \ref GlyphSequence, a GlyphRun does NOT maintain a hierarchy
45  * to perform culling. However, it does provide an interface to select
46  * continuous subsets of the glyphs for the purporse of rendering.
47  * In addition, since it does not carry a hierarchy for culling, it
48  * is also a lighter weight object than \ref GlyphSequence. Like \ref
49  * GlyphSequence, the methods of \ref GlyphRun are re-entrant but not
50  * thread safe, i.e. if an application uses the same \ref GlyphRun from
51  * multiple threads it needs to explicitely handle locking itself when
52  * using it.
53  */
55  {
56  public:
57  /*!
58  * Ctor that sets the \ref GlyphAttributePacker to come from
59  * \ref GlyphAttributePacker::standard_packer().
60  * \param format_size format size at which glyphs added via
61  * add_glyphs() or add_glyph() are formatted
62  * \param orientation screen orientation at which glyphs added by
63  * add_glyphs() or add_glyph() are formatted
64  * \param cache \ref GlyphCache used to fetch \ref Glyph values
65  * \param layout specifies if glyphs added by add_glyphs()
66  * or add_glyph() will be layed out horizontally
67  * or vertically
68  */
69  explicit
70  GlyphRun(float format_size,
71  enum PainterEnums::screen_orientation orientation,
72  GlyphCache &cache,
75 
76  /*!
77  * Ctor.
78  * \param format_size format size at which glyphs added via
79  * \param cache \ref GlyphCache used to fetch \ref Glyph values
80  * \param packer specifies how the \ref Glyph values
81  * will be realized as attribute and index data.
82  */
83  explicit
84  GlyphRun(float format_size, GlyphCache &cache,
86 
87  ~GlyphRun();
88 
89  /*!
90  * Add glyphs passing an array of positions and GlyphMetric values;
91  * values are -copied-.
92  * \param glyph_metrics specifies what glyphs to add
93  * \param positions specifies the positions of each glyph added
94  */
95  void
97  c_array<const vec2> positions);
98 
99  /*!
100  * Add \ref GlyphSource values and positions; values are -copied-.
101  * \param glyph_sources specifies what glyphs to add
102  * \param positions specifies the positions of each glyph added
103  */
104  void
106  c_array<const vec2> positions);
107 
108  /*!
109  * Add glyphs from a specific font and positions; values are -copied-.
110  * \param font font from which to fetch glyphs
111  * \param glyph_codes specifies what glyphs to add
112  * \param positions specifies the positions of each glyph added
113  */
114  void
115  add_glyphs(const FontBase *font,
116  c_array<const uint32_t> glyph_codes,
117  c_array<const vec2> positions);
118 
119  /*!
120  * Add a single \ref GlyphSource and position
121  * \param glyph_source specifies what glyph to add
122  * \param position specifies the position of the glyph added
123  */
124  void
125  add_glyph(const GlyphSource &glyph_source, const vec2 &position)
126  {
127  c_array<const GlyphSource> glyph_sources(&glyph_source, 1);
128  c_array<const vec2> positions(&position, 1);
129  add_glyphs(glyph_sources, positions);
130  }
131 
132  /*!
133  * Returns the number of \ref GlyphSource values added via
134  * add_glyph() and add_glyphs().
135  */
136  unsigned int
137  number_glyphs(void) const;
138 
139  /*!
140  * Returns the \ref GlyphSource and position value for
141  * the i'th glyph added via add_glyph() or add_glyphs().
142  * \param I index to select which glyph, must be that
143  * 0 <= I < number_glyphs()
144  * \param *out_glyph_metrics location to which to write
145  * the \ref GlyphMetrics value
146  * describing the glyph
147  * \param *out_position location to which to write the
148  * position of the glyph
149  */
150  void
151  added_glyph(unsigned int I,
152  GlyphMetrics *out_glyph_metrics,
153  vec2 *out_position) const;
154 
155  /*!
156  * Return the \ref GlyphCache used by this GlyphRun
157  * to fetch \ref Glyph values.
158  */
159  GlyphCache&
160  glyph_cache(void) const;
161 
162  /*!
163  * Format size with which glyph sequences added by
164  * add_glyphs() and add_glyph() are formatted.
165  */
166  float
167  format_size(void) const;
168 
169  /*!
170  * Returns the \ref GlyphAttributePacker that is used to
171  * create the attribute and index data.
172  */
173  const GlyphAttributePacker&
174  attribute_packer(void) const;
175 
176  /*!
177  * Returns a const-reference to \ref PainterAttributeWriter
178  * object for rendering a named range of glyphs for
179  * a specified \ref GlyphRenderer. The returned object
180  * is valid in value until this GlyphRun is destroyed or
181  * one of add_glyph(), add_glyphs(), subsequence() is called.
182  * The \ref PainterAttributeWriter will provide indices and
183  * attributes as packed by \ref attribute_packer().
184  * \param renderer how to render the glyphs
185  * \param begin index to select which is the first glyph
186  * \param count number of glyphs to take starting at begin
187  */
189  subsequence(GlyphRenderer renderer, unsigned int begin, unsigned int count) const;
190 
191  /*!
192  * Returns a const-reference to \ref PainterAttributeWriter
193  * object for rendering all glyphs from a starting point
194  * for a specified \ref GlyphRenderer. The returned object
195  * is valid in value until this GlyphRun is destroyed or
196  * one of add_glyph(), add_glyphs(), subsequence() is called.
197  * The \ref PainterAttributeWriter will provide indices and
198  * attributes as packed by \ref attribute_packer().
199  * \param renderer how to render the glyphs
200  * \param begin index to select which is the first glyph
201  */
203  subsequence(GlyphRenderer renderer, unsigned int begin) const;
204 
205  /*!
206  * Returns a const-reference to \ref PainterAttributeWriter
207  * object for rendering the entire range of glyphs for
208  * a specified \ref GlyphRenderer. The returned object
209  * is valid in value until this GlyphRun is destroyed or
210  * one of add_glyph(), add_glyphs(), subsequence() is called.
211  * The \ref PainterAttributeWriter will provide indices and
212  * attributes as packed by \ref attribute_packer().
213  * \param renderer how to render the glyphs
214  */
216  subsequence(GlyphRenderer renderer) const;
217 
218  private:
219  void *m_d;
220  };
221 
222 /*! @} */
223 }
224 
225 #endif
const GlyphAttributePacker & attribute_packer(void) const
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
void added_glyph(unsigned int I, GlyphMetrics *out_glyph_metrics, vec2 *out_position) const
FontBase provides an interface for a font to generate glyph rendering data.
Definition: font.hpp:47
A wrapper over a pointer to implement reference counting.
void add_glyph(const GlyphSource &glyph_source, const vec2 &position)
Definition: glyph_run.hpp:125
A GlyphCache represents a cache of glyphs and manages the uploading of the data to a GlyphAtlas...
Definition: glyph_cache.hpp:43
float format_size(void) const
A GlyphRun represents a sequence of glyph codes with positions. A GlyphRun provides an interface to g...
Definition: glyph_run.hpp:54
GlyphRun(float format_size, enum PainterEnums::screen_orientation orientation, GlyphCache &cache, enum PainterEnums::glyph_layout_type layout=PainterEnums::glyph_layout_horizontal)
const PainterAttributeWriter & subsequence(GlyphRenderer renderer, unsigned int begin, unsigned int count) const
void add_glyphs(c_array< const GlyphMetrics > glyph_metrics, c_array< const vec2 > positions)
file c_array.hpp
Provides an interface to write attribute and index data when a simple copy of data from c_array objec...
file painter_attribute_data.hpp
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
file glyph_source.hpp
GlyphCache & glyph_cache(void) const
A GlyphMetrics provides information on the metrics of a glyph, all the values are in units of the fon...
unsigned int number_glyphs(void) const
file glyph.hpp
A GlyphAttributePacker provides an interface to customize how glyph attribute and index data is reali...
Class for which copy ctor and assignment operator are private functions.
Definition: util.hpp:505
file painter_attribute_writer.hpp
Specifies how to render a glyph.
file font.hpp