diff --git a/src/hb-ot-cff1-table.cc b/src/hb-ot-cff1-table.cc index 437bdc091..4cbd79b78 100644 --- a/src/hb-ot-cff1-table.cc +++ b/src/hb-ot-cff1-table.cc @@ -665,6 +665,8 @@ _cff1_charstring_may_end_in_seac (const hb_ubytes_t &str, bool OT::cff1::accelerator_subset_t::get_seac_components (hb_codepoint_t glyph, hb_codepoint_t *base, hb_codepoint_t *accent) const { if (unlikely (!is_valid () || (glyph >= num_glyphs))) return false; + /* seac uses StandardEncoding names and is not defined in CID-keyed fonts. */ + if (is_CID ()) return false; unsigned int fd = fdSelect->get_fd (glyph); const hb_ubytes_t str = (*charStrings)[glyph]; diff --git a/test/api/fonts/cff1_cid_seac.otf b/test/api/fonts/cff1_cid_seac.otf new file mode 100644 index 000000000..511eb2a5f Binary files /dev/null and b/test/api/fonts/cff1_cid_seac.otf differ diff --git a/test/api/generate-cff-subset-regression-fonts.py b/test/api/generate-cff-subset-regression-fonts.py index 0ba145a6d..5844a6e3b 100644 --- a/test/api/generate-cff-subset-regression-fonts.py +++ b/test/api/generate-cff-subset-regression-fonts.py @@ -3,7 +3,7 @@ from pathlib import Path from fontTools.fontBuilder import FontBuilder from fontTools.misc.psCharStrings import T2CharString -from fontTools.cffLib import SubrsIndex, FDSelect +from fontTools.cffLib import SubrsIndex, FDSelect, FDArrayIndex, FontDict from fontTools.ttLib import TTFont OUT = Path(__file__).parent / "fonts" @@ -99,3 +99,24 @@ top = f["CFF "].cff.topDictIndex[0] top.Private.Subrs[0].setProgram([0, 0, 65, 194, "return"]) top.CharStrings["Aacute"].setProgram([-107, "callsubr", "endchar"]) f.save(OUT / "cff1_seac_subr_operands.otf") + +# A CID charset contains CIDs, not the standard SIDs needed by seac. Deliberately +# use CIDs 34 and 125, which collide with the SIDs for A and acute, so interpreting +# the invalid seac in CID 1000 would incorrectly retain those unrelated glyphs. +f = builder() +glyphs = [".notdef", "cid00034", "cid00125", "cid01000"] +f.setupGlyphOrder(glyphs) +f.setupCharacterMap({0x41: glyphs[1], 0x301: glyphs[2], 0xC1: glyphs[3]}) +f.setupHorizontalMetrics({g: (500, 0) for g in glyphs}) +cs = {g: T2CharString(program=["endchar"]) for g in glyphs} +cs["cid01000"].setProgram([0, 0, 65, 194, "endchar"]) +f.setupCFF("CIDSeacRegression", {"ROS": ("Adobe", "Identity", 0), "CIDCount": 1001}, cs, {}) +top = f.font["CFF "].cff.topDictIndex[0] +fd = FontDict() +fd.Private = top.Private +top.FDArray = FDArrayIndex() +top.FDArray.append(fd) +top.FDSelect = FDSelect(format=0) +top.FDSelect.gidArray = [0] * len(glyphs) +del top.Private +f.save(OUT / "cff1_cid_seac.otf") diff --git a/test/api/test-subset-cff1.c b/test/api/test-subset-cff1.c index 4a9629953..860e28daa 100644 --- a/test/api/test-subset-cff1.c +++ b/test/api/test-subset-cff1.c @@ -268,6 +268,28 @@ test_subset_cff1_seac (void) hb_face_destroy (face); } +static void +test_subset_cff1_cid_seac (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/cff1_cid_seac.otf"); + hb_subset_input_t *input = hb_subset_input_create_or_fail (); + hb_set_add (hb_subset_input_glyph_set (input), 3); + + hb_subset_plan_t *plan = hb_subset_plan_create_or_fail (face, input); + g_assert_nonnull (plan); + const hb_map_t *mapping = hb_subset_plan_old_to_new_glyph_mapping (plan); + /* The CID charset entries 34 and 125 are not seac components. */ + g_assert_cmpuint (hb_map_get_population (mapping), ==, 2); + g_assert_true (hb_map_has (mapping, 0)); + g_assert_true (hb_map_has (mapping, 3)); + g_assert_false (hb_map_has (mapping, 1)); + g_assert_false (hb_map_has (mapping, 2)); + + hb_subset_plan_destroy (plan); + hb_subset_input_destroy (input); + hb_face_destroy (face); +} + static void test_subset_cff1_seac_precheck (void) { @@ -586,6 +608,7 @@ main (int argc, char **argv) hb_test_add (test_subset_cff1_j_desubr_strip_hints); hb_test_add (test_subset_cff1_expert); hb_test_add (test_subset_cff1_seac); + hb_test_add (test_subset_cff1_cid_seac); hb_test_add (test_subset_cff1_seac_precheck); hb_test_add (test_subset_cff1_dotsection); hb_test_add (test_subset_cff1_retaingids);