2 * Copyright (C) 2012 Grigori Goronzy <greg@kinoho.net>
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.
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.
17 #include "hb-private.hh"
19 #include "hb-unicode-private.hh"
23 static const hb_script_t ucdn_script_translate[] =
52 HB_SCRIPT_CANADIAN_SYLLABICS,
80 HB_SCRIPT_NEW_TAI_LUE,
83 HB_SCRIPT_SYLOTI_NAGRI,
84 HB_SCRIPT_OLD_PERSIAN,
105 HB_SCRIPT_EGYPTIAN_HIEROGLYPHS,
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,
121 HB_SCRIPT_MEROITIC_CURSIVE,
122 HB_SCRIPT_MEROITIC_HIEROGLYPHS,
125 HB_SCRIPT_SORA_SOMPENG,
129 HB_SCRIPT_CAUCASIAN_ALBANIAN,
137 HB_SCRIPT_MANICHAEAN,
138 HB_SCRIPT_MENDE_KIKAKUI,
142 HB_SCRIPT_OLD_NORTH_ARABIAN,
143 HB_SCRIPT_OLD_PERMIC,
144 HB_SCRIPT_PAHAWH_HMONG,
146 HB_SCRIPT_PAU_CIN_HAU,
147 HB_SCRIPT_PSALTER_PAHLAVI,
150 HB_SCRIPT_WARANG_CITI,
152 HB_SCRIPT_ANATOLIAN_HIEROGLYPHS,
155 HB_SCRIPT_OLD_HUNGARIAN,
156 HB_SCRIPT_SIGNWRITING,
163 HB_SCRIPT_MASARAM_GONDI,
166 HB_SCRIPT_ZANABAZAR_SQUARE,
168 HB_SCRIPT_GUNJALA_GONDI,
169 HB_SCRIPT_HANIFI_ROHINGYA,
171 HB_SCRIPT_MEDEFAIDRIN,
172 HB_SCRIPT_OLD_SOGDIAN,
176 static hb_unicode_combining_class_t
177 hb_ucdn_combining_class(hb_unicode_funcs_t *ufuncs HB_UNUSED,
178 hb_codepoint_t unicode,
179 void *user_data HB_UNUSED)
181 return (hb_unicode_combining_class_t) ucdn_get_combining_class(unicode);
185 hb_ucdn_eastasian_width(hb_unicode_funcs_t *ufuncs HB_UNUSED,
186 hb_codepoint_t unicode,
187 void *user_data HB_UNUSED)
189 int w = ucdn_get_east_asian_width(unicode);
190 return (w == UCDN_EAST_ASIAN_F || w == UCDN_EAST_ASIAN_W) ? 2 : 1;
193 static hb_unicode_general_category_t
194 hb_ucdn_general_category(hb_unicode_funcs_t *ufuncs HB_UNUSED,
195 hb_codepoint_t unicode,
196 void *user_data HB_UNUSED)
198 return (hb_unicode_general_category_t)ucdn_get_general_category(unicode);
201 static hb_codepoint_t
202 hb_ucdn_mirroring(hb_unicode_funcs_t *ufuncs HB_UNUSED,
203 hb_codepoint_t unicode,
204 void *user_data HB_UNUSED)
206 return ucdn_mirror(unicode);
210 hb_ucdn_script(hb_unicode_funcs_t *ufuncs HB_UNUSED,
211 hb_codepoint_t unicode,
212 void *user_data HB_UNUSED)
214 return ucdn_script_translate[ucdn_get_script(unicode)];
218 hb_ucdn_compose(hb_unicode_funcs_t *ufuncs HB_UNUSED,
219 hb_codepoint_t a, hb_codepoint_t b, hb_codepoint_t *ab,
220 void *user_data HB_UNUSED)
222 return ucdn_compose(ab, a, b);
226 hb_ucdn_decompose(hb_unicode_funcs_t *ufuncs HB_UNUSED,
227 hb_codepoint_t ab, hb_codepoint_t *a, hb_codepoint_t *b,
228 void *user_data HB_UNUSED)
230 return ucdn_decompose(ab, a, b);
234 hb_ucdn_decompose_compatibility(hb_unicode_funcs_t *ufuncs HB_UNUSED,
235 hb_codepoint_t u, hb_codepoint_t *decomposed,
236 void *user_data HB_UNUSED)
238 return ucdn_compat_decompose(u, decomposed);
241 static hb_unicode_funcs_t *static_ucdn_funcs = nullptr;
245 void free_static_ucdn_funcs (void)
248 hb_unicode_funcs_t *ucdn_funcs = (hb_unicode_funcs_t *) hb_atomic_ptr_get (&static_ucdn_funcs);
249 if (!hb_atomic_ptr_cmpexch (&static_ucdn_funcs, ucdn_funcs, nullptr))
252 hb_unicode_funcs_destroy (ucdn_funcs);
256 extern "C" HB_INTERNAL
258 hb_ucdn_get_unicode_funcs (void)
261 hb_unicode_funcs_t *funcs = (hb_unicode_funcs_t *) hb_atomic_ptr_get (&static_ucdn_funcs);
263 if (unlikely (!funcs))
265 funcs = hb_unicode_funcs_create (nullptr);
267 #define HB_UNICODE_FUNC_IMPLEMENT(name) \
268 hb_unicode_funcs_set_##name##_func (funcs, hb_ucdn_##name, nullptr, nullptr);
269 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
270 #undef HB_UNICODE_FUNC_IMPLEMENT
272 hb_unicode_funcs_make_immutable (funcs);
274 if (!hb_atomic_ptr_cmpexch (&static_ucdn_funcs, nullptr, funcs)) {
275 hb_unicode_funcs_destroy (funcs);
280 atexit (free_static_ucdn_funcs); /* First person registers atexit() callback. */
284 return hb_unicode_funcs_reference (funcs);