diff options
Diffstat (limited to 'libraries/evas/src/lib/engines/common/language/evas_language_utils.c')
-rw-r--r-- | libraries/evas/src/lib/engines/common/language/evas_language_utils.c | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/libraries/evas/src/lib/engines/common/language/evas_language_utils.c b/libraries/evas/src/lib/engines/common/language/evas_language_utils.c new file mode 100644 index 0000000..9c9b3e3 --- /dev/null +++ b/libraries/evas/src/lib/engines/common/language/evas_language_utils.c | |||
@@ -0,0 +1,146 @@ | |||
1 | /** | ||
2 | * @internal | ||
3 | * @addtogroup Evas_Utils | ||
4 | * | ||
5 | * @{ | ||
6 | */ | ||
7 | /** | ||
8 | * @internal | ||
9 | * @defgroup Evas_Script Evas Script (language) utility functions | ||
10 | * | ||
11 | * This set of functions and types helps evas handle scripts correctly. | ||
12 | * @todo Document types, structures and macros. | ||
13 | * | ||
14 | * @{ | ||
15 | */ | ||
16 | #include <Eina.h> | ||
17 | |||
18 | #include "evas_language_utils.h" | ||
19 | #include "evas_bidi_utils.h" /* Used for splitting according to bidi */ | ||
20 | #include "../evas_font_ot.h" /* Used for harfbuzz info */ | ||
21 | |||
22 | #ifdef USE_HARFBUZZ | ||
23 | # include <hb.h> | ||
24 | #endif | ||
25 | |||
26 | #include "evas_script_table.h" | ||
27 | |||
28 | static Evas_Script_Type | ||
29 | _evas_common_language_char_script_search(Eina_Unicode unicode) | ||
30 | { | ||
31 | int min = 0; | ||
32 | int max = (sizeof(_evas_script_slow_table) / | ||
33 | sizeof(_evas_script_slow_table[0])) - 1; | ||
34 | int mid; | ||
35 | |||
36 | do | ||
37 | { | ||
38 | mid = (min + max) / 2; | ||
39 | |||
40 | if (unicode < _evas_script_slow_table[mid].start) | ||
41 | max = mid - 1; | ||
42 | else if (unicode >= _evas_script_slow_table[mid].start + | ||
43 | _evas_script_slow_table[mid].len) | ||
44 | min = mid + 1; | ||
45 | else | ||
46 | return _evas_script_slow_table[mid].script; | ||
47 | } | ||
48 | while (min <= max); | ||
49 | |||
50 | return EVAS_SCRIPT_UNKNOWN; | ||
51 | } | ||
52 | |||
53 | Evas_Script_Type | ||
54 | evas_common_language_char_script_get(Eina_Unicode unicode) | ||
55 | { | ||
56 | if ((unicode >= 0) && (unicode < EVAS_SCRIPT_DIRECT_TABLE_LIMIT)) | ||
57 | return _evas_script_fast_table[unicode]; | ||
58 | else | ||
59 | return _evas_common_language_char_script_search(unicode); | ||
60 | } | ||
61 | |||
62 | int | ||
63 | evas_common_language_script_end_of_run_get(const Eina_Unicode *str, | ||
64 | const Evas_BiDi_Paragraph_Props *bidi_props, size_t start, int len) | ||
65 | { | ||
66 | /* FIXME: Use the standard segmentation instead */ | ||
67 | Evas_Script_Type first = EVAS_SCRIPT_UNKNOWN; | ||
68 | int i; | ||
69 | for (i = 0 ; i < len ; i++, str++) | ||
70 | { | ||
71 | Evas_Script_Type tmp; | ||
72 | tmp = evas_common_language_char_script_get(*str); | ||
73 | /* Arabic is the first script in the array that's not | ||
74 | * common/inherited. */ | ||
75 | if ((first == EVAS_SCRIPT_UNKNOWN) && (tmp >= EVAS_SCRIPT_ARABIC)) | ||
76 | { | ||
77 | first = tmp; | ||
78 | continue; | ||
79 | } | ||
80 | if ((first != tmp) && (tmp >= EVAS_SCRIPT_ARABIC)) | ||
81 | { | ||
82 | break; | ||
83 | } | ||
84 | } | ||
85 | #ifdef BIDI_SUPPORT | ||
86 | { | ||
87 | int bidi_end; | ||
88 | bidi_end = evas_bidi_end_of_run_get(bidi_props, start, len); | ||
89 | if (bidi_end > 0) | ||
90 | { | ||
91 | i = (i < bidi_end) ? i : bidi_end; | ||
92 | } | ||
93 | } | ||
94 | #else | ||
95 | (void) bidi_props; | ||
96 | (void) start; | ||
97 | #endif | ||
98 | return (i < len) ? i : 0; | ||
99 | } | ||
100 | |||
101 | Evas_Script_Type | ||
102 | evas_common_language_script_type_get(const Eina_Unicode *str, size_t len) | ||
103 | { | ||
104 | Evas_Script_Type script = EVAS_SCRIPT_COMMON; | ||
105 | const Eina_Unicode *end = str + len; | ||
106 | /* Arabic is the first script in the array that's not a common/inherited */ | ||
107 | for ( ; str < end && ((script = evas_common_language_char_script_get(*str)) < EVAS_SCRIPT_ARABIC) ; str++) | ||
108 | ; | ||
109 | return script; | ||
110 | } | ||
111 | |||
112 | const char * | ||
113 | evas_common_language_from_locale_get(void) | ||
114 | { | ||
115 | static char lang[6]; /* FIXME: Maximum length I know about */ | ||
116 | if (*lang) return lang; | ||
117 | |||
118 | const char *locale; | ||
119 | locale = getenv("LANG"); | ||
120 | if (locale && *locale) | ||
121 | { | ||
122 | char *itr; | ||
123 | strncpy(lang, locale, 5); | ||
124 | lang[5] = '\0'; | ||
125 | itr = lang; | ||
126 | while (*itr) | ||
127 | { | ||
128 | if (*itr == '_') | ||
129 | { | ||
130 | *itr = '\0'; | ||
131 | } | ||
132 | itr++; | ||
133 | } | ||
134 | return lang; | ||
135 | } | ||
136 | |||
137 | return ""; | ||
138 | } | ||
139 | |||
140 | /* | ||
141 | * @} | ||
142 | */ | ||
143 | /* | ||
144 | * @} | ||
145 | */ | ||
146 | |||