diff --git a/src/hb-ot-cff1-table.cc b/src/hb-ot-cff1-table.cc index a8b3eef0f..437bdc091 100644 --- a/src/hb-ot-cff1-table.cc +++ b/src/hb-ot-cff1-table.cc @@ -654,6 +654,10 @@ _cff1_charstring_may_end_in_seac (const hb_ubytes_t &str, if (end >= 5 && str[end - 5] == OpCode_fixedcs) return true; + /* A subroutine can leave the seac operands on the shared stack. */ + if (last == OpCode_callsubr || last == OpCode_callgsubr) + return true; + /* Escaped operators include stack-preserving dotsection. */ return end >= 2 && str[end - 2] == OpCode_escape; } diff --git a/test/api/fonts/cff1_seac_subr_operands.otf b/test/api/fonts/cff1_seac_subr_operands.otf new file mode 100644 index 000000000..badba4b57 Binary files /dev/null and b/test/api/fonts/cff1_seac_subr_operands.otf differ diff --git a/test/api/generate-cff-subset-regression-fonts.py b/test/api/generate-cff-subset-regression-fonts.py index d627fd1ca..0ba145a6d 100644 --- a/test/api/generate-cff-subset-regression-fonts.py +++ b/test/api/generate-cff-subset-regression-fonts.py @@ -4,6 +4,7 @@ from pathlib import Path from fontTools.fontBuilder import FontBuilder from fontTools.misc.psCharStrings import T2CharString from fontTools.cffLib import SubrsIndex, FDSelect +from fontTools.ttLib import TTFont OUT = Path(__file__).parent / "fonts" @@ -90,3 +91,11 @@ f.setupCFF2( private = f.font["CFF2"].cff.topDictIndex[0].FDArray[0].Private private.BlueValues = [[i] + [0] * 40 for i in range(14)] f.save(OUT / "cff2_long_private_blends.otf") + +# A local subroutine can leave seac operands on the shared stack before the +# glyph's own endchar. +f = TTFont(OUT / "cff1_seac_subr_endchar.otf") +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") diff --git a/test/api/test-subset-cff1.c b/test/api/test-subset-cff1.c index a615febd4..d3d75e899 100644 --- a/test/api/test-subset-cff1.c +++ b/test/api/test-subset-cff1.c @@ -274,6 +274,7 @@ test_subset_cff1_seac_precheck (void) const char *fonts[] = { "fonts/cff1_seac_dotsection.otf", "fonts/cff1_seac_subr_endchar.otf", + "fonts/cff1_seac_subr_operands.otf", }; for (unsigned int i = 0; i < G_N_ELEMENTS (fonts); i++)