microvg  2.0.0
microvg
microvg_helper.h
Go to the documentation of this file.
1 /*
2  * C
3  *
4  * Copyright 2020-2022 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 
98 int MICROVG_HELPER_get_utf(unsigned short *text, int length, int *offset);
99 
100 
101 /*
102  * @brief Configures the font layouter with a font and a text
103  *
104  * @param[in] faceHandle: handle on font face.
105  * @param[in] text: text buffer encoded in UTF16 where to read UTF character.
106  * @param[in] length: text buffer length.
107  *
108  */
109 void MICROVG_HELPER_layout_configure(int faceHandle, unsigned short *text, int length);
110 
111 /*
112  * @brief Loads the next layouted glyph and gets index and positions.
113  *
114  * @param[out] glyph_idx: next glyph index.
115  * @param[out] x_advance: the horizontal advance to add to the cursor position after drawing the glyph.
116  * @param[out] y_advance: the vertical advance to add to thecursor after drawing the glyph.
117  * @param[out] x_offset: the hozizontal offset of the glyph, does not affect the cursor position.
118  * @param[out] y_offset: the vertical offset of the glyph, does not affect the cursor position.
119  *
120  * @return true if a glyph is available otherwise false.
121  */
122 bool MICROVG_HELPER_layout_load_glyph(int *glyph_idx, int *x_advance, int *y_advance, int *x_offset, int *y_offset);
123 
124 /*
125  * @brief Checks if the matrix is null. In that case, returns an identity matrix.
126  * This allows to prevent to make some checks on the matrix in the algorithms.
127  *
128  * The identity matrix can be used several times by the same algorithm. The caller
129  * must not modify it (read-only matrix).
130  *
131  * @param[in] the matrix to check
132  *
133  * @return the matrix or an identity matrix
134  */
135 jfloat* MICROVG_HELPER_check_matrix(jfloat* matrix);
136 
137 /*
138  * @brief Applies the global opacity on given color.
139  *
140  * @param[in] color: the 32-bit color.
141  * @param[in] alpha: the opacity.
142  *
143  * @return the new color.
144  */
145 uint32_t MICROVG_HELPER_apply_alpha(uint32_t color, uint32_t alpha) ;
146 
147 // -----------------------------------------------------------------------------
148 // EOF
149 // -----------------------------------------------------------------------------
150 
151 #ifdef __cplusplus
152 }
153 #endif
154 
155 #endif // !defined MICROVG_HELPER_H
int MICROVG_HELPER_get_utf(unsigned short *text, int length, int *offset)
Gets the next UTF character from a text buffer.