From f1e95e40edc871c840abe8a8a695efc252af40f5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 18 Dec 2018 16:49:08 -0500 Subject: [PATCH] [arrays] Remove hb_supplier_t<> --- src/hb-array.hh | 11 - src/hb-cff2-interp-cs.hh | 2 +- src/hb-face.cc | 6 +- src/hb-open-file.hh | 15 +- src/hb-open-type.hh | 18 +- src/hb-ot-cmap-table.hh | 3 +- src/hb-ot-layout-common.hh | 104 +++------ src/hb-ot-layout-gsub-table.hh | 257 +++++++++------------ src/hb-ot-shape-complex-arabic-fallback.hh | 23 +- 9 files changed, 170 insertions(+), 269 deletions(-) diff --git a/src/hb-array.hh b/src/hb-array.hh index c18d4dc4..33837b08 100644 --- a/src/hb-array.hh +++ b/src/hb-array.hh @@ -269,16 +269,5 @@ inline hb_sorted_array_t hb_sorted_array (T *array, unsigned int len) typedef hb_array_t hb_bytes_t; -template struct hb_supplier_t : hb_array_t -{ - HB_NO_CREATE_COPY_ASSIGN_TEMPLATE (hb_supplier_t, Type); - - hb_supplier_t (const Type *array, unsigned int len) : hb_array_t (array, len) {} - hb_supplier_t (hb_array_t v) : hb_array_t (v) {} - - /* Make sure no one calls the custom & operator on us. */ - Type * operator & () const; -}; - #endif /* HB_ARRAY_HH */ diff --git a/src/hb-cff2-interp-cs.hh b/src/hb-cff2-interp-cs.hh index 7756ca83..709bdefa 100644 --- a/src/hb-cff2-interp-cs.hh +++ b/src/hb-cff2-interp-cs.hh @@ -52,7 +52,7 @@ struct BlendArg : Number void set_real (double v) { reset_blends (); Number::set_real (v); } void set_blends (unsigned int numValues_, unsigned int valueIndex_, - unsigned int numBlends, const hb_array_t &blends_) + unsigned int numBlends, hb_array_t blends_) { numValues = numValues_; valueIndex = valueIndex_; diff --git a/src/hb-face.cc b/src/hb-face.cc index 825021f7..8bb8c512 100644 --- a/src/hb-face.cc +++ b/src/hb-face.cc @@ -648,11 +648,7 @@ _hb_face_builder_data_reference_blob (hb_face_builder_data_t *data) bool is_cff = data->tables.lsearch (HB_TAG ('C','F','F',' ')) || data->tables.lsearch (HB_TAG ('C','F','F','2')); hb_tag_t sfnt_tag = is_cff ? OT::OpenTypeFontFile::CFFTag : OT::OpenTypeFontFile::TrueTypeTag; - hb_supplier_t supplier (data->tables); - bool ret = f->serialize_single (&c, - sfnt_tag, - supplier, - table_count); + bool ret = f->serialize_single (&c, sfnt_tag, data->tables.as_array ()); c.end_serialize (); diff --git a/src/hb-open-file.hh b/src/hb-open-file.hh index 8890f523..822a92d3 100644 --- a/src/hb-open-file.hh +++ b/src/hb-open-file.hh @@ -121,8 +121,7 @@ typedef struct OffsetTable template bool serialize (hb_serialize_context_t *c, hb_tag_t sfnt_tag, - hb_supplier_t &items, - unsigned int table_count) + hb_array_t items) { TRACE_SERIALIZE (this); /* Alloc 12 for the OTHeader. */ @@ -131,13 +130,13 @@ typedef struct OffsetTable sfnt_version.set (sfnt_tag); /* Take space for numTables, searchRange, entrySelector, RangeShift * and the TableRecords themselves. */ - if (unlikely (!tables.serialize (c, table_count))) return_trace (false); + if (unlikely (!tables.serialize (c, items.len))) return_trace (false); const char *dir_end = (const char *) c->head; HBUINT32 *checksum_adjustment = nullptr; /* Write OffsetTables, alloc for and write actual table blobs. */ - for (unsigned int i = 0; i < table_count; i++) + for (unsigned int i = 0; i < tables.len; i++) { TableRecord &rec = tables.arrayZ[i]; hb_blob_t *blob = items[i].blob; @@ -164,7 +163,6 @@ typedef struct OffsetTable rec.checkSum.set_for_data (start, end - start); } - items += table_count; tables.qsort (); @@ -175,7 +173,7 @@ typedef struct OffsetTable /* The following line is a slower version of the following block. */ //checksum.set_for_data (this, (const char *) c->head - (const char *) this); checksum.set_for_data (this, dir_end - (const char *) this); - for (unsigned int i = 0; i < table_count; i++) + for (unsigned int i = 0; i < items.len; i++) { TableRecord &rec = tables.arrayZ[i]; checksum.set (checksum + rec.checkSum); @@ -485,13 +483,12 @@ struct OpenTypeFontFile template bool serialize_single (hb_serialize_context_t *c, hb_tag_t sfnt_tag, - hb_supplier_t &items, - unsigned int table_count) + hb_array_t items) { TRACE_SERIALIZE (this); assert (sfnt_tag != TTCTag); if (unlikely (!c->extend_min (*this))) return_trace (false); - return_trace (u.fontFace.serialize (c, sfnt_tag, items, table_count)); + return_trace (u.fontFace.serialize (c, sfnt_tag, items)); } bool sanitize (hb_sanitize_context_t *c) const diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 0dfcd3a1..6517c6bf 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -553,15 +553,12 @@ struct ArrayOf if (unlikely (!c->extend (*this))) return_trace (false); return_trace (true); } - bool serialize (hb_serialize_context_t *c, - hb_supplier_t &items, - unsigned int items_len) + bool serialize (hb_serialize_context_t *c, hb_array_t items) { TRACE_SERIALIZE (this); - if (unlikely (!serialize (c, items_len))) return_trace (false); - for (unsigned int i = 0; i < items_len; i++) + if (unlikely (!serialize (c, items.len))) return_trace (false); + for (unsigned int i = 0; i < items.len; i++) arrayZ[i] = items[i]; - items += items_len; return_trace (true); } @@ -701,17 +698,14 @@ struct HeadlessArrayOf { return lenP1.static_size + (lenP1 ? lenP1 - 1 : 0) * Type::static_size; } bool serialize (hb_serialize_context_t *c, - hb_supplier_t &items, - unsigned int items_len) + hb_array_t items) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); - lenP1.set (items_len); /* TODO(serialize) Overflow? */ - if (unlikely (!items_len)) return_trace (true); + lenP1.set (items.len + 1); /* TODO(serialize) Overflow? */ if (unlikely (!c->extend (*this))) return_trace (false); - for (unsigned int i = 0; i < items_len - 1; i++) + for (unsigned int i = 0; i < items.len; i++) arrayZ[i] = items[i]; - items += items_len - 1; return_trace (true); } diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 2f8c6413..7567e52c 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -495,8 +495,7 @@ struct CmapSubtableLongSegmented { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); - hb_supplier_t supplier (group_data); - if (unlikely (!groups.serialize (c, supplier, group_data.len))) return_trace (false); + if (unlikely (!groups.serialize (c, group_data.as_array ()))) return_trace (false); return true; } diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index ac739204..f11261ac 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -827,17 +827,10 @@ struct CoverageFormat1 } bool serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - unsigned int num_glyphs) + hb_array_t glyphs) { TRACE_SERIALIZE (this); - if (unlikely (!c->extend_min (*this))) return_trace (false); - glyphArray.len.set (num_glyphs); - if (unlikely (!c->extend (glyphArray))) return_trace (false); - for (unsigned int i = 0; i < num_glyphs; i++) - glyphArray[i] = glyphs[i]; - glyphs += num_glyphs; - return_trace (true); + return_trace (glyphArray.serialize (c, glyphs)); } bool sanitize (hb_sanitize_context_t *c) const @@ -902,20 +895,19 @@ struct CoverageFormat2 } bool serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - unsigned int num_glyphs) + hb_array_t glyphs) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); - if (unlikely (!num_glyphs)) + if (unlikely (!glyphs.len)) { rangeRecord.len.set (0); return_trace (true); } unsigned int num_ranges = 1; - for (unsigned int i = 1; i < num_glyphs; i++) + for (unsigned int i = 1; i < glyphs.len; i++) if (glyphs[i - 1] + 1 != glyphs[i]) num_ranges++; rangeRecord.len.set (num_ranges); @@ -924,7 +916,7 @@ struct CoverageFormat2 unsigned int range = 0; rangeRecord[range].start = glyphs[0]; rangeRecord[range].value.set (0); - for (unsigned int i = 1; i < num_glyphs; i++) + for (unsigned int i = 1; i < glyphs.len; i++) { if (glyphs[i - 1] + 1 != glyphs[i]) { @@ -934,7 +926,6 @@ struct CoverageFormat2 } rangeRecord[range].end = glyphs[i]; } - glyphs += num_glyphs; return_trace (true); } @@ -1051,22 +1042,21 @@ struct Coverage } bool serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - unsigned int num_glyphs) + hb_array_t glyphs) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); unsigned int num_ranges = 1; - for (unsigned int i = 1; i < num_glyphs; i++) + for (unsigned int i = 1; i < glyphs.len; i++) if (glyphs[i - 1] + 1 != glyphs[i]) num_ranges++; - u.format.set (num_glyphs * 2 < num_ranges * 3 ? 1 : 2); + u.format.set (glyphs.len * 2 < num_ranges * 3 ? 1 : 2); switch (u.format) { - case 1: return_trace (u.format1.serialize (c, glyphs, num_glyphs)); - case 2: return_trace (u.format2.serialize (c, glyphs, num_glyphs)); + case 1: return_trace (u.format1.serialize (c, glyphs)); + case 2: return_trace (u.format2.serialize (c, glyphs)); default:return_trace (false); } } @@ -1189,9 +1179,8 @@ struct Coverage */ static inline void ClassDef_serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - hb_supplier_t &klasses, - unsigned int num_glyphs); + hb_array_t glyphs, + hb_array_t klasses); struct ClassDefFormat1 { @@ -1204,14 +1193,13 @@ struct ClassDefFormat1 } bool serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - hb_supplier_t &klasses, - unsigned int num_glyphs) + hb_array_t glyphs, + hb_array_t klasses) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); - if (unlikely (!num_glyphs)) + if (unlikely (!glyphs.len)) { startGlyph.set (0); classValue.len.set (0); @@ -1219,7 +1207,7 @@ struct ClassDefFormat1 } hb_codepoint_t glyph_min = (hb_codepoint_t) -1, glyph_max = 0; - for (unsigned int i = 0; i < num_glyphs; i++) + for (unsigned int i = 0; i < glyphs.len; i++) { glyph_min = MIN (glyph_min, glyphs[i]); glyph_max = MAX (glyph_max, glyphs[i]); @@ -1229,10 +1217,9 @@ struct ClassDefFormat1 classValue.len.set (glyph_max - glyph_min + 1); if (unlikely (!c->extend (classValue))) return_trace (false); - for (unsigned int i = 0; i < num_glyphs; i++) + for (unsigned int i = 0; i < glyphs.len; i++) classValue[glyphs[i] - glyph_min] = klasses[i]; - glyphs += num_glyphs; - klasses += num_glyphs; + return_trace (true); } @@ -1255,13 +1242,7 @@ struct ClassDefFormat1 klasses.push()->set (value); } c->serializer->propagate_error (glyphs, klasses); - - hb_supplier_t glyphs_supplier (glyphs); - hb_supplier_t klasses_supplier (klasses); - ClassDef_serialize (c->serializer, - glyphs_supplier, - klasses_supplier, - glyphs.len); + ClassDef_serialize (c->serializer, glyphs, klasses); return_trace (glyphs.len); } @@ -1352,21 +1333,20 @@ struct ClassDefFormat2 } bool serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - hb_supplier_t &klasses, - unsigned int num_glyphs) + hb_array_t glyphs, + hb_array_t klasses) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); - if (unlikely (!num_glyphs)) + if (unlikely (!glyphs.len)) { rangeRecord.len.set (0); return_trace (true); } unsigned int num_ranges = 1; - for (unsigned int i = 1; i < num_glyphs; i++) + for (unsigned int i = 1; i < glyphs.len; i++) if (glyphs[i - 1] + 1 != glyphs[i] || klasses[i - 1] != klasses[i]) num_ranges++; @@ -1376,7 +1356,7 @@ struct ClassDefFormat2 unsigned int range = 0; rangeRecord[range].start = glyphs[0]; rangeRecord[range].value.set (klasses[0]); - for (unsigned int i = 1; i < num_glyphs; i++) + for (unsigned int i = 1; i < glyphs.len; i++) { if (glyphs[i - 1] + 1 != glyphs[i] || klasses[i - 1] != klasses[i]) @@ -1387,7 +1367,6 @@ struct ClassDefFormat2 } rangeRecord[range].end = glyphs[i]; } - glyphs += num_glyphs; return_trace (true); } @@ -1414,13 +1393,7 @@ struct ClassDefFormat2 } } c->serializer->propagate_error (glyphs, klasses); - - hb_supplier_t glyphs_supplier (glyphs); - hb_supplier_t klasses_supplier (klasses); - ClassDef_serialize (c->serializer, - glyphs_supplier, - klasses_supplier, - glyphs.len); + ClassDef_serialize (c->serializer, glyphs, klasses); return_trace (glyphs.len); } @@ -1509,21 +1482,20 @@ struct ClassDef } bool serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - hb_supplier_t &klasses, - unsigned int num_glyphs) + hb_array_t glyphs, + hb_array_t klasses) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); hb_codepoint_t glyph_min = (hb_codepoint_t) -1, glyph_max = 0; - for (unsigned int i = 0; i < num_glyphs; i++) + for (unsigned int i = 0; i < glyphs.len; i++) { glyph_min = MIN (glyph_min, glyphs[i]); glyph_max = MAX (glyph_max, glyphs[i]); } unsigned int num_ranges = 1; - for (unsigned int i = 1; i < num_glyphs; i++) + for (unsigned int i = 1; i < glyphs.len; i++) if (glyphs[i - 1] + 1 != glyphs[i] || klasses[i - 1] != klasses[i]) num_ranges++; @@ -1531,8 +1503,8 @@ struct ClassDef switch (u.format) { - case 1: return_trace (u.format1.serialize (c, glyphs, klasses, num_glyphs)); - case 2: return_trace (u.format2.serialize (c, glyphs, klasses, num_glyphs)); + case 1: return_trace (u.format1.serialize (c, glyphs, klasses)); + case 2: return_trace (u.format2.serialize (c, glyphs, klasses)); default:return_trace (false); } } @@ -1610,15 +1582,9 @@ struct ClassDef }; static inline void ClassDef_serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - hb_supplier_t &klasses, - unsigned int num_glyphs) -{ - c->start_embed ()->serialize (c, - glyphs, - klasses, - num_glyphs); -} + hb_array_t glyphs, + hb_array_t klasses) +{ c->start_embed ()->serialize (c, glyphs, klasses); } /* diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index fb59921a..180e7f2d 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -36,9 +36,8 @@ namespace OT { static inline void SingleSubst_serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - hb_supplier_t &substitutes, - unsigned int num_glyphs); + hb_array_t glyphs, + hb_array_t substitutes); struct SingleSubstFormat1 { @@ -95,13 +94,12 @@ struct SingleSubstFormat1 } bool serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - unsigned int num_glyphs, + hb_array_t glyphs, int delta) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); - if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return_trace (false); + if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs))) return_trace (false); deltaGlyphID.set (delta); /* TODO(serialize) overflow? */ return_trace (true); } @@ -121,13 +119,7 @@ struct SingleSubstFormat1 to.push ()->set (glyph_map[(iter.get_glyph () + delta) & 0xFFFF]); } c->serializer->propagate_error (from, to); - - hb_supplier_t from_supplier (from); - hb_supplier_t to_supplier (to); - SingleSubst_serialize (c->serializer, - from_supplier, - to_supplier, - from.len); + SingleSubst_serialize (c->serializer, from, to); return_trace (from.len); } @@ -201,14 +193,13 @@ struct SingleSubstFormat2 } bool serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - hb_supplier_t &substitutes, - unsigned int num_glyphs) + hb_array_t glyphs, + hb_array_t substitutes) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); - if (unlikely (!substitute.serialize (c, substitutes, num_glyphs))) return_trace (false); - if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return_trace (false); + if (unlikely (!substitute.serialize (c, substitutes))) return_trace (false); + if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs))) return_trace (false); return_trace (true); } @@ -226,13 +217,7 @@ struct SingleSubstFormat2 to.push ()->set (glyph_map[substitute[iter.get_coverage ()]]); } c->serializer->propagate_error (from, to); - - hb_supplier_t from_supplier (from); - hb_supplier_t to_supplier (to); - SingleSubst_serialize (c->serializer, - from_supplier, - to_supplier, - from.len); + SingleSubst_serialize (c->serializer, from, to); return_trace (from.len); } @@ -257,19 +242,19 @@ struct SingleSubstFormat2 struct SingleSubst { bool serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - hb_supplier_t &substitutes, - unsigned int num_glyphs) + hb_array_t glyphs, + hb_array_t substitutes) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (u.format))) return_trace (false); unsigned int format = 2; int delta = 0; - if (num_glyphs) { + if (glyphs.len) + { format = 1; /* TODO(serialize) check for wrap-around */ delta = substitutes[0] - glyphs[0]; - for (unsigned int i = 1; i < num_glyphs; i++) + for (unsigned int i = 1; i < glyphs.len; i++) if (delta != (int) (substitutes[i] - glyphs[i])) { format = 2; break; @@ -277,8 +262,8 @@ struct SingleSubst } u.format.set (format); switch (u.format) { - case 1: return_trace (u.format1.serialize (c, glyphs, num_glyphs, delta)); - case 2: return_trace (u.format2.serialize (c, glyphs, substitutes, num_glyphs)); + case 1: return_trace (u.format1.serialize (c, glyphs, delta)); + case 2: return_trace (u.format2.serialize (c, glyphs, substitutes)); default:return_trace (false); } } @@ -305,15 +290,9 @@ struct SingleSubst static inline void SingleSubst_serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - hb_supplier_t &substitutes, - unsigned int num_glyphs) -{ - c->start_embed ()->serialize (c, - glyphs, - substitutes, - num_glyphs); -} + hb_array_t glyphs, + hb_array_t substitutes) +{ c->start_embed ()->serialize (c, glyphs, substitutes); } struct Sequence { @@ -364,13 +343,10 @@ struct Sequence } bool serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - unsigned int num_glyphs) + hb_array_t glyphs) { TRACE_SERIALIZE (this); - if (unlikely (!c->extend_min (*this))) return_trace (false); - if (unlikely (!substitute.serialize (c, glyphs, num_glyphs))) return_trace (false); - return_trace (true); + return_trace (substitute.serialize (c, glyphs)); } bool sanitize (hb_sanitize_context_t *c) const @@ -432,21 +408,22 @@ struct MultipleSubstFormat1 } bool serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - hb_supplier_t &substitute_len_list, - unsigned int num_glyphs, - hb_supplier_t &substitute_glyphs_list) + hb_array_t glyphs, + hb_array_t substitute_len_list, + hb_array_t substitute_glyphs_list) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); - if (unlikely (!sequence.serialize (c, num_glyphs))) return_trace (false); - for (unsigned int i = 0; i < num_glyphs; i++) - if (unlikely (!sequence[i].serialize (c, this).serialize (c, - substitute_glyphs_list, - substitute_len_list[i]))) return_trace (false); - substitute_len_list += num_glyphs; - if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return_trace (false); - return_trace (true); + if (unlikely (!sequence.serialize (c, glyphs.len))) return_trace (false); + for (unsigned int i = 0; i < glyphs.len; i++) + { + unsigned int substitute_len = substitute_len_list[i]; + if (unlikely (!sequence[i].serialize (c, this) + .serialize (c, substitute_glyphs_list.sub_array (0, substitute_len)))) + return_trace (false); + substitute_glyphs_list += substitute_len; + } + return_trace (coverage.serialize (c, this).serialize (c, glyphs)); } bool subset (hb_subset_context_t *c) const @@ -477,17 +454,16 @@ struct MultipleSubstFormat1 struct MultipleSubst { bool serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - hb_supplier_t &substitute_len_list, - unsigned int num_glyphs, - hb_supplier_t &substitute_glyphs_list) + hb_array_t glyphs, + hb_array_t substitute_len_list, + hb_array_t substitute_glyphs_list) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (u.format))) return_trace (false); unsigned int format = 1; u.format.set (format); switch (u.format) { - case 1: return_trace (u.format1.serialize (c, glyphs, substitute_len_list, num_glyphs, substitute_glyphs_list)); + case 1: return_trace (u.format1.serialize (c, glyphs, substitute_len_list, substitute_glyphs_list)); default:return_trace (false); } } @@ -552,13 +528,10 @@ struct AlternateSet } bool serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - unsigned int num_glyphs) + hb_array_t glyphs) { TRACE_SERIALIZE (this); - if (unlikely (!c->extend_min (*this))) return_trace (false); - if (unlikely (!alternates.serialize (c, glyphs, num_glyphs))) return_trace (false); - return_trace (true); + return_trace (alternates.serialize (c, glyphs)); } bool sanitize (hb_sanitize_context_t *c) const @@ -625,21 +598,22 @@ struct AlternateSubstFormat1 } bool serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - hb_supplier_t &alternate_len_list, - unsigned int num_glyphs, - hb_supplier_t &alternate_glyphs_list) + hb_array_t glyphs, + hb_array_t alternate_len_list, + hb_array_t alternate_glyphs_list) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); - if (unlikely (!alternateSet.serialize (c, num_glyphs))) return_trace (false); - for (unsigned int i = 0; i < num_glyphs; i++) - if (unlikely (!alternateSet[i].serialize (c, this).serialize (c, - alternate_glyphs_list, - alternate_len_list[i]))) return_trace (false); - alternate_len_list += num_glyphs; - if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return_trace (false); - return_trace (true); + if (unlikely (!alternateSet.serialize (c, glyphs.len))) return_trace (false); + for (unsigned int i = 0; i < glyphs.len; i++) + { + unsigned int alternate_len = alternate_len_list[i]; + if (unlikely (!alternateSet[i].serialize (c, this) + .serialize (c, alternate_glyphs_list.sub_array (0, alternate_len)))) + return_trace (false); + alternate_glyphs_list += alternate_len; + } + return_trace (coverage.serialize (c, this).serialize (c, glyphs)); } bool subset (hb_subset_context_t *c) const @@ -670,17 +644,16 @@ struct AlternateSubstFormat1 struct AlternateSubst { bool serialize (hb_serialize_context_t *c, - hb_supplier_t &glyphs, - hb_supplier_t &alternate_len_list, - unsigned int num_glyphs, - hb_supplier_t &alternate_glyphs_list) + hb_array_t glyphs, + hb_array_t alternate_len_list, + hb_array_t alternate_glyphs_list) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (u.format))) return_trace (false); unsigned int format = 1; u.format.set (format); switch (u.format) { - case 1: return_trace (u.format1.serialize (c, glyphs, alternate_len_list, num_glyphs, alternate_glyphs_list)); + case 1: return_trace (u.format1.serialize (c, glyphs, alternate_len_list, alternate_glyphs_list)); default:return_trace (false); } } @@ -786,13 +759,12 @@ struct Ligature bool serialize (hb_serialize_context_t *c, GlyphID ligature, - hb_supplier_t &components, /* Starting from second */ - unsigned int num_components /* Including first component */) + hb_array_t components /* Starting from second */) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); ligGlyph = ligature; - if (unlikely (!component.serialize (c, components, num_components))) return_trace (false); + if (unlikely (!component.serialize (c, components))) return_trace (false); return_trace (true); } @@ -867,21 +839,23 @@ struct LigatureSet } bool serialize (hb_serialize_context_t *c, - hb_supplier_t &ligatures, - hb_supplier_t &component_count_list, - unsigned int num_ligatures, - hb_supplier_t &component_list /* Starting from second for each ligature */) + hb_array_t ligatures, + hb_array_t component_count_list, + hb_array_t component_list /* Starting from second for each ligature */) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); - if (unlikely (!ligature.serialize (c, num_ligatures))) return_trace (false); - for (unsigned int i = 0; i < num_ligatures; i++) - if (unlikely (!ligature[i].serialize (c, this).serialize (c, - ligatures[i], - component_list, - component_count_list[i]))) return_trace (false); - ligatures += num_ligatures; - component_count_list += num_ligatures; + if (unlikely (!ligature.serialize (c, ligatures.len))) return_trace (false); + for (unsigned int i = 0; i < ligatures.len; i++) + { + unsigned int component_count = MAX (component_count_list[i] - 1, 0); + if (unlikely (!ligature[i].serialize (c, this) + .serialize (c, + ligatures[i], + component_list.sub_array (0, component_count)))) + return_trace (false); + component_list += component_count; + } return_trace (true); } @@ -965,25 +939,29 @@ struct LigatureSubstFormat1 } bool serialize (hb_serialize_context_t *c, - hb_supplier_t &first_glyphs, - hb_supplier_t &ligature_per_first_glyph_count_list, - unsigned int num_first_glyphs, - hb_supplier_t &ligatures_list, - hb_supplier_t &component_count_list, - hb_supplier_t &component_list /* Starting from second for each ligature */) + hb_array_t first_glyphs, + hb_array_t ligature_per_first_glyph_count_list, + hb_array_t ligatures_list, + hb_array_t component_count_list, + hb_array_t component_list /* Starting from second for each ligature */) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); - if (unlikely (!ligatureSet.serialize (c, num_first_glyphs))) return_trace (false); - for (unsigned int i = 0; i < num_first_glyphs; i++) - if (unlikely (!ligatureSet[i].serialize (c, this).serialize (c, - ligatures_list, - component_count_list, - ligature_per_first_glyph_count_list[i], - component_list))) return_trace (false); - ligature_per_first_glyph_count_list += num_first_glyphs; - if (unlikely (!coverage.serialize (c, this).serialize (c, first_glyphs, num_first_glyphs))) return_trace (false); - return_trace (true); + if (unlikely (!ligatureSet.serialize (c, first_glyphs.len))) return_trace (false); + for (unsigned int i = 0; i < first_glyphs.len; i++) + { + unsigned int ligature_count = ligature_per_first_glyph_count_list[i]; + if (unlikely (!ligatureSet[i].serialize (c, this) + .serialize (c, + ligatures_list.sub_array (0, ligature_count), + component_count_list.sub_array (0, ligature_count), + component_list))) return_trace (false); + ligatures_list += ligature_count; + component_count_list += ligature_count; + for (unsigned int i = 0; i < ligature_count; i++) + component_list += MAX (component_count_list[i] - 1, 0); + } + return_trace (coverage.serialize (c, this).serialize (c, first_glyphs)); } bool subset (hb_subset_context_t *c) const @@ -1014,12 +992,11 @@ struct LigatureSubstFormat1 struct LigatureSubst { bool serialize (hb_serialize_context_t *c, - hb_supplier_t &first_glyphs, - hb_supplier_t &ligature_per_first_glyph_count_list, - unsigned int num_first_glyphs, - hb_supplier_t &ligatures_list, - hb_supplier_t &component_count_list, - hb_supplier_t &component_list /* Starting from second for each ligature */) + hb_array_t first_glyphs, + hb_array_t ligature_per_first_glyph_count_list, + hb_array_t ligatures_list, + hb_array_t component_count_list, + hb_array_t component_list /* Starting from second for each ligature */) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (u.format))) return_trace (false); @@ -1029,7 +1006,6 @@ struct LigatureSubst case 1: return_trace (u.format1.serialize (c, first_glyphs, ligature_per_first_glyph_count_list, - num_first_glyphs, ligatures_list, component_count_list, component_list)); @@ -1372,62 +1348,55 @@ struct SubstLookup : Lookup bool serialize_single (hb_serialize_context_t *c, uint32_t lookup_props, - hb_supplier_t &glyphs, - hb_supplier_t &substitutes, - unsigned int num_glyphs) + hb_array_t glyphs, + hb_array_t substitutes) { TRACE_SERIALIZE (this); if (unlikely (!Lookup::serialize (c, SubTable::Single, lookup_props, 1))) return_trace (false); - return_trace (serialize_subtable (c, 0).u.single.serialize (c, glyphs, substitutes, num_glyphs)); + return_trace (serialize_subtable (c, 0).u.single.serialize (c, glyphs, substitutes)); } bool serialize_multiple (hb_serialize_context_t *c, uint32_t lookup_props, - hb_supplier_t &glyphs, - hb_supplier_t &substitute_len_list, - unsigned int num_glyphs, - hb_supplier_t &substitute_glyphs_list) + hb_array_t glyphs, + hb_array_t substitute_len_list, + hb_array_t substitute_glyphs_list) { TRACE_SERIALIZE (this); if (unlikely (!Lookup::serialize (c, SubTable::Multiple, lookup_props, 1))) return_trace (false); return_trace (serialize_subtable (c, 0).u.multiple.serialize (c, glyphs, substitute_len_list, - num_glyphs, substitute_glyphs_list)); } bool serialize_alternate (hb_serialize_context_t *c, uint32_t lookup_props, - hb_supplier_t &glyphs, - hb_supplier_t &alternate_len_list, - unsigned int num_glyphs, - hb_supplier_t &alternate_glyphs_list) + hb_array_t glyphs, + hb_array_t alternate_len_list, + hb_array_t alternate_glyphs_list) { TRACE_SERIALIZE (this); if (unlikely (!Lookup::serialize (c, SubTable::Alternate, lookup_props, 1))) return_trace (false); return_trace (serialize_subtable (c, 0).u.alternate.serialize (c, glyphs, alternate_len_list, - num_glyphs, alternate_glyphs_list)); } bool serialize_ligature (hb_serialize_context_t *c, uint32_t lookup_props, - hb_supplier_t &first_glyphs, - hb_supplier_t &ligature_per_first_glyph_count_list, - unsigned int num_first_glyphs, - hb_supplier_t &ligatures_list, - hb_supplier_t &component_count_list, - hb_supplier_t &component_list /* Starting from second for each ligature */) + hb_array_t first_glyphs, + hb_array_t ligature_per_first_glyph_count_list, + hb_array_t ligatures_list, + hb_array_t component_count_list, + hb_array_t component_list /* Starting from second for each ligature */) { TRACE_SERIALIZE (this); if (unlikely (!Lookup::serialize (c, SubTable::Ligature, lookup_props, 1))) return_trace (false); return_trace (serialize_subtable (c, 0).u.ligature.serialize (c, first_glyphs, ligature_per_first_glyph_count_list, - num_first_glyphs, ligatures_list, component_count_list, component_list)); diff --git a/src/hb-ot-shape-complex-arabic-fallback.hh b/src/hb-ot-shape-complex-arabic-fallback.hh index ec472d05..2a1f2f84 100644 --- a/src/hb-ot-shape-complex-arabic-fallback.hh +++ b/src/hb-ot-shape-complex-arabic-fallback.hh @@ -79,8 +79,6 @@ arabic_fallback_synthesize_lookup_single (const hb_ot_shape_plan_t *plan HB_UNUS * May not be good-enough for presidential candidate interviews, but good-enough for us... */ hb_stable_sort (&glyphs[0], num_glyphs, (int(*)(const OT::GlyphID*, const OT::GlyphID *)) OT::GlyphID::cmp, &substitutes[0]); - hb_supplier_t glyphs_supplier (glyphs, num_glyphs); - hb_supplier_t substitutes_supplier (substitutes, num_glyphs); /* Each glyph takes four bytes max, and there's some overhead. */ char buf[(SHAPING_TABLE_LAST - SHAPING_TABLE_FIRST + 1) * 4 + 128]; @@ -88,9 +86,8 @@ arabic_fallback_synthesize_lookup_single (const hb_ot_shape_plan_t *plan HB_UNUS OT::SubstLookup *lookup = c.start_serialize (); bool ret = lookup->serialize_single (&c, OT::LookupFlag::IgnoreMarks, - glyphs_supplier, - substitutes_supplier, - num_glyphs); + hb_array (glyphs, num_glyphs), + hb_array (substitutes, num_glyphs)); c.end_serialize (); /* TODO sanitize the results? */ @@ -155,11 +152,6 @@ arabic_fallback_synthesize_lookup_ligature (const hb_ot_shape_plan_t *plan HB_UN if (!num_ligatures) return nullptr; - hb_supplier_t first_glyphs_supplier (first_glyphs, num_first_glyphs); - hb_supplier_t ligature_per_first_glyph_count_supplier (ligature_per_first_glyph_count_list, num_first_glyphs); - hb_supplier_t ligatures_supplier (ligature_list, num_ligatures); - hb_supplier_t component_count_supplier (component_count_list, num_ligatures); - hb_supplier_t component_supplier (component_list, num_ligatures); /* 16 bytes per ligature ought to be enough... */ char buf[ARRAY_LENGTH_CONST (ligature_list) * 16 + 128]; @@ -167,12 +159,11 @@ arabic_fallback_synthesize_lookup_ligature (const hb_ot_shape_plan_t *plan HB_UN OT::SubstLookup *lookup = c.start_serialize (); bool ret = lookup->serialize_ligature (&c, OT::LookupFlag::IgnoreMarks, - first_glyphs_supplier, - ligature_per_first_glyph_count_supplier, - num_first_glyphs, - ligatures_supplier, - component_count_supplier, - component_supplier); + hb_array (first_glyphs, num_first_glyphs), + hb_array (ligature_per_first_glyph_count_list, num_first_glyphs), + hb_array (ligature_list, num_ligatures), + hb_array (component_count_list, num_ligatures), + hb_array (component_list, num_ligatures)); c.end_serialize (); /* TODO sanitize the results? */ -- GitLab