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

Side by Side Diff: third_party/harfbuzz-ng/src/hb-ot-shape-complex-arabic.cc

Issue 396393005: Roll HarfBuzz to 0.9.32 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix for include order presubmit issue Created 6 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright © 2010,2012 Google, Inc. 2 * Copyright © 2010,2012 Google, Inc.
3 * 3 *
4 * This is part of HarfBuzz, a text shaping library. 4 * This is part of HarfBuzz, a text shaping library.
5 * 5 *
6 * Permission is hereby granted, without written agreement and without 6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this 7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the 8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in 9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software. 10 * all copies of this software.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 }; 50 };
51 51
52 /* 52 /*
53 * Joining types: 53 * Joining types:
54 */ 54 */
55 55
56 #include "hb-ot-shape-complex-arabic-table.hh" 56 #include "hb-ot-shape-complex-arabic-table.hh"
57 57
58 static unsigned int get_joining_type (hb_codepoint_t u, hb_unicode_general_categ ory_t gen_cat) 58 static unsigned int get_joining_type (hb_codepoint_t u, hb_unicode_general_categ ory_t gen_cat)
59 { 59 {
60 if (likely (hb_in_range<hb_codepoint_t> (u, JOINING_TABLE_FIRST, JOINING_TABLE _LAST))) { 60 unsigned int j_type = joining_type(u);
61 unsigned int j_type = joining_table[u - JOINING_TABLE_FIRST]; 61 if (likely (j_type != JOINING_TYPE_X))
62 if (likely (j_type != JOINING_TYPE_X)) 62 return j_type;
63 return j_type;
64 }
65 63
66 /* Mongolian joining data is not in ArabicJoining.txt yet. */ 64 return (FLAG(gen_cat) &
67 if (unlikely (hb_in_range<hb_codepoint_t> (u, 0x1800, 0x18AF))) 65 » (FLAG(HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) |
68 { 66 » FLAG(HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK) |
69 if (unlikely (hb_in_range<hb_codepoint_t> (u, 0x1880, 0x1886))) 67 » FLAG(HB_UNICODE_GENERAL_CATEGORY_FORMAT))
70 return JOINING_TYPE_U; 68 » ) ? JOINING_TYPE_T : JOINING_TYPE_U;
69 }
71 70
72 /* All letters, SIBE SYLLABLE BOUNDARY MARKER, and NIRUGU are D */ 71 #define FEATURE_IS_SYRIAC(tag) hb_in_range<unsigned char> ((unsigned char) (tag) , '2', '3')
73 if ((FLAG(gen_cat) & (FLAG (HB_UNICODE_GENERAL_CATEGORY_OTHER_LETTER) |
74 » » » FLAG (HB_UNICODE_GENERAL_CATEGORY_MODIFIER_LETTER)))
75 » || u == 0x1807 || u == 0x180A)
76 return JOINING_TYPE_D;
77 }
78
79 /* 'Phags-pa joining data is not in ArabicJoining.txt yet. */
80 if (unlikely (hb_in_range<hb_codepoint_t> (u, 0xA840, 0xA872)))
81 {
82 if (unlikely (u == 0xA872))
83 » return JOINING_TYPE_L;
84
85 return JOINING_TYPE_D;
86 }
87
88 if (unlikely (hb_in_range<hb_codepoint_t> (u, 0x200C, 0x200D)))
89 {
90 return u == 0x200C ? JOINING_TYPE_U : JOINING_TYPE_C;
91 }
92
93 return (FLAG(gen_cat) & (FLAG(HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) | FLAG(HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK) | FLAG(HB_UNICODE_GENERAL_CATEG ORY_FORMAT))) ?
94 » JOINING_TYPE_T : JOINING_TYPE_U;
95 }
96 72
97 static const hb_tag_t arabic_features[] = 73 static const hb_tag_t arabic_features[] =
98 { 74 {
99 HB_TAG('i','n','i','t'), 75 HB_TAG('i','s','o','l'),
100 HB_TAG('m','e','d','i'),
101 HB_TAG('f','i','n','a'), 76 HB_TAG('f','i','n','a'),
102 HB_TAG('i','s','o','l'),
103 /* Syriac */
104 HB_TAG('m','e','d','2'),
105 HB_TAG('f','i','n','2'), 77 HB_TAG('f','i','n','2'),
106 HB_TAG('f','i','n','3'), 78 HB_TAG('f','i','n','3'),
79 HB_TAG('m','e','d','i'),
80 HB_TAG('m','e','d','2'),
81 HB_TAG('i','n','i','t'),
107 HB_TAG_NONE 82 HB_TAG_NONE
108 }; 83 };
109 84
110 85
111 /* Same order as the feature array */ 86 /* Same order as the feature array */
112 enum { 87 enum {
113 INIT, 88 ISOL,
114 MEDI,
115 FINA, 89 FINA,
116 ISOL,
117
118 /* Syriac */
119 MED2,
120 FIN2, 90 FIN2,
121 FIN3, 91 FIN3,
92 MEDI,
93 MED2,
94 INIT,
122 95
123 NONE, 96 NONE,
124 97
125 ARABIC_NUM_FEATURES = NONE 98 ARABIC_NUM_FEATURES = NONE
126 }; 99 };
127 100
128 static const struct arabic_state_table_entry { 101 static const struct arabic_state_table_entry {
129 uint8_t prev_action; 102 uint8_t prev_action;
130 uint8_t curr_action; 103 uint8_t curr_action;
131 uint16_t next_state; 104 uint16_t next_state;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 static void 137 static void
165 arabic_fallback_shape (const hb_ot_shape_plan_t *plan, 138 arabic_fallback_shape (const hb_ot_shape_plan_t *plan,
166 hb_font_t *font, 139 hb_font_t *font,
167 hb_buffer_t *buffer); 140 hb_buffer_t *buffer);
168 141
169 static void 142 static void
170 collect_features_arabic (hb_ot_shape_planner_t *plan) 143 collect_features_arabic (hb_ot_shape_planner_t *plan)
171 { 144 {
172 hb_ot_map_builder_t *map = &plan->map; 145 hb_ot_map_builder_t *map = &plan->map;
173 146
174 /* For Language forms (in ArabicOT speak), we do the iso/fina/medi/init togeth er, 147 /* We apply features according to the Arabic spec, with pauses
175 * then rlig and calt each in their own stage. This makes IranNastaliq's ALLA H 148 * in between most.
176 * ligature work correctly. It's unfortunate though...
177 * 149 *
178 * This also makes Arial Bold in Windows7 work. See: 150 * The pause between init/medi/... and rlig is required. See eg:
179 * https://bugzilla.mozilla.org/show_bug.cgi?id=644184 151 * https://bugzilla.mozilla.org/show_bug.cgi?id=644184
180 * 152 *
181 * TODO: Add test cases for these two. 153 * The pauses between init/medi/... themselves are not necessarily
154 * needed as only one of those features is applied to any character.
155 * The only difference it makes is when fonts have contextual
156 * substitutions. We now follow the order of the spec, which makes
157 * for better experience if that's what Uniscribe is doing.
158 *
159 * At least for Arabic, looks like Uniscribe has a pause between
160 * rlig and calt. Otherwise the IranNastaliq's ALLAH ligature won't
161 * work. However, testing shows that rlig and calt are applied
162 * together for Mongolian in Uniscribe. As such, we only add a
163 * pause for Arabic, not other scripts.
182 */ 164 */
183 165
184 map->add_gsub_pause (nuke_joiners); 166 map->add_gsub_pause (nuke_joiners);
185 167
186 map->add_global_bool_feature (HB_TAG('c','c','m','p')); 168 map->add_global_bool_feature (HB_TAG('c','c','m','p'));
187 map->add_global_bool_feature (HB_TAG('l','o','c','l')); 169 map->add_global_bool_feature (HB_TAG('l','o','c','l'));
188 170
189 map->add_gsub_pause (NULL); 171 map->add_gsub_pause (NULL);
190 172
191 for (unsigned int i = 0; i < ARABIC_NUM_FEATURES; i++) 173 for (unsigned int i = 0; i < ARABIC_NUM_FEATURES; i++)
192 map->add_feature (arabic_features[i], 1, i < 4 ? F_HAS_FALLBACK : F_NONE); / * The first four features have fallback. */ 174 {
193 175 bool has_fallback = plan->props.script == HB_SCRIPT_ARABIC && !FEATURE_IS_SY RIAC (arabic_features[i]);
194 map->add_gsub_pause (NULL); 176 map->add_feature (arabic_features[i], 1, has_fallback ? F_HAS_FALLBACK : F_N ONE);
177 map->add_gsub_pause (NULL);
178 }
195 179
196 map->add_feature (HB_TAG('r','l','i','g'), 1, F_GLOBAL|F_HAS_FALLBACK); 180 map->add_feature (HB_TAG('r','l','i','g'), 1, F_GLOBAL|F_HAS_FALLBACK);
197 map->add_gsub_pause (arabic_fallback_shape); 181 if (plan->props.script == HB_SCRIPT_ARABIC)
182 map->add_gsub_pause (arabic_fallback_shape);
198 183
199 map->add_global_bool_feature (HB_TAG('c','a','l','t')); 184 map->add_global_bool_feature (HB_TAG('c','a','l','t'));
200 map->add_gsub_pause (NULL); 185 map->add_gsub_pause (NULL);
201 186
187 /* The spec includes 'cswh'. Earlier versions of Windows
188 * used to enable this by default, but testing suggests
189 * that Windows 8 and later do not enable it by default,
190 * and spec now says 'Off by default'.
191 * We disabled this in ae23c24c32.
192 * Note that IranNastaliq uses this feature extensively
193 * to fixup broken glyph sequences. Oh well...
194 * Test case: U+0643,U+0640,U+0631. */
195 //map->add_global_bool_feature (HB_TAG('c','s','w','h'));
202 map->add_global_bool_feature (HB_TAG('m','s','e','t')); 196 map->add_global_bool_feature (HB_TAG('m','s','e','t'));
203 } 197 }
204 198
205 #include "hb-ot-shape-complex-arabic-fallback.hh" 199 #include "hb-ot-shape-complex-arabic-fallback.hh"
206 200
207 struct arabic_shape_plan_t 201 struct arabic_shape_plan_t
208 { 202 {
209 ASSERT_POD (); 203 ASSERT_POD ();
210 204
211 /* The "+ 1" in the next array is to accommodate for the "NONE" command, 205 /* The "+ 1" in the next array is to accommodate for the "NONE" command,
212 * which is not an OpenType feature, but this simplifies the code by not 206 * which is not an OpenType feature, but this simplifies the code by not
213 * having to do a "if (... < NONE) ..." and just rely on the fact that 207 * having to do a "if (... < NONE) ..." and just rely on the fact that
214 * mask_array[NONE] == 0. */ 208 * mask_array[NONE] == 0. */
215 hb_mask_t mask_array[ARABIC_NUM_FEATURES + 1]; 209 hb_mask_t mask_array[ARABIC_NUM_FEATURES + 1];
216 210
217 bool do_fallback; 211 bool do_fallback;
218 arabic_fallback_plan_t *fallback_plan; 212 arabic_fallback_plan_t *fallback_plan;
219 }; 213 };
220 214
221 static void * 215 static void *
222 data_create_arabic (const hb_ot_shape_plan_t *plan) 216 data_create_arabic (const hb_ot_shape_plan_t *plan)
223 { 217 {
224 arabic_shape_plan_t *arabic_plan = (arabic_shape_plan_t *) calloc (1, sizeof ( arabic_shape_plan_t)); 218 arabic_shape_plan_t *arabic_plan = (arabic_shape_plan_t *) calloc (1, sizeof ( arabic_shape_plan_t));
225 if (unlikely (!arabic_plan)) 219 if (unlikely (!arabic_plan))
226 return NULL; 220 return NULL;
227 221
228 arabic_plan->do_fallback = plan->props.script == HB_SCRIPT_ARABIC; 222 arabic_plan->do_fallback = plan->props.script == HB_SCRIPT_ARABIC;
229 for (unsigned int i = 0; i < ARABIC_NUM_FEATURES; i++) { 223 for (unsigned int i = 0; i < ARABIC_NUM_FEATURES; i++) {
230 arabic_plan->mask_array[i] = plan->map.get_1_mask (arabic_features[i]); 224 arabic_plan->mask_array[i] = plan->map.get_1_mask (arabic_features[i]);
231 if (i < 4) 225 arabic_plan->do_fallback = arabic_plan->do_fallback &&
232 arabic_plan->do_fallback = arabic_plan->do_fallback && plan->map.needs_fal lback (arabic_features[i]); 226 » » » !FEATURE_IS_SYRIAC (arabic_features[i]) &&
227 » » » plan->map.needs_fallback (arabic_features[i]);
233 } 228 }
234 229
235 return arabic_plan; 230 return arabic_plan;
236 } 231 }
237 232
238 static void 233 static void
239 data_destroy_arabic (void *data) 234 data_destroy_arabic (void *data)
240 { 235 {
241 arabic_shape_plan_t *arabic_plan = (arabic_shape_plan_t *) data; 236 arabic_shape_plan_t *arabic_plan = (arabic_shape_plan_t *) data;
242 237
243 arabic_fallback_plan_destroy (arabic_plan->fallback_plan); 238 arabic_fallback_plan_destroy (arabic_plan->fallback_plan);
244 239
245 free (data); 240 free (data);
246 } 241 }
247 242
248 static void 243 static void
249 arabic_joining (hb_buffer_t *buffer) 244 arabic_joining (hb_buffer_t *buffer)
250 { 245 {
251 unsigned int count = buffer->len; 246 unsigned int count = buffer->len;
247 hb_glyph_info_t *info = buffer->info;
252 unsigned int prev = (unsigned int) -1, state = 0; 248 unsigned int prev = (unsigned int) -1, state = 0;
253 249
254 HB_BUFFER_ALLOCATE_VAR (buffer, arabic_shaping_action);
255
256 /* Check pre-context */ 250 /* Check pre-context */
257 if (!(buffer->flags & HB_BUFFER_FLAG_BOT)) 251 if (!(buffer->flags & HB_BUFFER_FLAG_BOT))
258 for (unsigned int i = 0; i < buffer->context_len[0]; i++) 252 for (unsigned int i = 0; i < buffer->context_len[0]; i++)
259 { 253 {
260 unsigned int this_type = get_joining_type (buffer->context[0][i], buffer-> unicode->general_category (buffer->context[0][i])); 254 unsigned int this_type = get_joining_type (buffer->context[0][i], buffer-> unicode->general_category (buffer->context[0][i]));
261 255
262 if (unlikely (this_type == JOINING_TYPE_T)) 256 if (unlikely (this_type == JOINING_TYPE_T))
263 continue; 257 continue;
264 258
265 const arabic_state_table_entry *entry = &arabic_state_table[state][this_ty pe]; 259 const arabic_state_table_entry *entry = &arabic_state_table[state][this_ty pe];
266 state = entry->next_state; 260 state = entry->next_state;
267 break; 261 break;
268 } 262 }
269 263
270 for (unsigned int i = 0; i < count; i++) 264 for (unsigned int i = 0; i < count; i++)
271 { 265 {
272 unsigned int this_type = get_joining_type (buffer->info[i].codepoint, _hb_gl yph_info_get_general_category (&buffer->info[i])); 266 unsigned int this_type = get_joining_type (info[i].codepoint, _hb_glyph_info _get_general_category (&info[i]));
273 267
274 if (unlikely (this_type == JOINING_TYPE_T)) { 268 if (unlikely (this_type == JOINING_TYPE_T)) {
275 buffer->info[i].arabic_shaping_action() = NONE; 269 info[i].arabic_shaping_action() = NONE;
276 continue; 270 continue;
277 } 271 }
278 272
279 const arabic_state_table_entry *entry = &arabic_state_table[state][this_type ]; 273 const arabic_state_table_entry *entry = &arabic_state_table[state][this_type ];
280 274
281 if (entry->prev_action != NONE && prev != (unsigned int) -1) 275 if (entry->prev_action != NONE && prev != (unsigned int) -1)
282 for (; prev < i; prev++) 276 info[prev].arabic_shaping_action() = entry->prev_action;
283 » buffer->info[prev].arabic_shaping_action() = entry->prev_action;
284 277
285 buffer->info[i].arabic_shaping_action() = entry->curr_action; 278 info[i].arabic_shaping_action() = entry->curr_action;
286 279
287 prev = i; 280 prev = i;
288 state = entry->next_state; 281 state = entry->next_state;
289 } 282 }
290 283
291 if (!(buffer->flags & HB_BUFFER_FLAG_EOT)) 284 if (!(buffer->flags & HB_BUFFER_FLAG_EOT))
292 for (unsigned int i = 0; i < buffer->context_len[1]; i++) 285 for (unsigned int i = 0; i < buffer->context_len[1]; i++)
293 { 286 {
294 unsigned int this_type = get_joining_type (buffer->context[1][i], buffer-> unicode->general_category (buffer->context[1][i])); 287 unsigned int this_type = get_joining_type (buffer->context[1][i], buffer-> unicode->general_category (buffer->context[1][i]));
295 288
296 if (unlikely (this_type == JOINING_TYPE_T)) 289 if (unlikely (this_type == JOINING_TYPE_T))
297 continue; 290 continue;
298 291
299 const arabic_state_table_entry *entry = &arabic_state_table[state][this_ty pe]; 292 const arabic_state_table_entry *entry = &arabic_state_table[state][this_ty pe];
300 if (entry->prev_action != NONE && prev != (unsigned int) -1) 293 if (entry->prev_action != NONE && prev != (unsigned int) -1)
301 » buffer->info[prev].arabic_shaping_action() = entry->prev_action; 294 » info[prev].arabic_shaping_action() = entry->prev_action;
302 break; 295 break;
303 } 296 }
304
305
306 HB_BUFFER_DEALLOCATE_VAR (buffer, arabic_shaping_action);
307 } 297 }
308 298
309 static void 299 static void
300 mongolian_variation_selectors (hb_buffer_t *buffer)
301 {
302 /* Copy arabic_shaping_action() from base to Mongolian variation selectors. */
303 unsigned int count = buffer->len;
304 hb_glyph_info_t *info = buffer->info;
305 for (unsigned int i = 1; i < count; i++)
306 if (unlikely (hb_in_range (info[i].codepoint, 0x180Bu, 0x180Du)))
307 info[i].arabic_shaping_action() = info[i - 1].arabic_shaping_action();
308 }
309
310 static void
310 setup_masks_arabic (const hb_ot_shape_plan_t *plan, 311 setup_masks_arabic (const hb_ot_shape_plan_t *plan,
311 hb_buffer_t *buffer, 312 hb_buffer_t *buffer,
312 hb_font_t *font HB_UNUSED) 313 hb_font_t *font HB_UNUSED)
313 { 314 {
315 HB_BUFFER_ALLOCATE_VAR (buffer, arabic_shaping_action);
316
314 const arabic_shape_plan_t *arabic_plan = (const arabic_shape_plan_t *) plan->d ata; 317 const arabic_shape_plan_t *arabic_plan = (const arabic_shape_plan_t *) plan->d ata;
315 318
316 arabic_joining (buffer); 319 arabic_joining (buffer);
320 if (plan->props.script == HB_SCRIPT_MONGOLIAN)
321 mongolian_variation_selectors (buffer);
322
317 unsigned int count = buffer->len; 323 unsigned int count = buffer->len;
324 hb_glyph_info_t *info = buffer->info;
318 for (unsigned int i = 0; i < count; i++) 325 for (unsigned int i = 0; i < count; i++)
319 buffer->info[i].mask |= arabic_plan->mask_array[buffer->info[i].arabic_shapi ng_action()]; 326 info[i].mask |= arabic_plan->mask_array[info[i].arabic_shaping_action()];
327
328 HB_BUFFER_DEALLOCATE_VAR (buffer, arabic_shaping_action);
320 } 329 }
321 330
322 331
323 static void 332 static void
324 nuke_joiners (const hb_ot_shape_plan_t *plan HB_UNUSED, 333 nuke_joiners (const hb_ot_shape_plan_t *plan HB_UNUSED,
325 hb_font_t *font HB_UNUSED, 334 hb_font_t *font HB_UNUSED,
326 hb_buffer_t *buffer) 335 hb_buffer_t *buffer)
327 { 336 {
328 unsigned int count = buffer->len; 337 unsigned int count = buffer->len;
338 hb_glyph_info_t *info = buffer->info;
329 for (unsigned int i = 0; i < count; i++) 339 for (unsigned int i = 0; i < count; i++)
330 if (_hb_glyph_info_is_zwj (&buffer->info[i])) 340 if (_hb_glyph_info_is_zwj (&info[i]))
331 _hb_glyph_info_flip_joiners (&buffer->info[i]); 341 _hb_glyph_info_flip_joiners (&info[i]);
332 } 342 }
333 343
334 static void 344 static void
335 arabic_fallback_shape (const hb_ot_shape_plan_t *plan, 345 arabic_fallback_shape (const hb_ot_shape_plan_t *plan,
336 hb_font_t *font, 346 hb_font_t *font,
337 hb_buffer_t *buffer) 347 hb_buffer_t *buffer)
338 { 348 {
339 const arabic_shape_plan_t *arabic_plan = (const arabic_shape_plan_t *) plan->d ata; 349 const arabic_shape_plan_t *arabic_plan = (const arabic_shape_plan_t *) plan->d ata;
340 350
341 if (!arabic_plan->do_fallback) 351 if (!arabic_plan->do_fallback)
(...skipping 23 matching lines...) Expand all
365 data_create_arabic, 375 data_create_arabic,
366 data_destroy_arabic, 376 data_destroy_arabic,
367 NULL, /* preprocess_text_arabic */ 377 NULL, /* preprocess_text_arabic */
368 HB_OT_SHAPE_NORMALIZATION_MODE_DEFAULT, 378 HB_OT_SHAPE_NORMALIZATION_MODE_DEFAULT,
369 NULL, /* decompose */ 379 NULL, /* decompose */
370 NULL, /* compose */ 380 NULL, /* compose */
371 setup_masks_arabic, 381 setup_masks_arabic,
372 HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE, 382 HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE,
373 true, /* fallback_position */ 383 true, /* fallback_position */
374 }; 384 };
OLDNEW
« no previous file with comments | « third_party/harfbuzz-ng/src/hb-ot-shape.cc ('k') | third_party/harfbuzz-ng/src/hb-ot-shape-complex-arabic-fallback.hh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698