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 != 1 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);
107 && (*offset < (length - 1))) {
109 unsigned short lowPart = GET_NEXT_CHARACTER(textCharRam, length, *(offset) + 1);
111 if ((lowPart >= MIN_LOW_SURROGATE) && (lowPart <= MAX_LOW_SURROGATE)) {
117 ret += ((int)lowPart - (
int)MIN_LOW_SURROGATE);
118 ret += (int)MIN_SUPPLEMENTARY_CODE_POINT;
125 ret = 0x0000FFFF & (int)highPart;
133 void MICROVG_HELPER_layout_configure(
int faceHandle,
unsigned short *text,
int length){
134 face = (FT_Face) faceHandle;
139 if(IS_SIMPLE_LAYOUT){
142 current_length = length;
144 previous_glyph_index = 0;
147 #if defined VG_FEATURE_FONT_COMPLEX_LAYOUT 148 static hb_font_t *hb_font;
149 static jint current_faceHandle = 0;
151 if(faceHandle != current_faceHandle){
152 if(0 != current_faceHandle){
153 hb_font_destroy(hb_font);
156 FT_Set_Pixel_Sizes (face, 0, face->units_per_EM);
157 hb_font = hb_ft_font_create(face, NULL);
158 current_faceHandle = faceHandle;
161 buf = hb_buffer_create();
162 hb_buffer_add_utf16(buf, (
const uint16_t *)text, length, 0, -1);
164 hb_buffer_guess_segment_properties(buf);
166 hb_shape(hb_font, buf, NULL, 0);
168 glyph_info = hb_buffer_get_glyph_infos(buf, &glyph_count);
169 glyph_pos = hb_buffer_get_glyph_positions(buf, &glyph_count);
172 #endif // VG_FEATURE_FONT_COMPLEX_LAYOUT 177 bool MICROVG_HELPER_layout_load_glyph(
int *glyph_idx,
int *x_advance,
int *y_advance,
int *x_offset,
int *y_offset){
188 if(IS_SIMPLE_LAYOUT){
192 FT_UInt glyph_index = FT_Get_Char_Index(face, next_char);
194 int error = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_SCALE);
195 if(FT_ERR(Ok) != error) {
196 MEJ_LOG_ERROR_MICROVG(
"Error while loading glyphid %d: 0x%x, refer to fterrdef.h\n",glyph_index, error);
199 *x_advance = face->glyph->advance.x;
202 if (FT_HAS_KERNING(face) && previous_glyph_index && glyph_index){
204 FT_Get_Kerning(face, previous_glyph_index, glyph_index, FT_KERNING_UNSCALED, &delta);
207 *x_advance += delta.x;
210 previous_glyph_index = glyph_index;
212 *glyph_idx = glyph_index;
218 #if defined VG_FEATURE_FONT_COMPLEX_LAYOUT 220 if(((
unsigned int) 0) != glyph_count){
222 *glyph_idx = glyph_info[current_glyph].codepoint;
223 *x_advance = glyph_pos[current_glyph].x_advance/64;
224 *y_advance = glyph_pos[current_glyph].y_advance/64;
225 *x_offset = glyph_pos[current_glyph].x_offset/64;
226 *y_offset = glyph_pos[current_glyph].y_offset/64;
232 int error = FT_Load_Glyph(face, *glyph_idx, FT_LOAD_NO_SCALE);
233 if(FT_ERR(Ok) != error) {
234 MEJ_LOG_ERROR_MICROVG(
"Error while loading glyphid %d: 0x%x, refer to fterrdef.h\n", *glyph_idx, error);
239 hb_buffer_destroy(buf);
242 #endif // VG_FEATURE_FONT_COMPLEX_LAYOUT 249 jfloat* MICROVG_HELPER_check_matrix(jfloat* matrix) {
250 return (NULL == matrix) ? g_identity_matrix : matrix;
254 uint32_t MICROVG_HELPER_apply_alpha(uint32_t color, uint32_t alpha) {
255 uint32_t color_alpha = (((color >> 24) & (uint32_t)0xff) * alpha) / (uint32_t)255;
256 return (color & (uint32_t)0xffffff) | (color_alpha << 24);
int MICROVG_HELPER_get_utf(unsigned short *textCharRam, int length, int *offset)
Gets the next UTF character from a text buffer.
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