From c65eb5a82e4a9a0f3fe60b770741f3f4d3391bc2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 19 Feb 2023 15:15:57 -0700 Subject: [PATCH] [cff] Specialize cff_private_dict_op_serializer_t for CFF1/2 --- src/hb-subset-cff-common.hh | 33 --------------------------------- src/hb-subset-cff1.cc | 32 +++++++++++++++++++++++++++++++- src/hb-subset-cff2.cc | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 35 deletions(-) diff --git a/src/hb-subset-cff-common.hh b/src/hb-subset-cff-common.hh index ea67dba1b..67197e89b 100644 --- a/src/hb-subset-cff-common.hh +++ b/src/hb-subset-cff-common.hh @@ -190,39 +190,6 @@ struct cff_font_dict_op_serializer_t : op_serializer_t } }; -struct cff_private_dict_op_serializer_t : op_serializer_t -{ - cff_private_dict_op_serializer_t (bool desubroutinize_, bool drop_hints_, bool pinned_ = false) - : desubroutinize (desubroutinize_), drop_hints (drop_hints_), pinned (pinned_) {} - - bool serialize (hb_serialize_context_t *c, - const op_str_t &opstr, - objidx_t subrs_link) const - { - TRACE_SERIALIZE (this); - - if (drop_hints && dict_opset_t::is_hint_op (opstr.op)) - return_trace (true); - if (pinned && opstr.op == OpCode_vsindexdict) - return_trace (true); - - if (opstr.op == OpCode_Subrs) - { - if (desubroutinize || !subrs_link) - return_trace (true); - else - return_trace (FontDict::serialize_link2_op (c, opstr.op, subrs_link)); - } - else - return_trace (copy_opstr (c, opstr)); - } - - protected: - const bool desubroutinize; - const bool drop_hints; - const bool pinned; -}; - struct flatten_param_t { str_buff_t &flatStr; diff --git a/src/hb-subset-cff1.cc b/src/hb-subset-cff1.cc index 538f28f5a..11fc0b9af 100644 --- a/src/hb-subset-cff1.cc +++ b/src/hb-subset-cff1.cc @@ -335,6 +335,36 @@ struct cff1_cs_opset_subr_subset_t : cff1_cs_opset_t SUPER; }; +struct cff1_private_dict_op_serializer_t : op_serializer_t +{ + cff1_private_dict_op_serializer_t (bool desubroutinize_, bool drop_hints_) + : desubroutinize (desubroutinize_), drop_hints (drop_hints_) {} + + bool serialize (hb_serialize_context_t *c, + const op_str_t &opstr, + objidx_t subrs_link) const + { + TRACE_SERIALIZE (this); + + if (drop_hints && dict_opset_t::is_hint_op (opstr.op)) + return_trace (true); + + if (opstr.op == OpCode_Subrs) + { + if (desubroutinize || !subrs_link) + return_trace (true); + else + return_trace (FontDict::serialize_link2_op (c, opstr.op, subrs_link)); + } + + return_trace (copy_opstr (c, opstr)); + } + + protected: + const bool desubroutinize; + const bool drop_hints; +}; + struct cff1_subr_subsetter_t : subr_subsetter_t { cff1_subr_subsetter_t (const OT::cff1::accelerator_subset_t &acc_, const hb_subset_plan_t *plan_) @@ -721,7 +751,7 @@ static bool _serialize_cff1 (hb_serialize_context_t *c, PrivateDict *pd = c->start_embed (); if (unlikely (!pd)) return false; c->push (); - cff_private_dict_op_serializer_t privSzr (plan.desubroutinize, plan.drop_hints); + cff1_private_dict_op_serializer_t privSzr (plan.desubroutinize, plan.drop_hints); /* N.B. local subrs immediately follows its corresponding private dict. i.e., subr offset == private dict size */ if (likely (pd->serialize (c, acc.privateDicts[i], privSzr, subrs_link))) { diff --git a/src/hb-subset-cff2.cc b/src/hb-subset-cff2.cc index 23bab9d8b..23fd89bfb 100644 --- a/src/hb-subset-cff2.cc +++ b/src/hb-subset-cff2.cc @@ -246,6 +246,40 @@ struct cff2_subr_subsetter_t : subr_subsetter_tstart_embed (); if (unlikely (!pd)) return false; c->push (); - cff_private_dict_op_serializer_t privSzr (plan.desubroutinize, plan.drop_hints, plan.pinned); + cff2_private_dict_op_serializer_t privSzr (plan.desubroutinize, plan.drop_hints, plan.pinned); if (likely (pd->serialize (c, acc.privateDicts[i], privSzr, subrs_link))) { unsigned fd = plan.fdmap[i];