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()
This commit is contained in:
Michiharu Ariza 2019-06-20 14:33:09 -07:00 committed by Behdad Esfahbod
parent 094966959f
commit f3ee2bd020
7 changed files with 33 additions and 23 deletions

View File

@ -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)

View File

@ -482,7 +482,7 @@ struct FDArray : CFFIndexOf<COUNT, FontDict>
if (fdmap.has (i))
{
FontDict *dict = c->start_embed<FontDict> ();
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);

View File

@ -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);

View File

@ -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 */

View File

@ -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])))

View File

@ -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<PrivateDict> ();
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 */

View File

@ -542,7 +542,7 @@ static inline bool _write_cff2 (const cff2_subset_plan &plan,
{
PrivateDict *pd = c.start_embed<PrivateDict> ();
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 */