diff --git a/src/hb-cff1-interp-cs.hh b/src/hb-cff1-interp-cs.hh index d8868efa5..d67b50b87 100644 --- a/src/hb-cff1-interp-cs.hh +++ b/src/hb-cff1-interp-cs.hh @@ -90,7 +90,7 @@ struct cff1_cs_opset_t : cs_opset_t= 5 && str[end - 5] == OpCode_fixedcs) return true; - /* A subroutine can leave the seac operands on the shared stack. */ - return last == OpCode_callsubr || last == OpCode_callgsubr; + /* Escaped operators include stack-preserving dotsection. */ + return end >= 2 && str[end - 2] == OpCode_escape; } bool OT::cff1::accelerator_subset_t::get_seac_components (hb_codepoint_t glyph, hb_codepoint_t *base, hb_codepoint_t *accent) const @@ -635,7 +664,7 @@ bool OT::cff1::accelerator_subset_t::get_seac_components (hb_codepoint_t glyph, unsigned int fd = fdSelect->get_fd (glyph); const hb_ubytes_t str = (*charStrings)[glyph]; - if (unlikely (!_cff1_charstring_may_end_in_seac (str))) return false; + if (unlikely (!_cff1_charstring_may_end_in_seac (str, subrs_may_end_in_seac))) return false; cff1_cs_interp_env_t env (str, *this, fd); cff1_cs_interpreter_t interp (env); get_seac_param_t param (this); diff --git a/src/hb-ot-cff1-table.hh b/src/hb-ot-cff1-table.hh index b20d5e588..6b77d2f7f 100644 --- a/src/hb-ot-cff1-table.hh +++ b/src/hb-ot-cff1-table.hh @@ -1517,7 +1517,7 @@ struct cff1 struct accelerator_subset_t : accelerator_templ_t { - accelerator_subset_t (hb_face_t *face) : SUPER (face) {} + HB_INTERNAL accelerator_subset_t (hb_face_t *face); ~accelerator_subset_t () { if (cff_accelerator) @@ -1530,6 +1530,7 @@ struct cff1 HB_INTERNAL bool get_seac_components (hb_codepoint_t glyph, hb_codepoint_t *base, hb_codepoint_t *accent) const; mutable CFF::cff_subset_accelerator_t* cff_accelerator = nullptr; + bool subrs_may_end_in_seac = false; typedef accelerator_templ_t SUPER; }; diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index e6b425b10..23b29e624 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -501,7 +501,13 @@ _populate_gids_to_retain (hb_subset_plan_t* plan, else plan->_glyphset.union_ (cur_glyphset); #ifndef HB_NO_SUBSET_CFF - if (!plan->accelerator || plan->accelerator->has_seac) + /* Component closure cannot add anything when all valid glyphs are already + * retained. A new accelerator still needs an accurate has_seac value for + * future partial subsets. */ + bool all_glyphs_retained = + cur_glyphset.get_population () == plan->source->get_num_glyphs (); + if ((!all_glyphs_retained || plan->attach_accelerator_data) && + (!plan->accelerator || plan->accelerator->has_seac)) { bool has_seac = false; if (cff->is_valid ()) diff --git a/test/api/fonts/cff1_seac_dotsection.otf b/test/api/fonts/cff1_seac_dotsection.otf new file mode 100644 index 000000000..970d7cfd1 Binary files /dev/null and b/test/api/fonts/cff1_seac_dotsection.otf differ diff --git a/test/api/fonts/cff1_seac_subr_endchar.otf b/test/api/fonts/cff1_seac_subr_endchar.otf new file mode 100644 index 000000000..23cd3a92a Binary files /dev/null and b/test/api/fonts/cff1_seac_subr_endchar.otf differ diff --git a/test/api/test-subset-cff1.c b/test/api/test-subset-cff1.c index fb130950f..a615febd4 100644 --- a/test/api/test-subset-cff1.c +++ b/test/api/test-subset-cff1.c @@ -268,6 +268,31 @@ test_subset_cff1_seac (void) hb_face_destroy (face); } +static void +test_subset_cff1_seac_precheck (void) +{ + const char *fonts[] = { + "fonts/cff1_seac_dotsection.otf", + "fonts/cff1_seac_subr_endchar.otf", + }; + + for (unsigned int i = 0; i < G_N_ELEMENTS (fonts); i++) + { + hb_face_t *face = hb_test_open_font_file (fonts[i]); + hb_set_t *codepoints = hb_set_create (); + hb_set_add (codepoints, 0xC1); /* Aacute */ + hb_face_t *subset = hb_subset_test_create_subset (face, + hb_subset_test_create_input (codepoints)); + hb_set_destroy (codepoints); + + /* .notdef, Aacute and both seac components. */ + g_assert_cmpuint (hb_face_get_glyph_count (subset), ==, 4); + + hb_face_destroy (subset); + hb_face_destroy (face); + } +} + static void test_subset_cff1_dotsection (void) { @@ -459,6 +484,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_seac_precheck); hb_test_add (test_subset_cff1_dotsection); hb_test_add (test_subset_cff1_retaingids); hb_test_add (test_subset_cff1_j_retaingids);