• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2009  Red Hat, Inc.
3  * Copyright © 2011  Codethink Limited
4  * Copyright © 2010,2011,2012  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 extern HB_INTERNAL const uint8_t _hb_modified_combining_class[256];
41 
42 /*
43  * hb_unicode_funcs_t
44  */
45 
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 */
56 
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 */
65 
66 struct hb_unicode_funcs_t {
67   hb_object_header_t header;
68   ASSERT_POD ();
69 
70   hb_unicode_funcs_t *parent;
71 
72   bool immutable;
73 
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
78 
composehb_unicode_funcs_t79   inline hb_bool_t compose (hb_codepoint_t a, hb_codepoint_t b,
80 			    hb_codepoint_t *ab)
81   {
82     *ab = 0;
83     if (unlikely (!a || !b)) return false;
84     return func.compose (this, a, b, ab, user_data.compose);
85   }
86 
decomposehb_unicode_funcs_t87   inline hb_bool_t decompose (hb_codepoint_t ab,
88 			      hb_codepoint_t *a, hb_codepoint_t *b)
89   {
90     *a = ab; *b = 0;
91     return func.decompose (this, ab, a, b, user_data.decompose);
92   }
93 
decompose_compatibilityhb_unicode_funcs_t94   inline unsigned int decompose_compatibility (hb_codepoint_t  u,
95 					       hb_codepoint_t *decomposed)
96   {
97     unsigned int ret = func.decompose_compatibility (this, u, decomposed, user_data.decompose_compatibility);
98     if (ret == 1 && u == decomposed[0]) {
99       decomposed[0] = 0;
100       return 0;
101     }
102     decomposed[ret] = 0;
103     return ret;
104   }
105 
106 
107   unsigned int
modified_combining_classhb_unicode_funcs_t108   modified_combining_class (hb_codepoint_t unicode)
109   {
110     /* XXX This hack belongs to the Myanmar shaper. */
111     if (unicode == 0x1037) unicode = 0x103A;
112 
113     return _hb_modified_combining_class[combining_class (unicode)];
114   }
115 
116   inline hb_bool_t
is_variation_selectorhb_unicode_funcs_t117   is_variation_selector (hb_codepoint_t unicode)
118   {
119     return unlikely (hb_in_ranges<hb_codepoint_t> (unicode,
120 						   0x180B, 0x180D, /* MONGOLIAN FREE VARIATION SELECTOR ONE..THREE */
121 						   0xFE00, 0xFE0F, /* VARIATION SELECTOR-1..16 */
122 						   0xE0100, 0xE01EF));  /* VARIATION SELECTOR-17..256 */
123   }
124 
125   /* Default_Ignorable codepoints:
126    *
127    * Note that as of Oct 2012 (Unicode 6.2), U+180E MONGOLIAN VOWEL SEPARATOR
128    * is NOT Default_Ignorable, but it really behaves in a way that it should
129    * be.  That has been reported to the Unicode Technical Committee for
130    * consideration.  As such, we include it here, since Uniscribe removes it.
131    *
132    * Note: While U+115F and U+1160 are Default_Ignorable, we do NOT want to
133    * hide them, as the way Uniscribe has implemented them is with regular
134    * spacing glyphs, and that's the way fonts are made to work.  As such,
135    * we make exceptions for those two.
136    *
137    * Gathered from:
138    * http://unicode.org/cldr/utility/list-unicodeset.jsp?a=[:DI:]&abb=on&ucd=on&esc=on
139    *
140    * Last updated to the page with the following versions:
141    * Version 3.6; ICU version: 50.0.1.0; Unicode version: 6.1.0.0
142    *
143    * 4,167 Code Points
144    *
145    * [\u00AD\u034F\u115F\u1160\u17B4\u17B5\u180B-\u180D\u200B-\u200F\u202A-\u202E\u2060-\u206F\u3164\uFE00-\uFE0F\uFEFF\uFFA0\uFFF0-\uFFF8\U0001D173-\U0001D17A\U000E0000-\U000E0FFF]
146    *
147    * 00AD ;SOFT HYPHEN
148    * 034F ;COMBINING GRAPHEME JOINER
149    * #115F ;HANGUL CHOSEONG FILLER
150    * #1160 ;HANGUL JUNGSEONG FILLER
151    * 17B4 ;KHMER VOWEL INHERENT AQ
152    * 17B5 ;KHMER VOWEL INHERENT AA
153    * 180B..180D ;MONGOLIAN FREE VARIATION SELECTOR THREE
154    * 200B..200F ;RIGHT-TO-LEFT MARK
155    * 202A..202E ;RIGHT-TO-LEFT OVERRIDE
156    * 2060..206F ;NOMINAL DIGIT SHAPES
157    * 3164 ;HANGUL FILLER
158    * FE00..FE0F ;VARIATION SELECTOR-16
159    * FEFF ;ZERO WIDTH NO-BREAK SPACE
160    * FFA0 ;HALFWIDTH HANGUL FILLER
161    * FFF0..FFF8 ;<unassigned-FFF8>
162    * 1D173..1D17A ;MUSICAL SYMBOL END PHRASE
163    * E0000..E0FFF ;<unassigned-E0FFF>
164    */
165   inline hb_bool_t
is_default_ignorablehb_unicode_funcs_t166   is_default_ignorable (hb_codepoint_t ch)
167   {
168     hb_codepoint_t plane = ch >> 16;
169     if (likely (plane == 0))
170     {
171       /* BMP */
172       hb_codepoint_t page = ch >> 8;
173       switch (page) {
174 	case 0x00: return unlikely (ch == 0x00AD);
175 	case 0x03: return unlikely (ch == 0x034F);
176 	case 0x17: return hb_in_range<hb_codepoint_t> (ch, 0x17B4, 0x17B5);
177 	case 0x18: return hb_in_range<hb_codepoint_t> (ch, 0x180B, 0x180E);
178 	case 0x20: return hb_in_ranges<hb_codepoint_t> (ch, 0x200B, 0x200F,
179 							    0x202A, 0x202E,
180 							    0x2060, 0x206F);
181 	case 0x31: return unlikely (ch == 0x3164);
182 	case 0xFE: return hb_in_range<hb_codepoint_t> (ch, 0xFE00, 0xFE0F) || ch == 0xFEFF;
183 	case 0xFF: return hb_in_range<hb_codepoint_t> (ch, 0xFFF0, 0xFFF8) || ch == 0xFFA0;
184 	default: return false;
185       }
186     }
187     else
188     {
189       /* Other planes */
190       switch (plane) {
191 	case 0x01: return hb_in_range<hb_codepoint_t> (ch, 0x0001D173, 0x0001D17A);
192 	case 0x0E: return hb_in_range<hb_codepoint_t> (ch, 0x000E0000, 0x000E0FFF);
193 	default: return false;
194       }
195     }
196   }
197 
198 
199   struct {
200 #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_func_t name;
201     HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
202 #undef HB_UNICODE_FUNC_IMPLEMENT
203   } func;
204 
205   struct {
206 #define HB_UNICODE_FUNC_IMPLEMENT(name) void *name;
207     HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
208 #undef HB_UNICODE_FUNC_IMPLEMENT
209   } user_data;
210 
211   struct {
212 #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_destroy_func_t name;
213     HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
214 #undef HB_UNICODE_FUNC_IMPLEMENT
215   } destroy;
216 };
217 
218 
219 extern HB_INTERNAL const hb_unicode_funcs_t _hb_unicode_funcs_nil;
220 
221 
222 /* Modified combining marks */
223 
224 /* Hebrew
225  *
226  * We permute the "fixed-position" classes 10-26 into the order
227  * described in the SBL Hebrew manual:
228  *
229  * http://www.sbl-site.org/Fonts/SBLHebrewUserManual1.5x.pdf
230  *
231  * (as recommended by:
232  *  http://forum.fontlab.com/archive-old-microsoft-volt-group/vista-and-diacritic-ordering-t6751.0.html)
233  *
234  * More details here:
235  * https://bugzilla.mozilla.org/show_bug.cgi?id=662055
236  */
237 #define HB_MODIFIED_COMBINING_CLASS_CCC10 22 /* sheva */
238 #define HB_MODIFIED_COMBINING_CLASS_CCC11 15 /* hataf segol */
239 #define HB_MODIFIED_COMBINING_CLASS_CCC12 16 /* hataf patah */
240 #define HB_MODIFIED_COMBINING_CLASS_CCC13 17 /* hataf qamats */
241 #define HB_MODIFIED_COMBINING_CLASS_CCC14 23 /* hiriq */
242 #define HB_MODIFIED_COMBINING_CLASS_CCC15 18 /* tsere */
243 #define HB_MODIFIED_COMBINING_CLASS_CCC16 19 /* segol */
244 #define HB_MODIFIED_COMBINING_CLASS_CCC17 20 /* patah */
245 #define HB_MODIFIED_COMBINING_CLASS_CCC18 21 /* qamats */
246 #define HB_MODIFIED_COMBINING_CLASS_CCC19 14 /* holam */
247 #define HB_MODIFIED_COMBINING_CLASS_CCC20 24 /* qubuts */
248 #define HB_MODIFIED_COMBINING_CLASS_CCC21 12 /* dagesh */
249 #define HB_MODIFIED_COMBINING_CLASS_CCC22 25 /* meteg */
250 #define HB_MODIFIED_COMBINING_CLASS_CCC23 13 /* rafe */
251 #define HB_MODIFIED_COMBINING_CLASS_CCC24 10 /* shin dot */
252 #define HB_MODIFIED_COMBINING_CLASS_CCC25 11 /* sin dot */
253 #define HB_MODIFIED_COMBINING_CLASS_CCC26 26 /* point varika */
254 
255 /*
256  * Arabic
257  *
258  * Modify to move Shadda (ccc=33) before other marks.  See:
259  * http://unicode.org/faq/normalization.html#8
260  * http://unicode.org/faq/normalization.html#9
261  */
262 #define HB_MODIFIED_COMBINING_CLASS_CCC27 28 /* fathatan */
263 #define HB_MODIFIED_COMBINING_CLASS_CCC28 29 /* dammatan */
264 #define HB_MODIFIED_COMBINING_CLASS_CCC29 30 /* kasratan */
265 #define HB_MODIFIED_COMBINING_CLASS_CCC30 31 /* fatha */
266 #define HB_MODIFIED_COMBINING_CLASS_CCC31 32 /* damma */
267 #define HB_MODIFIED_COMBINING_CLASS_CCC32 33 /* kasra */
268 #define HB_MODIFIED_COMBINING_CLASS_CCC33 27 /* shadda */
269 #define HB_MODIFIED_COMBINING_CLASS_CCC34 34 /* sukun */
270 #define HB_MODIFIED_COMBINING_CLASS_CCC35 35 /* superscript alef */
271 
272 /* Syriac */
273 #define HB_MODIFIED_COMBINING_CLASS_CCC36 36 /* superscript alaph */
274 
275 /* Telugu
276  *
277  * Modify Telugu length marks (ccc=84, ccc=91).
278  * These are the only matras in the main Indic scripts range that have
279  * a non-zero ccc.  That makes them reorder with the Halant that is
280  * ccc=9.  Just zero them, we don't need them in our Indic shaper.
281  */
282 #define HB_MODIFIED_COMBINING_CLASS_CCC84 0 /* length mark */
283 #define HB_MODIFIED_COMBINING_CLASS_CCC91 0 /* ai length mark */
284 
285 /* Thai
286  *
287  * Modify U+0E38 and U+0E39 (ccc=103) to be reordered before U+0E3A (ccc=9).
288  * Assign 3, which is unassigned otherwise.
289  * Uniscribe does this reordering too.
290  */
291 #define HB_MODIFIED_COMBINING_CLASS_CCC103 3 /* sara u / sara uu */
292 #define HB_MODIFIED_COMBINING_CLASS_CCC107 107 /* mai * */
293 
294 /* Lao */
295 #define HB_MODIFIED_COMBINING_CLASS_CCC118 118 /* sign u / sign uu */
296 #define HB_MODIFIED_COMBINING_CLASS_CCC122 122 /* mai * */
297 
298 /* Tibetan */
299 #define HB_MODIFIED_COMBINING_CLASS_CCC129 129 /* sign aa */
300 #define HB_MODIFIED_COMBINING_CLASS_CCC130 130 /* sign i */
301 #define HB_MODIFIED_COMBINING_CLASS_CCC132 132 /* sign u */
302 
303 
304 /* Misc */
305 
306 #define HB_UNICODE_GENERAL_CATEGORY_IS_MARK(gen_cat) \
307 	(FLAG (gen_cat) & \
308 	 (FLAG (HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK) | \
309 	  FLAG (HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK) | \
310 	  FLAG (HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)))
311 
312 
313 #endif /* HB_UNICODE_PRIVATE_HH */
314