19a891b4a84bd3c06377b4c29f29ea4ab968107e
[profile/ivi/org.tizen.video-player.git] / src / hb-unicode.c
1 /*
2  * Copyright (C) 2009  Red Hat, Inc.
3  *
4  *  This is part of HarfBuzz, a text shaping library.
5  *
6  * Permission is hereby granted, without written agreement and without
7  * license or royalty fees, to use, copy, modify, and distribute this
8  * software and its documentation for any purpose, provided that the
9  * above copyright notice and the following two paragraphs appear in
10  * all copies of this software.
11  *
12  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16  * DAMAGE.
17  *
18  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23  *
24  * Red Hat Author(s): Behdad Esfahbod
25  */
26
27 #include "hb-private.h"
28
29 #include "hb-unicode-private.h"
30
31 HB_BEGIN_DECLS
32
33
34 /*
35  * hb_unicode_funcs_t
36  */
37
38 static hb_codepoint_t hb_unicode_get_mirroring_nil (hb_codepoint_t unicode) { return unicode; }
39 static hb_category_t hb_unicode_get_general_category_nil (hb_codepoint_t unicode HB_UNUSED) { return HB_CATEGORY_OTHER_LETTER; }
40 static hb_script_t hb_unicode_get_script_nil (hb_codepoint_t unicode HB_UNUSED) { return HB_SCRIPT_UNKNOWN; }
41 static unsigned int hb_unicode_get_combining_class_nil (hb_codepoint_t unicode HB_UNUSED) { return 0; }
42 static unsigned int hb_unicode_get_eastasian_width_nil (hb_codepoint_t unicode HB_UNUSED) { return 1; }
43
44 hb_unicode_funcs_t _hb_unicode_funcs_nil = {
45   HB_REFERENCE_COUNT_INVALID, /* ref_count */
46   TRUE, /* immutable */
47   {
48     hb_unicode_get_general_category_nil,
49     hb_unicode_get_combining_class_nil,
50     hb_unicode_get_mirroring_nil,
51     hb_unicode_get_script_nil,
52     hb_unicode_get_eastasian_width_nil
53   }
54 };
55
56 hb_unicode_funcs_t *
57 hb_unicode_funcs_create (void)
58 {
59   hb_unicode_funcs_t *ufuncs;
60
61   if (!HB_OBJECT_DO_CREATE (hb_unicode_funcs_t, ufuncs))
62     return &_hb_unicode_funcs_nil;
63
64   ufuncs->v = _hb_unicode_funcs_nil.v;
65
66   return ufuncs;
67 }
68
69 hb_unicode_funcs_t *
70 hb_unicode_funcs_reference (hb_unicode_funcs_t *ufuncs)
71 {
72   HB_OBJECT_DO_REFERENCE (ufuncs);
73 }
74
75 unsigned int
76 hb_unicode_funcs_get_reference_count (hb_unicode_funcs_t *ufuncs)
77 {
78   HB_OBJECT_DO_GET_REFERENCE_COUNT (ufuncs);
79 }
80
81 void
82 hb_unicode_funcs_destroy (hb_unicode_funcs_t *ufuncs)
83 {
84   HB_OBJECT_DO_DESTROY (ufuncs);
85
86   free (ufuncs);
87 }
88
89 hb_unicode_funcs_t *
90 hb_unicode_funcs_copy (hb_unicode_funcs_t *other_ufuncs)
91 {
92   hb_unicode_funcs_t *ufuncs;
93
94   if (!HB_OBJECT_DO_CREATE (hb_unicode_funcs_t, ufuncs))
95     return &_hb_unicode_funcs_nil;
96
97   ufuncs->v = other_ufuncs->v;
98
99   return ufuncs;
100 }
101
102 void
103 hb_unicode_funcs_make_immutable (hb_unicode_funcs_t *ufuncs)
104 {
105   if (HB_OBJECT_IS_INERT (ufuncs))
106     return;
107
108   ufuncs->immutable = TRUE;
109 }
110
111
112 void
113 hb_unicode_funcs_set_mirroring_func (hb_unicode_funcs_t *ufuncs,
114                                      hb_unicode_get_mirroring_func_t mirroring_func)
115 {
116   if (ufuncs->immutable)
117     return;
118
119   ufuncs->v.get_mirroring = mirroring_func ? mirroring_func : hb_unicode_get_mirroring_nil;
120 }
121
122 void
123 hb_unicode_funcs_set_general_category_func (hb_unicode_funcs_t *ufuncs,
124                                             hb_unicode_get_general_category_func_t general_category_func)
125 {
126   if (ufuncs->immutable)
127     return;
128
129   ufuncs->v.get_general_category = general_category_func ? general_category_func : hb_unicode_get_general_category_nil;
130 }
131
132 void
133 hb_unicode_funcs_set_script_func (hb_unicode_funcs_t *ufuncs,
134                                   hb_unicode_get_script_func_t script_func)
135 {
136   if (ufuncs->immutable)
137     return;
138
139   ufuncs->v.get_script = script_func ? script_func : hb_unicode_get_script_nil;
140 }
141
142 void
143 hb_unicode_funcs_set_combining_class_func (hb_unicode_funcs_t *ufuncs,
144                                            hb_unicode_get_combining_class_func_t combining_class_func)
145 {
146   if (ufuncs->immutable)
147     return;
148
149   ufuncs->v.get_combining_class = combining_class_func ? combining_class_func : hb_unicode_get_combining_class_nil;
150 }
151
152 void
153 hb_unicode_funcs_set_eastasian_width_func (hb_unicode_funcs_t *ufuncs,
154                                            hb_unicode_get_eastasian_width_func_t eastasian_width_func)
155 {
156   if (ufuncs->immutable)
157     return;
158
159   ufuncs->v.get_eastasian_width = eastasian_width_func ? eastasian_width_func : hb_unicode_get_eastasian_width_nil;
160 }
161
162
163 hb_unicode_get_mirroring_func_t
164 hb_unicode_funcs_get_mirroring_func (hb_unicode_funcs_t *ufuncs)
165 {
166   return ufuncs->v.get_mirroring;
167 }
168
169 hb_unicode_get_general_category_func_t
170 hb_unicode_funcs_get_general_category_func (hb_unicode_funcs_t *ufuncs)
171 {
172   return ufuncs->v.get_general_category;
173 }
174
175 hb_unicode_get_script_func_t
176 hb_unicode_funcs_get_script_func (hb_unicode_funcs_t *ufuncs)
177 {
178   return ufuncs->v.get_script;
179 }
180
181 hb_unicode_get_combining_class_func_t
182 hb_unicode_funcs_get_combining_class_func (hb_unicode_funcs_t *ufuncs)
183 {
184   return ufuncs->v.get_combining_class;
185 }
186
187 hb_unicode_get_eastasian_width_func_t
188 hb_unicode_funcs_get_eastasian_width_func (hb_unicode_funcs_t *ufuncs)
189 {
190   return ufuncs->v.get_eastasian_width;
191 }
192
193
194
195 hb_codepoint_t
196 hb_unicode_get_mirroring (hb_unicode_funcs_t *ufuncs,
197                           hb_codepoint_t unicode)
198 {
199   return ufuncs->v.get_mirroring (unicode);
200 }
201
202 hb_category_t
203 hb_unicode_get_general_category (hb_unicode_funcs_t *ufuncs,
204                                  hb_codepoint_t unicode)
205 {
206   return ufuncs->v.get_general_category (unicode);
207 }
208
209 hb_script_t
210 hb_unicode_get_script (hb_unicode_funcs_t *ufuncs,
211                        hb_codepoint_t unicode)
212 {
213   return ufuncs->v.get_script (unicode);
214 }
215
216 unsigned int
217 hb_unicode_get_combining_class (hb_unicode_funcs_t *ufuncs,
218                                 hb_codepoint_t unicode)
219 {
220   return ufuncs->v.get_combining_class (unicode);
221 }
222
223 unsigned int
224 hb_unicode_get_eastasian_width (hb_unicode_funcs_t *ufuncs,
225                                 hb_codepoint_t unicode)
226 {
227   return ufuncs->v.get_eastasian_width (unicode);
228 }
229
230
231
232 #define LTR HB_DIRECTION_LTR
233 #define RTL HB_DIRECTION_RTL
234 const hb_direction_t horiz_dir[] =
235 {
236   LTR,  /* Zyyy */
237   LTR,  /* Qaai */
238   RTL,  /* Arab */
239   LTR,  /* Armn */
240   LTR,  /* Beng */
241   LTR,  /* Bopo */
242   LTR,  /* Cher */
243   LTR,  /* Qaac */
244   LTR,  /* Cyrl (Cyrs) */
245   LTR,  /* Dsrt */
246   LTR,  /* Deva */
247   LTR,  /* Ethi */
248   LTR,  /* Geor (Geon, Geoa) */
249   LTR,  /* Goth */
250   LTR,  /* Grek */
251   LTR,  /* Gujr */
252   LTR,  /* Guru */
253   LTR,  /* Hani */
254   LTR,  /* Hang */
255   RTL,  /* Hebr */
256   LTR,  /* Hira */
257   LTR,  /* Knda */
258   LTR,  /* Kana */
259   LTR,  /* Khmr */
260   LTR,  /* Laoo */
261   LTR,  /* Latn (Latf, Latg) */
262   LTR,  /* Mlym */
263   LTR,  /* Mong */
264   LTR,  /* Mymr */
265   LTR,  /* Ogam */
266   LTR,  /* Ital */
267   LTR,  /* Orya */
268   LTR,  /* Runr */
269   LTR,  /* Sinh */
270   RTL,  /* Syrc (Syrj, Syrn, Syre) */
271   LTR,  /* Taml */
272   LTR,  /* Telu */
273   RTL,  /* Thaa */
274   LTR,  /* Thai */
275   LTR,  /* Tibt */
276   LTR,  /* Cans */
277   LTR,  /* Yiii */
278   LTR,  /* Tglg */
279   LTR,  /* Hano */
280   LTR,  /* Buhd */
281   LTR,  /* Tagb */
282
283   /* Unicode-4.0 additions */
284   LTR,  /* Brai */
285   RTL,  /* Cprt */
286   LTR,  /* Limb */
287   LTR,  /* Osma */
288   LTR,  /* Shaw */
289   LTR,  /* Linb */
290   LTR,  /* Tale */
291   LTR,  /* Ugar */
292
293   /* Unicode-4.1 additions */
294   LTR,  /* Talu */
295   LTR,  /* Bugi */
296   LTR,  /* Glag */
297   LTR,  /* Tfng */
298   LTR,  /* Sylo */
299   LTR,  /* Xpeo */
300   LTR,  /* Khar */
301
302   /* Unicode-5.0 additions */
303   LTR,  /* Zzzz */
304   LTR,  /* Bali */
305   LTR,  /* Xsux */
306   RTL,  /* Phnx */
307   LTR,  /* Phag */
308   RTL,  /* Nkoo */
309
310   /* Unicode-5.1 additions */
311   LTR,  /* Kali */
312   LTR,  /* Lepc */
313   LTR,  /* Rjng */
314   LTR,  /* Sund */
315   LTR,  /* Saur */
316   LTR,  /* Cham */
317   LTR,  /* Olck */
318   LTR,  /* Vaii */
319   LTR,  /* Cari */
320   LTR,  /* Lyci */
321   LTR,  /* Lydi */
322
323   /* Unicode-5.2 additions */
324   RTL,  /* Avst */
325   LTR,  /* Bamu */
326   LTR,  /* Egyp */
327   RTL,  /* Armi */
328   RTL,  /* Phli */
329   RTL,  /* Prti */
330   LTR,  /* Java */
331   LTR,  /* Kthi */
332   LTR,  /* Lisu */
333   LTR,  /* Mtei */
334   RTL,  /* Sarb */
335   RTL,  /* Orkh */
336   RTL,  /* Samr */
337   LTR,  /* Lana */
338   LTR   /* Tavt */
339 };
340 #undef LTR
341 #undef RTL
342
343 hb_direction_t
344 _hb_script_get_horizontal_direction (hb_script_t script)
345 {
346   if (unlikely ((unsigned int) script >= ARRAY_LENGTH (horiz_dir)))
347     return HB_DIRECTION_LTR;
348
349   return horiz_dir[script];
350 }
351
352
353 HB_END_DECLS