diff --git a/src/hb-bimap.hh b/src/hb-bimap.hh index cdea03b9a..e9f3a6a52 100644 --- a/src/hb-bimap.hh +++ b/src/hb-bimap.hh @@ -94,6 +94,14 @@ struct hb_bimap_t /* Inremental bimap: only lhs is given, rhs is incrementally assigned */ struct hb_inc_bimap_t : hb_bimap_t { + hb_inc_bimap_t () { init (); } + + void init () + { + hb_bimap_t::init (); + next_value = 0; + } + /* Add a mapping from lhs to rhs with a unique value if lhs is unknown. * Return the rhs value as the result. */ @@ -102,12 +110,18 @@ struct hb_inc_bimap_t : hb_bimap_t hb_codepoint_t rhs = forw_map[lhs]; if (rhs == HB_MAP_VALUE_INVALID) { - rhs = get_population (); + rhs = next_value++; set (lhs, rhs); } return rhs; } + hb_codepoint_t skip () + { return next_value++; } + + hb_codepoint_t get_next_value () const + { return next_value; } + void add_set (const hb_set_t *set) { hb_codepoint_t i = HB_SET_VALUE_INVALID; @@ -144,6 +158,9 @@ struct hb_inc_bimap_t : hb_bimap_t for (hb_codepoint_t rhs = 0; rhs < count; rhs++) set (work[rhs], rhs); } + + protected: + unsigned int next_value; }; #endif /* HB_BIMAP_HH */ diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 8cc64336e..52bf4f8ce 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -1723,6 +1723,9 @@ struct VarData unsigned int get_region_index_count () const { return regionIndices.len; } + unsigned int get_row_size () const + { return shortCount + regionIndices.len; } + unsigned int get_size () const { return itemCount * get_row_size (); } @@ -1783,13 +1786,13 @@ struct VarData bool serialize (hb_serialize_context_t *c, const VarData *src, - const hb_bimap_t &inner_map, + const hb_inc_bimap_t &inner_map, const hb_bimap_t ®ion_map) { TRACE_SERIALIZE (this); if (unlikely (!c->extend_min (*this))) return_trace (false); - itemCount = inner_map.get_population (); - + itemCount = inner_map.get_next_value (); + /* Optimize short count */ unsigned short ri_count = src->regionIndices.len; enum delta_size_t { kZero=0, kByte, kShort }; @@ -1802,7 +1805,7 @@ struct VarData for (r = 0; r < ri_count; r++) { delta_sz[r] = kZero; - for (unsigned int i = 0; i < inner_map.get_population (); i++) + for (unsigned int i = 0; i < inner_map.get_next_value (); i++) { unsigned int old = inner_map.backward (i); int16_t delta = src->get_item_delta (old, r); @@ -1838,8 +1841,7 @@ struct VarData for (unsigned int i = 0; i < itemCount; i++) { - hb_codepoint_t old = inner_map.backward (i); - if (unlikely (old >= src->itemCount)) return_trace (false); + unsigned int old = inner_map.backward (i); for (unsigned int r = 0; r < ri_count; r++) if (delta_sz[r]) set_item_delta (i, ri_map[r], src->get_item_delta (old, r)); } @@ -1847,13 +1849,13 @@ struct VarData return_trace (true); } - void collect_region_refs (hb_inc_bimap_t ®ion_map, const hb_bimap_t &inner_map) const + void collect_region_refs (hb_inc_bimap_t ®ion_map, const hb_inc_bimap_t &inner_map) const { for (unsigned int r = 0; r < regionIndices.len; r++) { unsigned int region = regionIndices[r]; if (region_map.has (region)) continue; - for (unsigned int i = 0; i < inner_map.get_population (); i++) + for (unsigned int i = 0; i < inner_map.get_next_value (); i++) if (get_item_delta (inner_map.backward (i), r) != 0) { region_map.add (region); @@ -1863,9 +1865,6 @@ struct VarData } protected: - unsigned int get_row_size () const - { return shortCount + regionIndices.len; } - const HBUINT8 *get_delta_bytes () const { return &StructAfter (regionIndices); } @@ -1874,7 +1873,7 @@ struct VarData int16_t get_item_delta (unsigned int item, unsigned int region) const { - if (unlikely (item >= itemCount || region >= regionIndices.len)) return 0; + if ( item >= itemCount || unlikely (region >= regionIndices.len)) return 0; const HBINT8 *p = (const HBINT8 *)get_delta_bytes () + item * get_row_size (); if (region < shortCount) return ((const HBINT16 *)p)[region]; @@ -1940,20 +1939,20 @@ struct VariationStore bool serialize (hb_serialize_context_t *c, const VariationStore *src, - const hb_array_t &inner_remaps) + const hb_array_t &inner_maps) { TRACE_SERIALIZE (this); unsigned int set_count = 0; - for (unsigned int i = 0; i < inner_remaps.length; i++) - if (inner_remaps[i].get_population () > 0) set_count++; + for (unsigned int i = 0; i < inner_maps.length; i++) + if (inner_maps[i].get_population () > 0) set_count++; unsigned int size = min_size + HBUINT32::static_size * set_count; if (unlikely (!c->allocate_size (size))) return_trace (false); format = 1; hb_inc_bimap_t region_map; - for (unsigned int i = 0; i < inner_remaps.length; i++) - (src+src->dataSets[i]).collect_region_refs (region_map, inner_remaps[i]); + for (unsigned int i = 0; i < inner_maps.length; i++) + (src+src->dataSets[i]).collect_region_refs (region_map, inner_maps[i]); region_map.sort (); if (unlikely (!regions.serialize (c, this) @@ -1964,14 +1963,14 @@ struct VariationStore */ dataSets.len = set_count; unsigned int set_index = 0; - for (unsigned int i = 0; i < inner_remaps.length; i++) + for (unsigned int i = 0; i < inner_maps.length; i++) { - if (inner_remaps[i].get_population () == 0) continue; + if (inner_maps[i].get_population () == 0) continue; if (unlikely (!dataSets[set_index++].serialize (c, this) - .serialize (c, &(src+src->dataSets[i]), inner_remaps[i], region_map))) + .serialize (c, &(src+src->dataSets[i]), inner_maps[i], region_map))) return_trace (false); } - + return_trace (true); } @@ -1993,8 +1992,6 @@ struct VariationStore &scalars[0], num_scalars); } - const VarRegionList &get_regions () const { return this+regions; } - unsigned int get_sub_table_count () const { return dataSets.len; } protected: diff --git a/src/hb-ot-var-hvar-table.hh b/src/hb-ot-var-hvar-table.hh index 0fb1523c0..c1935f7d0 100644 --- a/src/hb-ot-var-hvar-table.hh +++ b/src/hb-ot-var-hvar-table.hh @@ -290,7 +290,10 @@ struct hvarvvar_subset_plan_t if (retain_adv_map) { for (hb_codepoint_t gid = 0; gid < plan->num_output_glyphs (); gid++) - inner_maps[0].add (hb_set_has (inner_sets[0], gid)? gid: HB_MAP_VALUE_INVALID); + if (hb_set_has (inner_sets[0], gid)) + inner_maps[0].add (gid); + else + inner_maps[0].skip (); } else { diff --git a/test/api/fonts/AdobeVFPrototype.ac.retaingids.otf b/test/api/fonts/AdobeVFPrototype.ac.retaingids.otf index d9048ee6e..15419b04d 100644 Binary files a/test/api/fonts/AdobeVFPrototype.ac.retaingids.otf and b/test/api/fonts/AdobeVFPrototype.ac.retaingids.otf differ diff --git a/test/api/fonts/SourceHanSans-Regular.41,4C2E.retaingids.otf b/test/api/fonts/SourceHanSans-Regular.41,4C2E.retaingids.otf index fa2a0e446..906bdbefd 100644 Binary files a/test/api/fonts/SourceHanSans-Regular.41,4C2E.retaingids.otf and b/test/api/fonts/SourceHanSans-Regular.41,4C2E.retaingids.otf differ diff --git a/test/api/fonts/SourceSansVariable-Roman.ac.retaingids.ttf b/test/api/fonts/SourceSansVariable-Roman.ac.retaingids.ttf index 186e6e9da..b2e744df2 100644 Binary files a/test/api/fonts/SourceSansVariable-Roman.ac.retaingids.ttf and b/test/api/fonts/SourceSansVariable-Roman.ac.retaingids.ttf differ diff --git a/test/api/fonts/SourceSerifVariable-Roman-VVAR.ac.retaingids.ttf b/test/api/fonts/SourceSerifVariable-Roman-VVAR.ac.retaingids.ttf index e0999884a..734f6e82a 100644 Binary files a/test/api/fonts/SourceSerifVariable-Roman-VVAR.ac.retaingids.ttf and b/test/api/fonts/SourceSerifVariable-Roman-VVAR.ac.retaingids.ttf differ