Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1003)

Side by Side Diff: third_party/harfbuzz-ng/src/hb-unicode.cc

Issue 10915172: harfbuzz-ng roll (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright © 2009 Red Hat, Inc. 2 * Copyright © 2009 Red Hat, Inc.
3 * Copyright © 2011 Codethink Limited 3 * Copyright © 2011 Codethink Limited
4 * Copyright © 2010,2011 Google, Inc. 4 * Copyright © 2010,2011,2012 Google, Inc.
5 * 5 *
6 * This is part of HarfBuzz, a text shaping library. 6 * This is part of HarfBuzz, a text shaping library.
7 * 7 *
8 * Permission is hereby granted, without written agreement and without 8 * Permission is hereby granted, without written agreement and without
9 * license or royalty fees, to use, copy, modify, and distribute this 9 * license or royalty fees, to use, copy, modify, and distribute this
10 * software and its documentation for any purpose, provided that the 10 * software and its documentation for any purpose, provided that the
11 * above copyright notice and the following two paragraphs appear in 11 * above copyright notice and the following two paragraphs appear in
12 * all copies of this software. 12 * all copies of this software.
13 * 13 *
14 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 14 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
(...skipping 16 matching lines...) Expand all
31 #include "hb-private.hh" 31 #include "hb-private.hh"
32 32
33 #include "hb-unicode-private.hh" 33 #include "hb-unicode-private.hh"
34 34
35 35
36 36
37 /* 37 /*
38 * hb_unicode_funcs_t 38 * hb_unicode_funcs_t
39 */ 39 */
40 40
41 static unsigned int 41 static hb_unicode_combining_class_t
42 hb_unicode_combining_class_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, 42 hb_unicode_combining_class_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
43 hb_codepoint_t unicode HB_UNUSED, 43 hb_codepoint_t unicode HB_UNUSED,
44 void *user_data HB_UNUSED) 44 void *user_data HB_UNUSED)
45 { 45 {
46 return 0; 46 return HB_UNICODE_COMBINING_CLASS_NOT_REORDERED;
47 } 47 }
48 48
49 static unsigned int 49 static unsigned int
50 hb_unicode_eastasian_width_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, 50 hb_unicode_eastasian_width_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
51 hb_codepoint_t unicode HB_UNUSED, 51 hb_codepoint_t unicode HB_UNUSED,
52 void *user_data HB_UNUSED) 52 void *user_data HB_UNUSED)
53 { 53 {
54 return 1; 54 return 1;
55 } 55 }
56 56
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 hb_unicode_decompose_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED, 92 hb_unicode_decompose_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED,
93 hb_codepoint_t ab HB_UNUSED, 93 hb_codepoint_t ab HB_UNUSED,
94 hb_codepoint_t *a HB_UNUSED, 94 hb_codepoint_t *a HB_UNUSED,
95 hb_codepoint_t *b HB_UNUSED, 95 hb_codepoint_t *b HB_UNUSED,
96 void *user_data HB_UNUSED) 96 void *user_data HB_UNUSED)
97 { 97 {
98 return false; 98 return false;
99 } 99 }
100 100
101 101
102 static unsigned int
103 hb_unicode_decompose_compatibility_nil (hb_unicode_funcs_t *ufuncs HB_UNUSED ,
104 hb_codepoint_t u HB_UNUSED ,
105 hb_codepoint_t *decomposed HB_UNUSED ,
106 void *user_data HB_UNUSED )
107 {
108 return 0;
109 }
110
111
112 #define HB_UNICODE_FUNCS_IMPLEMENT_SET \
113 HB_UNICODE_FUNCS_IMPLEMENT (glib) \
114 HB_UNICODE_FUNCS_IMPLEMENT (icu) \
115 HB_UNICODE_FUNCS_IMPLEMENT (nil) \
116 /* ^--- Add new callbacks before nil */
117
118 #define hb_nil_get_unicode_funcs hb_unicode_funcs_get_empty
119
120 /* Prototype them all */
121 #define HB_UNICODE_FUNCS_IMPLEMENT(set) \
122 extern "C" hb_unicode_funcs_t *hb_##set##_get_unicode_funcs (void);
123 HB_UNICODE_FUNCS_IMPLEMENT_SET
124 #undef HB_UNICODE_FUNCS_IMPLEMENT
125
102 126
103 hb_unicode_funcs_t * 127 hb_unicode_funcs_t *
104 hb_unicode_funcs_get_default (void) 128 hb_unicode_funcs_get_default (void)
105 { 129 {
106 return const_cast<hb_unicode_funcs_t *> (&_hb_unicode_funcs_default); 130 #define HB_UNICODE_FUNCS_IMPLEMENT(set) \
131 return hb_##set##_get_unicode_funcs ();
132
133 #ifdef HAVE_GLIB
134 HB_UNICODE_FUNCS_IMPLEMENT(glib)
135 #elif defined(HAVE_ICU)
136 HB_UNICODE_FUNCS_IMPLEMENT(icu)
137 #else
138 #define HB_UNICODE_FUNCS_NIL 1
139 HB_UNICODE_FUNCS_IMPLEMENT(nil)
140 #endif
141
142 #undef HB_UNICODE_FUNCS_IMPLEMENT
107 } 143 }
108 144
145 #if !defined(HB_NO_UNICODE_FUNCS) && defined(HB_UNICODE_FUNCS_NIL)
146 #pragma message("Could not find any Unicode functions implementation, you have t o provide your own.")
147 #pragma message("To suppress this warnings, define HB_NO_UNICODE_FUNCS.")
148 #endif
149
109 hb_unicode_funcs_t * 150 hb_unicode_funcs_t *
110 hb_unicode_funcs_create (hb_unicode_funcs_t *parent) 151 hb_unicode_funcs_create (hb_unicode_funcs_t *parent)
111 { 152 {
112 hb_unicode_funcs_t *ufuncs; 153 hb_unicode_funcs_t *ufuncs;
113 154
114 if (!(ufuncs = hb_object_create<hb_unicode_funcs_t> ())) 155 if (!(ufuncs = hb_object_create<hb_unicode_funcs_t> ()))
115 return hb_unicode_funcs_get_empty (); 156 return hb_unicode_funcs_get_empty ();
116 157
117 if (!parent) 158 if (!parent)
118 parent = hb_unicode_funcs_get_empty (); 159 parent = hb_unicode_funcs_get_empty ();
119 160
120 hb_unicode_funcs_make_immutable (parent); 161 hb_unicode_funcs_make_immutable (parent);
121 ufuncs->parent = hb_unicode_funcs_reference (parent); 162 ufuncs->parent = hb_unicode_funcs_reference (parent);
122 163
123 ufuncs->func = parent->func; 164 ufuncs->func = parent->func;
124 165
125 /* We can safely copy user_data from parent since we hold a reference 166 /* We can safely copy user_data from parent since we hold a reference
126 * onto it and it's immutable. We should not copy the destroy notifiers 167 * onto it and it's immutable. We should not copy the destroy notifiers
127 * though. */ 168 * though. */
128 ufuncs->user_data = parent->user_data; 169 ufuncs->user_data = parent->user_data;
129 170
130 return ufuncs; 171 return ufuncs;
131 } 172 }
132 173
133 174
134 extern HB_INTERNAL const hb_unicode_funcs_t _hb_unicode_funcs_nil;
135 const hb_unicode_funcs_t _hb_unicode_funcs_nil = { 175 const hb_unicode_funcs_t _hb_unicode_funcs_nil = {
136 HB_OBJECT_HEADER_STATIC, 176 HB_OBJECT_HEADER_STATIC,
137 177
138 NULL, /* parent */ 178 NULL, /* parent */
139 true, /* immutable */ 179 true, /* immutable */
140 { 180 {
141 #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_nil, 181 #define HB_UNICODE_FUNC_IMPLEMENT(name) hb_unicode_##name##_nil,
142 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS 182 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
143 #undef HB_UNICODE_FUNC_IMPLEMENT 183 #undef HB_UNICODE_FUNC_IMPLEMENT
144 } 184 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 ufuncs->func.name = func; \ 269 ufuncs->func.name = func; \
230 ufuncs->user_data.name = user_data; \ 270 ufuncs->user_data.name = user_data; \
231 ufuncs->destroy.name = destroy; \ 271 ufuncs->destroy.name = destroy; \
232 } else { \ 272 } else { \
233 ufuncs->func.name = ufuncs->parent->func.name; \ 273 ufuncs->func.name = ufuncs->parent->func.name; \
234 ufuncs->user_data.name = ufuncs->parent->user_data.name; \ 274 ufuncs->user_data.name = ufuncs->parent->user_data.name; \
235 ufuncs->destroy.name = NULL; \ 275 ufuncs->destroy.name = NULL; \
236 } \ 276 } \
237 } 277 }
238 278
239 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS 279 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS
240 #undef HB_UNICODE_FUNC_IMPLEMENT 280 #undef HB_UNICODE_FUNC_IMPLEMENT
241 281
242 282
243 #define HB_UNICODE_FUNC_IMPLEMENT(return_type, name) \ 283 #define HB_UNICODE_FUNC_IMPLEMENT(return_type, name) \
244 \ 284 \
245 return_type \ 285 return_type \
246 hb_unicode_##name (hb_unicode_funcs_t *ufuncs, \ 286 hb_unicode_##name (hb_unicode_funcs_t *ufuncs, \
247 hb_codepoint_t unicode) \ 287 hb_codepoint_t unicode) \
248 { \ 288 { \
249 return ufuncs->func.name (ufuncs, unicode, ufuncs->user_data.name);» » \ 289 return ufuncs->name (unicode);» » » » » » \
250 } 290 }
251 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE 291 HB_UNICODE_FUNCS_IMPLEMENT_CALLBACKS_SIMPLE
252 #undef HB_UNICODE_FUNC_IMPLEMENT 292 #undef HB_UNICODE_FUNC_IMPLEMENT
253 293
254 hb_bool_t 294 hb_bool_t
255 hb_unicode_compose (hb_unicode_funcs_t *ufuncs, 295 hb_unicode_compose (hb_unicode_funcs_t *ufuncs,
256 hb_codepoint_t a, 296 hb_codepoint_t a,
257 hb_codepoint_t b, 297 hb_codepoint_t b,
258 hb_codepoint_t *ab) 298 hb_codepoint_t *ab)
259 { 299 {
260 *ab = 0; 300 return ufuncs->compose (a, b, ab);
261 return ufuncs->func.compose (ufuncs, a, b, ab, ufuncs->user_data.compose);
262 } 301 }
263 302
264 hb_bool_t 303 hb_bool_t
265 hb_unicode_decompose (hb_unicode_funcs_t *ufuncs, 304 hb_unicode_decompose (hb_unicode_funcs_t *ufuncs,
266 hb_codepoint_t ab, 305 hb_codepoint_t ab,
267 hb_codepoint_t *a, 306 hb_codepoint_t *a,
268 hb_codepoint_t *b) 307 hb_codepoint_t *b)
269 { 308 {
270 *a = ab; *b = 0; 309 return ufuncs->decompose (ab, a, b);
271 return ufuncs->func.decompose (ufuncs, ab, a, b, ufuncs->user_data.decompose); 310 }
311
312 unsigned int
313 hb_unicode_decompose_compatibility (hb_unicode_funcs_t *ufuncs,
314 » » » » hb_codepoint_t u,
315 » » » » hb_codepoint_t *decomposed)
316 {
317 return ufuncs->decompose_compatibility (u, decomposed);
272 } 318 }
273 319
274 320
321 /* See hb-unicode-private.hh for details. */
322 const uint8_t
323 _hb_modified_combining_class[256] =
324 {
325 0, /* HB_UNICODE_COMBINING_CLASS_NOT_REORDERED */
326 1, /* HB_UNICODE_COMBINING_CLASS_OVERLAY */
327 2, 3, 4, 5, 6,
328 7, /* HB_UNICODE_COMBINING_CLASS_NUKTA */
329 8, /* HB_UNICODE_COMBINING_CLASS_KANA_VOICING */
330 9, /* HB_UNICODE_COMBINING_CLASS_VIRAMA */
275 331
276 unsigned int 332 /* Hebrew */
277 _hb_unicode_modified_combining_class (hb_unicode_funcs_t *ufuncs, 333 HB_MODIFIED_COMBINING_CLASS_CCC10,
278 » » » » hb_codepoint_t unicode) 334 HB_MODIFIED_COMBINING_CLASS_CCC11,
279 { 335 HB_MODIFIED_COMBINING_CLASS_CCC12,
280 int c = hb_unicode_combining_class (ufuncs, unicode); 336 HB_MODIFIED_COMBINING_CLASS_CCC13,
337 HB_MODIFIED_COMBINING_CLASS_CCC14,
338 HB_MODIFIED_COMBINING_CLASS_CCC15,
339 HB_MODIFIED_COMBINING_CLASS_CCC16,
340 HB_MODIFIED_COMBINING_CLASS_CCC17,
341 HB_MODIFIED_COMBINING_CLASS_CCC18,
342 HB_MODIFIED_COMBINING_CLASS_CCC19,
343 HB_MODIFIED_COMBINING_CLASS_CCC20,
344 HB_MODIFIED_COMBINING_CLASS_CCC21,
345 HB_MODIFIED_COMBINING_CLASS_CCC22,
346 HB_MODIFIED_COMBINING_CLASS_CCC23,
347 HB_MODIFIED_COMBINING_CLASS_CCC24,
348 HB_MODIFIED_COMBINING_CLASS_CCC25,
349 HB_MODIFIED_COMBINING_CLASS_CCC26,
281 350
282 if (unlikely (hb_in_range<int> (c, 27, 33))) 351 /* Arabic */
283 { 352 HB_MODIFIED_COMBINING_CLASS_CCC27,
284 /* Modify the combining-class to suit Arabic better. See: 353 HB_MODIFIED_COMBINING_CLASS_CCC28,
285 * http://unicode.org/faq/normalization.html#8 354 HB_MODIFIED_COMBINING_CLASS_CCC29,
286 * http://unicode.org/faq/normalization.html#9 355 HB_MODIFIED_COMBINING_CLASS_CCC30,
287 */ 356 HB_MODIFIED_COMBINING_CLASS_CCC31,
288 c = c == 33 ? 27 : c + 1; 357 HB_MODIFIED_COMBINING_CLASS_CCC32,
289 } 358 HB_MODIFIED_COMBINING_CLASS_CCC33,
290 else if (unlikely (hb_in_range<int> (c, 10, 25))) 359 HB_MODIFIED_COMBINING_CLASS_CCC34,
291 { 360 HB_MODIFIED_COMBINING_CLASS_CCC35,
292 /* The equivalent fix for Hebrew is more complex.
293 *
294 * We permute the "fixed-position" classes 10-25 into the order
295 * described in the SBL Hebrew manual:
296 *
297 * http://www.sbl-site.org/Fonts/SBLHebrewUserManual1.5x.pdf
298 *
299 * (as recommended by:
300 * http://forum.fontlab.com/archive-old-microsoft-volt-group/vista-and-diac ritic-ordering-t6751.0.html)
301 *
302 * More details here:
303 * https://bugzilla.mozilla.org/show_bug.cgi?id=662055
304 */
305 static const int permuted_hebrew_classes[25 - 10 + 1] = {
306 /* 10 sheva */ 22,
307 /* 11 hataf segol */ 15,
308 /* 12 hataf patah */ 16,
309 /* 13 hataf qamats */ 17,
310 /* 14 hiriq */ 23,
311 /* 15 tsere */ 18,
312 /* 16 segol */ 19,
313 /* 17 patah */ 20,
314 /* 18 qamats */ 21,
315 /* 19 holam */ 14,
316 /* 20 qubuts */ 24,
317 /* 21 dagesh */ 12,
318 /* 22 meteg */ 25,
319 /* 23 rafe */ 13,
320 /* 24 shin dot */ 10,
321 /* 25 sin dot */ 11,
322 };
323 c = permuted_hebrew_classes[c - 10];
324 }
325 361
326 return c; 362 /* Syriac */
327 } 363 HB_MODIFIED_COMBINING_CLASS_CCC36,
328 364
365 37, 38, 39,
366 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59 ,
367 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79 ,
368 80, 81, 82, 83,
369
370 /* Telugu */
371 HB_MODIFIED_COMBINING_CLASS_CCC84,
372 85, 86, 87, 88, 89, 90,
373 HB_MODIFIED_COMBINING_CLASS_CCC91,
374 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
375
376 /* Thai */
377 HB_MODIFIED_COMBINING_CLASS_CCC103,
378 104, 105, 106,
379 HB_MODIFIED_COMBINING_CLASS_CCC107,
380 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
381
382 /* Lao */
383 HB_MODIFIED_COMBINING_CLASS_CCC118,
384 119, 120, 121,
385 HB_MODIFIED_COMBINING_CLASS_CCC122,
386 123, 124, 125, 126, 127, 128,
387
388 /* Tibetan */
389 HB_MODIFIED_COMBINING_CLASS_CCC129,
390 HB_MODIFIED_COMBINING_CLASS_CCC130,
391 131,
392 HB_MODIFIED_COMBINING_CLASS_CCC132,
393 133, 134, 135, 136, 137, 138, 139,
394
395
396 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
397 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
398 160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
399 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
400 180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
401 190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
402
403 200, /* HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT */
404 201,
405 202, /* HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW */
406 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213,
407 214, /* HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE */
408 215,
409 216, /* HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT */
410 217,
411 218, /* HB_UNICODE_COMBINING_CLASS_BELOW_LEFT */
412 219,
413 220, /* HB_UNICODE_COMBINING_CLASS_BELOW */
414 221,
415 222, /* HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT */
416 223,
417 224, /* HB_UNICODE_COMBINING_CLASS_LEFT */
418 225,
419 226, /* HB_UNICODE_COMBINING_CLASS_RIGHT */
420 227,
421 228, /* HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT */
422 229,
423 230, /* HB_UNICODE_COMBINING_CLASS_ABOVE */
424 231,
425 232, /* HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT */
426 233, /* HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW */
427 234, /* HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE */
428 235, 236, 237, 238, 239,
429 240, /* HB_UNICODE_COMBINING_CLASS_IOTA_SUBSCRIPT */
430 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
431 255, /* HB_UNICODE_COMBINING_CLASS_INVALID */
432 };
OLDNEW
« no previous file with comments | « third_party/harfbuzz-ng/src/hb-unicode.h ('k') | third_party/harfbuzz-ng/src/hb-unicode-private.hh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698