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)
41 int left_bound, right_bound;
42 char_index += props->start;
43 size_t base_cluster = EVAS_FONT_OT_POS_GET(props->info->ot[char_index]);
44 for (i = (int) char_index ;
45 (i >= (int) props->start) &&
46 (EVAS_FONT_OT_POS_GET(props->info->ot[i]) == base_cluster) ;
50 for (i = (int) char_index + 1;
51 (i < (int) (props->start + props->len)) &&
52 (EVAS_FONT_OT_POS_GET(props->info->ot[i]) == base_cluster) ;
56 if (right_bound == left_bound)
60 else if (props->bidi.dir == EVAS_BIDI_DIRECTION_RTL)
64 items = props->start + props->len -
65 props->info->ot[left_bound + 1].source_cluster;
69 items = props->info->ot[left_bound].source_cluster -
70 props->info->ot[left_bound + 1].source_cluster;
75 if (right_bound == (int) props->len)
77 items = props->start + props->len -
78 props->info->ot[right_bound - 1].source_cluster;
82 items = props->info->ot[right_bound].source_cluster -
83 props->info->ot[right_bound - 1].source_cluster;
86 return (items > 0) ? items : 1;
90 evas_common_font_ot_load_face(void *_font)
92 RGBA_Font_Source *font = (RGBA_Font_Source *) _font;
93 /* Unload the face if by any chance it's already loaded */
94 evas_common_font_ot_unload_face(font);
95 font->hb.face = hb_ft_face_create(font->ft.face, NULL);
99 evas_common_font_ot_unload_face(void *_font)
101 RGBA_Font_Source *font = (RGBA_Font_Source *) _font;
102 if (!font->hb.face) return;
103 hb_face_destroy(font->hb.face);
104 font->hb.face = NULL;
108 _evas_common_font_ot_shape(hb_buffer_t *buffer, RGBA_Font_Source *src)
112 hb_font = hb_ft_font_create(src->ft.face, NULL);
114 hb_shape(hb_font, src->hb.face, buffer, NULL, 0);
115 hb_font_destroy(hb_font);
119 evas_common_font_ot_populate_text_props(void *_fn, const Eina_Unicode *text,
120 Evas_Text_Props *props, int len)
122 RGBA_Font *fn = (RGBA_Font *) _fn;
125 hb_glyph_position_t *positions;
126 hb_glyph_info_t *infos;
129 if (!evas_common_font_ot_is_enabled()) return EINA_TRUE;
131 fi = fn->fonts->data;
132 /* Load the font needed for this script */
134 /* Skip common chars */
135 const Eina_Unicode *tmp;
138 evas_common_language_char_script_get(*tmp) == EVAS_SCRIPT_COMMON ;
141 if (!*tmp && (tmp > text)) tmp--;
142 evas_common_font_glyph_search(fn, &fi, *tmp);
144 evas_common_font_int_reload(fi);
145 if (fi->src->current_size != fi->size)
148 FT_Activate_Size(fi->ft.size);
150 fi->src->current_size = fi->size;
155 slen = eina_unicode_strlen(text);
162 buffer = hb_buffer_create(slen);
163 hb_buffer_set_unicode_funcs(buffer, evas_common_language_unicode_funcs_get());
164 hb_buffer_set_language(buffer, hb_language_from_string(
165 evas_common_language_from_locale_get()));
166 hb_buffer_set_script(buffer, props->script);
167 hb_buffer_set_direction(buffer,
168 (props->bidi.dir == EVAS_BIDI_DIRECTION_RTL) ?
169 HB_DIRECTION_RTL : HB_DIRECTION_LTR);
170 /* FIXME: add run-time conversions if needed, which is very unlikely */
171 hb_buffer_add_utf32(buffer, (const uint32_t *) text, slen, 0, slen);
173 _evas_common_font_ot_shape(buffer, fi->src);
175 props->len = hb_buffer_get_length(buffer);
176 props->info->ot = calloc(props->len,
177 sizeof(Evas_Font_OT_Info));
178 props->info->glyph = calloc(props->len,
179 sizeof(Evas_Font_Glyph_Info));
180 positions = hb_buffer_get_glyph_positions(buffer);
181 infos = hb_buffer_get_glyph_infos(buffer);
182 for (i = 0 ; i < props->len ; i++)
184 props->info->ot[i].source_cluster = infos[i].cluster;
185 props->info->ot[i].x_offset = positions[i].x_offset;
186 props->info->ot[i].y_offset = positions[i].y_offset;
187 props->info->glyph[i].index = infos[i].codepoint;
188 props->info->glyph[i].advance = positions[i].x_advance;
191 hb_buffer_destroy(buffer);
192 evas_common_font_int_use_trim();