diff --git a/src/hb-ot-cff1-table.hh b/src/hb-ot-cff1-table.hh index 7a8477d08..089c2e0bb 100644 --- a/src/hb-ot-cff1-table.hh +++ b/src/hb-ot-cff1-table.hh @@ -1491,6 +1491,8 @@ struct cff1 accelerator_subset_t (hb_face_t *face) : SUPER (face) {} HB_INTERNAL bool subset (hb_subset_context_t *c) const; + HB_INTERNAL bool serialize (hb_serialize_context_t *c, + struct cff1_subset_plan &plan) const; typedef accelerator_templ_t SUPER; }; diff --git a/src/hb-ot-cff2-table.hh b/src/hb-ot-cff2-table.hh index 382e04fbb..a005de797 100644 --- a/src/hb-ot-cff2-table.hh +++ b/src/hb-ot-cff2-table.hh @@ -522,6 +522,9 @@ struct cff2 accelerator_subset_t (hb_face_t *face) : SUPER (face) {} HB_INTERNAL bool subset (hb_subset_context_t *c) const; + HB_INTERNAL bool serialize (hb_serialize_context_t *c, + struct cff2_subset_plan &plan, + hb_array_t normalized_coords) const; typedef accelerator_templ_t SUPER; }; diff --git a/src/hb-subset-cff1.cc b/src/hb-subset-cff1.cc index 90d80027f..9a48c900b 100644 --- a/src/hb-subset-cff1.cc +++ b/src/hb-subset-cff1.cc @@ -399,8 +399,10 @@ struct cff1_subr_subsetter_t : subr_subsetter_t= 0 ;) + for (int i = (int) privateDicts.length; --i >= 0 ;) { if (plan.fdmap.has (i)) { @@ -780,7 +783,7 @@ static bool _serialize_cff1 (hb_serialize_context_t *c, auto *pd = c->push (); 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))) + if (likely (pd->serialize (c, privateDicts[i], privSzr, subrs_link))) { unsigned fd = plan.fdmap[i]; plan.fontdicts_mod[fd].privateDictInfo.size = c->length (); @@ -794,7 +797,7 @@ static bool _serialize_cff1 (hb_serialize_context_t *c, } } - if (!acc.is_CID ()) + if (!is_CID ()) plan.info.privateDictInfo = plan.fontdicts_mod[0].privateDictInfo; /* CharStrings */ @@ -816,7 +819,7 @@ static bool _serialize_cff1 (hb_serialize_context_t *c, } /* FDArray (FD Index) */ - if (acc.fdArray != &Null (CFF1FDArray)) + if (fdArray != &Null (CFF1FDArray)) { auto *fda = c->push (); cff1_font_dict_op_serializer_t fontSzr; @@ -831,10 +834,10 @@ static bool _serialize_cff1 (hb_serialize_context_t *c, } /* FDSelect */ - if (acc.fdSelect != &Null (CFF1FDSelect)) + if (fdSelect != &Null (CFF1FDSelect)) { c->push (); - if (likely (hb_serialize_cff_fdselect (c, plan.num_glyphs, *acc.fdSelect, acc.fdCount, + if (likely (hb_serialize_cff_fdselect (c, plan.num_glyphs, *fdSelect, fdCount, plan.subset_fdselect_format, plan.info.fd_select.size, plan.subset_fdselect_ranges))) plan.info.fd_select.link = c->pop_pack (); @@ -893,7 +896,7 @@ static bool _serialize_cff1 (hb_serialize_context_t *c, /* String INDEX */ { auto *dest = c->push (); - if (likely (dest->serialize (c, *acc.stringIndex, plan.sidmap))) + if (likely (dest->serialize (c, *stringIndex, plan.sidmap))) c->pop_pack (); else { @@ -913,7 +916,7 @@ static bool _serialize_cff1 (hb_serialize_context_t *c, cff->offSize = 4; /* unused? */ /* name INDEX */ - if (unlikely (!c->embed (*acc.nameIndex))) return false; + if (unlikely (!c->embed (*nameIndex))) return false; /* top dict INDEX */ { @@ -941,7 +944,7 @@ static bool _serialize_cff1 (hb_serialize_context_t *c, bool OT::cff1::accelerator_subset_t::subset (hb_subset_context_t *c) const { - cff_subset_plan cff_plan; + cff1_subset_plan cff_plan; if (unlikely (!cff_plan.create (*this, c->plan))) { @@ -949,7 +952,7 @@ OT::cff1::accelerator_subset_t::subset (hb_subset_context_t *c) const return false; } - return _serialize_cff1 (c->serializer, cff_plan, *this); + return serialize (c->serializer, cff_plan); } diff --git a/src/hb-subset-cff2.cc b/src/hb-subset-cff2.cc index ef0217970..1dbf74314 100644 --- a/src/hb-subset-cff2.cc +++ b/src/hb-subset-cff2.cc @@ -421,6 +421,7 @@ struct cff2_private_dict_op_serializer_t : op_serializer_t }; +namespace OT { struct cff2_subset_plan { bool create (const OT::cff2::accelerator_subset_t &acc, @@ -510,17 +511,18 @@ struct cff2_subset_plan bool drop_hints = false; bool desubroutinize = false; }; +} // namespace OT -static bool _serialize_cff2 (hb_serialize_context_t *c, - cff2_subset_plan &plan, - const OT::cff2::accelerator_subset_t &acc, - hb_array_t normalized_coords) +bool +OT::cff2::accelerator_subset_t::serialize (hb_serialize_context_t *c, + struct cff2_subset_plan &plan, + hb_array_t normalized_coords) const { /* private dicts & local subrs */ hb_vector_t private_dict_infos; if (unlikely (!private_dict_infos.resize (plan.subset_fdcount))) return false; - for (int i = (int)acc.privateDicts.length; --i >= 0 ;) + for (int i = (int)privateDicts.length; --i >= 0 ;) { if (plan.fdmap.has (i)) { @@ -539,8 +541,8 @@ static bool _serialize_cff2 (hb_serialize_context_t *c, } auto *pd = c->push (); cff2_private_dict_op_serializer_t privSzr (plan.desubroutinize, plan.drop_hints, plan.pinned, - acc.varStore, normalized_coords); - if (likely (pd->serialize (c, acc.privateDicts[i], privSzr, subrs_link))) + varStore, normalized_coords); + if (likely (pd->serialize (c, privateDicts[i], privSzr, subrs_link))) { unsigned fd = plan.fdmap[i]; private_dict_infos[fd].size = c->length (); @@ -573,10 +575,10 @@ static bool _serialize_cff2 (hb_serialize_context_t *c, } /* FDSelect */ - if (acc.fdSelect != &Null (CFF2FDSelect)) + if (fdSelect != &Null (CFF2FDSelect)) { c->push (); - if (likely (hb_serialize_cff_fdselect (c, plan.num_glyphs, *(const FDSelect *)acc.fdSelect, + if (likely (hb_serialize_cff_fdselect (c, plan.num_glyphs, *(const FDSelect *)fdSelect, plan.orig_fdcount, plan.subset_fdselect_format, plan.subset_fdselect_size, plan.subset_fdselect_ranges))) @@ -593,9 +595,9 @@ static bool _serialize_cff2 (hb_serialize_context_t *c, auto *fda = c->push (); cff_font_dict_op_serializer_t fontSzr; auto it = - + hb_zip (+ hb_iter (acc.fontDicts) + + hb_zip (+ hb_iter (fontDicts) | hb_filter ([&] (const cff2_font_dict_values_t &_) - { return plan.fdmap.has (&_ - &acc.fontDicts[0]); }), + { return plan.fdmap.has (&_ - &fontDicts[0]); }), hb_iter (private_dict_infos)) ; if (unlikely (!fda->serialize (c, it, fontSzr))) @@ -607,11 +609,11 @@ static bool _serialize_cff2 (hb_serialize_context_t *c, } /* variation store */ - if (acc.varStore != &Null (CFF2VariationStore) && + if (varStore != &Null (CFF2VariationStore) && !plan.pinned) { auto *dest = c->push (); - if (unlikely (!dest->serialize (c, acc.varStore))) + if (unlikely (!dest->serialize (c, varStore))) { c->pop_discard (); return false; @@ -631,7 +633,7 @@ static bool _serialize_cff2 (hb_serialize_context_t *c, { TopDict &dict = cff2 + cff2->topDict; cff2_top_dict_op_serializer_t topSzr; - if (unlikely (!dict.serialize (c, acc.topDict, topSzr, plan.info))) return false; + if (unlikely (!dict.serialize (c, topDict, topSzr, plan.info))) return false; cff2->topDictSize = c->head - (const char *)&dict; } @@ -648,8 +650,8 @@ OT::cff2::accelerator_subset_t::subset (hb_subset_context_t *c) const cff2_subset_plan cff2_plan; if (unlikely (!cff2_plan.create (*this, c->plan))) return false; - return _serialize_cff2 (c->serializer, cff2_plan, *this, - c->plan->normalized_coords.as_array ()); + return serialize (c->serializer, cff2_plan, + c->plan->normalized_coords.as_array ()); } #endif