2 * Copyright © 2009 Red Hat, Inc.
3 * Copyright © 2011 Google, Inc.
5 * This is part of HarfBuzz, a text shaping library.
7 * Permission is hereby granted, without written agreement and without
8 * license or royalty fees, to use, copy, modify, and distribute this
9 * software and its documentation for any purpose, provided that the
10 * above copyright notice and the following two paragraphs appear in
11 * all copies of this software.
13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 * Red Hat Author(s): Behdad Esfahbod
26 * Google Author(s): Behdad Esfahbod
29 #include "hb-private.hh"
33 #include "hb-unicode-private.hh"
39 static const hb_script_t
40 glib_script_to_script[] =
82 HB_SCRIPT_CANADIAN_ABORIGINAL,
89 /* Unicode-4.0 additions */
99 /* Unicode-4.1 additions */
100 HB_SCRIPT_NEW_TAI_LUE,
102 HB_SCRIPT_GLAGOLITIC,
104 HB_SCRIPT_SYLOTI_NAGRI,
105 HB_SCRIPT_OLD_PERSIAN,
106 HB_SCRIPT_KHAROSHTHI,
108 /* Unicode-5.0 additions */
112 HB_SCRIPT_PHOENICIAN,
116 /* Unicode-5.1 additions */
121 HB_SCRIPT_SAURASHTRA,
129 /* Unicode-5.2 additions */
132 HB_SCRIPT_EGYPTIAN_HIEROGLYPHS,
133 HB_SCRIPT_IMPERIAL_ARAMAIC,
134 HB_SCRIPT_INSCRIPTIONAL_PAHLAVI,
135 HB_SCRIPT_INSCRIPTIONAL_PARTHIAN,
140 HB_SCRIPT_MEETEI_MAYEK,
141 HB_SCRIPT_OLD_SOUTH_ARABIAN,
142 HB_SCRIPT_OLD_TURKIC,
146 /* Unicode-6.0 additions */
153 hb_glib_script_to_script (GUnicodeScript script)
155 if (likely ((unsigned int) script < ARRAY_LENGTH (glib_script_to_script)))
156 return glib_script_to_script[script];
158 if (unlikely (script == G_UNICODE_SCRIPT_INVALID_CODE))
159 return HB_SCRIPT_INVALID;
161 return HB_SCRIPT_UNKNOWN;
165 hb_glib_script_from_script (hb_script_t script)
167 unsigned int count = ARRAY_LENGTH (glib_script_to_script);
168 for (unsigned int i = 0; i < count; i++)
169 if (glib_script_to_script[i] == script)
170 return (GUnicodeScript) i;
172 if (unlikely (script == HB_SCRIPT_INVALID))
173 return G_UNICODE_SCRIPT_INVALID_CODE;
175 return G_UNICODE_SCRIPT_UNKNOWN;
180 hb_glib_get_combining_class (hb_unicode_funcs_t *ufuncs,
181 hb_codepoint_t unicode,
185 return g_unichar_combining_class (unicode);
189 hb_glib_get_eastasian_width (hb_unicode_funcs_t *ufuncs,
190 hb_codepoint_t unicode,
193 return g_unichar_iswide (unicode) ? 2 : 1;
196 static hb_unicode_general_category_t
197 hb_glib_get_general_category (hb_unicode_funcs_t *ufuncs,
198 hb_codepoint_t unicode,
202 /* hb_unicode_general_category_t and GUnicodeType are identical */
203 return (hb_unicode_general_category_t) g_unichar_type (unicode);
206 static hb_codepoint_t
207 hb_glib_get_mirroring (hb_unicode_funcs_t *ufuncs,
208 hb_codepoint_t unicode,
211 g_unichar_get_mirror_char (unicode, &unicode);
216 hb_glib_get_script (hb_unicode_funcs_t *ufuncs,
217 hb_codepoint_t unicode,
220 return hb_glib_script_to_script (g_unichar_get_script (unicode));
223 extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_glib;
224 hb_unicode_funcs_t _hb_glib_unicode_funcs = {
225 HB_OBJECT_HEADER_STATIC,
228 TRUE, /* immutable */
230 hb_glib_get_combining_class,
231 hb_glib_get_eastasian_width,
232 hb_glib_get_general_category,
233 hb_glib_get_mirroring,
239 hb_glib_get_unicode_funcs (void)
241 return &_hb_glib_unicode_funcs;