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 HB_SCRIPT_AHOM,
152 HB_SCRIPT_ANATOLIAN_HIEROGLYPHS,
153 HB_SCRIPT_HATRAN,
154 HB_SCRIPT_MULTANI,
155 HB_SCRIPT_OLD_HUNGARIAN,
156 HB_SCRIPT_SIGNWRITING,
157 };
158
159 static hb_unicode_combining_class_t
hb_ucdn_combining_class(hb_unicode_funcs_t * ufuncs,hb_codepoint_t unicode,void * user_data HB_UNUSED)160 hb_ucdn_combining_class(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode,
161 void *user_data HB_UNUSED)
162 {
163 return (hb_unicode_combining_class_t) ucdn_get_combining_class(unicode);
164 }
165
166 static unsigned int
hb_ucdn_eastasian_width(hb_unicode_funcs_t * ufuncs,hb_codepoint_t unicode,void * user_data HB_UNUSED)167 hb_ucdn_eastasian_width(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode,
168 void *user_data HB_UNUSED)
169 {
170 int w = ucdn_get_east_asian_width(unicode);
171 return (w == UCDN_EAST_ASIAN_F || w == UCDN_EAST_ASIAN_W) ? 2 : 1;
172 }
173
174 static hb_unicode_general_category_t
hb_ucdn_general_category(hb_unicode_funcs_t * ufuncs,hb_codepoint_t unicode,void * user_data HB_UNUSED)175 hb_ucdn_general_category(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode,
176 void *user_data HB_UNUSED)
177 {
178 return (hb_unicode_general_category_t)ucdn_get_general_category(unicode);
179 }
180
181 static hb_codepoint_t
hb_ucdn_mirroring(hb_unicode_funcs_t * ufuncs,hb_codepoint_t unicode,void * user_data HB_UNUSED)182 hb_ucdn_mirroring(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode,
183 void *user_data HB_UNUSED)
184 {
185 return ucdn_mirror(unicode);
186 }
187
188 static hb_script_t
hb_ucdn_script(hb_unicode_funcs_t * ufuncs,hb_codepoint_t unicode,void * user_data HB_UNUSED)189 hb_ucdn_script(hb_unicode_funcs_t *ufuncs, hb_codepoint_t unicode,
190 void *user_data HB_UNUSED)
191 {
192 return ucdn_script_translate[ucdn_get_script(unicode)];
193 }
194
195 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)196 hb_ucdn_compose(hb_unicode_funcs_t *ufuncs,
197 hb_codepoint_t a, hb_codepoint_t b, hb_codepoint_t *ab,
198 void *user_data HB_UNUSED)
199 {
200 return ucdn_compose(ab, a, b);
201 }
202
203 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)204 hb_ucdn_decompose(hb_unicode_funcs_t *ufuncs,
205 hb_codepoint_t ab, hb_codepoint_t *a, hb_codepoint_t *b,
206 void *user_data HB_UNUSED)
207 {
208 return ucdn_decompose(ab, a, b);
209 }
210
211 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)212 hb_ucdn_decompose_compatibility(hb_unicode_funcs_t *ufuncs,
213 hb_codepoint_t u, hb_codepoint_t *decomposed,
214 void *user_data HB_UNUSED)
215 {
216 return ucdn_compat_decompose(u, decomposed);
217 }
218
219 extern "C" HB_INTERNAL
220 hb_unicode_funcs_t *
hb_ucdn_get_unicode_funcs(void)221 hb_ucdn_get_unicode_funcs (void)
222 {
223 static const hb_unicode_funcs_t _hb_ucdn_unicode_funcs = {
224 HB_OBJECT_HEADER_STATIC,
225
226 NULL, /* parent */
227 true, /* immutable */
228 {
229 #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_ucdn_##name,
230 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
231 #undef HB_UNICODE_FUNC_IMPLEMENT
232 }
233 };
234
235 return const_cast<hb_unicode_funcs_t *> (&_hb_ucdn_unicode_funcs);
236 }
237
238