1 #include "evas_font_ot.h"
8 #include "evas_common.h"
11 #include "evas_font_private.h"
14 static const hb_script_t
15 _evas_script_to_harfbuzz[] =
57 HB_SCRIPT_CANADIAN_ABORIGINAL,
64 /* Unicode-4.0 additions */
74 /* Unicode-4.1 additions */
75 HB_SCRIPT_NEW_TAI_LUE,
79 HB_SCRIPT_SYLOTI_NAGRI,
80 HB_SCRIPT_OLD_PERSIAN,
83 /* Unicode-5.0 additions */
91 /* Unicode-5.1 additions */
104 /* Unicode-5.2 additions */
107 HB_SCRIPT_EGYPTIAN_HIEROGLYPHS,
108 HB_SCRIPT_IMPERIAL_ARAMAIC,
109 HB_SCRIPT_INSCRIPTIONAL_PAHLAVI,
110 HB_SCRIPT_INSCRIPTIONAL_PARTHIAN,
115 HB_SCRIPT_MEETEI_MAYEK,
116 HB_SCRIPT_OLD_SOUTH_ARABIAN,
117 HB_SCRIPT_OLD_TURKIC,
121 /* Unicode-6.0 additions */
129 /* FIXME: doc. returns #items */
131 evas_common_font_ot_cluster_size_get(const Evas_Text_Props *props, size_t char_index)
135 int left_bound, right_bound;
137 char_index += props->start;
138 base_cluster = EVAS_FONT_OT_POS_GET(props->info->ot[char_index]);
139 for (i = (int) char_index ;
140 (i >= (int) props->start) &&
141 (EVAS_FONT_OT_POS_GET(props->info->ot[i]) == base_cluster) ;
145 for (i = (int) char_index + 1;
146 (i < (int) (props->start + props->len)) &&
147 (EVAS_FONT_OT_POS_GET(props->info->ot[i]) == base_cluster) ;
152 if (right_bound == left_bound)
156 else if (props->bidi.dir == EVAS_BIDI_DIRECTION_RTL)
160 items = props->text_offset + props->text_len - base_cluster;
164 items = props->info->ot[left_bound].source_cluster - base_cluster;
169 if (right_bound >= (int) (props->text_offset + props->text_len))
171 items = props->text_offset + props->text_len - base_cluster;
175 items = props->info->ot[right_bound].source_cluster - base_cluster;
178 return (items > 0) ? items : 1;
181 /* Harfbuzz font functions */
184 _evas_common_font_ot_hb_get_glyph_advance(hb_font_t *font,
185 void *font_data, hb_codepoint_t glyph,
189 RGBA_Font_Int *fi = (RGBA_Font_Int *) font_data;
193 fg = evas_common_font_int_cache_glyph_get(fi, glyph);
196 return fg->glyph->advance.x >> 10;
202 _evas_common_font_ot_hb_get_kerning(hb_font_t *font, void *font_data,
203 hb_codepoint_t first_glyph, hb_codepoint_t second_glyph, void *user_data)
205 RGBA_Font_Int *fi = (RGBA_Font_Int *) font_data;
209 if (evas_common_font_query_kerning(fi, first_glyph, second_glyph, &kern))
215 /* End of harfbuzz font funcs */
217 static inline hb_font_funcs_t *
218 _evas_common_font_ot_font_funcs_get(void)
220 static hb_font_funcs_t *font_funcs = NULL;
223 font_funcs = hb_font_funcs_create();
224 hb_font_funcs_set_glyph_h_advance_func(font_funcs,
225 _evas_common_font_ot_hb_get_glyph_advance, NULL, NULL);
226 hb_font_funcs_set_glyph_h_kerning_func(font_funcs,
227 _evas_common_font_ot_hb_get_kerning, NULL, NULL);
233 static inline hb_unicode_funcs_t *
234 _evas_common_font_ot_unicode_funcs_get(void)
236 static hb_unicode_funcs_t *unicode_funcs = NULL;
239 unicode_funcs = hb_unicode_funcs_get_default();
242 return unicode_funcs;
246 _evas_common_font_ot_shape(hb_buffer_t *buffer, RGBA_Font_Int *fi)
248 hb_font_t *hb_font, *hb_ft_font;
250 hb_ft_font = hb_ft_font_create(fi->src->ft.face, NULL);
251 hb_font = hb_font_create_sub_font(hb_ft_font);
253 hb_font_set_funcs(hb_font, _evas_common_font_ot_font_funcs_get(), fi, NULL);
255 hb_shape(hb_font, buffer, NULL, 0);
257 hb_font_destroy(hb_font);
258 hb_font_destroy(hb_ft_font);
262 evas_common_font_ot_populate_text_props(const Eina_Unicode *text,
263 Evas_Text_Props *props, int len)
267 hb_glyph_position_t *positions;
268 hb_glyph_info_t *infos;
271 Evas_Font_Glyph_Info *gl_itr;
272 Evas_Font_OT_Info *ot_itr;
273 Evas_Coord pen_x = 0;
275 fi = props->font_instance;
279 slen = eina_unicode_strlen(text);
286 #if HB_VERSION_CHECK(0,7,0)
287 buffer = hb_buffer_create(slen);
289 buffer = hb_buffer_create();
291 hb_buffer_set_unicode_funcs(buffer, _evas_common_font_ot_unicode_funcs_get());
292 #if HB_VERSION_CHECK(0,7,0)
293 hb_buffer_set_language(buffer, hb_language_from_string(
294 evas_common_language_from_locale_get()));
296 hb_buffer_set_language(buffer, hb_language_from_string(
297 evas_common_language_from_locale_get(), -1));
299 hb_buffer_set_script(buffer, _evas_script_to_harfbuzz[props->script]);
300 hb_buffer_set_direction(buffer,
301 (props->bidi.dir == EVAS_BIDI_DIRECTION_RTL) ?
302 HB_DIRECTION_RTL : HB_DIRECTION_LTR);
303 /* FIXME: add run-time conversions if needed, which is very unlikely */
304 hb_buffer_add_utf32(buffer, (const uint32_t *) text, slen, 0, slen);
306 _evas_common_font_ot_shape(buffer, fi);
308 props->len = hb_buffer_get_length(buffer);
309 props->info->ot = calloc(props->len,
310 sizeof(Evas_Font_OT_Info));
311 props->info->glyph = calloc(props->len,
312 sizeof(Evas_Font_Glyph_Info));
313 positions = hb_buffer_get_glyph_positions(buffer, NULL);
314 infos = hb_buffer_get_glyph_infos(buffer, NULL);
315 gl_itr = props->info->glyph;
316 ot_itr = props->info->ot;
317 for (i = 0 ; i < props->len ; i++)
320 ot_itr->source_cluster = infos->cluster;
321 ot_itr->x_offset = positions->x_offset;
322 ot_itr->y_offset = positions->y_offset;
323 gl_itr->index = infos->codepoint;
324 adv = positions->x_advance;
327 gl_itr->pen_after = EVAS_FONT_ROUND_26_6_TO_INT(pen_x);
335 hb_buffer_destroy(buffer);
336 evas_common_font_int_use_trim();