subset HVAR

Re-implemented & repurposed CFF:remap_t as hb_map2_t (moved to hb-ot-layout-common.hh) for two-way mapping for use by index map subsetting.
Hooked up HVAR subsetter through _subset2.
Some renaming in CFF code.
This commit is contained in:
Michiharu Ariza 2019-02-20 15:48:29 -08:00
parent 5bbe78a0f3
commit dd67214210
2 changed files with 79 additions and 4 deletions

View File

@ -1587,6 +1587,82 @@ static inline void ClassDef_serialize (hb_serialize_context_t *c,
hb_array_t<const HBUINT16> klasses)
{ c->start_embed<ClassDef> ()->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<HBUINT8> (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 */

View File

@ -159,7 +159,7 @@ struct index_map_subset_plan_t
continue;
}
if (v != last_val) break;
last_gid = gid;
}