diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 535e25e1b..70b6234aa 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -1883,7 +1883,11 @@ struct VariationStore const hb_array_t &inner_remaps) { 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 (size))) return_trace (false); format = 1; if (unlikely (!regions.serialize (c, this) @@ -1892,12 +1896,14 @@ struct VariationStore /* TODO: The following code could be simplified when * 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++) { - 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]))) - return_trace (false); + return_trace (false); } return_trace (true); diff --git a/test/api/fonts/SourceSansVariable-Roman-modHVAR.abc.ttf b/test/api/fonts/SourceSansVariable-Roman-modHVAR.abc.ttf new file mode 100644 index 000000000..397e7a547 Binary files /dev/null and b/test/api/fonts/SourceSansVariable-Roman-modHVAR.abc.ttf differ diff --git a/test/api/fonts/SourceSansVariable-Roman-modHVAR.ac.ttf b/test/api/fonts/SourceSansVariable-Roman-modHVAR.ac.ttf new file mode 100644 index 000000000..cfdbe1de7 Binary files /dev/null and b/test/api/fonts/SourceSansVariable-Roman-modHVAR.ac.ttf differ diff --git a/test/api/test-subset-hvar.c b/test/api/test-subset-hvar.c index 3326e6db1..2a6c2a977 100644 --- a/test/api/test-subset-hvar.c +++ b/test/api/test-subset-hvar.c @@ -90,6 +90,26 @@ test_subset_map_HVAR_retaingids (void) 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 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); 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); hb_test_add (test_subset_identity_HVAR_retaingids);