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(const 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_cluster;
68 items = props->ot_data->items[left_bound].source_cluster -
69 props->ot_data->items[left_bound + 1].source_cluster;
74 if (right_bound == (int) props->ot_data->len)
77 props->ot_data->items[right_bound - 1].source_cluster;
81 items = props->ot_data->items[right_bound].source_cluster -
82 props->ot_data->items[right_bound - 1].source_cluster;
85 return (items > 0) ? items : 1;
89 evas_common_font_ot_load_face(void *_font)
91 RGBA_Font_Source *font = (RGBA_Font_Source *) _font;
92 font->hb.face = hb_ft_face_create(font->ft.face, NULL);
96 evas_common_font_ot_unload_face(void *_font)
98 RGBA_Font_Source *font = (RGBA_Font_Source *) _font;
99 if (!font->hb.face) return;
100 hb_face_destroy(font->hb.face);
101 font->hb.face = NULL;
105 _evas_common_font_ot_shape(hb_buffer_t *buffer, RGBA_Font_Source *src)
109 hb_font = hb_ft_font_create(src->ft.face, NULL);
111 hb_shape(hb_font, src->hb.face, buffer, NULL, 0);
112 hb_font_destroy(hb_font);
115 /* Won't work in the middle of ligatures */
117 evas_common_font_ot_cutoff_text_props(Evas_Text_Props *props, int cutoff)
119 Evas_Font_OT_Data_Item *tmp;
120 if ((cutoff <= 0) || (!props->ot_data) ||
121 (((size_t) cutoff) >= props->ot_data->len))
124 if (props->bidi.dir == EVAS_BIDI_DIRECTION_RTL)
126 memmove(props->ot_data->items,
127 props->ot_data->items + (props->ot_data->len - cutoff),
128 cutoff * sizeof(Evas_Font_OT_Data_Item));
130 tmp = realloc(props->ot_data->items,
131 cutoff * sizeof(Evas_Font_OT_Data_Item));
132 props->ot_data->items = tmp;
133 props->ot_data->len = cutoff;
138 evas_common_font_ot_populate_text_props(void *_fn, const Eina_Unicode *text,
139 Evas_Text_Props *props, int len)
141 RGBA_Font *fn = (RGBA_Font *) _fn;
144 hb_glyph_position_t *positions;
145 hb_glyph_info_t *infos;
148 if (!evas_common_font_ot_is_enabled()) return EINA_TRUE;
151 evas_common_font_ot_props_unref(props->ot_data);
153 props->ot_data = calloc(1, sizeof(Evas_Font_OT_Data));
154 props->ot_data->refcount = 1;
156 fi = fn->fonts->data;
157 if (fi->src->current_size != fi->size)
160 FT_Activate_Size(fi->ft.size);
162 fi->src->current_size = fi->size;
164 /* Load the font needed for this script */
165 evas_common_font_glyph_search(fn, &fi, *text);
169 slen = eina_unicode_strlen(text);
176 buffer = hb_buffer_create(slen);
177 hb_buffer_set_unicode_funcs(buffer, evas_common_language_unicode_funcs_get());
178 hb_buffer_set_language(buffer, hb_language_from_string(
179 evas_common_language_from_locale_get()));
180 hb_buffer_set_script(buffer, props->script);
181 hb_buffer_set_direction(buffer,
182 (props->bidi.dir == EVAS_BIDI_DIRECTION_RTL) ?
183 HB_DIRECTION_RTL : HB_DIRECTION_LTR);
184 /* FIXME: add run-time conversions if needed, which is very unlikely */
185 hb_buffer_add_utf32(buffer, (const uint32_t *) text, slen, 0, slen);
187 _evas_common_font_ot_shape(buffer, fi->src);
189 props->ot_data->len = hb_buffer_get_length(buffer);
190 props->ot_data->items = calloc(props->ot_data->len,
191 sizeof(Evas_Font_OT_Data_Item));
192 positions = hb_buffer_get_glyph_positions(buffer);
193 infos = hb_buffer_get_glyph_infos(buffer);
194 for (i = 0 ; i < props->ot_data->len ; i++)
196 props->ot_data->items[i].index = infos[i].codepoint;
197 props->ot_data->items[i].source_cluster = infos[i].cluster;
198 props->ot_data->items[i].x_advance = positions[i].x_advance;
199 props->ot_data->items[i].x_offset = positions[i].x_offset;
200 props->ot_data->items[i].y_offset = positions[i].y_offset;
203 hb_buffer_destroy(buffer);
209 evas_common_font_ot_props_ref(Evas_Font_OT_Data *data)
215 evas_common_font_ot_props_unref(Evas_Font_OT_Data *data)
218 if (--data->refcount == 0)