32 #if (defined(LLVG_MAJOR_VERSION) && (LLVG_MAJOR_VERSION != 1)) || (defined(LLVG_MINOR_VERSION) && \
33 (LLVG_MINOR_VERSION < 3))
34 #error "This CCO is only compatible with VG Pack [1.3.0,2.0.0["
50 #if !defined MICROVG_CONFIGURATION_VERSION
51 #error "Undefined MICROVG_CONFIGURATION_VERSION, it must be defined in vg_configuration.h"
54 #if defined MICROVG_CONFIGURATION_VERSION && MICROVG_CONFIGURATION_VERSION != 3
55 #error "Version of the configuration file vg_configuration.h is not compatible with this implementation."
62 #include <LLVG_MATRIX_impl.h>
66 #include "vg_drawing.h"
68 #if defined VG_FEATURE_PATH
72 #if defined VG_FEATURE_FONT
73 #include <freetype/internal/ftobjs.h>
77 #if defined VG_FEATURE_FONT_COMPLEX_LAYOUT
86 #define MIN_HIGH_SURROGATE ((unsigned short)0xD800)
87 #define MAX_HIGH_SURROGATE ((unsigned short)0xDBFF)
88 #define MIN_LOW_SURROGATE ((unsigned short)0xDC00)
89 #define MAX_LOW_SURROGATE ((unsigned short)0xDFFF)
90 #define MIN_SUPPLEMENTARY_CODE_POINT 0x010000
92 #define GET_NEXT_CHARACTER(t, l, o) ((o) >= (l) ? (unsigned short)0 : (t)[o])
94 #ifdef VG_FEATURE_FONT_COMPLEX_LAYOUT
95 #define IS_SIMPLE_LAYOUT (!(face->face_flags & FT_FACE_FLAG_COMPLEX_LAYOUT))
97 #define IS_SIMPLE_LAYOUT true
107 int32_t VG_TRACE_group_id;
113 static jfloat g_identity_matrix[LLVG_MATRIX_SIZE];
115 #if defined VG_FEATURE_FONT
119 static const unsigned short *current_text;
120 static unsigned int current_length;
121 static int current_offset;
122 static FT_UInt previous_glyph_index;
125 #if defined VG_FEATURE_FONT_COMPLEX_LAYOUT
127 static hb_glyph_info_t *glyph_info;
128 static hb_glyph_position_t *glyph_pos;
129 static unsigned int glyph_count;
130 static int current_glyph;
131 static hb_buffer_t *buf;
139 void VG_HELPER_initialize(
void) {
141 VG_TRACE_group_id = LLTRACE_IMPL_declare_event_group(
"MicroVG", LOG_MICROVG_EVENTS);
144 LLVG_MATRIX_IMPL_identity(g_identity_matrix);
147 VG_DRAWING_initialize();
150 #ifdef VG_FEATURE_PATH
151 VG_PATH_initialize();
155 #if defined VG_FEATURE_FONT && \
156 (defined VG_FEATURE_FONT_FREETYPE_VECTOR || defined VG_FEATURE_FONT_FREETYPE_BITMAP) && \
157 (VG_FEATURE_FONT == VG_FEATURE_FONT_FREETYPE_VECTOR || VG_FEATURE_FONT == VG_FEATURE_FONT_FREETYPE_BITMAP)
159 VG_FREETYPE_initialize();
165 unsigned short highPart = GET_NEXT_CHARACTER(textCharRam, length, *offset);
168 if ((highPart >= MIN_HIGH_SURROGATE) && (highPart <= MAX_HIGH_SURROGATE)) {
169 if (*offset < (length - 1)) {
170 unsigned short lowPart = GET_NEXT_CHARACTER(textCharRam, length, *(offset) + 1);
172 if ((lowPart >= MIN_LOW_SURROGATE) && (lowPart <= MAX_LOW_SURROGATE)) {
176 ret += ((int)highPart - (
int)MIN_HIGH_SURROGATE);
178 ret += ((int)lowPart - (
int)MIN_LOW_SURROGATE);
179 ret += (int)MIN_SUPPLEMENTARY_CODE_POINT;
188 ret = 0x0000FFFF & (int)highPart;
194 #if defined VG_FEATURE_FONT
196 void VG_HELPER_layout_configure(
int faceHandle,
const unsigned short *text,
int length) {
197 face = (FT_Face)faceHandle;
202 if (IS_SIMPLE_LAYOUT) {
205 current_length = length;
207 previous_glyph_index = 0;
209 #if defined VG_FEATURE_FONT_COMPLEX_LAYOUT
210 static hb_font_t *hb_font;
211 static jint current_faceHandle = 0;
213 if (faceHandle != current_faceHandle) {
214 if (0 != current_faceHandle) {
215 hb_font_destroy(hb_font);
218 FT_Set_Pixel_Sizes(face, 0, face->units_per_EM);
219 hb_font = hb_ft_font_create(face, NULL);
220 current_faceHandle = faceHandle;
223 buf = hb_buffer_create();
224 hb_buffer_add_utf16(buf, (
const uint16_t *)text, length, 0, -1);
226 hb_buffer_guess_segment_properties(buf);
228 hb_shape(hb_font, buf, NULL, 0);
230 glyph_info = hb_buffer_get_glyph_infos(buf, &glyph_count);
231 glyph_pos = hb_buffer_get_glyph_positions(buf, &glyph_count);
240 #if defined VG_FEATURE_FONT
242 bool VG_HELPER_layout_load_glyph(
int *glyph_idx,
int *x_advance,
int *y_advance,
int *x_offset,
int *y_offset) {
252 if (IS_SIMPLE_LAYOUT) {
254 FT_ULong next_char =
VG_HELPER_get_utf(current_text, current_length, ¤t_offset);
255 if (0 != next_char) {
256 FT_UInt glyph_index = FT_Get_Char_Index(face, next_char);
258 int error = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_SCALE);
259 if (FT_ERR(Ok) != error) {
260 MEJ_LOG_ERROR_MICROVG(
"Error while loading glyphid %d: 0x%x, refer to fterrdef.h\n", glyph_index,
264 *x_advance = face->glyph->advance.x;
267 if (FT_HAS_KERNING(face) && previous_glyph_index && glyph_index) {
269 FT_Get_Kerning(face, previous_glyph_index, glyph_index, FT_KERNING_UNSCALED, &delta);
272 *x_advance += delta.x;
275 previous_glyph_index = glyph_index;
277 *glyph_idx = glyph_index;
282 #if defined VG_FEATURE_FONT_COMPLEX_LAYOUT
284 if (((
unsigned int)0) != glyph_count) {
285 *glyph_idx = glyph_info[current_glyph].codepoint;
286 *x_advance = glyph_pos[current_glyph].x_advance / 64;
287 *y_advance = glyph_pos[current_glyph].y_advance / 64;
288 *x_offset = glyph_pos[current_glyph].x_offset / 64;
289 *y_offset = glyph_pos[current_glyph].y_offset / 64;
295 int error = FT_Load_Glyph(face, *glyph_idx, FT_LOAD_NO_SCALE);
296 if (FT_ERR(Ok) != error) {
297 MEJ_LOG_ERROR_MICROVG(
"Error while loading glyphid %d: 0x%x, refer to fterrdef.h\n", *glyph_idx, error);
302 hb_buffer_destroy(buf);
314 const jfloat * VG_HELPER_check_matrix(
const jfloat *matrix) {
315 return (NULL == matrix) ? g_identity_matrix : matrix;
319 uint32_t VG_HELPER_apply_alpha(uint32_t color, uint32_t alpha) {
320 uint32_t color_alpha = (((color >> 24) & (uint32_t)0xff) * alpha) / (uint32_t)255;
321 return (color & (uint32_t)0xffffff) | (color_alpha << 24);
325 void VG_HELPER_prepare_matrix(jfloat *dest, jfloat x, jfloat y,
const jfloat *matrix) {
326 const jfloat *local_matrix = VG_HELPER_check_matrix(matrix);
328 if ((0 != x) || (0 != y)) {
330 LLVG_MATRIX_IMPL_setTranslate(dest, x, y);
331 LLVG_MATRIX_IMPL_concatenate(dest, local_matrix);
334 LLVG_MATRIX_IMPL_copy(dest, local_matrix);
MicroEJ MicroVG library low level API: enable some features according to the hardware capacities.
MicroEJ MicroVG library low level API: implementation over FreeType.
int VG_HELPER_get_utf(const unsigned short *textCharRam, int length, int *offset)
Gets the UTF character from a text buffer at the given offset and updates the offset to point to the ...
MicroEJ MicroVG library low level API: helper to implement library natives methods.
MicroEJ MicroVG library low level API: implementation of Path.