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_unicode_general_category_t hb_unicode_get_general_category_nil (hb_codepoint_t unicode HB_UNUSED) { return HB_UNICODE_GENERAL_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;
112 hb_unicode_funcs_is_immutable (hb_unicode_funcs_t *ufuncs)
114 return ufuncs->immutable;
119 hb_unicode_funcs_set_mirroring_func (hb_unicode_funcs_t *ufuncs,
120 hb_unicode_get_mirroring_func_t mirroring_func)
122 if (ufuncs->immutable)
125 ufuncs->v.get_mirroring = mirroring_func ? mirroring_func : hb_unicode_get_mirroring_nil;
129 hb_unicode_funcs_set_general_category_func (hb_unicode_funcs_t *ufuncs,
130 hb_unicode_get_general_category_func_t general_category_func)
132 if (ufuncs->immutable)
135 ufuncs->v.get_general_category = general_category_func ? general_category_func : hb_unicode_get_general_category_nil;
139 hb_unicode_funcs_set_script_func (hb_unicode_funcs_t *ufuncs,
140 hb_unicode_get_script_func_t script_func)
142 if (ufuncs->immutable)
145 ufuncs->v.get_script = script_func ? script_func : hb_unicode_get_script_nil;
149 hb_unicode_funcs_set_combining_class_func (hb_unicode_funcs_t *ufuncs,
150 hb_unicode_get_combining_class_func_t combining_class_func)
152 if (ufuncs->immutable)
155 ufuncs->v.get_combining_class = combining_class_func ? combining_class_func : hb_unicode_get_combining_class_nil;
159 hb_unicode_funcs_set_eastasian_width_func (hb_unicode_funcs_t *ufuncs,
160 hb_unicode_get_eastasian_width_func_t eastasian_width_func)
162 if (ufuncs->immutable)
165 ufuncs->v.get_eastasian_width = eastasian_width_func ? eastasian_width_func : hb_unicode_get_eastasian_width_nil;
169 hb_unicode_get_mirroring_func_t
170 hb_unicode_funcs_get_mirroring_func (hb_unicode_funcs_t *ufuncs)
172 return ufuncs->v.get_mirroring;
175 hb_unicode_get_general_category_func_t
176 hb_unicode_funcs_get_general_category_func (hb_unicode_funcs_t *ufuncs)
178 return ufuncs->v.get_general_category;
181 hb_unicode_get_script_func_t
182 hb_unicode_funcs_get_script_func (hb_unicode_funcs_t *ufuncs)
184 return ufuncs->v.get_script;
187 hb_unicode_get_combining_class_func_t
188 hb_unicode_funcs_get_combining_class_func (hb_unicode_funcs_t *ufuncs)
190 return ufuncs->v.get_combining_class;
193 hb_unicode_get_eastasian_width_func_t
194 hb_unicode_funcs_get_eastasian_width_func (hb_unicode_funcs_t *ufuncs)
196 return ufuncs->v.get_eastasian_width;
202 hb_unicode_get_mirroring (hb_unicode_funcs_t *ufuncs,
203 hb_codepoint_t unicode)
205 return ufuncs->v.get_mirroring (unicode);
208 hb_unicode_general_category_t
209 hb_unicode_get_general_category (hb_unicode_funcs_t *ufuncs,
210 hb_codepoint_t unicode)
212 return ufuncs->v.get_general_category (unicode);
216 hb_unicode_get_script (hb_unicode_funcs_t *ufuncs,
217 hb_codepoint_t unicode)
219 return ufuncs->v.get_script (unicode);
223 hb_unicode_get_combining_class (hb_unicode_funcs_t *ufuncs,
224 hb_codepoint_t unicode)
226 return ufuncs->v.get_combining_class (unicode);
230 hb_unicode_get_eastasian_width (hb_unicode_funcs_t *ufuncs,
231 hb_codepoint_t unicode)
233 return ufuncs->v.get_eastasian_width (unicode);