microvg  6.0.1
microvg
vg_helper.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 
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 
78 // -----------------------------------------------------------------------------
79 // API
80 // -----------------------------------------------------------------------------
81 
82 /*
83  * @brief Initializes the MicroVG CCO according to the options set in vg_configuration.h
84  *
85  * This function must be explicitly called in the implementation of LLVG_IMPL_initialize()
86  * (which is GPU dependant).
87  */
88 void VG_HELPER_initialize(void);
89 
109 int VG_HELPER_get_utf(const unsigned short *text, int length, int *offset);
110 
111 /*
112  * @brief Configures the font layouter with a font and a text
113  *
114  * @param[in] faceHandle: handle on font face.
115  * @param[in] text: text buffer encoded in UTF16 where to read UTF character.
116  * @param[in] length: text buffer length.
117  *
118  */
119 void VG_HELPER_layout_configure(int faceHandle, const unsigned short *text, int length);
120 
121 /*
122  * @brief Loads the next layouted glyph and gets index and positions.
123  *
124  * @param[out] glyph_idx: next glyph index.
125  * @param[out] x_advance: the horizontal advance to add to the cursor position after drawing the glyph.
126  * @param[out] y_advance: the vertical advance to add to thecursor after drawing the glyph.
127  * @param[out] x_offset: the hozizontal offset of the glyph, does not affect the cursor position.
128  * @param[out] y_offset: the vertical offset of the glyph, does not affect the cursor position.
129  *
130  * @return true if a glyph is available otherwise false.
131  */
132 bool VG_HELPER_layout_load_glyph(int *glyph_idx, int *x_advance, int *y_advance, int *x_offset, int *y_offset);
133 
134 /*
135  * @brief Checks if the matrix is null. In that case, returns an identity matrix.
136  * This allows to prevent to make some checks on the matrix in the algorithms.
137  *
138  * The identity matrix can be used several times by the same algorithm. The caller
139  * must not modify it (read-only matrix).
140  *
141  * @param[in] the matrix to check
142  *
143  * @return the matrix or an identity matrix
144  */
145 const jfloat * VG_HELPER_check_matrix(const jfloat *matrix);
146 
147 /*
148  * @brief Applies the global opacity on given color.
149  *
150  * @param[in] color: the 32-bit color.
151  * @param[in] alpha: the opacity.
152  *
153  * @return the new color.
154  */
155 uint32_t VG_HELPER_apply_alpha(uint32_t color, uint32_t alpha);
156 
157 /*
158  * @brief Converts a MicroVG matrix in another MicroVG matrix applying a translation.
159  *
160  * @param[out] dest the MicroVG matrix to set
161  * @param[in] x the X translation to apply
162  * @param[in] y the Y translation to apply
163  * @param[in] matrix the MicroVG transformation to apply (can be null)
164  */
165 void VG_HELPER_prepare_matrix(jfloat *dest, jfloat x, jfloat y, const jfloat *matrix);
166 
167 // -----------------------------------------------------------------------------
168 // EOF
169 // -----------------------------------------------------------------------------
170 
171 #ifdef __cplusplus
172 }
173 #endif
174 
175 #endif // !defined VG_HELPER_H
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:164