20 #include <LLVG_MATRIX_impl.h> 21 #include <freetype/internal/ftobjs.h> 38 #if !defined MICROVG_CONFIGURATION_VERSION 39 #error "Undefined MICROVG_CONFIGURATION_VERSION, it must be defined in microvg_configuration.h" 42 #if defined MICROVG_CONFIGURATION_VERSION && MICROVG_CONFIGURATION_VERSION != 2 43 #error "Version of the configuration file microvg_configuration.h is not compatible with this implementation." 46 #if defined VG_FEATURE_FONT_COMPLEX_LAYOUT 55 #define MIN_HIGH_SURROGATE ((unsigned short)0xD800) 56 #define MAX_HIGH_SURROGATE ((unsigned short)0xDBFF) 57 #define MIN_LOW_SURROGATE ((unsigned short)0xDC00) 58 #define MAX_LOW_SURROGATE ((unsigned short)0xDFFF) 59 #define MIN_SUPPLEMENTARY_CODE_POINT 0x010000 61 #define GET_NEXT_CHARACTER(t,l,o) ((o) >= (l) ? (unsigned short)0 : (t)[o]) 63 #ifdef VG_FEATURE_FONT_COMPLEX_LAYOUT 64 #define IS_SIMPLE_LAYOUT (!(face->face_flags & FT_FACE_FLAG_COMPLEX_LAYOUT)) 66 #define IS_SIMPLE_LAYOUT true 67 #endif // VG_FEATURE_FONT_COMPLEX_LAYOUT 73 static jfloat g_identity_matrix[LLVG_MATRIX_SIZE];
78 static unsigned short *current_text;
79 static unsigned int current_length;
80 static int current_offset;
81 static FT_UInt previous_glyph_index;
83 #if defined VG_FEATURE_FONT_COMPLEX_LAYOUT 85 static hb_glyph_info_t *glyph_info;
86 static hb_glyph_position_t *glyph_pos;
87 static unsigned int glyph_count;
88 static int current_glyph;
89 static hb_buffer_t *buf;
96 void MICROVG_HELPER_initialize(
void) {
97 LLVG_MATRIX_IMPL_identity(g_identity_matrix);
103 unsigned short highPart = GET_NEXT_CHARACTER(textCharRam, length, *offset);
108 if (*offset < (length - 1)) {
110 unsigned short lowPart = GET_NEXT_CHARACTER(textCharRam, length, *(offset) + 1);
112 if ((lowPart >= MIN_LOW_SURROGATE) && (lowPart <= MAX_LOW_SURROGATE)) {
118 ret += ((int)lowPart - (
int)MIN_LOW_SURROGATE);
119 ret += (int)MIN_SUPPLEMENTARY_CODE_POINT;
129 ret = 0x0000FFFF & (int)highPart;
136 void MICROVG_HELPER_layout_configure(
int faceHandle,
unsigned short *text,
int length){
137 face = (FT_Face) faceHandle;
142 if(IS_SIMPLE_LAYOUT){
145 current_length = length;
147 previous_glyph_index = 0;
150 #if defined VG_FEATURE_FONT_COMPLEX_LAYOUT 151 static hb_font_t *hb_font;
152 static jint current_faceHandle = 0;
154 if(faceHandle != current_faceHandle){
155 if(0 != current_faceHandle){
156 hb_font_destroy(hb_font);
159 FT_Set_Pixel_Sizes (face, 0, face->units_per_EM);
160 hb_font = hb_ft_font_create(face, NULL);
161 current_faceHandle = faceHandle;
164 buf = hb_buffer_create();
165 hb_buffer_add_utf16(buf, (
const uint16_t *)text, length, 0, -1);
167 hb_buffer_guess_segment_properties(buf);
169 hb_shape(hb_font, buf, NULL, 0);
171 glyph_info = hb_buffer_get_glyph_infos(buf, &glyph_count);
172 glyph_pos = hb_buffer_get_glyph_positions(buf, &glyph_count);
175 #endif // VG_FEATURE_FONT_COMPLEX_LAYOUT 180 bool MICROVG_HELPER_layout_load_glyph(
int *glyph_idx,
int *x_advance,
int *y_advance,
int *x_offset,
int *y_offset){
191 if(IS_SIMPLE_LAYOUT){
195 FT_UInt glyph_index = FT_Get_Char_Index(face, next_char);
197 int error = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_SCALE);
198 if(FT_ERR(Ok) != error) {
199 MEJ_LOG_ERROR_MICROVG(
"Error while loading glyphid %d: 0x%x, refer to fterrdef.h\n",glyph_index, error);
202 *x_advance = face->glyph->advance.x;
205 if (FT_HAS_KERNING(face) && previous_glyph_index && glyph_index){
207 FT_Get_Kerning(face, previous_glyph_index, glyph_index, FT_KERNING_UNSCALED, &delta);
210 *x_advance += delta.x;
213 previous_glyph_index = glyph_index;
215 *glyph_idx = glyph_index;
221 #if defined VG_FEATURE_FONT_COMPLEX_LAYOUT 223 if(((
unsigned int) 0) != glyph_count){
225 *glyph_idx = glyph_info[current_glyph].codepoint;
226 *x_advance = glyph_pos[current_glyph].x_advance/64;
227 *y_advance = glyph_pos[current_glyph].y_advance/64;
228 *x_offset = glyph_pos[current_glyph].x_offset/64;
229 *y_offset = glyph_pos[current_glyph].y_offset/64;
235 int error = FT_Load_Glyph(face, *glyph_idx, FT_LOAD_NO_SCALE);
236 if(FT_ERR(Ok) != error) {
237 MEJ_LOG_ERROR_MICROVG(
"Error while loading glyphid %d: 0x%x, refer to fterrdef.h\n", *glyph_idx, error);
242 hb_buffer_destroy(buf);
245 #endif // VG_FEATURE_FONT_COMPLEX_LAYOUT 252 jfloat* MICROVG_HELPER_check_matrix(jfloat* matrix) {
253 return (NULL == matrix) ? g_identity_matrix : matrix;
257 uint32_t MICROVG_HELPER_apply_alpha(uint32_t color, uint32_t alpha) {
258 uint32_t color_alpha = (((color >> 24) & (uint32_t)0xff) * alpha) / (uint32_t)255;
259 return (color & (uint32_t)0xffffff) | (color_alpha << 24);
int MICROVG_HELPER_get_utf(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: enable some features according to the hardware capacities...
#define MIN_HIGH_SURROGATE