2 * Copyright (C) 2009 Red Hat, Inc.
4 * This is part of HarfBuzz, a text shaping library.
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.
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
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.
24 * Red Hat Author(s): Behdad Esfahbod
27 #include "hb-private.h"
29 #include "hb-unicode-private.h"
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; }
44 hb_unicode_funcs_t _hb_unicode_funcs_nil = {
45 HB_REFERENCE_COUNT_INVALID, /* ref_count */
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
57 hb_unicode_funcs_create (void)
59 hb_unicode_funcs_t *ufuncs;
61 if (!HB_OBJECT_DO_CREATE (hb_unicode_funcs_t, ufuncs))
62 return &_hb_unicode_funcs_nil;
64 ufuncs->v = _hb_unicode_funcs_nil.v;
70 hb_unicode_funcs_reference (hb_unicode_funcs_t *ufuncs)
72 HB_OBJECT_DO_REFERENCE (ufuncs);
76 hb_unicode_funcs_get_reference_count (hb_unicode_funcs_t *ufuncs)
78 HB_OBJECT_DO_GET_REFERENCE_COUNT (ufuncs);
82 hb_unicode_funcs_destroy (hb_unicode_funcs_t *ufuncs)
84 HB_OBJECT_DO_DESTROY (ufuncs);
90 hb_unicode_funcs_copy (hb_unicode_funcs_t *other_ufuncs)
92 hb_unicode_funcs_t *ufuncs;
94 if (!HB_OBJECT_DO_CREATE (hb_unicode_funcs_t, ufuncs))
95 return &_hb_unicode_funcs_nil;
97 ufuncs->v = other_ufuncs->v;
103 hb_unicode_funcs_make_immutable (hb_unicode_funcs_t *ufuncs)
105 if (HB_OBJECT_IS_INERT (ufuncs))
108 ufuncs->immutable = TRUE;
113 hb_unicode_funcs_set_mirroring_func (hb_unicode_funcs_t *ufuncs,
114 hb_unicode_get_mirroring_func_t mirroring_func)
116 if (ufuncs->immutable)
119 ufuncs->v.get_mirroring = mirroring_func ? mirroring_func : hb_unicode_get_mirroring_nil;
123 hb_unicode_funcs_set_general_category_func (hb_unicode_funcs_t *ufuncs,
124 hb_unicode_get_general_category_func_t general_category_func)
126 if (ufuncs->immutable)
129 ufuncs->v.get_general_category = general_category_func ? general_category_func : hb_unicode_get_general_category_nil;
133 hb_unicode_funcs_set_script_func (hb_unicode_funcs_t *ufuncs,
134 hb_unicode_get_script_func_t script_func)
136 if (ufuncs->immutable)
139 ufuncs->v.get_script = script_func ? script_func : hb_unicode_get_script_nil;
143 hb_unicode_funcs_set_combining_class_func (hb_unicode_funcs_t *ufuncs,
144 hb_unicode_get_combining_class_func_t combining_class_func)
146 if (ufuncs->immutable)
149 ufuncs->v.get_combining_class = combining_class_func ? combining_class_func : hb_unicode_get_combining_class_nil;
153 hb_unicode_funcs_set_eastasian_width_func (hb_unicode_funcs_t *ufuncs,
154 hb_unicode_get_eastasian_width_func_t eastasian_width_func)
156 if (ufuncs->immutable)
159 ufuncs->v.get_eastasian_width = eastasian_width_func ? eastasian_width_func : hb_unicode_get_eastasian_width_nil;
163 hb_unicode_get_mirroring_func_t
164 hb_unicode_funcs_get_mirroring_func (hb_unicode_funcs_t *ufuncs)
166 return ufuncs->v.get_mirroring;
169 hb_unicode_get_general_category_func_t
170 hb_unicode_funcs_get_general_category_func (hb_unicode_funcs_t *ufuncs)
172 return ufuncs->v.get_general_category;
175 hb_unicode_get_script_func_t
176 hb_unicode_funcs_get_script_func (hb_unicode_funcs_t *ufuncs)
178 return ufuncs->v.get_script;
181 hb_unicode_get_combining_class_func_t
182 hb_unicode_funcs_get_combining_class_func (hb_unicode_funcs_t *ufuncs)
184 return ufuncs->v.get_combining_class;
187 hb_unicode_get_eastasian_width_func_t
188 hb_unicode_funcs_get_eastasian_width_func (hb_unicode_funcs_t *ufuncs)
190 return ufuncs->v.get_eastasian_width;
196 hb_unicode_get_mirroring (hb_unicode_funcs_t *ufuncs,
197 hb_codepoint_t unicode)
199 return ufuncs->v.get_mirroring (unicode);
203 hb_unicode_get_general_category (hb_unicode_funcs_t *ufuncs,
204 hb_codepoint_t unicode)
206 return ufuncs->v.get_general_category (unicode);
210 hb_unicode_get_script (hb_unicode_funcs_t *ufuncs,
211 hb_codepoint_t unicode)
213 return ufuncs->v.get_script (unicode);
217 hb_unicode_get_combining_class (hb_unicode_funcs_t *ufuncs,
218 hb_codepoint_t unicode)
220 return ufuncs->v.get_combining_class (unicode);
224 hb_unicode_get_eastasian_width (hb_unicode_funcs_t *ufuncs,
225 hb_codepoint_t unicode)
227 return ufuncs->v.get_eastasian_width (unicode);
232 #define LTR HB_DIRECTION_LTR
233 #define RTL HB_DIRECTION_RTL
234 const hb_direction_t horiz_dir[] =
244 LTR, /* Cyrl (Cyrs) */
248 LTR, /* Geor (Geon, Geoa) */
261 LTR, /* Latn (Latf, Latg) */
270 RTL, /* Syrc (Syrj, Syrn, Syre) */
283 /* Unicode-4.0 additions */
293 /* Unicode-4.1 additions */
302 /* Unicode-5.0 additions */
310 /* Unicode-5.1 additions */
323 /* Unicode-5.2 additions */
344 _hb_script_get_horizontal_direction (hb_script_t script)
346 if (unlikely ((unsigned int) script >= ARRAY_LENGTH (horiz_dir)))
347 return HB_DIRECTION_LTR;
349 return horiz_dir[script];