OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2011,2012 Google, Inc. | 2 * Copyright © 2011,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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 283 |
284 return a < b ? -1 : a == b ? 0 : +1; | 284 return a < b ? -1 : a == b ? 0 : +1; |
285 } | 285 } |
286 | 286 |
287 | 287 |
288 void | 288 void |
289 _hb_ot_shape_normalize (const hb_ot_shape_plan_t *plan, | 289 _hb_ot_shape_normalize (const hb_ot_shape_plan_t *plan, |
290 hb_buffer_t *buffer, | 290 hb_buffer_t *buffer, |
291 hb_font_t *font) | 291 hb_font_t *font) |
292 { | 292 { |
| 293 if (unlikely (!buffer->len)) return; |
| 294 |
293 _hb_buffer_assert_unicode_vars (buffer); | 295 _hb_buffer_assert_unicode_vars (buffer); |
294 | 296 |
295 hb_ot_shape_normalization_mode_t mode = plan->shaper->normalization_preference
; | 297 hb_ot_shape_normalization_mode_t mode = plan->shaper->normalization_preference
; |
296 const hb_ot_shape_normalize_context_t c = { | 298 const hb_ot_shape_normalize_context_t c = { |
297 plan, | 299 plan, |
298 buffer, | 300 buffer, |
299 font, | 301 font, |
300 buffer->unicode, | 302 buffer->unicode, |
301 plan->shaper->decompose ? plan->shaper->decompose : decompose_unicode, | 303 plan->shaper->decompose ? plan->shaper->decompose : decompose_unicode, |
302 plan->shaper->compose ? plan->shaper->compose : compose_unicode | 304 plan->shaper->compose ? plan->shaper->compose : compose_unicode |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 for (unsigned int i = 0; i < count; i++) | 339 for (unsigned int i = 0; i < count; i++) |
338 { | 340 { |
339 if (_hb_glyph_info_get_modified_combining_class (&buffer->info[i]) == 0) | 341 if (_hb_glyph_info_get_modified_combining_class (&buffer->info[i]) == 0) |
340 continue; | 342 continue; |
341 | 343 |
342 unsigned int end; | 344 unsigned int end; |
343 for (end = i + 1; end < count; end++) | 345 for (end = i + 1; end < count; end++) |
344 if (_hb_glyph_info_get_modified_combining_class (&buffer->info[end]) == 0) | 346 if (_hb_glyph_info_get_modified_combining_class (&buffer->info[end]) == 0) |
345 break; | 347 break; |
346 | 348 |
347 /* We are going to do a bubble-sort. Only do this if the | 349 /* We are going to do a O(n^2). Only do this if the sequence is short. */ |
348 * sequence is short. Doing it on long sequences can result | |
349 * in an O(n^2) DoS. */ | |
350 if (end - i > 10) { | 350 if (end - i > 10) { |
351 i = end; | 351 i = end; |
352 continue; | 352 continue; |
353 } | 353 } |
354 | 354 |
355 hb_bubble_sort (buffer->info + i, end - i, compare_combining_class); | 355 buffer->sort (i, end, compare_combining_class); |
356 | 356 |
357 i = end; | 357 i = end; |
358 } | 358 } |
359 | 359 |
360 | 360 |
361 if (mode == HB_OT_SHAPE_NORMALIZATION_MODE_NONE || | 361 if (mode == HB_OT_SHAPE_NORMALIZATION_MODE_NONE || |
362 mode == HB_OT_SHAPE_NORMALIZATION_MODE_DECOMPOSED) | 362 mode == HB_OT_SHAPE_NORMALIZATION_MODE_DECOMPOSED) |
363 return; | 363 return; |
364 | 364 |
365 /* Third round, recompose */ | 365 /* Third round, recompose */ |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 | 407 |
408 /* Blocked, or doesn't compose. */ | 408 /* Blocked, or doesn't compose. */ |
409 buffer->next_glyph (); | 409 buffer->next_glyph (); |
410 | 410 |
411 if (_hb_glyph_info_get_modified_combining_class (&buffer->prev()) == 0) | 411 if (_hb_glyph_info_get_modified_combining_class (&buffer->prev()) == 0) |
412 starter = buffer->out_len - 1; | 412 starter = buffer->out_len - 1; |
413 } | 413 } |
414 buffer->swap_buffers (); | 414 buffer->swap_buffers (); |
415 | 415 |
416 } | 416 } |
OLD | NEW |