FastUIDraw
glyph_attribute_packer.hpp
Go to the documentation of this file.
1 /*!
2  * \file glyph_attribute_packer.hpp
3  * \brief file glyph_attribute_packer.hpp
4  *
5  * Copyright 2019 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_ATTRIBUTE_PACKER_HPP
20 #define FASTUIDRAW_GLYPH_ATTRIBUTE_PACKER_HPP
21 
23 
24 namespace fastuidraw
25 {
26 /*!\addtogroup PainterAttribute
27  * @{
28  */
29 
30  /*!
31  * \brief
32  * A GlyphAttributePacker provides an interface to customize
33  * how glyph attribute and index data is realized by a \ref
34  * GlyphRun and \ref GlyphSequence.
35  */
36  class GlyphAttributePacker:public reference_counted<GlyphAttributePacker>::concurrent
37  {
38  public:
39  virtual
41  {}
42 
43  /*!
44  * To be implemented by a derived class to return
45  * the positions of the bottom-left and top-right
46  * coordinates of a glyph at the named position
47  * using only the information from \ref GlyphMetrics.
48  * \param metrics GlyphMertics to use to compute the bounding
49  * box
50  * \param position position of bottom left of glyph
51  * \param scale_factor the amount by which to scale from the
52  * \ref Glyph object's coordinates
53  * \param[out] p_bl location to which to write the bottom-left
54  * coordinate of the glyph
55  * \param[out] p_tr location to which to write the top-right
56  * coordinate of the glyph
57  */
58  virtual
59  void
61  const vec2 position, float scale_factor,
62  vec2 *p_bl, vec2 *p_tr) const = 0;
63 
64  /*!
65  * To be implemented by a derived class to return
66  * the positions of the bottom-left and top-right
67  * coordinates of a glyph at the named position.
68  * \param glyph Glyph to realize
69  * \param position position of bottom left of glyph
70  * \param scale_factor the amount by which to scale from the
71  * \ref Glyph object's coordinates
72  * \param[out] p_bl location to which to write the bottom-left
73  * coordinate of the glyph
74  * \param[out] p_tr location to which to write the top-right
75  * coordinate of the glyph
76  */
77  virtual
78  void
79  glyph_position(Glyph glyph,
80  const vec2 position, float scale_factor,
81  vec2 *p_bl, vec2 *p_tr) const = 0;
82 
83  /*!
84  * To be implemented by a derived class to return
85  * how many indices and attributes are needed to
86  * realize a single glyph.
87  * \param glyph_renderer \ref Glyph::renderer() of \ref Glyph to realize
88  * \param glyph_attributes \ref Glyph::attributes() of \ref Glyph to realize
89  * \param[out] out_num_indices number of indices needed
90  * to realize the glyph
91  * \param[out] out_num_attributes number of attributes
92  * needed to realize the glyph
93  */
94  virtual
95  void
96  compute_needed_room(GlyphRenderer glyph_renderer,
97  c_array<const GlyphAttribute> glyph_attributes,
98  unsigned int *out_num_indices,
99  unsigned int *out_num_attributes) const = 0;
100 
101  /*!
102  * To be implemented by a derived class to provide the
103  * attributes and indices to realize a glyph.
104  * \param glyph_renderer \ref Glyph::renderer() of \ref Glyph to realize
105  * \param glyph_attributes \ref Glyph::attributes() of \ref Glyph to realize
106  * \param dst_indices location to which to write the indices;
107  * the values are offsets into dst_attribs
108  * \param dst_attribs location to which to write the attributes
109  * \param p_bl position of bottom left of glyph as emited by
110  * \ref glyph_position()
111  * \param p_tr position of top right of glyph as emited by
112  * \ref glyph_position()
113  */
114  virtual
115  void
116  realize_attribute_data(GlyphRenderer glyph_renderer,
117  c_array<const GlyphAttribute> glyph_attributes,
118  c_array<PainterIndex> dst_indices,
119  c_array<PainterAttribute> dst_attribs,
120  const vec2 p_bl, const vec2 p_tr) const = 0;
121 
122  /*!
123  * Returns a \ref GlyphAttributePacker suitable for the
124  * specified \ref PainterEnums::screen_orientation and \ref
125  * PainterEnums::glyph_layout_type that packs each single
126  * \ref Glyph object as exactly 4 attributes and 6 indices as
127  * follows:
128  * - PainterAttribute::m_attrib0 .xy -> position in item coordinates of the
129  * vertex of the quad to draw the glyph (float)
130  * - PainterAttribute::m_attrib0 .zw -> the difference in item coordinates
131  * between the bottom-left vertex position
132  * and the top-right vertex position.
133  * - PainterAttribute::m_attrib1 .x -> Glyph::attribute()[0]
134  * - PainterAttribute::m_attrib1 .y -> Glyph::attribute()[1]
135  * - PainterAttribute::m_attrib1. z -> Glyph::attribute()[2]
136  * - PainterAttribute::m_attrib1 .w -> Glyph::attribute()[3]
137  * - PainterAttribute::m_attrib2 .x -> Glyph::attribute()[4]
138  * - PainterAttribute::m_attrib2 .y -> Glyph::attribute()[5]
139  * - PainterAttribute::m_attrib2 .z -> Glyph::attribute()[6]
140  * - PainterAttribute::m_attrib2 .w -> Glyph::attribute()[7]
141  * \param orientation screen orientation to use
142  * \param layout glyph layout to use
143  */
144  static
145  const GlyphAttributePacker&
147  enum PainterEnums::glyph_layout_type layout);
148  };
149 
150 /*! @} */
151 }
152 
153 #endif
static const GlyphAttributePacker & standard_packer(enum PainterEnums::screen_orientation orientation, enum PainterEnums::glyph_layout_type layout)
virtual void glyph_position(Glyph glyph, const vec2 position, float scale_factor, vec2 *p_bl, vec2 *p_tr) const =0
screen_orientation
Enumeration to indicate in what direction the y-coordinate increases.
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
virtual void realize_attribute_data(GlyphRenderer glyph_renderer, c_array< const GlyphAttribute > glyph_attributes, c_array< PainterIndex > dst_indices, c_array< PainterAttribute > dst_attribs, const vec2 p_bl, const vec2 p_tr) const =0
virtual void compute_needed_room(GlyphRenderer glyph_renderer, c_array< const GlyphAttribute > glyph_attributes, unsigned int *out_num_indices, unsigned int *out_num_attributes) const =0
virtual void glyph_position_from_metrics(GlyphMetrics metrics, const vec2 position, float scale_factor, vec2 *p_bl, vec2 *p_tr) const =0
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.
Defines default reference counting base classes.
A GlyphMetrics provides information on the metrics of a glyph, all the values are in units of the fon...
A Glyph is essentially an opaque pointer to data for rendering and performing layout of a glyph...
Definition: glyph.hpp:48
file glyph.hpp
A GlyphAttributePacker provides an interface to customize how glyph attribute and index data is reali...
Specifies how to render a glyph.