1 #include "evas_font_ot.h"
8 #include "evas_common.h"
11 #include "evas_font_private.h"
14 evas_common_font_ot_is_enabled(void)
24 env = getenv("EVAS_USE_OT");
35 /* FIXME: doc. returns #items */
37 evas_common_font_ot_cluster_size_get(Evas_Text_Props *props, size_t char_index, int orig_len)
41 int left_bound, right_bound;
42 size_t base_cluster = EVAS_FONT_OT_POS_GET(props->ot_data->items[char_index]);
43 for (i = (int) char_index ;
45 (EVAS_FONT_OT_POS_GET(props->ot_data->items[i]) == base_cluster) ;
49 for (i = (int) char_index + 1;
50 (i < (int) props->ot_data->len) &&
51 (EVAS_FONT_OT_POS_GET(props->ot_data->items[i]) == base_cluster) ;
55 if (right_bound == left_bound)
59 else if (props->bidi.dir == EVAS_BIDI_DIRECTION_RTL)
64 props->ot_data->items[left_bound + 1].source_pos;
68 items = props->ot_data->items[left_bound].source_pos -
69 props->ot_data->items[left_bound + 1].source_pos;
74 if (right_bound == (int) props->ot_data->len)
76 items = orig_len - props->ot_data->items[left_bound].source_pos;
80 items = props->ot_data->items[right_bound - 1].source_pos -
81 props->ot_data->items[right_bound].source_pos;
84 return (items > 0) ? items : 1;
88 _evas_common_font_ot_shape(hb_buffer_t *buffer, FT_Face face)
93 hb_face = hb_ft_face_create(face, NULL);
94 hb_font = hb_ft_font_create(face, NULL);
96 hb_shape(hb_font, hb_face, buffer, NULL, 0);
97 hb_font_destroy(hb_font);
98 hb_face_destroy(hb_face);
102 evas_common_font_ot_populate_text_props(void *_fn, const Eina_Unicode *text,
103 Evas_Text_Props *props, int len)
105 RGBA_Font *fn = (RGBA_Font *) _fn;
108 hb_glyph_position_t *positions;
109 hb_glyph_info_t *infos;
112 if (!evas_common_font_ot_is_enabled()) return EINA_TRUE;
115 evas_common_font_ot_props_unref(props->ot_data);
117 props->ot_data = calloc(1, sizeof(Evas_Font_OT_Data));
118 props->ot_data->refcount = 1;
120 fi = fn->fonts->data;
121 if (fi->src->current_size != fi->size)
124 FT_Activate_Size(fi->ft.size);
126 fi->src->current_size = fi->size;
128 /* Load the font needed for this script */
129 evas_common_font_glyph_search(fn, &fi, *text);
133 slen = eina_unicode_strlen(text);
140 buffer = hb_buffer_create(slen);
141 hb_buffer_set_unicode_funcs(buffer, evas_common_language_unicode_funcs_get());
142 hb_buffer_set_language(buffer, hb_language_from_string(
143 evas_common_language_from_locale_get()));
144 hb_buffer_set_script(buffer, props->script);
145 hb_buffer_set_direction(buffer,
146 (props->bidi.dir == EVAS_BIDI_DIRECTION_RTL) ?
147 HB_DIRECTION_RTL : HB_DIRECTION_LTR);
148 /* FIXME: add run-time conversions if needed, which is very unlikely */
149 hb_buffer_add_utf32(buffer, (const uint32_t *) text, slen, 0, slen);
151 _evas_common_font_ot_shape(buffer, fi->src->ft.face);
153 props->ot_data->len = hb_buffer_get_length(buffer);
154 props->ot_data->items = calloc(props->ot_data->len,
155 sizeof(Evas_Font_OT_Data_Item));
156 positions = hb_buffer_get_glyph_positions(buffer);
157 infos = hb_buffer_get_glyph_infos(buffer);
158 for (i = 0 ; i < props->ot_data->len ; i++)
160 props->ot_data->items[i].index = infos[i].codepoint;
161 props->ot_data->items[i].source_pos = infos[i].cluster;
162 props->ot_data->items[i].x_advance = positions[i].x_advance;
163 props->ot_data->items[i].x_offset = positions[i].x_offset;
164 props->ot_data->items[i].y_offset = positions[i].y_offset;
167 hb_buffer_destroy(buffer);
173 evas_common_font_ot_props_ref(Evas_Font_OT_Data *data)
179 evas_common_font_ot_props_unref(Evas_Font_OT_Data *data)
182 if (--data->refcount == 0)