microvg  3.0.1
microvg
microvg_helper.h
Go to the documentation of this file.
1 /*
2  * C
3  *
4  * Copyright 2020-2023 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 MICROVG_HELPER_H
17 #define MICROVG_HELPER_H
18 
19 #if defined __cplusplus
20 extern "C" {
21 #endif
22 
23 // -----------------------------------------------------------------------------
24 // Includes
25 // -----------------------------------------------------------------------------
26 
27 
28 // cppcheck-suppress [misra-c2012-21.6] required to use "printf"
29 #include <stdio.h>
30 
31 #include <sni.h>
32 
33 #include "mej_log.h"
34 
35 // -----------------------------------------------------------------------------
36 // Macros and Defines
37 // -----------------------------------------------------------------------------
38 
39 #if defined MEJ_LOG_INFO_LEVEL && defined MEJ_LOG_MICROVG
40 #define MEJ_LOG_INFO_MICROVG(fmt, ...) MEJ_LOG(INFO,MICROVG,fmt, ##__VA_ARGS__ )
41 #else
42 #define MEJ_LOG_INFO_MICROVG(fmt, ...)
43 #endif
44 
45 // Errors should always be printed
46 #define MEJ_LOG_ERROR_MICROVG(fmt, ...) MEJ_LOG(ERROR,MICROVG,fmt, ##__VA_ARGS__ )
47 
53 //#define MICROVG_MONITOR_HEAP
54 
58 #define MICROVG_HELPER_NULL_GRADIENT 0
59 
67 #define FT_FACE_FLAG_COMPLEX_LAYOUT (((uint32_t)1) << 31)
68 
69 #ifndef M_PI
70 #define M_PI 3.1415926535
71 #endif
72 
73 #define RAD_TO_DEG(r) ((r) * (180.0f / M_PI))
74 #define DEG_TO_RAD(d) (((d) * M_PI) / 180.0f)
75 
76 #define JFLOAT_TO_UINT32_t(f) (*(uint32_t*)&(f))
77 #define UINT32_t_TO_JFLOAT(i) (*(float*)&(i))
78 
79 // -----------------------------------------------------------------------------
80 // API
81 // -----------------------------------------------------------------------------
82 
83 /*
84  * @brief Initializes the helper
85  */
86 void MICROVG_HELPER_initialize(void);
87 
107 int MICROVG_HELPER_get_utf(unsigned short *text, int length, int *offset);
108 
109 /*
110  * @brief Configures the font layouter with a font and a text
111  *
112  * @param[in] faceHandle: handle on font face.
113  * @param[in] text: text buffer encoded in UTF16 where to read UTF character.
114  * @param[in] length: text buffer length.
115  *
116  */
117 void MICROVG_HELPER_layout_configure(int faceHandle, unsigned short *text, int length);
118 
119 /*
120  * @brief Loads the next layouted glyph and gets index and positions.
121  *
122  * @param[out] glyph_idx: next glyph index.
123  * @param[out] x_advance: the horizontal advance to add to the cursor position after drawing the glyph.
124  * @param[out] y_advance: the vertical advance to add to thecursor after drawing the glyph.
125  * @param[out] x_offset: the hozizontal offset of the glyph, does not affect the cursor position.
126  * @param[out] y_offset: the vertical offset of the glyph, does not affect the cursor position.
127  *
128  * @return true if a glyph is available otherwise false.
129  */
130 bool MICROVG_HELPER_layout_load_glyph(int *glyph_idx, int *x_advance, int *y_advance, int *x_offset, int *y_offset);
131 
132 /*
133  * @brief Checks if the matrix is null. In that case, returns an identity matrix.
134  * This allows to prevent to make some checks on the matrix in the algorithms.
135  *
136  * The identity matrix can be used several times by the same algorithm. The caller
137  * must not modify it (read-only matrix).
138  *
139  * @param[in] the matrix to check
140  *
141  * @return the matrix or an identity matrix
142  */
143 jfloat* MICROVG_HELPER_check_matrix(jfloat* matrix);
144 
145 /*
146  * @brief Applies the global opacity on given color.
147  *
148  * @param[in] color: the 32-bit color.
149  * @param[in] alpha: the opacity.
150  *
151  * @return the new color.
152  */
153 uint32_t MICROVG_HELPER_apply_alpha(uint32_t color, uint32_t alpha) ;
154 
155 // -----------------------------------------------------------------------------
156 // EOF
157 // -----------------------------------------------------------------------------
158 
159 #ifdef __cplusplus
160 }
161 #endif
162 
163 #endif // !defined MICROVG_HELPER_H
int MICROVG_HELPER_get_utf(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 ...