fd1fd44f817c4aed3810727eff3a871d2bac774a
[framework/uifw/harfbuzz.git] / src / hb-unicode-private.hh
1 /*
2  * Copyright © 2009  Red Hat, Inc.
3  * Copyright © 2011  Codethink Limited
4  * Copyright © 2010,2011  Google, Inc.
5  *
6  *  This is part of HarfBuzz, a text shaping library.
7  *
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.
13  *
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
18  * DAMAGE.
19  *
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.
25  *
26  * Red Hat Author(s): Behdad Esfahbod
27  * Codethink Author(s): Ryan Lortie
28  * Google Author(s): Behdad Esfahbod
29  */
30
31 #ifndef HB_UNICODE_PRIVATE_HH
32 #define HB_UNICODE_PRIVATE_HH
33
34 #include "hb-private.hh"
35
36 #include "hb-unicode.h"
37 #include "hb-object-private.hh"
38
39
40
41 /*
42  * hb_unicode_funcs_t
43  */
44
45 #define HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS \
46   HB_UNICODE_FUNC_IMPLEMENT (combining_class) \
47   HB_UNICODE_FUNC_IMPLEMENT (eastasian_width) \
48   HB_UNICODE_FUNC_IMPLEMENT (general_category) \
49   HB_UNICODE_FUNC_IMPLEMENT (mirroring) \
50   HB_UNICODE_FUNC_IMPLEMENT (script) \
51   HB_UNICODE_FUNC_IMPLEMENT (compose) \
52   HB_UNICODE_FUNC_IMPLEMENT (decompose) \
53   /* ^--- Add new callbacks here */
54
55 /* Simple callbacks are those taking a hb_codepoint_t and returning a hb_codepoint_t */
56 #define HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE \
57   HB_UNICODE_FUNC_IMPLEMENT (unsigned int, combining_class) \
58   HB_UNICODE_FUNC_IMPLEMENT (unsigned int, eastasian_width) \
59   HB_UNICODE_FUNC_IMPLEMENT (hb_unicode_general_category_t, general_category) \
60   HB_UNICODE_FUNC_IMPLEMENT (hb_codepoint_t, mirroring) \
61   HB_UNICODE_FUNC_IMPLEMENT (hb_script_t, script) \
62   /* ^--- Add new simple callbacks here */
63
64 struct _hb_unicode_funcs_t {
65   hb_object_header_t header;
66   ASSERT_POD ();
67
68   hb_unicode_funcs_t *parent;
69
70   bool immutable;
71
72   /* Don't access these directly.  Call hb_unicode_*() instead. */
73
74   struct {
75 #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_func_t name;
76     HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
77 #undef HB_UNICODE_FUNC_IMPLEMENT
78   } func;
79
80   struct {
81 #define HB_UNICODE_FUNC_IMPLEMENT(name) void *name;
82     HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
83 #undef HB_UNICODE_FUNC_IMPLEMENT
84   } user_data;
85
86   struct {
87 #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_destroy_func_t name;
88     HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
89 #undef HB_UNICODE_FUNC_IMPLEMENT
90   } destroy;
91 };
92
93
94 #ifdef HAVE_GLIB
95 extern HB_INTERNAL const hb_unicode_funcs_t _hb_glib_unicode_funcs;
96 #define _hb_unicode_funcs_default _hb_glib_unicode_funcs
97 #elif defined(HAVE_ICU)
98 extern HB_INTERNAL const hb_unicode_funcs_t _hb_icu_unicode_funcs;
99 #define _hb_unicode_funcs_default _hb_icu_unicode_funcs
100 #else
101 #define HB_UNICODE_FUNCS_NIL 1
102 extern HB_INTERNAL const hb_unicode_funcs_t _hb_unicode_funcs_nil;
103 #define _hb_unicode_funcs_default _hb_unicode_funcs_nil
104 #endif
105
106
107 HB_INTERNAL unsigned int
108 _hb_unicode_modified_combining_class (hb_unicode_funcs_t *ufuncs,
109                                       hb_codepoint_t      unicode);
110
111 static inline hb_bool_t
112 _hb_unicode_is_variation_selector (hb_codepoint_t unicode)
113 {
114   return unlikely ((unicode >=  0x180B && unicode <=  0x180D) || /* MONGOLIAN FREE VARIATION SELECTOR ONE..THREE */
115                    (unicode >=  0xFE00 && unicode <=  0xFE0F) || /* VARIATION SELECTOR-1..16 */
116                    (unicode >= 0xE0100 && unicode <= 0xE01EF));  /* VARIATION SELECTOR-17..256 */
117 }
118
119 /* Zero-Width invisible characters:
120  *
121  *  00AD  SOFT HYPHEN
122  *  034F  COMBINING GRAPHEME JOINER
123  *
124  *  200B  ZERO WIDTH SPACE
125  *  200C  ZERO WIDTH NON-JOINER
126  *  200D  ZERO WIDTH JOINER
127  *  200E  LEFT-TO-RIGHT MARK
128  *  200F  RIGHT-TO-LEFT MARK
129  *
130  *  2028  LINE SEPARATOR
131  *
132  *  202A  LEFT-TO-RIGHT EMBEDDING
133  *  202B  RIGHT-TO-LEFT EMBEDDING
134  *  202C  POP DIRECTIONAL FORMATTING
135  *  202D  LEFT-TO-RIGHT OVERRIDE
136  *  202E  RIGHT-TO-LEFT OVERRIDE
137  *
138  *  2060  WORD JOINER
139  *  2061  FUNCTION APPLICATION
140  *  2062  INVISIBLE TIMES
141  *  2063  INVISIBLE SEPARATOR
142  *
143  *  FEFF  ZERO WIDTH NO-BREAK SPACE
144  */
145 static inline hb_bool_t
146 _hb_unicode_is_zero_width (hb_codepoint_t ch)
147 {
148   return ((ch & ~0x007F) == 0x2000 && (
149           (ch >= 0x200B && ch <= 0x200F) ||
150           (ch >= 0x202A && ch <= 0x202E) ||
151           (ch >= 0x2060 && ch <= 0x2063) ||
152           (ch == 0x2028)
153          )) || unlikely (ch == 0x0009
154                       || ch == 0x00AD
155                       || ch == 0x034F
156                       || ch == 0xFEFF);
157 }
158
159 #endif /* HB_UNICODE_PRIVATE_HH */