diff options
Diffstat (limited to 'src/3rdparty/harfbuzz-ng/src/hb-subset-cff2.cc')
-rw-r--r-- | src/3rdparty/harfbuzz-ng/src/hb-subset-cff2.cc | 147 |
1 files changed, 81 insertions, 66 deletions
diff --git a/src/3rdparty/harfbuzz-ng/src/hb-subset-cff2.cc b/src/3rdparty/harfbuzz-ng/src/hb-subset-cff2.cc index 8ab4620194..eb5cb0c625 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-subset-cff2.cc +++ b/src/3rdparty/harfbuzz-ng/src/hb-subset-cff2.cc @@ -31,7 +31,6 @@ #include "hb-open-type.hh" #include "hb-ot-cff2-table.hh" #include "hb-set.h" -#include "hb-subset-cff2.hh" #include "hb-subset-plan.hh" #include "hb-subset-cff-common.hh" #include "hb-cff2-interp-cs.hh" @@ -249,7 +248,7 @@ struct cff2_subr_subsetter_t : subr_subsetter_t<cff2_subr_subsetter_t, CFF2Subrs struct cff2_private_blend_encoder_param_t { cff2_private_blend_encoder_param_t (hb_serialize_context_t *c, - const CFF2VariationStore *varStore, + const CFF2ItemVariationStore *varStore, hb_array_t<int> normalized_coords) : c (c), varStore (varStore), normalized_coords (normalized_coords) {} @@ -285,7 +284,7 @@ struct cff2_private_blend_encoder_param_t unsigned ivs = 0; unsigned region_count = 0; hb_vector_t<float> scalars; - const CFF2VariationStore *varStore = nullptr; + const CFF2ItemVariationStore *varStore = nullptr; hb_array_t<int> normalized_coords; }; @@ -379,7 +378,7 @@ struct cff2_private_dict_blend_opset_t : dict_opset_t struct cff2_private_dict_op_serializer_t : op_serializer_t { cff2_private_dict_op_serializer_t (bool desubroutinize_, bool drop_hints_, bool pinned_, - const CFF::CFF2VariationStore* varStore_, + const CFF::CFF2ItemVariationStore* varStore_, hb_array_t<int> normalized_coords_) : desubroutinize (desubroutinize_), drop_hints (drop_hints_), pinned (pinned_), varStore (varStore_), normalized_coords (normalized_coords_) {} @@ -417,16 +416,22 @@ struct cff2_private_dict_op_serializer_t : op_serializer_t const bool desubroutinize; const bool drop_hints; const bool pinned; - const CFF::CFF2VariationStore* varStore; + const CFF::CFF2ItemVariationStore* varStore; hb_array_t<int> normalized_coords; }; +namespace OT { struct cff2_subset_plan { bool create (const OT::cff2::accelerator_subset_t &acc, hb_subset_plan_t *plan) { + /* make sure notdef is first */ + hb_codepoint_t old_glyph; + if (!plan->old_gid_for_new_gid (0, &old_glyph) || (old_glyph != 0)) return false; + + num_glyphs = plan->num_output_glyphs (); orig_fdcount = acc.fdArray->count; drop_hints = plan->flags & HB_SUBSET_FLAGS_NO_HINTING; @@ -434,6 +439,12 @@ struct cff2_subset_plan desubroutinize = plan->flags & HB_SUBSET_FLAGS_DESUBROUTINIZE || pinned; // For instancing we need this path + #ifdef HB_EXPERIMENTAL_API + min_charstrings_off_size = (plan->flags & HB_SUBSET_FLAGS_IFTB_REQUIREMENTS) ? 4 : 0; + #else + min_charstrings_off_size = 0; + #endif + if (desubroutinize) { /* Flatten global & local subrs */ @@ -489,6 +500,7 @@ struct cff2_subset_plan cff2_sub_table_info_t info; + unsigned int num_glyphs; unsigned int orig_fdcount = 0; unsigned int subset_fdcount = 1; unsigned int subset_fdselect_size = 0; @@ -504,19 +516,50 @@ struct cff2_subset_plan bool drop_hints = false; bool desubroutinize = false; + + unsigned min_charstrings_off_size = 0; }; +} // namespace OT -static bool _serialize_cff2 (hb_serialize_context_t *c, +static bool _serialize_cff2_charstrings (hb_serialize_context_t *c, cff2_subset_plan &plan, - const OT::cff2::accelerator_subset_t &acc, - unsigned int num_glyphs, - hb_array_t<int> normalized_coords) + const OT::cff2::accelerator_subset_t &acc) +{ + c->push (); + + unsigned data_size = 0; + unsigned total_size = CFF2CharStrings::total_size (plan.subset_charstrings, &data_size, plan.min_charstrings_off_size); + if (unlikely (!c->start_zerocopy (total_size))) + return false; + + auto *cs = c->start_embed<CFF2CharStrings> (); + if (unlikely (!cs->serialize (c, plan.subset_charstrings, &data_size, plan.min_charstrings_off_size))) + { + c->pop_discard (); + return false; + } + + plan.info.char_strings_link = c->pop_pack (false); + return true; +} + +bool +OT::cff2::accelerator_subset_t::serialize (hb_serialize_context_t *c, + struct cff2_subset_plan &plan, + hb_array_t<int> normalized_coords) const { + /* push charstrings onto the object stack first which will ensure it packs as the last + object in the table. Keeping the chastrings last satisfies the requirements for patching + via IFTB. If this ordering needs to be changed in the future, charstrings should be left + at the end whenever HB_SUBSET_FLAGS_ITFB_REQUIREMENTS is enabled. */ + if (!_serialize_cff2_charstrings(c, plan, *this)) + return false; + /* private dicts & local subrs */ hb_vector_t<table_info_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)) { @@ -524,9 +567,7 @@ static bool _serialize_cff2 (hb_serialize_context_t *c, if (plan.subset_localsubrs[i].length > 0) { - CFF2Subrs *dest = c->start_embed <CFF2Subrs> (); - if (unlikely (!dest)) return false; - c->push (); + auto *dest = c->push <CFF2Subrs> (); if (likely (dest->serialize (c, plan.subset_localsubrs[i]))) subrs_link = c->pop_pack (false); else @@ -535,12 +576,10 @@ static bool _serialize_cff2 (hb_serialize_context_t *c, return false; } } - PrivateDict *pd = c->start_embed<PrivateDict> (); - if (unlikely (!pd)) return false; - c->push (); + auto *pd = c->push<PrivateDict> (); 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 (); @@ -554,31 +593,11 @@ static bool _serialize_cff2 (hb_serialize_context_t *c, } } - /* CharStrings */ - { - c->push (); - - unsigned total_size = CFF2CharStrings::total_size (plan.subset_charstrings); - if (unlikely (!c->start_zerocopy (total_size))) - return false; - - CFF2CharStrings *cs = c->start_embed<CFF2CharStrings> (); - if (unlikely (!cs)) return false; - - if (likely (cs->serialize (c, plan.subset_charstrings))) - plan.info.char_strings_link = c->pop_pack (false); - else - { - c->pop_discard (); - return false; - } - } - /* FDSelect */ - if (acc.fdSelect != &Null (CFF2FDSelect)) + if (fdSelect != &Null (CFF2FDSelect)) { c->push (); - if (likely (hb_serialize_cff_fdselect (c, 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))) @@ -592,27 +611,32 @@ static bool _serialize_cff2 (hb_serialize_context_t *c, /* FDArray (FD Index) */ { - c->push (); - CFF2FDArray *fda = c->start_embed<CFF2FDArray> (); - if (unlikely (!fda)) return false; + auto *fda = c->push<CFF2FDArray> (); 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))) return false; + if (unlikely (!fda->serialize (c, it, fontSzr))) + { + c->pop_discard (); + return false; + } plan.info.fd_array_link = c->pop_pack (false); } /* variation store */ - if (acc.varStore != &Null (CFF2VariationStore) && + if (varStore != &Null (CFF2ItemVariationStore) && !plan.pinned) { - c->push (); - CFF2VariationStore *dest = c->start_embed<CFF2VariationStore> (); - if (unlikely (!dest || !dest->serialize (c, acc.varStore))) return false; + auto *dest = c->push<CFF2ItemVariationStore> (); + if (unlikely (!dest->serialize (c, varStore))) + { + c->pop_discard (); + return false; + } plan.info.var_store_link = c->pop_pack (false); } @@ -628,34 +652,25 @@ 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; } /* global subrs */ { - CFF2Subrs *dest = c->start_embed <CFF2Subrs> (); - if (unlikely (!dest)) return false; + auto *dest = c->start_embed <CFF2Subrs> (); return dest->serialize (c, plan.subset_globalsubrs); } } -static bool -_hb_subset_cff2 (const OT::cff2::accelerator_subset_t &acc, - hb_subset_context_t *c) +bool +OT::cff2::accelerator_subset_t::subset (hb_subset_context_t *c) const { cff2_subset_plan cff2_plan; - if (unlikely (!cff2_plan.create (acc, c->plan))) return false; - return _serialize_cff2 (c->serializer, cff2_plan, acc, c->plan->num_output_glyphs (), - c->plan->normalized_coords.as_array ()); -} - -bool -hb_subset_cff2 (hb_subset_context_t *c) -{ - OT::cff2::accelerator_subset_t acc (c->plan->source); - return acc.is_valid () && _hb_subset_cff2 (acc, c); + if (unlikely (!cff2_plan.create (*this, c->plan))) return false; + return serialize (c->serializer, cff2_plan, + c->plan->normalized_coords.as_array ()); } #endif |