2 * Copyright © 2009 Red Hat, Inc.
3 * Copyright © 2011 Codethink Limited
4 * Copyright © 2010,2011,2012 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 #ifndef HB_UNICODE_PRIVATE_HH
32 #define HB_UNICODE_PRIVATE_HH
34 #include "hb-private.hh"
36 #include "hb-unicode.h"
37 #include "hb-object-private.hh"
40 extern HB_INTERNAL const uint8_t _hb_modified_combining_class[256];
46 #define HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS \
47 HB_UNICODE_FUNC_IMPLEMENT (combining_class) \
48 HB_UNICODE_FUNC_IMPLEMENT (eastasian_width) \
49 HB_UNICODE_FUNC_IMPLEMENT (general_category) \
50 HB_UNICODE_FUNC_IMPLEMENT (mirroring) \
51 HB_UNICODE_FUNC_IMPLEMENT (script) \
52 HB_UNICODE_FUNC_IMPLEMENT (compose) \
53 HB_UNICODE_FUNC_IMPLEMENT (decompose) \
54 HB_UNICODE_FUNC_IMPLEMENT (decompose_compatibility) \
55 /* ^--- Add new callbacks here */
57 /* Simple callbacks are those taking a hb_codepoint_t and returning a hb_codepoint_t */
58 #define HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE \
59 HB_UNICODE_FUNC_IMPLEMENT (hb_unicode_combining_class_t, combining_class) \
60 HB_UNICODE_FUNC_IMPLEMENT (unsigned int, eastasian_width) \
61 HB_UNICODE_FUNC_IMPLEMENT (hb_unicode_general_category_t, general_category) \
62 HB_UNICODE_FUNC_IMPLEMENT (hb_codepoint_t, mirroring) \
63 HB_UNICODE_FUNC_IMPLEMENT (hb_script_t, script) \
64 /* ^--- Add new simple callbacks here */
66 struct hb_unicode_funcs_t {
67 hb_object_header_t header;
70 hb_unicode_funcs_t *parent;
74 #define HB_UNICODE_FUNC_IMPLEMENT(return_type, name) \
75 inline return_type name (hb_codepoint_t unicode) { return func.name (this, unicode, user_data.name); }
76 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE
77 #undef HB_UNICODE_FUNC_IMPLEMENT
79 inline hb_bool_t compose (hb_codepoint_t a, hb_codepoint_t b,
83 if (unlikely (!a || !b)) return false;
84 return func.compose (this, a, b, ab, user_data.compose);
87 inline hb_bool_t decompose (hb_codepoint_t ab,
88 hb_codepoint_t *a, hb_codepoint_t *b)
91 return func.decompose (this, ab, a, b, user_data.decompose);
94 inline unsigned int decompose_compatibility (hb_codepoint_t u,
95 hb_codepoint_t *decomposed)
97 unsigned int ret = func.decompose_compatibility (this, u, decomposed, user_data.decompose_compatibility);
98 if (ret == 1 && u == decomposed[0]) {
108 modified_combining_class (hb_codepoint_t unicode)
110 return _hb_modified_combining_class[combining_class (unicode)];
114 is_variation_selector (hb_codepoint_t unicode)
116 return unlikely (hb_in_ranges<hb_codepoint_t> (unicode,
117 0x180B, 0x180D, /* MONGOLIAN FREE VARIATION SELECTOR ONE..THREE */
118 0xFE00, 0xFE0F, /* VARIATION SELECTOR-1..16 */
119 0xE0100, 0xE01EF)); /* VARIATION SELECTOR-17..256 */
122 /* Zero-Width invisible characters:
125 * 034F COMBINING GRAPHEME JOINER
127 * 180E MONGOLIAN VOWEL SEPARATOR
129 * 200B ZERO WIDTH SPACE
130 * 200C ZERO WIDTH NON-JOINER
131 * 200D ZERO WIDTH JOINER
132 * 200E LEFT-TO-RIGHT MARK
133 * 200F RIGHT-TO-LEFT MARK
135 * 2028 LINE SEPARATOR
137 * 202A LEFT-TO-RIGHT EMBEDDING
138 * 202B RIGHT-TO-LEFT EMBEDDING
139 * 202C POP DIRECTIONAL FORMATTING
140 * 202D LEFT-TO-RIGHT OVERRIDE
141 * 202E RIGHT-TO-LEFT OVERRIDE
144 * 2061 FUNCTION APPLICATION
145 * 2062 INVISIBLE TIMES
146 * 2063 INVISIBLE SEPARATOR
148 * FEFF ZERO WIDTH NO-BREAK SPACE
151 is_zero_width (hb_codepoint_t ch)
153 return ((ch & ~0x007F) == 0x2000 && (hb_in_ranges<hb_codepoint_t> (ch,
158 unlikely (ch == 0x0009 ||
167 #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_func_t name;
168 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
169 #undef HB_UNICODE_FUNC_IMPLEMENT
173 #define HB_UNICODE_FUNC_IMPLEMENT(name) void *name;
174 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
175 #undef HB_UNICODE_FUNC_IMPLEMENT
179 #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_destroy_func_t name;
180 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
181 #undef HB_UNICODE_FUNC_IMPLEMENT
186 extern HB_INTERNAL const hb_unicode_funcs_t _hb_unicode_funcs_nil;
189 /* Modified combining marks */
193 * We permute the "fixed-position" classes 10-26 into the order
194 * described in the SBL Hebrew manual:
196 * http://www.sbl-site.org/Fonts/SBLHebrewUserManual1.5x.pdf
198 * (as recommended by:
199 * http://forum.fontlab.com/archive-old-microsoft-volt-group/vista-and-diacritic-ordering-t6751.0.html)
202 * https://bugzilla.mozilla.org/show_bug.cgi?id=662055
204 #define HB_MODIFIED_COMBINING_CLASS_CCC10 22 /* sheva */
205 #define HB_MODIFIED_COMBINING_CLASS_CCC11 15 /* hataf segol */
206 #define HB_MODIFIED_COMBINING_CLASS_CCC12 16 /* hataf patah */
207 #define HB_MODIFIED_COMBINING_CLASS_CCC13 17 /* hataf qamats */
208 #define HB_MODIFIED_COMBINING_CLASS_CCC14 23 /* hiriq */
209 #define HB_MODIFIED_COMBINING_CLASS_CCC15 18 /* tsere */
210 #define HB_MODIFIED_COMBINING_CLASS_CCC16 19 /* segol */
211 #define HB_MODIFIED_COMBINING_CLASS_CCC17 20 /* patah */
212 #define HB_MODIFIED_COMBINING_CLASS_CCC18 21 /* qamats */
213 #define HB_MODIFIED_COMBINING_CLASS_CCC19 14 /* holam */
214 #define HB_MODIFIED_COMBINING_CLASS_CCC20 24 /* qubuts */
215 #define HB_MODIFIED_COMBINING_CLASS_CCC21 12 /* dagesh */
216 #define HB_MODIFIED_COMBINING_CLASS_CCC22 25 /* meteg */
217 #define HB_MODIFIED_COMBINING_CLASS_CCC23 13 /* rafe */
218 #define HB_MODIFIED_COMBINING_CLASS_CCC24 10 /* shin dot */
219 #define HB_MODIFIED_COMBINING_CLASS_CCC25 11 /* sin dot */
220 #define HB_MODIFIED_COMBINING_CLASS_CCC26 26 /* point varika */
225 * Modify to move Shadda (ccc=33) before other marks. See:
226 * http://unicode.org/faq/normalization.html#8
227 * http://unicode.org/faq/normalization.html#9
229 #define HB_MODIFIED_COMBINING_CLASS_CCC27 28 /* fathatan */
230 #define HB_MODIFIED_COMBINING_CLASS_CCC28 29 /* dammatan */
231 #define HB_MODIFIED_COMBINING_CLASS_CCC29 30 /* kasratan */
232 #define HB_MODIFIED_COMBINING_CLASS_CCC30 31 /* fatha */
233 #define HB_MODIFIED_COMBINING_CLASS_CCC31 32 /* damma */
234 #define HB_MODIFIED_COMBINING_CLASS_CCC32 33 /* kasra */
235 #define HB_MODIFIED_COMBINING_CLASS_CCC33 27 /* shadda */
236 #define HB_MODIFIED_COMBINING_CLASS_CCC34 34 /* sukun */
237 #define HB_MODIFIED_COMBINING_CLASS_CCC35 35 /* superscript alef */
240 #define HB_MODIFIED_COMBINING_CLASS_CCC36 36 /* superscript alaph */
244 * Modify Telugu length marks (ccc=84, ccc=91).
245 * These are the only matras in the main Indic scripts range that have
246 * a non-zero ccc. That makes them reorder with the Halant that is
247 * ccc=9. Just zero them, we don't need them in our Indic shaper.
249 #define HB_MODIFIED_COMBINING_CLASS_CCC84 0 /* length mark */
250 #define HB_MODIFIED_COMBINING_CLASS_CCC91 0 /* ai length mark */
254 * Modify U+0E38 and U+0E39 (ccc=103) to be reordered before U+0E3A (ccc=9).
255 * Assign 3, which is unassigned otherwise.
256 * Uniscribe does this reordering too.
258 #define HB_MODIFIED_COMBINING_CLASS_CCC103 3 /* sara u / sara uu */
259 #define HB_MODIFIED_COMBINING_CLASS_CCC107 107 /* mai * */
262 #define HB_MODIFIED_COMBINING_CLASS_CCC118 118 /* sign u / sign uu */
263 #define HB_MODIFIED_COMBINING_CLASS_CCC122 122 /* mai * */
266 #define HB_MODIFIED_COMBINING_CLASS_CCC129 129 /* sign aa */
267 #define HB_MODIFIED_COMBINING_CLASS_CCC130 130 /* sign i */
268 #define HB_MODIFIED_COMBINING_CLASS_CCC132 132 /* sign u */
271 #endif /* HB_UNICODE_PRIVATE_HH */