FastUIDraw
font.hpp
Go to the documentation of this file.
1 /*!
2  * \file font.hpp
3  * \brief file font.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_FONT_HPP
21 #define FASTUIDRAW_FONT_HPP
22 
25 #include <fastuidraw/util/vecN.hpp>
26 #include <fastuidraw/path.hpp>
27 #include <fastuidraw/text/character_encoding.hpp>
32 #include <fastuidraw/text/glyph_metrics_value.hpp>
33 
34 namespace fastuidraw
35 {
36 /*!\addtogroup Glyph
37  * @{
38  */
39  class Glyph;
40  class GlyphCache;
41 
42  /*!
43  * \brief
44  * FontBase provides an interface for a font
45  * to generate glyph rendering data.
46  */
47  class FontBase:
48  public reference_counted<FontBase>::concurrent
49  {
50  public:
51  /*!
52  * Ctor.
53  * \param pprops font properties describing the font
54  * \param pmetrics metrics common to all glyphs of the font
55  */
56  FontBase(const FontProperties &pprops,
57  const FontMetrics &pmetrics);
58 
59  virtual
60  ~FontBase();
61 
62  /*!
63  * Returns the properties of the font.
64  */
65  const FontProperties&
66  properties(void) const;
67 
68  /*!
69  * Returns the metrics of the font.
70  */
71  const FontMetrics&
72  metrics(void) const;
73 
74  /*!
75  * Returns the unique ID of the \ref FontBase object.
76  * The value is gauranteed to be unique and different
77  * from any previously created fonts (even those that
78  * have been destroyed). The value is assigned by the
79  * first \ref FontBase created gets the value 0 and
80  * each subsequence \ref FontBase created increments
81  * the global value by 1. Thus it is reasonable, to
82  * use arrays instead of associative keys for font
83  * choosing.
84  */
85  unsigned int
86  unique_id(void) const;
87 
88  /*!
89  * To be implemented by a derived class to return the
90  * index values (glyph codes) for a sequence of character
91  * code. A glyph code of 0 indicates that a character
92  * code is not present in the font.
93  * \param encoding character encoding of character codes
94  * \param in_character_codes character codes from which to
95  * fetch glyph codes
96  * \param[out] out_glyph_codes location to which to write
97  * glyph codes.
98  */
99  virtual
100  void
102  c_array<const uint32_t> in_character_codes,
103  c_array<uint32_t> out_glyph_codes) const = 0;
104 
105  /*!
106  * Provided as a conveniance, equivalent to
107  * \code
108  * glyph_codes(CharacterEncoding::unicode,
109  * in_character_codes,
110  * out_glyph_codes);
111  * \endcode
112  * \param in_character_codes character codes from which to
113  * fetch glyph codes
114  * \param[out] out_glyph_codes location to which to write
115  * glyph codes.
116  */
117  void
119  c_array<uint32_t> out_glyph_codes) const
120  {
121  glyph_codes(CharacterEncoding::unicode, in_character_codes, out_glyph_codes);
122  }
123 
124  /*!
125  * Provided as a conveniance to fetch a single
126  * glyph_code.
127  * \param pcharacter_code Unicode character code from which to
128  * fetch a glyph code.
129  */
130  uint32_t
131  glyph_code(uint32_t pcharacter_code) const
132  {
133  uint32_t return_value(0);
134  c_array<const uint32_t> p(&pcharacter_code, 1);
135  c_array<uint32_t> g(&return_value, 1);
136  glyph_codes(p, g);
137  return return_value;
138  }
139 
140  /*!
141  * To be implemented by a derived class to return
142  * the number of glyph codes the instance has.
143  * In particular the return value of glyph_code()
144  * is always less than number_glyphs() and the
145  * input to compute_metrics() will also have value
146  * no more than number_glyphs().
147  */
148  virtual
149  unsigned int
150  number_glyphs(void) const = 0;
151 
152  /*!
153  * To be implemented by a derived class to indicate
154  * that it will return non-nullptr in
155  * compute_rendering_data() when passed a
156  * GlyphRenderer whose GlyphRenderer::m_type
157  * is a specified value.
158  */
159  virtual
160  bool
161  can_create_rendering_data(enum glyph_type tp) const = 0;
162 
163  /*!
164  * To be implemented by a derived class to provide the metrics
165  * data for the named glyph.
166  * \param glyph_code glyph code of glyph to compute the metric values
167  * \param[out] metrics location to which to place the metric values for the glyph
168  */
169  virtual
170  void
171  compute_metrics(uint32_t glyph_code, GlyphMetricsValue &metrics) const = 0;
172 
173  /*!
174  * To be implemented by a derived class to generate glyph
175  * rendering data given a glyph code and GlyphRenderer.
176  * \param render specifies object to return via GlyphRenderer::type(),
177  * it is guaranteed by the caller that can_create_rendering_data()
178  * returns true on render.type()
179  * \param glyph_metrics GlyphMetrics values as computed by compute_metrics()
180  * \param[out] path location to which to write the Path of the glyph
181  * \param[out] render_size location to which to write the render size
182  * of the glyph
183  */
184  virtual
186  compute_rendering_data(GlyphRenderer render, GlyphMetrics glyph_metrics,
187  Path &path, vec2 &render_size) const = 0;
188 
189  private:
190  void *m_d;
191  };
192 /*! @} */
193 }
194 
195 #endif
GlyphRenderData provides an interface to specify data used for rendering glyphs and to pack that data...
encoding_value_t
Enumeration type to define character encodings.
virtual GlyphRenderData * compute_rendering_data(GlyphRenderer render, GlyphMetrics glyph_metrics, Path &path, vec2 &render_size) const =0
FontBase(const FontProperties &pprops, const FontMetrics &pmetrics)
unsigned int unique_id(void) const
file glyph_render_data.hpp
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
virtual unsigned int number_glyphs(void) const =0
FontBase provides an interface for a font to generate glyph rendering data.
Definition: font.hpp:47
A GlyphMetricsValue is to be used by a FontBase derived object to specify the values of a GlyphMetric...
Represents defining properties of a font used by FontDatabase to perform font merging.
file c_array.hpp
file path.hpp
file font_properties.hpp
glyph_type
Provides an enumeration of the rendering data for a glyph.
virtual void glyph_codes(enum CharacterEncoding::encoding_value_t encoding, c_array< const uint32_t > in_character_codes, c_array< uint32_t > out_glyph_codes) const =0
virtual bool can_create_rendering_data(enum glyph_type tp) const =0
file vecN.hpp
Defines default reference counting base classes.
virtual void compute_metrics(uint32_t glyph_code, GlyphMetricsValue &metrics) const =0
A GlyphMetrics provides information on the metrics of a glyph, all the values are in units of the fon...
uint32_t glyph_code(uint32_t pcharacter_code) const
Definition: font.hpp:131
file font_metrics.hpp
A Path represents a collection of PathContour objects.
Definition: path.hpp:668
Represents various metric values global to an entire font.
file glyph_metrics.hpp
Specifies how to render a glyph.
void glyph_codes(c_array< const uint32_t > in_character_codes, c_array< uint32_t > out_glyph_codes) const
Definition: font.hpp:118
const FontMetrics & metrics(void) const
const FontProperties & properties(void) const
file reference_counted.hpp