1 #include "evas_font_ot.h"
8 #include "evas_common.h"
11 #include "evas_font_private.h"
14 /* FIXME: doc. returns #items */
16 evas_common_font_ot_cluster_size_get(const Evas_Text_Props *props, size_t char_index)
20 int left_bound, right_bound;
22 char_index += props->start;
23 base_cluster = EVAS_FONT_OT_POS_GET(props->info->ot[char_index]);
24 for (i = (int) char_index ;
25 (i >= (int) props->start) &&
26 (EVAS_FONT_OT_POS_GET(props->info->ot[i]) == base_cluster) ;
30 for (i = (int) char_index + 1;
31 (i < (int) (props->start + props->len)) &&
32 (EVAS_FONT_OT_POS_GET(props->info->ot[i]) == base_cluster) ;
37 if (right_bound == left_bound)
41 else if (props->bidi.dir == EVAS_BIDI_DIRECTION_RTL)
45 items = props->text_offset + props->text_len - base_cluster;
49 items = props->info->ot[left_bound].source_cluster - base_cluster;
54 if (right_bound >= (int) (props->text_offset + props->text_len))
56 items = props->text_offset + props->text_len - base_cluster;
60 items = props->info->ot[right_bound].source_cluster - base_cluster;
63 return (items > 0) ? items : 1;
67 evas_common_font_ot_load_face(void *_font)
69 RGBA_Font_Source *font = (RGBA_Font_Source *) _font;
70 /* Unload the face if by any chance it's already loaded */
71 evas_common_font_ot_unload_face(font);
72 font->hb.face = hb_ft_face_create(font->ft.face, NULL);
76 evas_common_font_ot_unload_face(void *_font)
78 RGBA_Font_Source *font = (RGBA_Font_Source *) _font;
79 if (!font->hb.face) return;
80 hb_face_destroy(font->hb.face);
84 /* Harfbuzz font functions */
85 static hb_font_funcs_t *_ft_font_funcs = NULL;
88 _evas_common_font_ot_hb_get_glyph(hb_font_t *font, hb_face_t *face,
89 const void *user_data, hb_codepoint_t unicode,
90 hb_codepoint_t variation_selector)
92 RGBA_Font_Int *fi = (RGBA_Font_Int *) user_data;
93 return hb_font_funcs_get_glyph_func(_ft_font_funcs)(font, face,
94 fi->src->ft.face, unicode, variation_selector);
98 _evas_common_font_ot_hb_get_glyph_advance(hb_font_t *font, hb_face_t *face,
99 const void *user_data, hb_codepoint_t glyph,
100 hb_position_t *x_advance, hb_position_t *y_advance)
103 RGBA_Font_Int *fi = (RGBA_Font_Int *) user_data;
107 fg = evas_common_font_int_cache_glyph_get(fi, glyph);
110 *x_advance = fg->glyph->advance.x >> 10;
111 *y_advance = fg->glyph->advance.y >> 10;
116 _evas_common_font_ot_hb_get_glyph_extents(hb_font_t *font, hb_face_t *face,
117 const void *user_data, hb_codepoint_t glyph, hb_glyph_extents_t *extents)
119 RGBA_Font_Int *fi = (RGBA_Font_Int *) user_data;
120 hb_font_funcs_get_glyph_extents_func(_ft_font_funcs)(font, face,
121 fi->src->ft.face, glyph, extents);
125 _evas_common_font_ot_hb_get_contour_point(hb_font_t *font, hb_face_t *face,
126 const void *user_data, unsigned int point_index, hb_codepoint_t glyph,
127 hb_position_t *x, hb_position_t *y)
129 RGBA_Font_Int *fi = (RGBA_Font_Int *) user_data;
130 return hb_font_funcs_get_contour_point_func(_ft_font_funcs)(font, face,
131 fi->src->ft.face, point_index, glyph, x, y);
135 _evas_common_font_ot_hb_get_kerning(hb_font_t *font, hb_face_t *face,
136 const void *user_data, hb_codepoint_t first_glyph,
137 hb_codepoint_t second_glyph)
139 RGBA_Font_Int *fi = (RGBA_Font_Int *) user_data;
143 if (evas_common_font_query_kerning(fi, first_glyph, second_glyph, &kern))
149 /* End of harfbuzz font funcs */
151 static hb_font_funcs_t *
152 _evas_common_font_ot_font_funcs_get(void)
154 static hb_font_funcs_t *font_funcs = NULL;
157 _ft_font_funcs = hb_ft_get_font_funcs();
158 font_funcs = hb_font_funcs_create();
159 hb_font_funcs_set_glyph_func(font_funcs,
160 _evas_common_font_ot_hb_get_glyph);
161 hb_font_funcs_set_glyph_advance_func(font_funcs,
162 _evas_common_font_ot_hb_get_glyph_advance);
163 hb_font_funcs_set_glyph_extents_func(font_funcs,
164 _evas_common_font_ot_hb_get_glyph_extents);
165 hb_font_funcs_set_contour_point_func(font_funcs,
166 _evas_common_font_ot_hb_get_contour_point);
167 hb_font_funcs_set_kerning_func(font_funcs,
168 _evas_common_font_ot_hb_get_kerning);
175 _evas_common_font_ot_shape(hb_buffer_t *buffer, RGBA_Font_Int *fi)
179 hb_font = hb_ft_font_create(fi->src->ft.face, NULL);
180 hb_font_set_funcs(hb_font, _evas_common_font_ot_font_funcs_get(), NULL, fi);
182 hb_shape(hb_font, fi->src->hb.face, buffer, NULL, 0);
183 hb_font_destroy(hb_font);
187 evas_common_font_ot_populate_text_props(void *_fn, const Eina_Unicode *text,
188 Evas_Text_Props *props, int len)
190 RGBA_Font *fn = (RGBA_Font *) _fn;
193 hb_glyph_position_t *positions;
194 hb_glyph_info_t *infos;
197 Evas_Font_Glyph_Info *gl_itr;
198 Evas_Font_OT_Info *ot_itr;
200 fi = fn->fonts->data;
201 /* Load the font needed for this script */
203 /* Skip common chars */
204 const Eina_Unicode *tmp;
207 evas_common_language_char_script_get(*tmp) == EVAS_SCRIPT_COMMON ;
210 if (!*tmp && (tmp > text)) tmp--;
211 evas_common_font_glyph_search(fn, &fi, *tmp);
213 evas_common_font_int_reload(fi);
214 if (fi->src->current_size != fi->size)
217 FT_Activate_Size(fi->ft.size);
219 fi->src->current_size = fi->size;
224 slen = eina_unicode_strlen(text);
231 buffer = hb_buffer_create(slen);
232 hb_buffer_set_unicode_funcs(buffer, evas_common_language_unicode_funcs_get());
233 hb_buffer_set_language(buffer, hb_language_from_string(
234 evas_common_language_from_locale_get()));
235 hb_buffer_set_script(buffer, props->script);
236 hb_buffer_set_direction(buffer,
237 (props->bidi.dir == EVAS_BIDI_DIRECTION_RTL) ?
238 HB_DIRECTION_RTL : HB_DIRECTION_LTR);
239 /* FIXME: add run-time conversions if needed, which is very unlikely */
240 hb_buffer_add_utf32(buffer, (const uint32_t *) text, slen, 0, slen);
242 _evas_common_font_ot_shape(buffer, fi);
244 props->len = hb_buffer_get_length(buffer);
245 props->info->ot = calloc(props->len,
246 sizeof(Evas_Font_OT_Info));
247 props->info->glyph = calloc(props->len,
248 sizeof(Evas_Font_Glyph_Info));
249 positions = hb_buffer_get_glyph_positions(buffer);
250 infos = hb_buffer_get_glyph_infos(buffer);
251 gl_itr = props->info->glyph;
252 ot_itr = props->info->ot;
253 for (i = 0 ; i < props->len ; i++)
255 ot_itr->source_cluster = infos->cluster;
256 ot_itr->x_offset = positions->x_offset;
257 ot_itr->y_offset = positions->y_offset;
258 gl_itr->index = infos->codepoint;
259 gl_itr->advance = positions->x_advance;
267 hb_buffer_destroy(buffer);
268 evas_common_font_int_use_trim();