1 /*
2 * Copyright (C) 2012 Grigori Goronzy <greg@kinoho.net>
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include "hb-private.hh"
18
19 #include "hb-unicode-private.hh"
20
21 #include "ucdn.h"
22
23 static const hb_script_t ucdn_script_translate[] =
24 {
25 HB_SCRIPT_COMMON,
26 HB_SCRIPT_LATIN,
27 HB_SCRIPT_GREEK,
28 HB_SCRIPT_CYRILLIC,
29 HB_SCRIPT_ARMENIAN,
30 HB_SCRIPT_HEBREW,
31 HB_SCRIPT_ARABIC,
32 HB_SCRIPT_SYRIAC,
33 HB_SCRIPT_THAANA,
34 HB_SCRIPT_DEVANAGARI,
35 HB_SCRIPT_BENGALI,
36 HB_SCRIPT_GURMUKHI,
37 HB_SCRIPT_GUJARATI,
38 HB_SCRIPT_ORIYA,
39 HB_SCRIPT_TAMIL,
40 HB_SCRIPT_TELUGU,
41 HB_SCRIPT_KANNADA,
42 HB_SCRIPT_MALAYALAM,
43 HB_SCRIPT_SINHALA,
44 HB_SCRIPT_THAI,
45 HB_SCRIPT_LAO,
46 HB_SCRIPT_TIBETAN,
47 HB_SCRIPT_MYANMAR,
48 HB_SCRIPT_GEORGIAN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LYCIAN,
99 HB_SCRIPT_CARIAN,
100 HB_SCRIPT_LYDIAN,
101 HB_SCRIPT_CHAM,
102 HB_SCRIPT_TAI_THAM,
103 HB_SCRIPT_TAI_VIET,
104 HB_SCRIPT_AVESTAN,
105 HB_SCRIPT_EGYPTIAN_HIEROGLYPHS,
106 HB_SCRIPT_SAMARITAN,
107 HB_SCRIPT_LISU,
108 HB_SCRIPT_BAMUM,
109 HB_SCRIPT_JAVANESE,
110 HB_SCRIPT_MEETEI_MAYEK,
111 HB_SCRIPT_IMPERIAL_ARAMAIC,
112 HB_SCRIPT_OLD_SOUTH_ARABIAN,
113 HB_SCRIPT_INSCRIPTIONAL_PARTHIAN,
114 HB_SCRIPT_INSCRIPTIONAL_PAHLAVI,
115 HB_SCRIPT_OLD_TURKIC,
116 HB_SCRIPT_KAITHI,
117 HB_SCRIPT_BATAK,
118 HB_SCRIPT_BRAHMI,
119 HB_SCRIPT_MANDAIC,
120 HB_SCRIPT_CHAKMA,
121 HB_SCRIPT_MEROITIC_CURSIVE,
122 HB_SCRIPT_MEROITIC_HIEROGLYPHS,
123 HB_SCRIPT_MIAO,
124 HB_SCRIPT_SHARADA,
125 HB_SCRIPT_SORA_SOMPENG,
126 HB_SCRIPT_TAKRI,
127 HB_SCRIPT_UNKNOWN,
128 HB_SCRIPT_BASSA_VAH,
129 HB_SCRIPT_CAUCASIAN_ALBANIAN,
130 HB_SCRIPT_DUPLOYAN,
131 HB_SCRIPT_ELBASAN,
132 HB_SCRIPT_GRANTHA,
133 HB_SCRIPT_KHOJKI,
134 HB_SCRIPT_KHUDAWADI,
135 HB_SCRIPT_LINEAR_A,
136 HB_SCRIPT_MAHAJANI,
137 HB_SCRIPT_MANICHAEAN,
138 HB_SCRIPT_MENDE_KIKAKUI,
139 HB_SCRIPT_MODI,
140 HB_SCRIPT_MRO,
141 HB_SCRIPT_NABATAEAN,
142 HB_SCRIPT_OLD_NORTH_ARABIAN,
143 HB_SCRIPT_OLD_PERMIC,
144 HB_SCRIPT_PAHAWH_HMONG,
145 HB_SCRIPT_PALMYRENE,
146 HB_SCRIPT_PAU_CIN_HAU,
147 HB_SCRIPT_PSALTER_PAHLAVI,
148 HB_SCRIPT_SIDDHAM,
149 HB_SCRIPT_TIRHUTA,
150 HB_SCRIPT_WARANG_CITI,
151 };
152
153 static hb_unicode_combining_class_t
hb_ucdn_combining_class(hb_unicode_funcs_t * ufuncs,hb_codepoint_t unicode,void * user_data HB_UNUSED)154 hb_ucdn_combining_class(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode,
155 void *user_data HB_UNUSED)
156 {
157 return (hb_unicode_combining_class_t) ucdn_get_combining_class(unicode);
158 }
159
160 static unsigned int
hb_ucdn_eastasian_width(hb_unicode_funcs_t * ufuncs,hb_codepoint_t unicode,void * user_data HB_UNUSED)161 hb_ucdn_eastasian_width(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode,
162 void *user_data HB_UNUSED)
163 {
164 int w = ucdn_get_east_asian_width(unicode);
165 return (w == UCDN_EAST_ASIAN_F || w == UCDN_EAST_ASIAN_W) ? 2 : 1;
166 }
167
168 static hb_unicode_general_category_t
hb_ucdn_general_category(hb_unicode_funcs_t * ufuncs,hb_codepoint_t unicode,void * user_data HB_UNUSED)169 hb_ucdn_general_category(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode,
170 void *user_data HB_UNUSED)
171 {
172 return (hb_unicode_general_category_t)ucdn_get_general_category(unicode);
173 }
174
175 static hb_codepoint_t
hb_ucdn_mirroring(hb_unicode_funcs_t * ufuncs,hb_codepoint_t unicode,void * user_data HB_UNUSED)176 hb_ucdn_mirroring(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode,
177 void *user_data HB_UNUSED)
178 {
179 return ucdn_mirror(unicode);
180 }
181
182 static hb_script_t
hb_ucdn_script(hb_unicode_funcs_t * ufuncs,hb_codepoint_t unicode,void * user_data HB_UNUSED)183 hb_ucdn_script(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode,
184 void *user_data HB_UNUSED)
185 {
186 return ucdn_script_translate[ucdn_get_script(unicode)];
187 }
188
189 static hb_bool_t
hb_ucdn_compose(hb_unicode_funcs_t * ufuncs,hb_codepoint_t a,hb_codepoint_t b,hb_codepoint_t * ab,void * user_data HB_UNUSED)190 hb_ucdn_compose(hb_unicode_funcs_t *ufuncs,
191 hb_codepoint_t a, hb_codepoint_t b, hb_codepoint_t *ab,
192 void *user_data HB_UNUSED)
193 {
194 return ucdn_compose(ab, a, b);
195 }
196
197 static hb_bool_t
hb_ucdn_decompose(hb_unicode_funcs_t * ufuncs,hb_codepoint_t ab,hb_codepoint_t * a,hb_codepoint_t * b,void * user_data HB_UNUSED)198 hb_ucdn_decompose(hb_unicode_funcs_t *ufuncs,
199 hb_codepoint_t ab, hb_codepoint_t *a, hb_codepoint_t *b,
200 void *user_data HB_UNUSED)
201 {
202 return ucdn_decompose(ab, a, b);
203 }
204
205 static unsigned int
hb_ucdn_decompose_compatibility(hb_unicode_funcs_t * ufuncs,hb_codepoint_t u,hb_codepoint_t * decomposed,void * user_data HB_UNUSED)206 hb_ucdn_decompose_compatibility(hb_unicode_funcs_t *ufuncs,
207 hb_codepoint_t u, hb_codepoint_t *decomposed,
208 void *user_data HB_UNUSED)
209 {
210 return ucdn_compat_decompose(u, decomposed);
211 }
212
213 extern "C" HB_INTERNAL
214 hb_unicode_funcs_t *
hb_ucdn_get_unicode_funcs(void)215 hb_ucdn_get_unicode_funcs (void)
216 {
217 static const hb_unicode_funcs_t _hb_ucdn_unicode_funcs = {
218 HB_OBJECT_HEADER_STATIC,
219
220 NULL, /* parent */
221 true, /* immutable */
222 {
223 #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_ucdn_##name,
224 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
225 #undef HB_UNICODE_FUNC_IMPLEMENT
226 }
227 };
228
229 return const_cast<hb_unicode_funcs_t *> (&_hb_ucdn_unicode_funcs);
230 }
231
232