microvg  8.0.0
microvg
vg_helper.h
Go to the documentation of this file.
1 /*
2  * C
3  *
4  * Copyright 2020-2026 MicroEJ Corp. All rights reserved.
5  * MicroEJ Corp. PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */
7 
16 #if !defined VG_HELPER_H
17 #define VG_HELPER_H
18 
19 #if defined __cplusplus
20 extern "C" {
21 #endif
22 
23 // -----------------------------------------------------------------------------
24 // Includes
25 // -----------------------------------------------------------------------------
26 
27 // cppcheck-suppress [misra-c2012-21.6] required to use "printf"
28 #include <stdio.h>
29 
30 #include <sni.h>
31 
32 #include "mej_log.h"
33 
34 // -----------------------------------------------------------------------------
35 // Macros and Defines
36 // -----------------------------------------------------------------------------
37 
38 #if defined MEJ_LOG_INFO_LEVEL && defined MEJ_LOG_MICROVG
39 #define MEJ_LOG_INFO_MICROVG(fmt, ...) MEJ_LOG(INFO, MICROVG, fmt, ## __VA_ARGS__)
40 #else
41 #define MEJ_LOG_INFO_MICROVG(fmt, ...)
42 #endif
43 
44 // Errors should always be printed
45 #define MEJ_LOG_ERROR_MICROVG(fmt, ...) MEJ_LOG(ERROR, MICROVG, fmt, ## __VA_ARGS__)
46 
52 //#define MICROVG_MONITOR_HEAP
53 
57 #define VG_HELPER_NULL_GRADIENT 0
58 
66 #define FT_FACE_FLAG_COMPLEX_LAYOUT (((uint32_t)1) << 31)
67 
68 #ifndef M_PI
69 #define M_PI 3.1415926535
70 #endif
71 
72 #define RAD_TO_DEG(r) ((r) * (180.0f / M_PI))
73 #define DEG_TO_RAD(d) (((d) * M_PI) / 180.0f)
74 
75 #define JFLOAT_TO_UINT32_t(f) (*(uint32_t *)&(f))
76 #define UINT32_t_TO_JFLOAT(i) (*(float *)&(i))
77 
81 #define REGISTERDESC(desc, buf, buf_len) if ((buf_len) >= sizeof(desc)) { (void)memcpy((buf), (desc), sizeof(desc)); }
82 
83 // --------------------------------------------------------------------------------
84 // UI Pack > 14.5.1 function
85 // --------------------------------------------------------------------------------
86 
100 
101 // -----------------------------------------------------------------------------
102 // API
103 // -----------------------------------------------------------------------------
104 
124 int VG_HELPER_get_utf(const unsigned short *text, int length, int *offset);
125 
126 /*
127  * @brief Configures the font layouter with a font and a text
128  *
129  * @param[in] faceHandle: handle on font face.
130  * @param[in] text: text buffer encoded in UTF16 where to read UTF character.
131  * @param[in] length: text buffer length.
132  *
133  */
134 void VG_HELPER_layout_configure(int faceHandle, const unsigned short *text, int length);
135 
136 /*
137  * @brief Loads the next layouted glyph and gets index and positions.
138  *
139  * @param[out] glyph_idx: next glyph index.
140  * @param[out] x_advance: the horizontal advance to add to the cursor position after drawing the glyph.
141  * @param[out] y_advance: the vertical advance to add to thecursor after drawing the glyph.
142  * @param[out] x_offset: the hozizontal offset of the glyph, does not affect the cursor position.
143  * @param[out] y_offset: the vertical offset of the glyph, does not affect the cursor position.
144  *
145  * @return true if a glyph is available otherwise false.
146  */
147 bool VG_HELPER_layout_load_glyph(uint32_t *glyph_idx, int *x_advance, int *y_advance, int *x_offset, int *y_offset);
148 
149 /*
150  * @brief Checks if the matrix is null. In that case, returns an identity matrix.
151  * This allows to prevent to make some checks on the matrix in the algorithms.
152  *
153  * The identity matrix can be used several times by the same algorithm. The caller
154  * must not modify it (read-only matrix).
155  *
156  * @param[in] the matrix to check
157  *
158  * @return the matrix or an identity matrix
159  */
160 const jfloat * VG_HELPER_check_matrix(const jfloat *matrix);
161 
162 /*
163  * @brief Applies the global opacity on given color.
164  *
165  * @param[in] color: the 32-bit color.
166  * @param[in] alpha: the opacity.
167  *
168  * @return the new color.
169  */
170 uint32_t VG_HELPER_apply_alpha(uint32_t color, uint32_t alpha);
171 
172 /*
173  * @brief Converts a MicroVG matrix in another MicroVG matrix applying a translation.
174  *
175  * @param[out] dest the MicroVG matrix to set
176  * @param[in] x the X translation to apply
177  * @param[in] y the Y translation to apply
178  * @param[in] matrix the MicroVG transformation to apply (can be null)
179  */
180 void VG_HELPER_prepare_matrix(jfloat *dest, jfloat x, jfloat y, const jfloat *matrix);
181 
182 // -----------------------------------------------------------------------------
183 // EOF
184 // -----------------------------------------------------------------------------
185 
186 #ifdef __cplusplus
187 }
188 #endif
189 
190 #endif // !defined VG_HELPER_H
void LLUI_DISPLAY_waitAsynchronousDrawingEnd(void)
Waits until the end of current asynchronous drawing.
Definition: vg_helper.c:150
int VG_HELPER_get_utf(const unsigned short *text, int length, int *offset)
Gets the UTF character from a text buffer at the given offset and updates the offset to point to the ...
Definition: vg_helper.c:159