diff --git a/src/OT/Layout/GPOS/PairPosFormat1.hh b/src/OT/Layout/GPOS/PairPosFormat1.hh index f05d83fb1..47e80b6bf 100644 --- a/src/OT/Layout/GPOS/PairPosFormat1.hh +++ b/src/OT/Layout/GPOS/PairPosFormat1.hh @@ -241,8 +241,6 @@ struct PairPosFormat1_3 bool strip_hints, bool strip_empty, const hb_hashmap_t> *varidx_delta_map = nullptr) const { - unsigned record_size = PairSet::get_size (valueFormat); - unsigned format1 = 0; unsigned format2 = 0; for (const auto & _ : @@ -252,18 +250,10 @@ struct PairPosFormat1_3 ) { const PairSet& set = (this + _); - const PairValueRecord *record = &set.firstPairValueRecord; - - unsigned count = set.len; - for (unsigned i = 0; i < count; i++) - { - if (record->intersects (glyphset)) - { - format1 = format1 | valueFormat[0].get_effective_format (record->get_values_1 (), strip_hints, strip_empty, &set, varidx_delta_map); - format2 = format2 | valueFormat[1].get_effective_format (record->get_values_2 (valueFormat[0]), strip_hints, strip_empty, &set, varidx_delta_map); - } - record = &StructAtOffset (record, record_size); - } + auto formats = set.get_values_view (valueFormat).compute_effective_value_formats ( + glyphset, valueFormat, strip_hints, strip_empty, varidx_delta_map); + format1 |= formats.first; + format2 |= formats.second; if (!varidx_delta_map && format1 == valueFormat[0] && format2 == valueFormat[1]) diff --git a/src/OT/Layout/GPOS/PairSet.hh b/src/OT/Layout/GPOS/PairSet.hh index fc4cd0bd3..3a089ac04 100644 --- a/src/OT/Layout/GPOS/PairSet.hh +++ b/src/OT/Layout/GPOS/PairSet.hh @@ -8,6 +8,60 @@ namespace Layout { namespace GPOS_impl { +/* Pair records vary in glyph width; their value traversal need not. */ +struct pair_set_values_t +{ + const ValueBase *base; + glyph_data_t glyphs; + const Value *values; + unsigned count; + unsigned record_size; + + unsigned get_glyph (unsigned i) const + { + glyph_data_t glyph = glyphs; + glyph.data = (const char *) glyph.data + i * record_size; + return glyph[0]; + } + + const Value *get_values (unsigned i) const + { return reinterpret_cast ((const char *) values + i * record_size); } + + hb_pair_t + compute_effective_value_formats (const hb_set_t &glyphset, + const ValueFormat valueFormats[2], + bool strip_hints, bool strip_empty, + const hb_hashmap_t> *varidx_delta_map) const + { + unsigned len1 = valueFormats[0].get_len (); + unsigned format1 = 0, format2 = 0; + for (unsigned i = 0; i < count; i++) + { + if (!glyphset.has (get_glyph (i))) continue; + const Value *v = get_values (i); + format1 |= valueFormats[0].get_effective_format (v, strip_hints, strip_empty, base, varidx_delta_map); + format2 |= valueFormats[1].get_effective_format (v + len1, strip_hints, strip_empty, base, varidx_delta_map); + } + return hb_pair (format1, format2); + } + + void collect_variation_indices (hb_collect_variation_indices_context_t *c, + const ValueFormat valueFormats[2]) const + { + unsigned len1 = valueFormats[0].get_len (); + unsigned len2 = valueFormats[1].get_len (); + for (unsigned i = 0; i < count; i++) + { + if (!c->glyph_set->has (get_glyph (i))) continue; + const hb_array_t v = hb_array (get_values (i), len1 + len2); + if (valueFormats[0].has_device ()) + valueFormats[0].collect_variation_indices (c, base, v.sub_array (0, len1)); + if (valueFormats[1].has_device ()) + valueFormats[1].collect_variation_indices (c, base, v.sub_array (len1, len2)); + } + } +}; + template struct PairSet : ValueBase { @@ -94,20 +148,16 @@ struct PairSet : ValueBase glyphs->add_array (&record->secondGlyph, len, record_size); } + pair_set_values_t get_values_view (const ValueFormat valueFormats[2]) const + { + return {this, &firstPairValueRecord.secondGlyph, &firstPairValueRecord.values[0], + (unsigned) len, (unsigned) get_size (valueFormats)}; + } + void collect_variation_indices (hb_collect_variation_indices_context_t *c, const ValueFormat *valueFormats) const { - unsigned record_size = get_size (valueFormats); - - const PairValueRecord *record = &firstPairValueRecord; - unsigned count = (unsigned) len; - for (unsigned i = 0; i < count; i++) - { - if (c->glyph_set->has (record->secondGlyph)) - { record->collect_variation_indices (c, valueFormats, this); } - - record = &StructAtOffset (record, record_size); - } + get_values_view (valueFormats).collect_variation_indices (c, valueFormats); } bool apply (hb_ot_apply_context_t *c, @@ -190,7 +240,7 @@ struct PairSet : ValueBase unsigned len2 = valueFormats[1].get_len (); unsigned record_size = get_size (len1, len2); - typename PairValueRecord::context_t context = + pair_value_record_context_t context = { this, valueFormats, diff --git a/src/OT/Layout/GPOS/PairValueRecord.hh b/src/OT/Layout/GPOS/PairValueRecord.hh index d00618b76..028999a31 100644 --- a/src/OT/Layout/GPOS/PairValueRecord.hh +++ b/src/OT/Layout/GPOS/PairValueRecord.hh @@ -8,6 +8,24 @@ namespace Layout { namespace GPOS_impl { +struct pair_value_record_context_t +{ + const ValueBase *base; + const ValueFormat *valueFormats; + const ValueFormat *newFormats; + unsigned len1; /* valueFormats[0].get_len() */ + const hb_map_t *glyph_map; + const hb_hashmap_t> *layout_variation_idx_delta_map; + + void copy_values (hb_serialize_context_t *s, const Value *values) const + { + valueFormats[0].copy_values (s, newFormats[0], base, values, + layout_variation_idx_delta_map); + valueFormats[1].copy_values (s, newFormats[1], base, values + len1, + layout_variation_idx_delta_map); + } +}; + template struct PairValueRecord { @@ -27,18 +45,8 @@ struct PairValueRecord int cmp (hb_codepoint_t k) const { return secondGlyph.cmp (k); } - struct context_t - { - const ValueBase *base; - const ValueFormat *valueFormats; - const ValueFormat *newFormats; - unsigned len1; /* valueFormats[0].get_len() */ - const hb_map_t *glyph_map; - const hb_hashmap_t> *layout_variation_idx_delta_map; - }; - bool subset (hb_subset_context_t *c, - context_t *closure) const + pair_value_record_context_t *closure) const { TRACE_SERIALIZE (this); auto *s = c->serializer; @@ -47,15 +55,7 @@ struct PairValueRecord out->secondGlyph = (*closure->glyph_map)[secondGlyph]; - closure->valueFormats[0].copy_values (s, - closure->newFormats[0], - closure->base, &values[0], - closure->layout_variation_idx_delta_map); - closure->valueFormats[1].copy_values (s, - closure->newFormats[1], - closure->base, - &values[closure->len1], - closure->layout_variation_idx_delta_map); + closure->copy_values (s, values); return_trace (true); }