fix VarData serialize to remove unused data sets

add api test case for that
This commit is contained in:
Michiharu Ariza 2019-04-12 12:48:48 -07:00
parent a90e4916df
commit 3e524bf772
4 changed files with 31 additions and 4 deletions

View File

@ -1883,7 +1883,11 @@ struct VariationStore
const hb_array_t <hb_bimap_t> &inner_remaps) const hb_array_t <hb_bimap_t> &inner_remaps)
{ {
TRACE_SUBSET (this); TRACE_SUBSET (this);
unsigned int size = min_size + HBUINT32::static_size * inner_remaps.length; unsigned int set_count = 0;
for (unsigned int i = 0; i < inner_remaps.length; i++)
if (inner_remaps[i].get_count () > 0) set_count++;
unsigned int size = min_size + HBUINT32::static_size * set_count;
if (unlikely (!c->allocate_size<HBUINT32> (size))) return_trace (false); if (unlikely (!c->allocate_size<HBUINT32> (size))) return_trace (false);
format = 1; format = 1;
if (unlikely (!regions.serialize (c, this) if (unlikely (!regions.serialize (c, this)
@ -1892,10 +1896,12 @@ struct VariationStore
/* TODO: The following code could be simplified when /* TODO: The following code could be simplified when
* OffsetListOf::subset () can take a custom param to be passed to VarData::serialize () * OffsetListOf::subset () can take a custom param to be passed to VarData::serialize ()
*/ */
dataSets.len = inner_remaps.length; dataSets.len = set_count;
unsigned int set_index = 0;
for (unsigned int i = 0; i < inner_remaps.length; i++) for (unsigned int i = 0; i < inner_remaps.length; i++)
{ {
if (unlikely (!dataSets[i].serialize (c, this) if (inner_remaps[i].get_count () == 0) continue;
if (unlikely (!dataSets[set_index++].serialize (c, this)
.serialize (c, &(src+src->dataSets[i]), inner_remaps[i]))) .serialize (c, &(src+src->dataSets[i]), inner_remaps[i])))
return_trace (false); return_trace (false);
} }

Binary file not shown.

View File

@ -90,6 +90,26 @@ test_subset_map_HVAR_retaingids (void)
hb_face_destroy (face_ac); hb_face_destroy (face_ac);
} }
static void
test_subset_map_modHVAR (void)
{
hb_face_t *face_abc = hb_test_open_font_file ("fonts/SourceSansVariable-Roman-modHVAR.abc.ttf");
hb_face_t *face_ac = hb_test_open_font_file ("fonts/SourceSansVariable-Roman-modHVAR.ac.ttf");
hb_set_t *codepoints = hb_set_create ();
hb_face_t *face_abc_subset;
hb_set_add (codepoints, 'a');
hb_set_add (codepoints, 'c');
face_abc_subset = hb_subset_test_create_subset (face_abc, hb_subset_test_create_input (codepoints));
hb_set_destroy (codepoints);
hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('H','V','A','R'));
hb_face_destroy (face_abc_subset);
hb_face_destroy (face_abc);
hb_face_destroy (face_ac);
}
static void static void
test_subset_identity_HVAR_noop (void) test_subset_identity_HVAR_noop (void)
{ {
@ -160,6 +180,7 @@ main (int argc, char **argv)
hb_test_add (test_subset_map_HVAR_noop); hb_test_add (test_subset_map_HVAR_noop);
hb_test_add (test_subset_map_HVAR); hb_test_add (test_subset_map_HVAR);
hb_test_add (test_subset_map_HVAR_retaingids); hb_test_add (test_subset_map_HVAR_retaingids);
hb_test_add (test_subset_map_modHVAR);
hb_test_add (test_subset_identity_HVAR_noop); hb_test_add (test_subset_identity_HVAR_noop);
hb_test_add (test_subset_identity_HVAR); hb_test_add (test_subset_identity_HVAR);
hb_test_add (test_subset_identity_HVAR_retaingids); hb_test_add (test_subset_identity_HVAR_retaingids);