diff --git a/src/hb-subset.cc b/src/hb-subset.cc index d36ac0239..792eeecf9 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -265,13 +265,23 @@ _dependencies_satisfied (hb_subset_plan_t *plan, hb_tag_t tag, const hb_set_t &subsetted_tags, const hb_set_t &pending_subset_tags) { + bool outline_pending = pending_subset_tags.has (HB_TAG('g','l','y','f')); +#ifndef HB_NO_BEYOND_64K + outline_pending |= pending_subset_tags.has (HB_TAG('G','L','Y','F')); +#endif + switch (tag) { case HB_TAG('h','m','t','x'): case HB_TAG('v','m','t','x'): case HB_TAG('m','a','x','p'): +#ifndef HB_NO_BEYOND_64K + case HB_TAG('H','M','T','X'): + case HB_TAG('V','M','T','X'): + case HB_TAG('M','A','X','P'): +#endif case HB_TAG('O','S','/','2'): - return !plan->normalized_coords || !pending_subset_tags.has (HB_TAG('g','l','y','f')); + return !plan->normalized_coords || !outline_pending; case HB_TAG('G','P','O','S'): return plan->all_axes_pinned || !pending_subset_tags.has (HB_TAG('G','D','E','F')); default: diff --git a/test/api/test-subset-hmtx.c b/test/api/test-subset-hmtx.c index 1f29e1d5f..8a1e92501 100644 --- a/test/api/test-subset-hmtx.c +++ b/test/api/test-subset-hmtx.c @@ -269,6 +269,83 @@ test_subset_hybrid_hmtx (void) hb_face_destroy (subset); hb_face_destroy (face); } + +static hb_face_t * +create_upper_metrics_face (hb_face_t *source) +{ + hb_face_t *face = hb_face_builder_create (); + unsigned count = hb_face_get_table_tags (source, 0, NULL, NULL); + hb_tag_t *tags = g_new (hb_tag_t, count); + unsigned total = count; + g_assert_cmpuint (hb_face_get_table_tags (source, 0, &count, tags), ==, total); + + for (unsigned i = 0; i < count; i++) + { + if (tags[i] == HB_TAG ('h','h','e','a') || + tags[i] == HB_TAG ('h','m','t','x')) + continue; + + hb_blob_t *blob = hb_face_reference_table (source, tags[i]); + g_assert_true (hb_face_builder_add_table (face, tags[i], blob)); + hb_blob_destroy (blob); + } + g_free (tags); + + hb_blob_t *hhea = hb_face_reference_table (source, HB_TAG ('h','h','e','a')); + unsigned hhea_length; + const char *hhea_data = hb_blob_get_data (hhea, &hhea_length); + g_assert_cmpuint (hhea_length, >=, 36); + char *HHEA_data = g_malloc (hhea_length + 2); + memcpy (HHEA_data, hhea_data, 34); + HHEA_data[34] = HHEA_data[35] = 0; + memcpy (HHEA_data + 36, hhea_data + 34, hhea_length - 34); + hb_blob_t *HHEA = hb_blob_create (HHEA_data, hhea_length + 2, + HB_MEMORY_MODE_WRITABLE, HHEA_data, g_free); + g_assert_true (hb_face_builder_add_table (face, HB_TAG ('H','H','E','A'), HHEA)); + hb_blob_destroy (HHEA); + hb_blob_destroy (hhea); + + hb_blob_t *hmtx = hb_face_reference_table (source, HB_TAG ('h','m','t','x')); + g_assert_true (hb_face_builder_add_table (face, HB_TAG ('H','M','T','X'), hmtx)); + hb_blob_destroy (hmtx); + + return face; +} + +static hb_face_t * +instance_face (hb_face_t *face) +{ + hb_subset_input_t *input = hb_subset_input_create_or_fail (); + g_assert_true (hb_subset_input_pin_axis_location (input, face, + HB_TAG ('w','g','h','t'), + 900)); + hb_face_t *instance = hb_subset_or_fail (face, input); + g_assert_nonnull (instance); + hb_subset_input_destroy (input); + return instance; +} + +static void +test_subset_upper_hmtx_after_glyf (void) +{ + hb_face_t *source = hb_test_open_font_file ("fonts/SourceSansVariable-Roman.abc.ttf"); + hb_face_t *upper_source = create_upper_metrics_face (source); + hb_face_t *expected = instance_face (source); + hb_face_t *actual = instance_face (upper_source); + + hb_font_t *expected_font = hb_font_create (expected); + hb_font_t *actual_font = hb_font_create (actual); + for (hb_codepoint_t glyph = 0; glyph < hb_face_get_glyph_count (expected); glyph++) + g_assert_cmpint (hb_font_get_glyph_h_advance (actual_font, glyph), ==, + hb_font_get_glyph_h_advance (expected_font, glyph)); + + hb_font_destroy (actual_font); + hb_font_destroy (expected_font); + hb_face_destroy (actual); + hb_face_destroy (expected); + hb_face_destroy (upper_source); + hb_face_destroy (source); +} #endif int @@ -284,6 +361,7 @@ main (int argc, char **argv) hb_test_add (test_subset_invalid_hmtx); #ifndef HB_NO_BEYOND_64K hb_test_add (test_subset_hybrid_hmtx); + hb_test_add (test_subset_upper_hmtx_after_glyf); #endif return hb_test_run();