[HB] Initialize unicode funcs to nil getters
[framework/uifw/harfbuzz.git] / src / hb-unicode.c
1 /*
2  * Copyright (C) 2009  Red Hat, Inc.
3  *
4  *  This is part of HarfBuzz, an OpenType Layout engine 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 /*
32  * hb_unicode_funcs_t
33  */
34
35 static hb_codepoint_t hb_unicode_get_mirroring_char_nil (hb_codepoint_t unicode) { return unicode; }
36 static hb_category_t hb_unicode_get_general_category_nil (hb_codepoint_t unicode) { return HB_CATEGORY_OTHER_LETTER; }
37 static hb_script_t hb_unicode_get_script_nil (hb_codepoint_t unicode) { return HB_SCRIPT_UNKNOWN; }
38 static unsigned int hb_unicode_get_combining_class_nil (hb_codepoint_t unicode) { return 0; }
39 static unsigned int hb_unicode_get_eastasian_width_nil (hb_codepoint_t unicode) { return 1; }
40
41 static hb_unicode_funcs_t _hb_unicode_funcs_nil = {
42   HB_REFERENCE_COUNT_INVALID, /* ref_count */
43
44   hb_unicode_get_general_category_nil,
45   hb_unicode_get_combining_class_nil,
46   hb_unicode_get_mirroring_char_nil,
47   hb_unicode_get_script_nil,
48   hb_unicode_get_eastasian_width_nil
49 };
50
51 hb_unicode_funcs_t *
52 hb_unicode_funcs_create (void)
53 {
54   hb_unicode_funcs_t *ufuncs;
55
56   if (!HB_OBJECT_DO_CREATE (hb_unicode_funcs_t, ufuncs))
57     return &_hb_unicode_funcs_nil;
58
59   *ufuncs = _hb_unicode_funcs_nil;
60   HB_OBJECT_DO_INIT (ufuncs);
61
62   return ufuncs;
63 }
64
65 hb_unicode_funcs_t *
66 hb_unicode_funcs_reference (hb_unicode_funcs_t *ufuncs)
67 {
68   HB_OBJECT_DO_REFERENCE (ufuncs);
69 }
70
71 unsigned int
72 hb_unicode_funcs_get_reference_count (hb_unicode_funcs_t *ufuncs)
73 {
74   HB_OBJECT_DO_GET_REFERENCE_COUNT (ufuncs);
75 }
76
77 void
78 hb_unicode_funcs_destroy (hb_unicode_funcs_t *ufuncs)
79 {
80   HB_OBJECT_DO_DESTROY (ufuncs);
81
82   free (ufuncs);
83 }
84
85 hb_unicode_funcs_t *
86 hb_unicode_funcs_copy (hb_unicode_funcs_t *other_ufuncs)
87 {
88   hb_unicode_funcs_t *ufuncs;
89
90   if (!HB_OBJECT_DO_CREATE (hb_unicode_funcs_t, ufuncs))
91     return &_hb_unicode_funcs_nil;
92
93   *ufuncs = *other_ufuncs;
94   HB_OBJECT_DO_INIT (ufuncs);
95
96   return ufuncs;
97 }
98
99
100 void
101 hb_unicode_funcs_set_mirroring_char_func (hb_unicode_funcs_t *ufuncs,
102                                           hb_unicode_get_mirroring_char_func_t mirroring_char_func)
103 {
104   if (HB_OBJECT_IS_INERT (ufuncs))
105     return;
106
107   ufuncs->get_mirroring_char = mirroring_char_func ? mirroring_char_func : hb_unicode_get_mirroring_char_nil;
108 }
109
110 void
111 hb_unicode_funcs_set_general_category_func (hb_unicode_funcs_t *ufuncs,
112                                             hb_unicode_get_general_category_func_t general_category_func)
113 {
114   if (HB_OBJECT_IS_INERT (ufuncs))
115     return;
116
117   ufuncs->get_general_category = general_category_func ? general_category_func : hb_unicode_get_general_category_nil;
118 }
119
120 void
121 hb_unicode_funcs_set_script_func (hb_unicode_funcs_t *ufuncs,
122                                   hb_unicode_get_script_func_t script_func)
123 {
124   if (HB_OBJECT_IS_INERT (ufuncs))
125     return;
126
127   ufuncs->get_script = script_func ? script_func : hb_unicode_get_script_nil;
128 }
129
130 void
131 hb_unicode_funcs_set_combining_class_func (hb_unicode_funcs_t *ufuncs,
132                                            hb_unicode_get_combining_class_func_t combining_class_func)
133 {
134   if (HB_OBJECT_IS_INERT (ufuncs))
135     return;
136
137   ufuncs->get_combining_class = combining_class_func ? combining_class_func : hb_unicode_get_combining_class_nil;
138 }
139
140 void
141 hb_unicode_funcs_set_eastasian_width_func (hb_unicode_funcs_t *ufuncs,
142                                            hb_unicode_get_eastasian_width_func_t eastasian_width_func)
143 {
144   if (HB_OBJECT_IS_INERT (ufuncs))
145     return;
146
147   ufuncs->get_eastasian_width = eastasian_width_func ? eastasian_width_func : hb_unicode_get_eastasian_width_nil;
148 }
149