microvg  7.0.0
microvg
vg_freetype.h
Go to the documentation of this file.
1 /*
2  * C
3  *
4  * Copyright 2020-2024 MicroEJ Corp. All rights reserved.
5  * Use of this source code is governed by a BSD-style license that can be found with this software.
6  */
7 
15 #if !defined VG_FREETYPE_H
16 #define VG_FREETYPE_H
17 
18 #if defined __cplusplus
19 extern "C" {
20 #endif
21 
22 #include "vg_configuration.h"
23 
24 #if defined VG_FEATURE_FONT && \
25  (defined VG_FEATURE_FONT_FREETYPE_VECTOR || defined VG_FEATURE_FONT_FREETYPE_BITMAP) && \
26  (VG_FEATURE_FONT == VG_FEATURE_FONT_FREETYPE_VECTOR || VG_FEATURE_FONT == VG_FEATURE_FONT_FREETYPE_BITMAP)
27 
28 // -----------------------------------------------------------------------------
29 // Includes
30 // -----------------------------------------------------------------------------
31 
32 #include "vg_path.h"
33 
34 // --------------------------------------------------------------------------------
35 // Typedef
36 // --------------------------------------------------------------------------------
37 
38 /*
39  * @brief Function to draw a character element: a glyph. A glyph is a vectorial path.
40  *
41  * This function is called by VG_FREETYPE_draw_string(). Two implementations
42  * are required: one that draws the path with a color and one that draws the path with
43  * a gradient.
44  *
45  * The list of the drawing parameters is reduced to the elements that the Freetype engine
46  * changes for each glyph: the glyph's path, the transformation to apply on the glyph,
47  * the glyph color (useful for colored glyphs like emoji), the glyph's outine.
48  *
49  * All others elements required by the drawer (if any) have to be listed in the dedicated
50  * structure user_data.
51  *
52  * @return: the MicroVG error code
53  */
54 typedef jint (* VG_FREETYPE_draw_glyph_t) (
55  /*
56  * @brief The path of the glyph.
57  */
58  VG_PATH_HEADER_t *path,
59 
60  /*
61  * @brief The deformation to apply on the path.
62  */
63  jfloat *matrix,
64 
65  /*
66  * @brief The specific glyph color (example: emoji) or the current destination
67  * color. Useless if the string is drawn with a gradient.
68  */
69  uint32_t color,
70 
71  /*
72  * @brief The glyph outline: true: EVEN_ODD or false: NON_ZERO.
73  */
74  bool fill_rule_even_odd,
75 
76  /*
77  * @brief The custom drawer data (may be null). For instance this structure can
78  * hold the gradient if the GPU's drawing function requires it. In case of
79  * the gradient is set before calling VG_FREETYPE_draw_string(), the
80  * gradient doesn't need to be stored in this structure.
81  */
82  void *user_data);
83 
84 // --------------------------------------------------------------------------------
85 // API
86 // --------------------------------------------------------------------------------
87 
88 /*
89  * @brief Initializes the lowlevel font library.
90  */
91 void VG_FREETYPE_initialize(void);
92 
93 /*
94  * @brief Measures the width of a text for the specified font and size.
95  *
96  * The text is measured from first pixel of the first glyph to last pixel of the last glyph.
97  *
98  * @param[in] text the array of characters to draw.
99  * @param[in] length the length of the array
100  * @param[in] face_handle the font reference handle
101  * @param[in] size the height of the font in pixels.
102  * @param[in] letter_spacing the extra letter spacing to use
103  *
104  * @return the width of the specified string, in pixels or a negative error code on error.
105  */
106 jfloat VG_FREETYPE_string_width(jchar *text, jint length, jint face_handle, jfloat size, jfloat letter_spacing);
107 
108 /*
109  * @brief Draws a string using the Freetype engine along a line or a circle, with a
110  * color or a linear gradient. The implementation does not draw, it calls the
111  * drawer function for each glyph: VG_FREETYPE_draw_glyph_t.
112  *
113  * @param[in] drawer the function to draw a glyph.
114  * @param[in] text the array of characters to draw.
115  * @param[in] length the length of the array
116  * @param[in] face_handle the font reference handle.
117  * @param[in] size the height of the font in pixels.
118  * @param[in] matrix the transformation to apply.
119  * @param[in] color the 32-bit color to apply (useless when drawing with a gradient).
120  * @param[in] letter_spacing the extra letter spacing to use.
121  * @param[in] radius the radius of the circle (0 to draw along a line).
122  * @param[in] direction the direction of the text along the circle (0 to draw along a line).
123  * @param[in] user_data the data used by the drawer; may be null.
124  *
125  * @return LLVG_SUCCESS if something has been drawn, an different value otherwise
126  */
127 jint VG_FREETYPE_draw_string(VG_FREETYPE_draw_glyph_t drawer, const jchar *text, jint length, jint face_handle,
128  jfloat size, const jfloat *matrix, uint32_t color, jfloat letter_spacing, jfloat radius,
129  jint direction, void *user_data);
130 
131 // -----------------------------------------------------------------------------
132 // Implementation
133 // -----------------------------------------------------------------------------
134 
135 /*
136  * @brief Converts an ARGB8888 color to a format compatible with the GPU. The default
137  * implementation does nothing and just returns the original color.
138  */
139 jint VG_FREETYPE_IMPL_convert_color(jint color);
140 
141 // -----------------------------------------------------------------------------
142 // EOF
143 // -----------------------------------------------------------------------------
144 #endif \
145  // defined VG_FEATURE_FONT && \
146  // (defined VG_FEATURE_FONT_FREETYPE_VECTOR || defined VG_FEATURE_FONT_FREETYPE_BITMAP) && \
147  // (VG_FEATURE_FONT == VG_FEATURE_FONT_FREETYPE_VECTOR || VG_FEATURE_FONT == VG_FEATURE_FONT_FREETYPE_BITMAP)
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #endif // !defined VG_FREETYPE_H
MicroEJ MicroVG library low level API: enable some features according to the hardware capacities.
MicroEJ MicroVG library low level API: implementation of Path.