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"
42 #define HB_UNICODE_FUNC_IMPLEMENT(return_type, name, default_value) \
46 hb_unicode_get_##name##_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, \
47 hb_codepoint_t unicode HB_UNUSED, \
48 void *user_data HB_UNUSED) \
50 return default_value; \
53 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
54 #undef HB_UNICODE_FUNC_IMPLEMENT
57 hb_unicode_funcs_t _hb_unicode_funcs_nil = {
58 HB_OBJECT_HEADER_STATIC,
63 #define HB_UNICODE_FUNC_IMPLEMENT(return_type, name, default_value) hb_unicode_get_##name##_nil,
64 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
65 #undef HB_UNICODE_FUNC_IMPLEMENT
71 hb_unicode_funcs_get_default (void)
73 return &_hb_unicode_funcs_default;
77 hb_unicode_funcs_create (hb_unicode_funcs_t *parent)
79 hb_unicode_funcs_t *ufuncs;
81 if (!(ufuncs = hb_object_create<hb_unicode_funcs_t> ()))
82 return &_hb_unicode_funcs_nil;
85 parent = &_hb_unicode_funcs_nil;
87 hb_unicode_funcs_make_immutable (parent);
88 ufuncs->parent = hb_unicode_funcs_reference (parent);
90 ufuncs->get = parent->get;
92 /* We can safely copy user_data from parent since we hold a reference
93 * onto it and it's immutable. We should not copy the destroy notifiers
95 ufuncs->user_data = parent->user_data;
101 hb_unicode_funcs_get_empty (void)
103 return &_hb_unicode_funcs_nil;
107 hb_unicode_funcs_reference (hb_unicode_funcs_t *ufuncs)
109 return hb_object_reference (ufuncs);
113 hb_unicode_funcs_destroy (hb_unicode_funcs_t *ufuncs)
115 if (!hb_object_destroy (ufuncs)) return;
117 #define HB_UNICODE_FUNC_IMPLEMENT(return_type, name, default_value) \
118 if (ufuncs->destroy.name) ufuncs->destroy.name (ufuncs->user_data.name);
119 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
120 #undef HB_UNICODE_FUNC_IMPLEMENT
122 hb_unicode_funcs_destroy (ufuncs->parent);
128 hb_unicode_funcs_set_user_data (hb_unicode_funcs_t *ufuncs,
129 hb_user_data_key_t *key,
131 hb_destroy_func_t destroy)
133 return hb_object_set_user_data (ufuncs, key, data, destroy);
137 hb_unicode_funcs_get_user_data (hb_unicode_funcs_t *ufuncs,
138 hb_user_data_key_t *key)
140 return hb_object_get_user_data (ufuncs, key);
145 hb_unicode_funcs_make_immutable (hb_unicode_funcs_t *ufuncs)
147 if (hb_object_is_inert (ufuncs))
150 ufuncs->immutable = TRUE;
154 hb_unicode_funcs_is_immutable (hb_unicode_funcs_t *ufuncs)
156 return ufuncs->immutable;
160 hb_unicode_funcs_get_parent (hb_unicode_funcs_t *ufuncs)
162 return ufuncs->parent ? ufuncs->parent : &_hb_unicode_funcs_nil;
166 #define HB_UNICODE_FUNC_IMPLEMENT(return_type, name, default_value) \
169 hb_unicode_funcs_set_##name##_func (hb_unicode_funcs_t *ufuncs, \
170 hb_unicode_get_##name##_func_t func, \
172 hb_destroy_func_t destroy) \
174 if (ufuncs->immutable) \
177 if (ufuncs->destroy.name) \
178 ufuncs->destroy.name (ufuncs->user_data.name); \
181 ufuncs->get.name = func; \
182 ufuncs->user_data.name = user_data; \
183 ufuncs->destroy.name = destroy; \
185 ufuncs->get.name = ufuncs->parent->get.name; \
186 ufuncs->user_data.name = ufuncs->parent->user_data.name; \
187 ufuncs->destroy.name = NULL; \
192 hb_unicode_get_##name (hb_unicode_funcs_t *ufuncs, \
193 hb_codepoint_t unicode) \
195 return ufuncs->get.name (ufuncs, unicode, ufuncs->user_data.name); \
198 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
199 #undef HB_UNICODE_FUNC_IMPLEMENT