| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright © 2007,2008,2009 Red Hat, Inc. | 2 * Copyright © 2007,2008,2009 Red Hat, Inc. |
| 3 * Copyright © 2010,2012 Google, Inc. | 3 * Copyright © 2010,2012 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 if (record_count) { | 96 if (record_count) { |
| 97 const Record<Type> *arr = this->sub_array (start_offset, record_count); | 97 const Record<Type> *arr = this->sub_array (start_offset, record_count); |
| 98 unsigned int count = *record_count; | 98 unsigned int count = *record_count; |
| 99 for (unsigned int i = 0; i < count; i++) | 99 for (unsigned int i = 0; i < count; i++) |
| 100 record_tags[i] = arr[i].tag; | 100 record_tags[i] = arr[i].tag; |
| 101 } | 101 } |
| 102 return this->len; | 102 return this->len; |
| 103 } | 103 } |
| 104 inline bool find_index (hb_tag_t tag, unsigned int *index) const | 104 inline bool find_index (hb_tag_t tag, unsigned int *index) const |
| 105 { | 105 { |
| 106 int i = this->search (tag); | 106 /* If we want to allow non-sorted data, we can lsearch(). */ |
| 107 int i = this->/*lsearch*/bsearch (tag); |
| 107 if (i != -1) { | 108 if (i != -1) { |
| 108 if (index) *index = i; | 109 if (index) *index = i; |
| 109 return true; | 110 return true; |
| 110 } else { | 111 } else { |
| 111 if (index) *index = Index::NOT_FOUND_INDEX; | 112 if (index) *index = Index::NOT_FOUND_INDEX; |
| 112 return false; | 113 return false; |
| 113 } | 114 } |
| 114 } | 115 } |
| 115 }; | 116 }; |
| 116 | 117 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 { | 183 { |
| 183 inline unsigned int get_feature_count (void) const | 184 inline unsigned int get_feature_count (void) const |
| 184 { return featureIndex.len; } | 185 { return featureIndex.len; } |
| 185 inline hb_tag_t get_feature_index (unsigned int i) const | 186 inline hb_tag_t get_feature_index (unsigned int i) const |
| 186 { return featureIndex[i]; } | 187 { return featureIndex[i]; } |
| 187 inline unsigned int get_feature_indexes (unsigned int start_offset, | 188 inline unsigned int get_feature_indexes (unsigned int start_offset, |
| 188 unsigned int *feature_count /* IN/OUT
*/, | 189 unsigned int *feature_count /* IN/OUT
*/, |
| 189 unsigned int *feature_indexes /* OUT
*/) const | 190 unsigned int *feature_indexes /* OUT
*/) const |
| 190 { return featureIndex.get_indexes (start_offset, feature_count, feature_indexe
s); } | 191 { return featureIndex.get_indexes (start_offset, feature_count, feature_indexe
s); } |
| 191 | 192 |
| 192 inline bool has_required_feature (void) const { return reqFeatureIndex != 0xff
ff; } | 193 inline bool has_required_feature (void) const { return reqFeatureIndex != 0xFF
FFu; } |
| 193 inline unsigned int get_required_feature_index (void) const | 194 inline unsigned int get_required_feature_index (void) const |
| 194 { | 195 { |
| 195 if (reqFeatureIndex == 0xffff) | 196 if (reqFeatureIndex == 0xFFFFu) |
| 196 return Index::NOT_FOUND_INDEX; | 197 return Index::NOT_FOUND_INDEX; |
| 197 return reqFeatureIndex;; | 198 return reqFeatureIndex;; |
| 198 } | 199 } |
| 199 | 200 |
| 200 inline bool sanitize (hb_sanitize_context_t *c, | 201 inline bool sanitize (hb_sanitize_context_t *c, |
| 201 const Record<LangSys>::sanitize_closure_t * = NULL) { | 202 const Record<LangSys>::sanitize_closure_t * = NULL) { |
| 202 TRACE_SANITIZE (this); | 203 TRACE_SANITIZE (this); |
| 203 return TRACE_RETURN (c->check_struct (this) && featureIndex.sanitize (c)); | 204 return TRACE_RETURN (c->check_struct (this) && featureIndex.sanitize (c)); |
| 204 } | 205 } |
| 205 | 206 |
| 206 Offset» lookupOrder;» /* = Null (reserved for an offset to a | 207 Offset<>» lookupOrderZ;» /* = Null (reserved for an offset to a |
| 207 * reordering table) */ | 208 * reordering table) */ |
| 208 USHORT reqFeatureIndex;/* Index of a feature required for this | 209 USHORT reqFeatureIndex;/* Index of a feature required for this |
| 209 * language system--if no required features | 210 * language system--if no required features |
| 210 » » » » * = 0xFFFF */ | 211 » » » » * = 0xFFFFu */ |
| 211 IndexArray featureIndex; /* Array of indices into the FeatureList */ | 212 IndexArray featureIndex; /* Array of indices into the FeatureList */ |
| 212 public: | 213 public: |
| 213 DEFINE_SIZE_ARRAY (6, featureIndex); | 214 DEFINE_SIZE_ARRAY (6, featureIndex); |
| 214 }; | 215 }; |
| 215 DEFINE_NULL_DATA (LangSys, "\0\0\xFF\xFF"); | 216 DEFINE_NULL_DATA (LangSys, "\0\0\xFF\xFF"); |
| 216 | 217 |
| 217 | 218 |
| 218 struct Script | 219 struct Script |
| 219 { | 220 { |
| 220 inline unsigned int get_lang_sys_count (void) const | 221 inline unsigned int get_lang_sys_count (void) const |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 public: | 441 public: |
| 441 DEFINE_SIZE_ARRAY (14, characters); | 442 DEFINE_SIZE_ARRAY (14, characters); |
| 442 }; | 443 }; |
| 443 | 444 |
| 444 struct FeatureParams | 445 struct FeatureParams |
| 445 { | 446 { |
| 446 inline bool sanitize (hb_sanitize_context_t *c, hb_tag_t tag) { | 447 inline bool sanitize (hb_sanitize_context_t *c, hb_tag_t tag) { |
| 447 TRACE_SANITIZE (this); | 448 TRACE_SANITIZE (this); |
| 448 if (tag == HB_TAG ('s','i','z','e')) | 449 if (tag == HB_TAG ('s','i','z','e')) |
| 449 return TRACE_RETURN (u.size.sanitize (c)); | 450 return TRACE_RETURN (u.size.sanitize (c)); |
| 450 if ((tag & 0xFFFF0000) == HB_TAG ('s','s','\0','\0')) /* ssXX */ | 451 if ((tag & 0xFFFF0000u) == HB_TAG ('s','s','\0','\0')) /* ssXX */ |
| 451 return TRACE_RETURN (u.stylisticSet.sanitize (c)); | 452 return TRACE_RETURN (u.stylisticSet.sanitize (c)); |
| 452 if ((tag & 0xFFFF0000) == HB_TAG ('c','v','\0','\0')) /* cvXX */ | 453 if ((tag & 0xFFFF0000u) == HB_TAG ('c','v','\0','\0')) /* cvXX */ |
| 453 return TRACE_RETURN (u.characterVariants.sanitize (c)); | 454 return TRACE_RETURN (u.characterVariants.sanitize (c)); |
| 454 return TRACE_RETURN (true); | 455 return TRACE_RETURN (true); |
| 455 } | 456 } |
| 456 | 457 |
| 457 inline const FeatureParamsSize& get_size_params (hb_tag_t tag) const | 458 inline const FeatureParamsSize& get_size_params (hb_tag_t tag) const |
| 458 { | 459 { |
| 459 if (tag == HB_TAG ('s','i','z','e')) | 460 if (tag == HB_TAG ('s','i','z','e')) |
| 460 return u.size; | 461 return u.size; |
| 461 return Null(FeatureParamsSize); | 462 return Null(FeatureParamsSize); |
| 462 } | 463 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 * FeatureParams subtable from the beginning of the FeatureList table! | 495 * FeatureParams subtable from the beginning of the FeatureList table! |
| 495 * | 496 * |
| 496 * If sanitizing "failed" for the FeatureParams subtable, try it with the | 497 * If sanitizing "failed" for the FeatureParams subtable, try it with the |
| 497 * alternative location. We would know sanitize "failed" if old value | 498 * alternative location. We would know sanitize "failed" if old value |
| 498 * of the offset was non-zero, but it's zeroed now. | 499 * of the offset was non-zero, but it's zeroed now. |
| 499 * | 500 * |
| 500 * Only do this for the 'size' feature, since at the time of the faulty | 501 * Only do this for the 'size' feature, since at the time of the faulty |
| 501 * Adobe tools, only the 'size' feature had FeatureParams defined. | 502 * Adobe tools, only the 'size' feature had FeatureParams defined. |
| 502 */ | 503 */ |
| 503 | 504 |
| 504 Offset orig_offset = featureParams; | 505 OffsetTo<FeatureParams> orig_offset = featureParams; |
| 505 if (unlikely (!featureParams.sanitize (c, this, closure ? closure->tag : HB_
TAG_NONE))) | 506 if (unlikely (!featureParams.sanitize (c, this, closure ? closure->tag : HB_
TAG_NONE))) |
| 506 return TRACE_RETURN (false); | 507 return TRACE_RETURN (false); |
| 507 | 508 |
| 508 if (likely (!orig_offset)) | 509 if (likely (orig_offset.is_null ())) |
| 509 return TRACE_RETURN (true); | 510 return TRACE_RETURN (true); |
| 510 | 511 |
| 511 if (featureParams == 0 && closure && | 512 if (featureParams == 0 && closure && |
| 512 closure->tag == HB_TAG ('s','i','z','e') && | 513 closure->tag == HB_TAG ('s','i','z','e') && |
| 513 closure->list_base && closure->list_base < this) | 514 closure->list_base && closure->list_base < this) |
| 514 { | 515 { |
| 515 unsigned int new_offset_int = (unsigned int) orig_offset - | 516 unsigned int new_offset_int = (unsigned int) orig_offset - |
| 516 » » » » ((char *) this - (char *) closure->list_base
); | 517 » » » » (((char *) this) - ((char *) closure->list_b
ase)); |
| 517 | 518 |
| 518 Offset new_offset; | 519 OffsetTo<FeatureParams> new_offset; |
| 519 /* Check that it did not overflow. */ | 520 /* Check that it did not overflow. */ |
| 520 new_offset.set (new_offset_int); | 521 new_offset.set (new_offset_int); |
| 521 if (new_offset == new_offset_int && | 522 if (new_offset == new_offset_int && |
| 522 » featureParams.try_set (c, new_offset) && | 523 » c->try_set (&featureParams, new_offset) && |
| 523 !featureParams.sanitize (c, this, closure ? closure->tag : HB_TAG_NONE
)) | 524 !featureParams.sanitize (c, this, closure ? closure->tag : HB_TAG_NONE
)) |
| 524 return TRACE_RETURN (false); | 525 return TRACE_RETURN (false); |
| 525 } | 526 } |
| 526 | 527 |
| 527 return TRACE_RETURN (true); | 528 return TRACE_RETURN (true); |
| 528 } | 529 } |
| 529 | 530 |
| 530 OffsetTo<FeatureParams> | 531 OffsetTo<FeatureParams> |
| 531 featureParams; /* Offset to Feature Parameters table (if one | 532 featureParams; /* Offset to Feature Parameters table (if one |
| 532 * has been defined for the feature), relative | 533 * has been defined for the feature), relative |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 } | 578 } |
| 578 | 579 |
| 579 inline bool serialize (hb_serialize_context_t *c, | 580 inline bool serialize (hb_serialize_context_t *c, |
| 580 unsigned int lookup_type, | 581 unsigned int lookup_type, |
| 581 uint32_t lookup_props, | 582 uint32_t lookup_props, |
| 582 unsigned int num_subtables) | 583 unsigned int num_subtables) |
| 583 { | 584 { |
| 584 TRACE_SERIALIZE (this); | 585 TRACE_SERIALIZE (this); |
| 585 if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); | 586 if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
| 586 lookupType.set (lookup_type); | 587 lookupType.set (lookup_type); |
| 587 lookupFlag.set (lookup_props & 0xFFFF); | 588 lookupFlag.set (lookup_props & 0xFFFFu); |
| 588 if (unlikely (!subTable.serialize (c, num_subtables))) return TRACE_RETURN (
false); | 589 if (unlikely (!subTable.serialize (c, num_subtables))) return TRACE_RETURN (
false); |
| 589 if (lookupFlag & LookupFlag::UseMarkFilteringSet) | 590 if (lookupFlag & LookupFlag::UseMarkFilteringSet) |
| 590 { | 591 { |
| 591 USHORT &markFilteringSet = StructAfter<USHORT> (subTable); | 592 USHORT &markFilteringSet = StructAfter<USHORT> (subTable); |
| 592 markFilteringSet.set (lookup_props >> 16); | 593 markFilteringSet.set (lookup_props >> 16); |
| 593 } | 594 } |
| 594 return TRACE_RETURN (true); | 595 return TRACE_RETURN (true); |
| 595 } | 596 } |
| 596 | 597 |
| 597 inline bool sanitize (hb_sanitize_context_t *c) { | 598 inline bool sanitize (hb_sanitize_context_t *c) { |
| 598 TRACE_SANITIZE (this); | 599 TRACE_SANITIZE (this); |
| 599 /* Real sanitize of the subtables is done by GSUB/GPOS/... */ | 600 /* Real sanitize of the subtables is done by GSUB/GPOS/... */ |
| 600 if (!(c->check_struct (this) && subTable.sanitize (c))) return TRACE_RETURN
(false); | 601 if (!(c->check_struct (this) && subTable.sanitize (c))) return TRACE_RETURN
(false); |
| 601 if (lookupFlag & LookupFlag::UseMarkFilteringSet) | 602 if (lookupFlag & LookupFlag::UseMarkFilteringSet) |
| 602 { | 603 { |
| 603 USHORT &markFilteringSet = StructAfter<USHORT> (subTable); | 604 USHORT &markFilteringSet = StructAfter<USHORT> (subTable); |
| 604 if (!markFilteringSet.sanitize (c)) return TRACE_RETURN (false); | 605 if (!markFilteringSet.sanitize (c)) return TRACE_RETURN (false); |
| 605 } | 606 } |
| 606 return TRACE_RETURN (true); | 607 return TRACE_RETURN (true); |
| 607 } | 608 } |
| 608 | 609 |
| 609 USHORT lookupType; /* Different enumerations for GSUB and G
POS */ | 610 USHORT lookupType; /* Different enumerations for GSUB and G
POS */ |
| 610 USHORT lookupFlag; /* Lookup qualifiers */ | 611 USHORT lookupFlag; /* Lookup qualifiers */ |
| 611 ArrayOf<Offset> | 612 ArrayOf<Offset<> > |
| 612 subTable; /* Array of SubTables */ | 613 subTable; /* Array of SubTables */ |
| 613 USHORT markFilteringSetX[VAR]; /* Index (base 0) into GDEF mark glyph s
ets | 614 USHORT markFilteringSetX[VAR]; /* Index (base 0) into GDEF mark glyph s
ets |
| 614 * structure. This field is only present
if bit | 615 * structure. This field is only present
if bit |
| 615 * UseMarkFilteringSet of lookup flags i
s set. */ | 616 * UseMarkFilteringSet of lookup flags i
s set. */ |
| 616 public: | 617 public: |
| 617 DEFINE_SIZE_ARRAY2 (6, subTable, markFilteringSetX); | 618 DEFINE_SIZE_ARRAY2 (6, subTable, markFilteringSetX); |
| 618 }; | 619 }; |
| 619 | 620 |
| 620 typedef OffsetListOf<Lookup> LookupList; | 621 typedef OffsetListOf<Lookup> LookupList; |
| 621 | 622 |
| 622 | 623 |
| 623 /* | 624 /* |
| 624 * Coverage Table | 625 * Coverage Table |
| 625 */ | 626 */ |
| 626 | 627 |
| 627 struct CoverageFormat1 | 628 struct CoverageFormat1 |
| 628 { | 629 { |
| 629 friend struct Coverage; | 630 friend struct Coverage; |
| 630 | 631 |
| 631 private: | 632 private: |
| 632 inline unsigned int get_coverage (hb_codepoint_t glyph_id) const | 633 inline unsigned int get_coverage (hb_codepoint_t glyph_id) const |
| 633 { | 634 { |
| 634 int i = glyphArray.search (glyph_id); | 635 int i = glyphArray.bsearch (glyph_id); |
| 635 ASSERT_STATIC (((unsigned int) -1) == NOT_COVERED); | 636 ASSERT_STATIC (((unsigned int) -1) == NOT_COVERED); |
| 636 return i; | 637 return i; |
| 637 } | 638 } |
| 638 | 639 |
| 639 inline bool serialize (hb_serialize_context_t *c, | 640 inline bool serialize (hb_serialize_context_t *c, |
| 640 Supplier<GlyphID> &glyphs, | 641 Supplier<GlyphID> &glyphs, |
| 641 unsigned int num_glyphs) | 642 unsigned int num_glyphs) |
| 642 { | 643 { |
| 643 TRACE_SERIALIZE (this); | 644 TRACE_SERIALIZE (this); |
| 644 if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); | 645 if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 DEFINE_SIZE_ARRAY (4, glyphArray); | 690 DEFINE_SIZE_ARRAY (4, glyphArray); |
| 690 }; | 691 }; |
| 691 | 692 |
| 692 struct CoverageFormat2 | 693 struct CoverageFormat2 |
| 693 { | 694 { |
| 694 friend struct Coverage; | 695 friend struct Coverage; |
| 695 | 696 |
| 696 private: | 697 private: |
| 697 inline unsigned int get_coverage (hb_codepoint_t glyph_id) const | 698 inline unsigned int get_coverage (hb_codepoint_t glyph_id) const |
| 698 { | 699 { |
| 699 int i = rangeRecord.search (glyph_id); | 700 int i = rangeRecord.bsearch (glyph_id); |
| 700 if (i != -1) { | 701 if (i != -1) { |
| 701 const RangeRecord &range = rangeRecord[i]; | 702 const RangeRecord &range = rangeRecord[i]; |
| 702 return (unsigned int) range.value + (glyph_id - range.start); | 703 return (unsigned int) range.value + (glyph_id - range.start); |
| 703 } | 704 } |
| 704 return NOT_COVERED; | 705 return NOT_COVERED; |
| 705 } | 706 } |
| 706 | 707 |
| 707 inline bool serialize (hb_serialize_context_t *c, | 708 inline bool serialize (hb_serialize_context_t *c, |
| 708 Supplier<GlyphID> &glyphs, | 709 Supplier<GlyphID> &glyphs, |
| 709 unsigned int num_glyphs) | 710 unsigned int num_glyphs) |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 DEFINE_SIZE_ARRAY (6, classValue); | 986 DEFINE_SIZE_ARRAY (6, classValue); |
| 986 }; | 987 }; |
| 987 | 988 |
| 988 struct ClassDefFormat2 | 989 struct ClassDefFormat2 |
| 989 { | 990 { |
| 990 friend struct ClassDef; | 991 friend struct ClassDef; |
| 991 | 992 |
| 992 private: | 993 private: |
| 993 inline unsigned int get_class (hb_codepoint_t glyph_id) const | 994 inline unsigned int get_class (hb_codepoint_t glyph_id) const |
| 994 { | 995 { |
| 995 int i = rangeRecord.search (glyph_id); | 996 int i = rangeRecord.bsearch (glyph_id); |
| 996 if (i != -1) | 997 if (i != -1) |
| 997 return rangeRecord[i].value; | 998 return rangeRecord[i].value; |
| 998 return 0; | 999 return 0; |
| 999 } | 1000 } |
| 1000 | 1001 |
| 1001 inline bool sanitize (hb_sanitize_context_t *c) { | 1002 inline bool sanitize (hb_sanitize_context_t *c) { |
| 1002 TRACE_SANITIZE (this); | 1003 TRACE_SANITIZE (this); |
| 1003 return TRACE_RETURN (rangeRecord.sanitize (c)); | 1004 return TRACE_RETURN (rangeRecord.sanitize (c)); |
| 1004 } | 1005 } |
| 1005 | 1006 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 if (unlikely (f < 1 || f > 3)) | 1124 if (unlikely (f < 1 || f > 3)) |
| 1124 return 0; | 1125 return 0; |
| 1125 | 1126 |
| 1126 if (ppem_size < startSize || ppem_size > endSize) | 1127 if (ppem_size < startSize || ppem_size > endSize) |
| 1127 return 0; | 1128 return 0; |
| 1128 | 1129 |
| 1129 unsigned int s = ppem_size - startSize; | 1130 unsigned int s = ppem_size - startSize; |
| 1130 | 1131 |
| 1131 unsigned int byte = deltaValue[s >> (4 - f)]; | 1132 unsigned int byte = deltaValue[s >> (4 - f)]; |
| 1132 unsigned int bits = (byte >> (16 - (((s & ((1 << (4 - f)) - 1)) + 1) << f)))
; | 1133 unsigned int bits = (byte >> (16 - (((s & ((1 << (4 - f)) - 1)) + 1) << f)))
; |
| 1133 unsigned int mask = (0xFFFF >> (16 - (1 << f))); | 1134 unsigned int mask = (0xFFFFu >> (16 - (1 << f))); |
| 1134 | 1135 |
| 1135 int delta = bits & mask; | 1136 int delta = bits & mask; |
| 1136 | 1137 |
| 1137 if ((unsigned int) delta >= ((mask + 1) >> 1)) | 1138 if ((unsigned int) delta >= ((mask + 1) >> 1)) |
| 1138 delta -= mask + 1; | 1139 delta -= mask + 1; |
| 1139 | 1140 |
| 1140 return delta; | 1141 return delta; |
| 1141 } | 1142 } |
| 1142 | 1143 |
| 1143 inline unsigned int get_size (void) const | 1144 inline unsigned int get_size (void) const |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1163 USHORT deltaValue[VAR]; /* Array of compressed data */ | 1164 USHORT deltaValue[VAR]; /* Array of compressed data */ |
| 1164 public: | 1165 public: |
| 1165 DEFINE_SIZE_ARRAY (6, deltaValue); | 1166 DEFINE_SIZE_ARRAY (6, deltaValue); |
| 1166 }; | 1167 }; |
| 1167 | 1168 |
| 1168 | 1169 |
| 1169 } /* namespace OT */ | 1170 } /* namespace OT */ |
| 1170 | 1171 |
| 1171 | 1172 |
| 1172 #endif /* HB_OT_LAYOUT_COMMON_PRIVATE_HH */ | 1173 #endif /* HB_OT_LAYOUT_COMMON_PRIVATE_HH */ |
| OLD | NEW |