diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 13e8b3c2e..38dca26ba 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -238,16 +238,18 @@ struct CmapSubtableFormat4 void serialize (hb_serialize_context_t *c, Iterator it) { - unsigned table_initpos = c->length (); - if (unlikely (!c->extend_min (*this))) return; - this->format = 4; - auto format4_iter = + it | hb_filter ([&] (const hb_pair_t _) { return _.first <= 0xFFFF; }) ; + if (format4_iter.len () == 0) return; + + unsigned table_initpos = c->length (); + if (unlikely (!c->extend_min (*this))) return; + this->format = 4; + //serialize endCode[] HBUINT16 *endCode = serialize_endcode_array (c, format4_iter); if (unlikely (!endCode)) return; diff --git a/test/api/fonts/Roboto-Regular.empty.ttf b/test/api/fonts/Roboto-Regular.empty.ttf new file mode 100644 index 000000000..fbd4fbac0 Binary files /dev/null and b/test/api/fonts/Roboto-Regular.empty.ttf differ diff --git a/test/api/test-subset-cmap.c b/test/api/test-subset-cmap.c index f9f8f5472..a6c24fccf 100644 --- a/test/api/test-subset-cmap.c +++ b/test/api/test-subset-cmap.c @@ -113,6 +113,26 @@ test_subset_cmap4_no_exceeding_maximum_codepoint (void) hb_face_destroy (face_origin); } +static void +test_subset_cmap_empty_tables (void) +{ + hb_face_t *face_abc = hb_test_open_font_file ("fonts/Roboto-Regular.abc.ttf"); + hb_face_t *face_empty = hb_test_open_font_file ("fonts/Roboto-Regular.empty.ttf"); + + hb_set_t *codepoints = hb_set_create (); + hb_face_t *face_abc_subset; + hb_set_add (codepoints, 100); + hb_set_add (codepoints, 101); + 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_empty, face_abc_subset, HB_TAG ('c','m','a','p')); + + hb_face_destroy (face_abc_subset); + hb_face_destroy (face_abc); + hb_face_destroy (face_empty); +} + // TODO(rsheeter) test cmap to no codepoints int @@ -124,6 +144,7 @@ main (int argc, char **argv) hb_test_add (test_subset_cmap_noop); hb_test_add (test_subset_cmap_non_consecutive_glyphs); hb_test_add (test_subset_cmap4_no_exceeding_maximum_codepoint); + hb_test_add (test_subset_cmap_empty_tables); return hb_test_run(); } diff --git a/test/subset/data/expected/japanese/Mplus1p-Regular.default.25771.ttf b/test/subset/data/expected/japanese/Mplus1p-Regular.default.25771.ttf new file mode 100644 index 000000000..423b406e4 Binary files /dev/null and b/test/subset/data/expected/japanese/Mplus1p-Regular.default.25771.ttf differ diff --git a/test/subset/data/expected/japanese/Mplus1p-Regular.drop-hints.25771.ttf b/test/subset/data/expected/japanese/Mplus1p-Regular.drop-hints.25771.ttf new file mode 100644 index 000000000..d73593616 Binary files /dev/null and b/test/subset/data/expected/japanese/Mplus1p-Regular.drop-hints.25771.ttf differ diff --git a/test/subset/data/tests/japanese.tests b/test/subset/data/tests/japanese.tests index b4fe387cf..d923491be 100644 --- a/test/subset/data/tests/japanese.tests +++ b/test/subset/data/tests/japanese.tests @@ -12,5 +12,6 @@ acek あいうえおか あいう珠度輸 𝜕𝟘AB +𥝱