2 * Copyright © 2009 Red Hat, Inc.
3 * Copyright © 2011 Codethink Limited
4 * Copyright © 2010,2011 Google, Inc.
6 * This is part of HarfBuzz, a text shaping library.
8 * Permission is hereby granted, without written agreement and without
9 * license or royalty fees, to use, copy, modify, and distribute this
10 * software and its documentation for any purpose, provided that the
11 * above copyright notice and the following two paragraphs appear in
12 * all copies of this software.
14 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
15 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
17 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
20 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
21 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
23 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
24 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
26 * Red Hat Author(s): Behdad Esfahbod
27 * Codethink Author(s): Ryan Lortie
28 * Google Author(s): Behdad Esfahbod
31 #include "hb-private.hh"
33 #include "hb-unicode-private.hh"
43 hb_unicode_get_combining_class_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
44 hb_codepoint_t unicode HB_UNUSED,
45 void *user_data HB_UNUSED)
51 hb_unicode_get_eastasian_width_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
52 hb_codepoint_t unicode HB_UNUSED,
53 void *user_data HB_UNUSED)
58 static hb_unicode_general_category_t
59 hb_unicode_get_general_category_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
60 hb_codepoint_t unicode HB_UNUSED,
61 void *user_data HB_UNUSED)
63 return HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER;
67 hb_unicode_get_mirroring_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
68 hb_codepoint_t unicode HB_UNUSED,
69 void *user_data HB_UNUSED)
75 hb_unicode_get_script_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
76 hb_codepoint_t unicode HB_UNUSED,
77 void *user_data HB_UNUSED)
79 return HB_SCRIPT_UNKNOWN;
83 extern HB_INTERNAL hb_unicode_funcs_t _hb_unicode_funcs_nil;
84 hb_unicode_funcs_t _hb_unicode_funcs_nil = {
85 HB_OBJECT_HEADER_STATIC,
90 hb_unicode_get_combining_class_nil,
91 hb_unicode_get_eastasian_width_nil,
92 hb_unicode_get_general_category_nil,
93 hb_unicode_get_mirroring_nil,
94 hb_unicode_get_script_nil,
100 hb_unicode_funcs_get_default (void)
102 return &_hb_unicode_funcs_default;
106 hb_unicode_funcs_create (hb_unicode_funcs_t *parent)
108 hb_unicode_funcs_t *ufuncs;
110 if (!(ufuncs = hb_object_create<hb_unicode_funcs_t> ()))
111 return &_hb_unicode_funcs_nil;
114 parent = &_hb_unicode_funcs_nil;
116 hb_unicode_funcs_make_immutable (parent);
117 ufuncs->parent = hb_unicode_funcs_reference (parent);
119 ufuncs->get = parent->get;
121 /* We can safely copy user_data from parent since we hold a reference
122 * onto it and it's immutable. We should not copy the destroy notifiers
124 ufuncs->user_data = parent->user_data;
130 hb_unicode_funcs_reference (hb_unicode_funcs_t *ufuncs)
132 return hb_object_reference (ufuncs);
136 hb_unicode_funcs_destroy (hb_unicode_funcs_t *ufuncs)
138 if (!hb_object_destroy (ufuncs)) return;
140 #define DESTROY(name) if (ufuncs->destroy.name) ufuncs->destroy.name (ufuncs->user_data.name)
141 DESTROY (combining_class);
142 DESTROY (eastasian_width);
143 DESTROY (general_category);
148 hb_unicode_funcs_destroy (ufuncs->parent);
154 hb_unicode_funcs_set_user_data (hb_unicode_funcs_t *ufuncs,
155 hb_user_data_key_t *key,
157 hb_destroy_func_t destroy)
159 return hb_object_set_user_data (ufuncs, key, data, destroy);
163 hb_unicode_funcs_get_user_data (hb_unicode_funcs_t *ufuncs,
164 hb_user_data_key_t *key)
166 return hb_object_get_user_data (ufuncs, key);
171 hb_unicode_funcs_make_immutable (hb_unicode_funcs_t *ufuncs)
173 if (hb_object_is_inert (ufuncs))
176 ufuncs->immutable = TRUE;
180 hb_unicode_funcs_is_immutable (hb_unicode_funcs_t *ufuncs)
182 return ufuncs->immutable;
186 hb_unicode_funcs_get_parent (hb_unicode_funcs_t *ufuncs)
188 return ufuncs->parent ? ufuncs->parent : &_hb_unicode_funcs_nil;
192 #define IMPLEMENT(return_type, name) \
195 hb_unicode_funcs_set_##name##_func (hb_unicode_funcs_t *ufuncs, \
196 hb_unicode_get_##name##_func_t func, \
198 hb_destroy_func_t destroy) \
200 if (ufuncs->immutable) \
203 if (ufuncs->destroy.name) \
204 ufuncs->destroy.name (ufuncs->user_data.name); \
207 ufuncs->get.name = func; \
208 ufuncs->user_data.name = user_data; \
209 ufuncs->destroy.name = destroy; \
210 } else if (ufuncs->parent != NULL) { \
211 ufuncs->get.name = ufuncs->parent->get.name; \
212 ufuncs->user_data.name = ufuncs->parent->user_data.name; \
213 ufuncs->destroy.name = NULL; \
215 ufuncs->get.name = hb_unicode_get_##name##_nil; \
216 ufuncs->user_data.name = NULL; \
217 ufuncs->destroy.name = NULL; \
222 hb_unicode_get_##name (hb_unicode_funcs_t *ufuncs, \
223 hb_codepoint_t unicode) \
225 return ufuncs->get.name (ufuncs, unicode, ufuncs->user_data.name); \
228 IMPLEMENT (unsigned int, combining_class)
229 IMPLEMENT (unsigned int, eastasian_width)
230 IMPLEMENT (hb_unicode_general_category_t, general_category)
231 IMPLEMENT (hb_codepoint_t, mirroring)
232 IMPLEMENT (hb_script_t, script)