Implement win32 thread-safety stuff
[profile/ivi/org.tizen.video-player.git] / src / hb-glib.cc
1 /*
2  * Copyright © 2009  Red Hat, Inc.
3  * Copyright © 2011  Google, Inc.
4  *
5  *  This is part of HarfBuzz, a text shaping library.
6  *
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.
12  *
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
17  * DAMAGE.
18  *
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.
24  *
25  * Red Hat Author(s): Behdad Esfahbod
26  * Google Author(s): Behdad Esfahbod
27  */
28
29 #include "hb-private.hh"
30
31 #include "hb-glib.h"
32
33 #include "hb-unicode-private.hh"
34
35 #include <glib.h>
36
37 HB_BEGIN_DECLS
38
39 static const hb_script_t
40 glib_script_to_script[] =
41 {
42   HB_SCRIPT_COMMON,
43   HB_SCRIPT_INHERITED,
44   HB_SCRIPT_ARABIC,
45   HB_SCRIPT_ARMENIAN,
46   HB_SCRIPT_BENGALI,
47   HB_SCRIPT_BOPOMOFO,
48   HB_SCRIPT_CHEROKEE,
49   HB_SCRIPT_COPTIC,
50   HB_SCRIPT_CYRILLIC,
51   HB_SCRIPT_DESERET,
52   HB_SCRIPT_DEVANAGARI,
53   HB_SCRIPT_ETHIOPIC,
54   HB_SCRIPT_GEORGIAN,
55   HB_SCRIPT_GOTHIC,
56   HB_SCRIPT_GREEK,
57   HB_SCRIPT_GUJARATI,
58   HB_SCRIPT_GURMUKHI,
59   HB_SCRIPT_HAN,
60   HB_SCRIPT_HANGUL,
61   HB_SCRIPT_HEBREW,
62   HB_SCRIPT_HIRAGANA,
63   HB_SCRIPT_KANNADA,
64   HB_SCRIPT_KATAKANA,
65   HB_SCRIPT_KHMER,
66   HB_SCRIPT_LAO,
67   HB_SCRIPT_LATIN,
68   HB_SCRIPT_MALAYALAM,
69   HB_SCRIPT_MONGOLIAN,
70   HB_SCRIPT_MYANMAR,
71   HB_SCRIPT_OGHAM,
72   HB_SCRIPT_OLD_ITALIC,
73   HB_SCRIPT_ORIYA,
74   HB_SCRIPT_RUNIC,
75   HB_SCRIPT_SINHALA,
76   HB_SCRIPT_SYRIAC,
77   HB_SCRIPT_TAMIL,
78   HB_SCRIPT_TELUGU,
79   HB_SCRIPT_THAANA,
80   HB_SCRIPT_THAI,
81   HB_SCRIPT_TIBETAN,
82   HB_SCRIPT_CANADIAN_ABORIGINAL,
83   HB_SCRIPT_YI,
84   HB_SCRIPT_TAGALOG,
85   HB_SCRIPT_HANUNOO,
86   HB_SCRIPT_BUHID,
87   HB_SCRIPT_TAGBANWA,
88
89   /* Unicode-4.0 additions */
90   HB_SCRIPT_BRAILLE,
91   HB_SCRIPT_CYPRIOT,
92   HB_SCRIPT_LIMBU,
93   HB_SCRIPT_OSMANYA,
94   HB_SCRIPT_SHAVIAN,
95   HB_SCRIPT_LINEAR_B,
96   HB_SCRIPT_TAI_LE,
97   HB_SCRIPT_UGARITIC,
98
99   /* Unicode-4.1 additions */
100   HB_SCRIPT_NEW_TAI_LUE,
101   HB_SCRIPT_BUGINESE,
102   HB_SCRIPT_GLAGOLITIC,
103   HB_SCRIPT_TIFINAGH,
104   HB_SCRIPT_SYLOTI_NAGRI,
105   HB_SCRIPT_OLD_PERSIAN,
106   HB_SCRIPT_KHAROSHTHI,
107
108   /* Unicode-5.0 additions */
109   HB_SCRIPT_UNKNOWN,
110   HB_SCRIPT_BALINESE,
111   HB_SCRIPT_CUNEIFORM,
112   HB_SCRIPT_PHOENICIAN,
113   HB_SCRIPT_PHAGS_PA,
114   HB_SCRIPT_NKO,
115
116   /* Unicode-5.1 additions */
117   HB_SCRIPT_KAYAH_LI,
118   HB_SCRIPT_LEPCHA,
119   HB_SCRIPT_REJANG,
120   HB_SCRIPT_SUNDANESE,
121   HB_SCRIPT_SAURASHTRA,
122   HB_SCRIPT_CHAM,
123   HB_SCRIPT_OL_CHIKI,
124   HB_SCRIPT_VAI,
125   HB_SCRIPT_CARIAN,
126   HB_SCRIPT_LYCIAN,
127   HB_SCRIPT_LYDIAN,
128
129   /* Unicode-5.2 additions */
130   HB_SCRIPT_AVESTAN,
131   HB_SCRIPT_BAMUM,
132   HB_SCRIPT_EGYPTIAN_HIEROGLYPHS,
133   HB_SCRIPT_IMPERIAL_ARAMAIC,
134   HB_SCRIPT_INSCRIPTIONAL_PAHLAVI,
135   HB_SCRIPT_INSCRIPTIONAL_PARTHIAN,
136   HB_SCRIPT_JAVANESE,
137   HB_SCRIPT_KAITHI,
138   HB_SCRIPT_TAI_THAM,
139   HB_SCRIPT_LISU,
140   HB_SCRIPT_MEETEI_MAYEK,
141   HB_SCRIPT_OLD_SOUTH_ARABIAN,
142   HB_SCRIPT_OLD_TURKIC,
143   HB_SCRIPT_SAMARITAN,
144   HB_SCRIPT_TAI_VIET,
145
146   /* Unicode-6.0 additions */
147   HB_SCRIPT_BATAK,
148   HB_SCRIPT_BRAHMI,
149   HB_SCRIPT_MANDAIC
150 };
151
152 hb_script_t
153 hb_glib_script_to_script (GUnicodeScript script)
154 {
155   if (likely ((unsigned int) script < ARRAY_LENGTH (glib_script_to_script)))
156     return glib_script_to_script[script];
157
158   if (unlikely (script == G_UNICODE_SCRIPT_INVALID_CODE))
159     return HB_SCRIPT_INVALID;
160
161   return HB_SCRIPT_UNKNOWN;
162 }
163
164 GUnicodeScript
165 hb_glib_script_from_script (hb_script_t script)
166 {
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;
171
172   if (unlikely (script == HB_SCRIPT_INVALID))
173     return G_UNICODE_SCRIPT_INVALID_CODE;
174
175   return G_UNICODE_SCRIPT_UNKNOWN;
176 }
177
178
179 static unsigned int
180 hb_glib_get_combining_class (hb_unicode_funcs_t *ufuncs,
181                              hb_codepoint_t      unicode,
182                              void               *user_data)
183
184 {
185   return g_unichar_combining_class (unicode);
186 }
187
188 static unsigned int
189 hb_glib_get_eastasian_width (hb_unicode_funcs_t *ufuncs,
190                              hb_codepoint_t      unicode,
191                              void               *user_data)
192 {
193   return g_unichar_iswide (unicode) ? 2 : 1;
194 }
195
196 static hb_unicode_general_category_t
197 hb_glib_get_general_category (hb_unicode_funcs_t *ufuncs,
198                               hb_codepoint_t      unicode,
199                               void               *user_data)
200
201 {
202   /* hb_unicode_general_category_t and GUnicodeType are identical */
203   return (hb_unicode_general_category_t) g_unichar_type (unicode);
204 }
205
206 static hb_codepoint_t
207 hb_glib_get_mirroring (hb_unicode_funcs_t *ufuncs,
208                        hb_codepoint_t      unicode,
209                        void               *user_data)
210 {
211   g_unichar_get_mirror_char (unicode, &unicode);
212   return unicode;
213 }
214
215 static hb_script_t
216 hb_glib_get_script (hb_unicode_funcs_t *ufuncs,
217                     hb_codepoint_t      unicode,
218                     void               *user_data)
219 {
220   return hb_glib_script_to_script (g_unichar_get_script (unicode));
221 }
222
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,
226
227   NULL, /* parent */
228   TRUE, /* immutable */
229   {
230     hb_glib_get_combining_class,
231     hb_glib_get_eastasian_width,
232     hb_glib_get_general_category,
233     hb_glib_get_mirroring,
234     hb_glib_get_script
235   }
236 };
237
238 hb_unicode_funcs_t *
239 hb_glib_get_unicode_funcs (void)
240 {
241   return &_hb_glib_unicode_funcs;
242 }
243
244
245 HB_END_DECLS