microvg  6.0.1
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 Draws a string using the Freetype engine along a line or a circle, with a
95  * color or a linear gradient. The implementation does not draw, it calls the
96  * drawer function for each glyph: VG_FREETYPE_draw_glyph_t.
97  *
98  * @param[in] drawer the function to draw a glyph.
99  * @param[in] text the array of characters to draw.
100  * @param[in] face_handle the font reference handle.
101  * @param[in] size the height of the font in pixels.
102  * @param[in] matrix the transformation to apply.
103  * @param[in] color the 32-bit color to apply (useless when drawing with a gradient).
104  * @param[in] letter_spacing the extra letter spacing to use.
105  * @param[in] radius the radius of the circle (0 to draw along a line).
106  * @param[in] direction the direction of the text along the circle (0 to draw along a line).
107  * @param[in] user_data the data used by the drawer; may be null.
108  *
109  * @return LLVG_SUCCESS if something has been drawn, an different value otherwise
110  */
111 jint VG_FREETYPE_draw_string(VG_FREETYPE_draw_glyph_t drawer, const jchar *text, jint face_handle, jfloat size,
112  const jfloat *matrix, uint32_t color, jfloat letter_spacing, jfloat radius, jint direction,
113  void *user_data);
114 
115 // -----------------------------------------------------------------------------
116 // Implementation
117 // -----------------------------------------------------------------------------
118 
119 /*
120  * @brief Converts an ARGB8888 color to a format compatible with the GPU. The default
121  * implementation does nothing and just returns the original color.
122  */
123 jint VG_FREETYPE_IMPL_convert_color(jint color);
124 
125 // -----------------------------------------------------------------------------
126 // EOF
127 // -----------------------------------------------------------------------------
128 #endif \
129  // defined VG_FEATURE_FONT && \
130  // (defined VG_FEATURE_FONT_FREETYPE_VECTOR || defined VG_FEATURE_FONT_FREETYPE_BITMAP) && \
131  // (VG_FEATURE_FONT == VG_FEATURE_FONT_FREETYPE_VECTOR || VG_FEATURE_FONT == VG_FEATURE_FONT_FREETYPE_BITMAP)
132 
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #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.