OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2007,2008,2009,2010 Red Hat, Inc. | 2 * Copyright © 2007,2008,2009,2010 Red Hat, Inc. |
3 * Copyright © 2010,2012,2013 Google, Inc. | 3 * Copyright © 2010,2012,2013 Google, Inc. |
4 * | 4 * |
5 * This is part of HarfBuzz, a text shaping library. | 5 * This is part of HarfBuzz, a text shaping library. |
6 * | 6 * |
7 * Permission is hereby granted, without written agreement and without | 7 * Permission is hereby granted, without written agreement and without |
8 * license or royalty fees, to use, copy, modify, and distribute this | 8 * license or royalty fees, to use, copy, modify, and distribute this |
9 * software and its documentation for any purpose, provided that the | 9 * software and its documentation for any purpose, provided that the |
10 * above copyright notice and the following two paragraphs appear in | 10 * above copyright notice and the following two paragraphs appear in |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 inline bool apply (hb_apply_context_t *c, | 595 inline bool apply (hb_apply_context_t *c, |
596 const ValueFormat *valueFormats, | 596 const ValueFormat *valueFormats, |
597 unsigned int pos) const | 597 unsigned int pos) const |
598 { | 598 { |
599 TRACE_APPLY (this); | 599 TRACE_APPLY (this); |
600 hb_buffer_t *buffer = c->buffer; | 600 hb_buffer_t *buffer = c->buffer; |
601 unsigned int len1 = valueFormats[0].get_len (); | 601 unsigned int len1 = valueFormats[0].get_len (); |
602 unsigned int len2 = valueFormats[1].get_len (); | 602 unsigned int len2 = valueFormats[1].get_len (); |
603 unsigned int record_size = USHORT::static_size * (1 + len1 + len2); | 603 unsigned int record_size = USHORT::static_size * (1 + len1 + len2); |
604 | 604 |
605 const PairValueRecord *record = CastP<PairValueRecord> (arrayZ); | 605 const PairValueRecord *record_array = CastP<PairValueRecord> (arrayZ); |
606 unsigned int count = len; | 606 unsigned int count = len; |
607 for (unsigned int i = 0; i < count; i++) | 607 |
| 608 /* Hand-coded bsearch. */ |
| 609 if (unlikely (!count)) |
| 610 return TRACE_RETURN (false); |
| 611 hb_codepoint_t x = buffer->info[pos].codepoint; |
| 612 int min = 0, max = (int) count - 1; |
| 613 while (min <= max) |
608 { | 614 { |
609 /* TODO bsearch */ | 615 int mid = (min + max) / 2; |
610 if (buffer->info[pos].codepoint == record->secondGlyph) | 616 const PairValueRecord *record = &StructAtOffset<PairValueRecord> (record_a
rray, record_size * mid); |
| 617 hb_codepoint_t mid_x = record->secondGlyph; |
| 618 if (x < mid_x) |
| 619 max = mid - 1; |
| 620 else if (x > mid_x) |
| 621 min = mid + 1; |
| 622 else |
611 { | 623 { |
612 valueFormats[0].apply_value (c->font, c->direction, this, | 624 valueFormats[0].apply_value (c->font, c->direction, this, |
613 &record->values[0], buffer->cur_pos()); | 625 &record->values[0], buffer->cur_pos()); |
614 valueFormats[1].apply_value (c->font, c->direction, this, | 626 valueFormats[1].apply_value (c->font, c->direction, this, |
615 &record->values[len1], buffer->pos[pos]); | 627 &record->values[len1], buffer->pos[pos]); |
616 if (len2) | 628 if (len2) |
617 pos++; | 629 pos++; |
618 buffer->idx = pos; | 630 buffer->idx = pos; |
619 return TRACE_RETURN (true); | 631 return TRACE_RETURN (true); |
620 } | 632 } |
621 record = &StructAtOffset<PairValueRecord> (record, record_size); | |
622 } | 633 } |
623 | 634 |
624 return TRACE_RETURN (false); | 635 return TRACE_RETURN (false); |
625 } | 636 } |
626 | 637 |
627 struct sanitize_closure_t { | 638 struct sanitize_closure_t { |
628 void *base; | 639 void *base; |
629 ValueFormat *valueFormats; | 640 ValueFormat *valueFormats; |
630 unsigned int len1; /* valueFormats[0].get_len() */ | 641 unsigned int len1; /* valueFormats[0].get_len() */ |
631 unsigned int stride; /* 1 + len1 + len2 */ | 642 unsigned int stride; /* 1 + len1 + len2 */ |
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1628 | 1639 |
1629 | 1640 |
1630 #undef attach_lookback | 1641 #undef attach_lookback |
1631 #undef cursive_chain | 1642 #undef cursive_chain |
1632 | 1643 |
1633 | 1644 |
1634 } /* namespace OT */ | 1645 } /* namespace OT */ |
1635 | 1646 |
1636 | 1647 |
1637 #endif /* HB_OT_LAYOUT_GPOS_TABLE_HH */ | 1648 #endif /* HB_OT_LAYOUT_GPOS_TABLE_HH */ |
OLD | NEW |