diff --git a/src/OT/glyf/glyf-helpers.hh b/src/OT/glyf/glyf-helpers.hh index f157bf002..66af16b5d 100644 --- a/src/OT/glyf/glyf-helpers.hh +++ b/src/OT/glyf/glyf-helpers.hh @@ -89,7 +89,8 @@ templateplan->num_output_glyphs () + 1; unsigned entry_size = use_short_loca ? 2 : 4; @@ -112,7 +113,7 @@ _add_loca_and_head (hb_subset_context_t *c, loca_prime_data, hb_free); - bool result = c->plan->add_table (HB_OT_TAG_loca, loca_blob) + bool result = c->plan->add_table (extended ? HB_OT_TAG_LOCA : HB_OT_TAG_loca, loca_blob) && _add_head_and_set_loca_version (c->plan, use_short_loca); hb_blob_destroy (loca_blob); diff --git a/src/OT/glyf/glyf.hh b/src/OT/glyf/glyf.hh index bee2f77ee..1d2dadf12 100644 --- a/src/OT/glyf/glyf.hh +++ b/src/OT/glyf/glyf.hh @@ -38,6 +38,20 @@ struct glyf return head.indexToLocFormat <= 1 && head.glyphDataFormat <= 1; } + static bool has_extended_glyf (hb_face_t *face) + { +#ifndef HB_NO_BEYOND_64K + hb_blob_ptr_t GLYF_table = hb_sanitize_context_t ().reference_table (face, HB_OT_TAG_GLYF); + hb_blob_ptr_t LOCA_table = hb_sanitize_context_t ().reference_table (face, HB_OT_TAG_LOCA); + bool ret = GLYF_table.get_length () && LOCA_table.get_length (); + GLYF_table.destroy (); + LOCA_table.destroy (); + return ret; +#else + return false; +#endif + } + bool sanitize (hb_sanitize_context_t *c HB_UNUSED) const { TRACE_SANITIZE (this); @@ -79,6 +93,12 @@ struct glyf { TRACE_SUBSET (this); + bool extended = has_extended_glyf (c->plan->source); +#ifndef HB_NO_BEYOND_64K + if (extended != (c->table_tag == HB_OT_TAG_GLYF)) + return_trace (false); +#endif + if (!has_valid_glyf_format (c->plan->source)) { // glyf format is unknown don't attempt to subset it. DEBUG_MSG (SUBSET, nullptr, @@ -134,7 +154,8 @@ struct glyf if (unlikely (!c->serializer->check_success (glyf_impl::_add_loca_and_head (c, padded_offsets.iter (), - use_short_loca)))) + use_short_loca, + extended)))) return_trace (false); return result; @@ -163,6 +184,13 @@ struct glyf * defining it _MIN instead. */ }; +#ifndef HB_NO_BEYOND_64K +struct GLYF : glyf +{ + static constexpr hb_tag_t tableTag = HB_OT_TAG_GLYF; +}; +#endif + struct glyf_accelerator_t { glyf_accelerator_t (hb_face_t *face) diff --git a/src/hb-subset-table-other.cc b/src/hb-subset-table-other.cc index 8c56b3dbd..d98744406 100644 --- a/src/hb-subset-table-other.cc +++ b/src/hb-subset-table-other.cc @@ -23,6 +23,7 @@ bool _hb_subset_table_other (hb_subset_plan_t *plan, hb_vector_t &buf, hb case HB_TAG('v','m','t','x'): *success = _hb_subset_table (plan, buf); return true; case HB_TAG('m','a','x','p'): *success = _hb_subset_table (plan, buf); return true; #ifndef HB_NO_BEYOND_64K + case HB_TAG('G','L','Y','F'): *success = _hb_subset_table (plan, buf); return true; case HB_TAG('H','H','E','A'): *success = true; return true; /* skip HHEA, handled by HMTX */ case HB_TAG('H','M','T','X'): *success = _hb_subset_table (plan, buf); return true; case HB_TAG('V','H','E','A'): *success = true; return true; /* skip VHEA, handled by VMTX */ @@ -30,6 +31,9 @@ bool _hb_subset_table_other (hb_subset_plan_t *plan, hb_vector_t &buf, hb case HB_TAG('M','A','X','P'): *success = _hb_subset_table (plan, buf); return true; #endif case HB_TAG('l','o','c','a'): *success = true; return true; /* skip loca, handled by glyf */ +#ifndef HB_NO_BEYOND_64K + case HB_TAG('L','O','C','A'): *success = true; return true; /* skip LOCA, handled by GLYF */ +#endif case HB_TAG('c','m','a','p'): *success = _hb_subset_table (plan, buf); return true; case HB_TAG('O','S','/','2'): *success = _hb_subset_table (plan, buf); return true; case HB_TAG('p','o','s','t'): *success = _hb_subset_table (plan, buf); return true; diff --git a/test/api/test-subset-glyf.c b/test/api/test-subset-glyf.c index d617cee58..4d5eeee79 100644 --- a/test/api/test-subset-glyf.c +++ b/test/api/test-subset-glyf.c @@ -57,6 +57,68 @@ static void check_maxp_num_glyphs (hb_face_t *face, uint16_t expected_num_glyphs hb_blob_destroy (maxp_blob); } +#ifndef HB_NO_BEYOND_64K +static void +test_subset_GLYF (void) +{ + static const char maxp_data[] = + "\x00\x00\x50\x00" /* version */ + "\x00\x01" /* numGlyphs */ + ; + static const char head_data[54] = + "\x00\x01\x00\x00" /* version */ + "\x00\x00\x00\x00" /* fontRevision */ + "\x00\x00\x00\x00" /* checkSumAdjustment */ + "\x5F\x0F\x3C\xF5" /* magicNumber */ + "\x00\x00" /* flags */ + "\x03\xE8" /* unitsPerEm */ + "\x00\x00\x00\x00\x00\x00\x00\x00" /* created */ + "\x00\x00\x00\x00\x00\x00\x00\x00" /* modified */ + "\x00\x00\x00\x00\x00\x00\x00\x00" /* bounds */ + "\x00\x00" /* macStyle */ + "\x00\x00" /* lowestRecPPEM */ + "\x00\x00" /* fontDirectionHint */ + "\x00\x01" /* indexToLocFormat */ + "\x00\x00" /* glyphDataFormat */ + ; + static const char loca_data[8] = + "\x00\x00\x00\x00" + "\x00\x00\x00\x01" + ; + static const char glyf_data[] = "\0"; + + hb_face_t *face = hb_face_builder_create (); + HB_FACE_ADD_TABLE (face, "maxp", maxp_data); + HB_FACE_ADD_TABLE (face, "head", head_data); + HB_FACE_ADD_TABLE (face, "glyf", glyf_data); + HB_FACE_ADD_TABLE (face, "loca", loca_data); + HB_FACE_ADD_TABLE (face, "GLYF", glyf_data); + HB_FACE_ADD_TABLE (face, "LOCA", loca_data); + + hb_set_t *glyphs = hb_set_create (); + hb_set_add (glyphs, 0); + hb_face_t *subset = hb_subset_test_create_subset (face, + hb_subset_test_create_input_from_glyphs (glyphs)); + hb_set_destroy (glyphs); + + hb_blob_t *blob = hb_face_reference_table (subset, HB_TAG ('G','L','Y','F')); + g_assert_cmpuint (hb_blob_get_length (blob), >, 0); + hb_blob_destroy (blob); + blob = hb_face_reference_table (subset, HB_TAG ('L','O','C','A')); + g_assert_cmpuint (hb_blob_get_length (blob), >, 0); + hb_blob_destroy (blob); + blob = hb_face_reference_table (subset, HB_TAG ('g','l','y','f')); + g_assert_cmpuint (hb_blob_get_length (blob), ==, 0); + hb_blob_destroy (blob); + blob = hb_face_reference_table (subset, HB_TAG ('l','o','c','a')); + g_assert_cmpuint (hb_blob_get_length (blob), ==, 0); + hb_blob_destroy (blob); + + hb_face_destroy (subset); + hb_face_destroy (face); +} +#endif + static void test_subset_glyf (void) { @@ -393,6 +455,9 @@ main (int argc, char **argv) { hb_test_init (&argc, &argv); +#ifndef HB_NO_BEYOND_64K + hb_test_add (test_subset_GLYF); +#endif hb_test_add (test_subset_glyf_noop); hb_test_add (test_subset_glyf); hb_test_add (test_subset_glyf_set_overlaps_flag);