From 68ac767e430c4dfe4c556b2c4f962cc3dfc5d3e4 Mon Sep 17 00:00:00 2001 From: blueshade7 Date: Fri, 12 Jul 2019 23:02:29 -0700 Subject: [PATCH] added skip(), get_next_value() to inc_bimap to subset VarStore with retain-gids --- src/hb-bimap.hh | 25 ++++++++++++++++++++++++- src/hb-ot-layout-common.hh | 14 +++++++------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/hb-bimap.hh b/src/hb-bimap.hh index a773951ab..cae0a4dea 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,24 @@ 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; + while (hb_set_next (set, &i)) add (i); + } + /* Create an identity map. */ bool identity (unsigned int size) { @@ -138,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 7082f08b8..ba4cca8a9 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -1786,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 }; @@ -1805,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); @@ -1849,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); @@ -1939,7 +1939,7 @@ struct VariationStore bool serialize (hb_serialize_context_t *c, const VariationStore *src, - const hb_array_t &inner_maps) + const hb_array_t &inner_maps) { TRACE_SERIALIZE (this); unsigned int set_count = 0;