diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index a82e2d95d..ab4b40d1c 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -1587,6 +1587,82 @@ static inline void ClassDef_serialize (hb_serialize_context_t *c, hb_array_t klasses) { c->start_embed ()->serialize (c, glyphs, klasses); } +struct hb_map2_t +{ + hb_map2_t () { init (); } + ~hb_map2_t () { fini (); } + + void init (void) + { + count = 0; + old_to_new_map.init (); + new_to_old_map.init (); + set.init (); + } + + void fini (void) + { + old_to_new_map.fini (); + new_to_old_map.fini (); + set.fini (); + } + + bool has (hb_codepoint_t id) const { return set.has (id); } + + hb_codepoint_t add (hb_codepoint_t i) + { + hb_codepoint_t v = old_to_new_map[i]; + if (v == HB_MAP_VALUE_INVALID) + { + set.add (i); + v = count++; + old_to_new_map.set (i, v); + new_to_old_map.set (v, i); + } + return v; + } + + /* returns HB_MAP_VALUE_INVALID if unmapped */ + hb_codepoint_t operator [] (hb_codepoint_t i) const { return old_to_new (i); } + hb_codepoint_t old_to_new (hb_codepoint_t i) const { return old_to_new_map[i]; } + hb_codepoint_t new_to_old (hb_codepoint_t i) const { return new_to_old_map[i]; } + + bool identity (unsigned int size) + { + hb_codepoint_t i; + old_to_new_map.clear (); + new_to_old_map.clear (); + set.clear (); + for (i = 0; i < size; i++) + { + old_to_new_map.set (i, i); + new_to_old_map.set (i, i); + set.add (i); + } + count = i; + return old_to_new_map.successful && new_to_old_map.successful && set.successful; + } + + /* Optional: after finished adding all mappings in a random order, + * reorder outputs in the same order as the inputs. */ + void reorder (void) + { + for (hb_codepoint_t i = HB_SET_VALUE_INVALID, count = 0; set.next (&i); count++) + { + new_to_old_map.set (count, i); + old_to_new_map.set (i, count); + } + } + + unsigned int get_count () const { return count; } + unsigned int get_bits () const { return count? hb_bit_storage (count - 1): 0; } + + protected: + unsigned int count; + hb_map_t old_to_new_map; + hb_map_t new_to_old_map; + hb_set_t set; +}; /* * Item Variation Store @@ -1755,7 +1831,7 @@ struct VarData if (unlikely (!c->extend_min (*this))) return_trace (false); itemCount.set (remap.get_count ()); shortCount.set (src->shortCount); - + unsigned int row_size = src->get_row_size (); if (unlikely (!c->allocate_size (src->regionIndices.get_size () + (row_size * remap.get_count ())))) return_trace (false); @@ -1841,7 +1917,7 @@ struct VariationStore .serialize (c, &(src+src->dataSets[i]), inner_remaps[i]))) return_trace (false); } - + return_trace (true); } @@ -2242,7 +2318,6 @@ struct Device DEFINE_SIZE_UNION (6, b); }; - } /* namespace OT */ diff --git a/src/hb-ot-var-hvar-table.hh b/src/hb-ot-var-hvar-table.hh index 97e70605c..e9768f3f1 100644 --- a/src/hb-ot-var-hvar-table.hh +++ b/src/hb-ot-var-hvar-table.hh @@ -159,7 +159,7 @@ struct index_map_subset_plan_t continue; } if (v != last_val) break; - + last_gid = gid; }