From f3ee2bd020f8ca313fae783cc49a374f1377e877 Mon Sep 17 00:00:00 2001 From: Michiharu Ariza Date: Thu, 20 Jun 2019 14:33:09 -0700 Subject: [PATCH] add ops & methods to hb_bimap_t making it more like hb_map_t moved has () to hb_bimap_t from hb_inc_bimap_t moved identity () to hb_inc_bimap_t removed forward() --- src/hb-bimap.hh | 38 ++++++++++++++++++++++++-------------- src/hb-ot-cff-common.hh | 2 +- src/hb-ot-cff1-table.hh | 4 ++-- src/hb-subset-cff-common.cc | 2 +- src/hb-subset-cff-common.hh | 4 ++-- src/hb-subset-cff1.cc | 4 ++-- src/hb-subset-cff2.cc | 2 +- 7 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/hb-bimap.hh b/src/hb-bimap.hh index 9dbe0df..cd7729c 100644 --- a/src/hb-bimap.hh +++ b/src/hb-bimap.hh @@ -47,9 +47,13 @@ struct hb_bimap_t back_map.fini (); } - /* returns HB_MAP_VALUE_INVALID if unmapped */ - hb_codepoint_t forward (hb_codepoint_t lhs) const { return forw_map[lhs]; } - hb_codepoint_t backward (hb_codepoint_t rhs) const { return back_map[rhs]; } + void reset () + { + forw_map.reset (); + back_map.reset (); + } + + bool in_error () const { return forw_map.in_error () || back_map.in_error (); } void set (hb_codepoint_t lhs, hb_codepoint_t rhs) { @@ -57,12 +61,16 @@ struct hb_bimap_t back_map.set (rhs, lhs); } - /* Create an identity map. */ - bool identity (unsigned int size) + hb_codepoint_t get (hb_codepoint_t lhs) const { return forw_map.get (lhs); } + hb_codepoint_t backward (hb_codepoint_t rhs) const { return back_map[rhs]; } + + hb_codepoint_t operator [] (hb_codepoint_t lhs) const { return get (lhs); } + bool has (hb_codepoint_t lhs, hb_codepoint_t *vp = nullptr) const { return forw_map.has (lhs, vp); } + + void del (hb_codepoint_t lhs) { - clear (); - for (hb_codepoint_t i = 0; i < size; i++) set (i, i); - return forw_map.successful && back_map.successful; + back_map.del (get (lhs)); + forw_map.del (lhs); } void clear () @@ -71,11 +79,7 @@ struct hb_bimap_t back_map.clear (); } - void reset () - { - forw_map.reset (); - back_map.reset (); - } + bool is_empty () const { return get_population () == 0; } unsigned int get_population () const { return forw_map.get_population (); } @@ -101,7 +105,13 @@ struct hb_inc_bimap_t : hb_bimap_t return rhs; } - bool has (hb_codepoint_t lhs) const { return forw_map.has (lhs); } + /* Create an identity map. */ + bool identity (unsigned int size) + { + clear (); + for (hb_codepoint_t i = 0; i < size; i++) set (i, i); + return !in_error (); + } protected: static int cmp_id (const void* a, const void* b) diff --git a/src/hb-ot-cff-common.hh b/src/hb-ot-cff-common.hh index 2de5a29..8b8e592 100644 --- a/src/hb-ot-cff-common.hh +++ b/src/hb-ot-cff-common.hh @@ -482,7 +482,7 @@ struct FDArray : CFFIndexOf if (fdmap.has (i)) { FontDict *dict = c->start_embed (); - if (unlikely (!dict->serialize (c, fontDicts[i], opszr, privateInfos[fdmap.forward (i)]))) + if (unlikely (!dict->serialize (c, fontDicts[i], opszr, privateInfos[fdmap[i]]))) return_trace (false); } return_trace (true); diff --git a/src/hb-ot-cff1-table.hh b/src/hb-ot-cff1-table.hh index 0dbd0ba..4050b7d 100644 --- a/src/hb-ot-cff1-table.hh +++ b/src/hb-ot-cff1-table.hh @@ -611,7 +611,7 @@ struct CFF1StringIndex : CFF1Index return_trace (false); for (unsigned int i = 0; i < strings.count; i++) { - hb_codepoint_t j = sidmap.forward (i); + hb_codepoint_t j = sidmap[i]; if (j != CFF_UNDEF_CODE) bytesArray[j] = strings[i]; } @@ -630,7 +630,7 @@ struct CFF1StringIndex : CFF1Index unsigned int dataSize = 0; for (unsigned int i = 0; i < count; i++) - if (sidmap.forward (i) != CFF_UNDEF_CODE) + if (sidmap[i] != CFF_UNDEF_CODE) dataSize += length_at (i); offSize_ = calcOffSize(dataSize); diff --git a/src/hb-subset-cff-common.cc b/src/hb-subset-cff-common.cc index 1da5c4a..b71ac57 100644 --- a/src/hb-subset-cff-common.cc +++ b/src/hb-subset-cff-common.cc @@ -114,7 +114,7 @@ hb_plan_subset_cff_fdselect (const hb_subset_plan_t *plan, /* update each font dict index stored as "code" in fdselect_ranges */ for (unsigned int i = 0; i < fdselect_ranges.length; i++) - fdselect_ranges[i].code = fdmap.forward (fdselect_ranges[i].code); + fdselect_ranges[i].code = fdmap[fdselect_ranges[i].code]; } /* determine which FDSelect format is most compact */ diff --git a/src/hb-subset-cff-common.hh b/src/hb-subset-cff-common.hh index 5c95841..6c36e45 100644 --- a/src/hb-subset-cff-common.hh +++ b/src/hb-subset-cff-common.hh @@ -563,7 +563,7 @@ struct subr_remap_t : hb_inc_bimap_t int biased_num (unsigned int old_num) const { - hb_codepoint_t new_num = forward (old_num); + hb_codepoint_t new_num = get (old_num); return (int)new_num - bias; } @@ -761,7 +761,7 @@ struct subr_subsetter_t return false; for (unsigned int old_num = 0; old_num < subrs.length; old_num++) { - hb_codepoint_t new_num = remap.forward (old_num); + hb_codepoint_t new_num = remap[old_num]; if (new_num != CFF_UNDEF_CODE) { if (unlikely (!encode_str (subrs[old_num], fd, buffArray[new_num]))) diff --git a/src/hb-subset-cff1.cc b/src/hb-subset-cff1.cc index 8c0447d..21bd97f 100644 --- a/src/hb-subset-cff1.cc +++ b/src/hb-subset-cff1.cc @@ -54,7 +54,7 @@ struct remap_sid_t : hb_inc_bimap_t if (is_std_std (sid) || (sid == CFF_UNDEF_SID)) return sid; else - return offset_sid (forward (unoffset_sid (sid))); + return offset_sid (get (unoffset_sid (sid))); } static const unsigned int num_std_strings = 391; @@ -1038,7 +1038,7 @@ static inline bool _write_cff1 (const cff_subset_plan &plan, { PrivateDict *pd = c.start_embed (); if (unlikely (pd == nullptr)) return false; - unsigned int priv_size = plan.fontdicts_mod[plan.fdmap.forward (i)].privateDictInfo.size; + unsigned int priv_size = plan.fontdicts_mod[plan.fdmap[i]].privateDictInfo.size; bool result; cff_private_dict_op_serializer_t privSzr (plan.desubroutinize, plan.drop_hints); /* N.B. local subrs immediately follows its corresponding private dict. i.e., subr offset == private dict size */ diff --git a/src/hb-subset-cff2.cc b/src/hb-subset-cff2.cc index 5e36c7f..e89ca69 100644 --- a/src/hb-subset-cff2.cc +++ b/src/hb-subset-cff2.cc @@ -542,7 +542,7 @@ static inline bool _write_cff2 (const cff2_subset_plan &plan, { PrivateDict *pd = c.start_embed (); if (unlikely (pd == nullptr)) return false; - unsigned int priv_size = plan.privateDictInfos[plan.fdmap.forward (i)].size; + unsigned int priv_size = plan.privateDictInfos[plan.fdmap[i]].size; bool result; cff_private_dict_op_serializer_t privSzr (plan.desubroutinize, plan.drop_hints); /* N.B. local subrs immediately follows its corresponding private dict. i.e., subr offset == private dict size */ -- 2.7.4