4 #include "evas_common.h"
5 #include "evas_intl_utils.h"
7 #include "evas_font_private.h"
9 #ifdef INTERNATIONAL_SUPPORT
10 #include <fribidi/fribidi.h>
12 #define UTF8_BYTES_PER_CHAR 4
15 static LK(fribidi_lock);
18 /* FIXME: fribidi_utf8_to_unicode should use char len and not byte len!*/
20 evas_intl_utf8_to_visual(const char *text,
22 EvasIntlParType *direction,
23 EvasIntlStrIndex **position_L_to_V_list,
24 EvasIntlStrIndex **position_V_to_L_list,
25 EvasIntlLevel **embedding_level_list)
27 FriBidiChar *unicode_in, *unicode_out;
28 EvasIntlStrIndex *tmp_L_to_V_list = NULL;
29 EvasIntlStrIndex *tmp_V_to_L_list = NULL;
30 EvasIntlLevel *tmp_level_list = NULL;
38 len = evas_string_char_len_get(text);
40 byte_len = strlen(text); /* we need the actual number of bytes, not number of chars */
42 unicode_in = (FriBidiChar *)alloca(sizeof(FriBidiChar) * (len + 1));
50 len = fribidi_utf8_to_unicode(text, byte_len, unicode_in);
54 unicode_out = (FriBidiChar *)alloca(sizeof(FriBidiChar) * (len + 1));
61 if (embedding_level_list)
63 *embedding_level_list = (EvasIntlLevel *)malloc(sizeof(EvasIntlLevel) * len);
64 if (!*embedding_level_list)
69 tmp_level_list = *embedding_level_list;
72 if (position_L_to_V_list)
74 *position_L_to_V_list = (EvasIntlStrIndex *)malloc(sizeof(EvasIntlStrIndex) * len);
75 if (!*position_L_to_V_list)
80 tmp_L_to_V_list = *position_L_to_V_list;
83 if (position_V_to_L_list)
85 *position_V_to_L_list = (EvasIntlStrIndex *)malloc(sizeof(EvasIntlStrIndex) * len);
86 if (!*position_V_to_L_list)
91 tmp_V_to_L_list = *position_V_to_L_list;
95 /* fix arabic context */
96 evas_intl_arabic_to_context(unicode_in);
99 if (!fribidi_log2vis(unicode_in, len, direction,
100 unicode_out, tmp_L_to_V_list, tmp_V_to_L_list, tmp_level_list))
108 text_out = malloc(UTF8_BYTES_PER_CHAR * len + 1);
115 fribidi_unicode_to_utf8(unicode_out, len, text_out);
125 free(*position_V_to_L_list);
126 *position_V_to_L_list = NULL;
128 free(*position_L_to_V_list);
129 *position_L_to_V_list = NULL;
131 free(*embedding_level_list);
132 *embedding_level_list = NULL;
142 evas_intl_is_rtl_char(EvasIntlLevel *embedded_level_list, EvasIntlStrIndex i)
144 if(embedded_level_list || i < 0)
146 return FRIBIDI_IS_RTL(embedded_level_list[i]);