34 #if (defined(LLVG_MAJOR_VERSION) && (LLVG_MAJOR_VERSION != 1)) || (defined(LLVG_MINOR_VERSION) && \
35 (LLVG_MINOR_VERSION < 8))
36 #error "This Abstraction Layer is only compatible with VG Pack [1.8.0,2.0.0["
43 #include <LLVG_MATRIX_impl.h>
50 #if defined VG_FEATURE_PATH
54 #if defined VG_FEATURE_FONT
55 #include <freetype/internal/ftobjs.h>
62 #if defined VG_FEATURE_FONT_COMPLEX_LAYOUT && (VG_FEATURE_FONT_COMPLEX_LAYOUT == 1)
71 #define MIN_HIGH_SURROGATE ((unsigned short)0xD800)
72 #define MAX_HIGH_SURROGATE ((unsigned short)0xDBFF)
73 #define MIN_LOW_SURROGATE ((unsigned short)0xDC00)
74 #define MAX_LOW_SURROGATE ((unsigned short)0xDFFF)
75 #define MIN_SUPPLEMENTARY_CODE_POINT 0x010000
77 #define GET_NEXT_CHARACTER(t, l, o) ((o) >= (l) ? (unsigned short)0 : (t)[o])
79 #if defined VG_FEATURE_FONT_COMPLEX_LAYOUT && (VG_FEATURE_FONT_COMPLEX_LAYOUT == 1)
80 #define IS_SIMPLE_LAYOUT (!(face->face_flags & FT_FACE_FLAG_COMPLEX_LAYOUT))
82 #define IS_SIMPLE_LAYOUT true
98 static jfloat g_identity_matrix[LLVG_MATRIX_SIZE];
100 #if defined VG_FEATURE_FONT
104 static const unsigned short *current_text;
105 static unsigned int current_length;
106 static int current_offset;
107 static FT_UInt previous_glyph_index;
110 #if defined VG_FEATURE_FONT_COMPLEX_LAYOUT && (VG_FEATURE_FONT_COMPLEX_LAYOUT == 1)
112 static hb_glyph_info_t *glyph_info;
113 static hb_glyph_position_t *glyph_pos;
114 static unsigned int glyph_count;
115 static int current_glyph;
116 static hb_buffer_t *buf;
119 static hb_font_t *hb_font;
120 static jint current_faceHandle;
128 void LLVG_IMPL_initialize(jint trace_group) {
133 LLVG_MATRIX_IMPL_identity(g_identity_matrix);
139 #ifdef VG_FEATURE_PATH
144 #if defined VG_FEATURE_FONT && \
145 (defined VG_FEATURE_FONT_FREETYPE_VECTOR || defined VG_FEATURE_FONT_FREETYPE_BITMAP) && \
146 (VG_FEATURE_FONT == VG_FEATURE_FONT_FREETYPE_VECTOR || VG_FEATURE_FONT == VG_FEATURE_FONT_FREETYPE_BITMAP)
167 unsigned short highPart = GET_NEXT_CHARACTER(textCharRam, length, *offset);
170 if ((highPart >= MIN_HIGH_SURROGATE) && (highPart <= MAX_HIGH_SURROGATE)) {
171 if (*offset < (length - 1)) {
172 unsigned short lowPart = GET_NEXT_CHARACTER(textCharRam, length, *(offset) + 1);
174 if ((lowPart >= MIN_LOW_SURROGATE) && (lowPart <= MAX_LOW_SURROGATE)) {
178 ret += ((int)highPart - (
int)MIN_HIGH_SURROGATE);
180 ret += ((int)lowPart - (
int)MIN_LOW_SURROGATE);
181 ret += (int)MIN_SUPPLEMENTARY_CODE_POINT;
190 ret = 0x0000FFFF & (int)highPart;
196 #if defined VG_FEATURE_FONT
203 face = (FT_Face)faceHandle;
208 if (IS_SIMPLE_LAYOUT) {
211 current_length = length;
213 previous_glyph_index = 0;
215 #if defined VG_FEATURE_FONT_COMPLEX_LAYOUT && (VG_FEATURE_FONT_COMPLEX_LAYOUT == 1)
217 if (faceHandle != current_faceHandle) {
218 if (0 != current_faceHandle) {
219 hb_font_destroy(hb_font);
222 FT_Set_Pixel_Sizes(face, 0, face->units_per_EM);
223 hb_font = hb_ft_font_create(face, NULL);
224 current_faceHandle = faceHandle;
227 buf = hb_buffer_create();
228 hb_buffer_add_utf16(buf, (
const uint16_t *)text, length, 0, -1);
230 hb_buffer_guess_segment_properties(buf);
232 hb_shape(hb_font, buf, NULL, 0);
234 glyph_info = hb_buffer_get_glyph_infos(buf, &glyph_count);
235 glyph_pos = hb_buffer_get_glyph_positions(buf, &glyph_count);
244 #if defined VG_FEATURE_FONT_COMPLEX_LAYOUT && (VG_FEATURE_FONT_COMPLEX_LAYOUT == 1)
245 if (faceHandle == current_faceHandle) {
246 hb_font_destroy(hb_font);
248 current_faceHandle = 0;
257 #if defined VG_FEATURE_FONT
269 if (IS_SIMPLE_LAYOUT) {
271 FT_ULong next_char =
VG_HELPER_get_utf(current_text, current_length, ¤t_offset);
272 if (0 != next_char) {
273 FT_UInt glyph_index = FT_Get_Char_Index(face, next_char);
275 int error = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_SCALE);
276 if (FT_ERR(Ok) != error) {
277 VG_LOG_ERROR(
"Error while loading glyphid %u: 0x%x, refer to fterrdef.h", glyph_index,
281 *x_advance = face->glyph->advance.x;
284 if (FT_HAS_KERNING(face) && previous_glyph_index && glyph_index) {
286 FT_Get_Kerning(face, previous_glyph_index, glyph_index, FT_KERNING_UNSCALED, &delta);
289 *x_advance += delta.x;
292 previous_glyph_index = glyph_index;
294 *glyph_idx = glyph_index;
299 #if defined VG_FEATURE_FONT_COMPLEX_LAYOUT && (VG_FEATURE_FONT_COMPLEX_LAYOUT == 1)
301 if (((
unsigned int)0) != glyph_count) {
302 *glyph_idx = glyph_info[current_glyph].codepoint;
303 *x_advance = glyph_pos[current_glyph].x_advance / 64;
304 *y_advance = glyph_pos[current_glyph].y_advance / 64;
305 *x_offset = glyph_pos[current_glyph].x_offset / 64;
306 *y_offset = glyph_pos[current_glyph].y_offset / 64;
312 int error = FT_Load_Glyph(face, *glyph_idx, FT_LOAD_NO_SCALE);
313 if (FT_ERR(Ok) != error) {
314 VG_LOG_ERROR(
"Error while loading glyphid %" PRIu32
": 0x%x, refer to fterrdef.h", *glyph_idx, error);
320 hb_buffer_destroy(buf);
333 #if defined VG_FEATURE_FONT_COMPLEX_LAYOUT && (VG_FEATURE_FONT_COMPLEX_LAYOUT == 1)
337 hb_buffer_destroy(buf);
348 return (NULL == matrix) ? g_identity_matrix : matrix;
353 uint32_t color_alpha = (((color >> 24) & (uint32_t)0xff) * alpha) / (uint32_t)255;
354 return (color & (uint32_t)0xffffff) | (color_alpha << 24);
361 if ((0 != x) || (0 != y)) {
363 LLVG_MATRIX_IMPL_setTranslate(dest, x, y);
364 LLVG_MATRIX_IMPL_concatenate(dest, local_matrix);
367 LLVG_MATRIX_IMPL_copy(dest, local_matrix);
MicroEJ MicroVG library low level API: enable some features according to the hardware capacities.
#define VG_LOG_DECLARE_MODULE()
Declares the log module, once at the top of each source file that logs.
Provides drawing functions called by MicroVG native drawing functions.
void VG_DRAWING_initialize(void)
Called when initializing MicroVG.
MicroEJ MicroVG library low level API: implementation over FreeType.
void VG_FREETYPE_initialize(void)
Initializes the lowlevel font library.
uint32_t VG_HELPER_apply_alpha(uint32_t color, uint32_t alpha)
Applies the global opacity on given color.
BSP_DECLARE_WEAK_FCNT void LLUI_DISPLAY_waitAsynchronousDrawingEnd(void)
Waits until the end of current asynchronous drawing.
int32_t LLVG_TRACE_group
Identifies the MicroVG group to trace an event.
void VG_HELPER_prepare_matrix(jfloat *dest, jfloat x, jfloat y, const jfloat *matrix)
Converts a MicroVG matrix in another MicroVG matrix applying a translation.
const jfloat * VG_HELPER_check_matrix(const jfloat *matrix)
Checks if the matrix is null. In that case, returns an identity matrix. This allows to prevent to mak...
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.
void VG_HELPER_layout_dispose(int faceHandle)
Releases the font layouter's state built from a font face, when that face is about to be freed....
void VG_HELPER_layout_stop(void)
Releases what the layouter still holds for the current iteration. Does nothing when there is nothing ...
void VG_HELPER_layout_configure(int faceHandle, const unsigned short *text, int length)
Configures the font layouter with a font and a text.
#define VG_LOG_ERROR(fmt,...)
Logs an error. The format has no trailing line return.
bool VG_HELPER_layout_load_glyph(uint32_t *glyph_idx, int *x_advance, int *y_advance, int *x_offset, int *y_offset)
Loads the next layouted glyph and gets index and positions.
MicroEJ MicroVG library low level API: implementation of Path.
void VG_PATH_initialize(void)
Initializes the path builder.