From cc52e53cf0cb76809145ae7407a8b613e9e61153 Mon Sep 17 00:00:00 2001 From: Michiharu Ariza Date: Mon, 10 Sep 2018 16:27:49 -0700 Subject: [PATCH] Removed unused subr subset code --- src/hb-subset-cff-common.hh | 98 ++----------------------------------- src/hb-subset-cff1.cc | 92 ++++------------------------------ src/hb-subset-cff2.cc | 90 +++------------------------------- 3 files changed, 22 insertions(+), 258 deletions(-) diff --git a/src/hb-subset-cff-common.hh b/src/hb-subset-cff-common.hh index 38290085a..6f944d306 100644 --- a/src/hb-subset-cff-common.hh +++ b/src/hb-subset-cff-common.hh @@ -212,8 +212,8 @@ struct CFFFontDict_OpSerializer : OpSerializer struct CFFPrivateDict_OpSerializer : OpSerializer { - inline CFFPrivateDict_OpSerializer (bool drop_hints_=false, bool flatten_subrs_=false) - : drop_hints (drop_hints_), flatten_subrs (flatten_subrs_) {} + inline CFFPrivateDict_OpSerializer (bool drop_hints_=false) + : drop_hints (drop_hints_) {} inline bool serialize (hb_serialize_context_t *c, const OpStr &opstr, @@ -224,12 +224,7 @@ struct CFFPrivateDict_OpSerializer : OpSerializer if (drop_hints && DictOpSet::is_hint_op (opstr.op)) return true; if (opstr.op == OpCode_Subrs) - { - if (flatten_subrs) - return_trace (true); - else - return_trace (FontDict::serialize_offset2_op(c, OpCode_Subrs, subrsOffset)); - } + return_trace (true); else return_trace (copy_opstr (c, opstr)); } @@ -239,19 +234,13 @@ struct CFFPrivateDict_OpSerializer : OpSerializer if (drop_hints && DictOpSet::is_hint_op (opstr.op)) return 0; if (opstr.op == OpCode_Subrs) - { - if (flatten_subrs) - return 0; - else - return OpCode_Size (OpCode_shortint) + 2 + OpCode_Size (OpCode_Subrs); - } + return 0; else return opstr.str.len; } protected: const bool drop_hints; - const bool flatten_subrs; }; struct FlattenParam @@ -295,85 +284,6 @@ struct SubrFlattener const hb_vector_t &glyphs; bool drop_hints; }; - -struct SubrRefMaps -{ - inline void init (void) - { - valid = false; - global_map = nullptr; - local_maps.init (); - } - - inline void init (unsigned int fd_count) - { - valid = true; - global_map = hb_set_create (); - if (global_map == hb_set_get_empty ()) - valid = false; - if (!local_maps.resize (fd_count)) - valid = false; - - for (unsigned int i = 0; i < local_maps.len; i++) - { - local_maps[i] = hb_set_create (); - if (local_maps[i] == hb_set_get_empty ()) - valid = false; - } - } - - inline void fini (void) - { - hb_set_destroy (global_map); - for (unsigned int i = 0; i < local_maps.len; i++) - hb_set_destroy (local_maps[i]); - local_maps.fini (); - } - - bool is_valid (void) const { return valid; } - bool valid; - hb_set_t *global_map; - hb_vector_t local_maps; -}; - -struct SubrRefMapPair -{ - inline void init (void) {} - - hb_set_t *global_map; - hb_set_t *local_map; -}; - -template -struct SubrSubsetter -{ - inline SubrSubsetter (const ACC &acc_, const hb_vector_t &glyphs_) - : acc (acc_), - glyphs (glyphs_) - {} - - bool collect_refs (SubrRefMaps& refmaps /*OUT*/) - { - refmaps.init (acc.fdCount); - if (unlikely (!refmaps.valid)) return false; - for (unsigned int i = 0; i < glyphs.len; i++) - { - hb_codepoint_t glyph = glyphs[i]; - const ByteStr str = (*acc.charStrings)[glyph]; - unsigned int fd = acc.fdSelect->get_fd (glyph); - SubrRefMapPair pair = { refmaps.global_map, refmaps.local_maps[fd] }; - CSInterpreter interp; - interp.env.init (str, acc, fd); - if (unlikely (!interp.interpret (pair))) - return false; - } - return true; - } - - const ACC &acc; - const hb_vector_t &glyphs; -}; - }; /* namespace CFF */ HB_INTERNAL bool diff --git a/src/hb-subset-cff1.cc b/src/hb-subset-cff1.cc index 7b68ea1ac..1179210cd 100644 --- a/src/hb-subset-cff1.cc +++ b/src/hb-subset-cff1.cc @@ -321,31 +321,6 @@ struct CFF1CSOpSet_Flatten : CFF1CSOpSet typedef CFF1CSOpSet SUPER; }; -struct CFF1CSOpSet_SubsetSubrs : CFF1CSOpSet -{ - static inline bool process_op (OpCode op, CFF1CSInterpEnv &env, SubrRefMapPair& refMapPair) - { - unsigned int subr_num; - switch (op) { - case OpCode_callsubr: - if (!unlikely (env.popSubrNum(env.localSubrs, subr_num))) - return false; - env.argStack.unpop (); - refMapPair.local_map->add (subr_num); - break; - case OpCode_callgsubr: - if (!unlikely (env.popSubrNum(env.globalSubrs, subr_num))) - return false; - env.argStack.unpop (); - refMapPair.global_map->add (subr_num); - break; - default: - break; - } - return CFF1CSOpSet::process_op (op, env, refMapPair); - } -}; - struct cff_subset_plan { inline cff_subset_plan (void) : final_size (0), @@ -353,7 +328,6 @@ struct cff_subset_plan { subset_fdcount (1), subset_fdselect_format (0), offsets (), - flatten_subrs (true), drop_hints (false) { topdict_sizes.init (); @@ -364,7 +338,6 @@ struct cff_subset_plan { subset_charstrings.init (); flat_charstrings.init (); fontdicts_mod.init (); - subrRefMaps.init (); subset_enc_code_ranges.init (); subset_enc_supp_codes.init (); subset_charset_ranges.init (); @@ -382,7 +355,6 @@ struct cff_subset_plan { subset_charstrings.fini (); flat_charstrings.fini (); fontdicts_mod.fini (); - subrRefMaps.fini (); subset_enc_code_ranges.fini (); subset_enc_supp_codes.init (); subset_charset_ranges.fini (); @@ -621,7 +593,6 @@ struct cff_subset_plan { final_size += offsets.stringIndexInfo.size; } - if (flatten_subrs) { /* Flatten global & local subrs */ SubrFlattener @@ -632,19 +603,7 @@ struct cff_subset_plan { /* no global/local subroutines */ offsets.globalSubrsInfo.size = HBUINT16::static_size; /* count 0 only */ } - else - { - /* Subset global & local subrs */ - SubrSubsetter subsetter(acc, plan->glyphs); - if (!subsetter.collect_refs (subrRefMaps)) - return false; - - offsets.globalSubrsInfo.size = acc.globalSubrs->calculate_serialized_size (offsets.globalSubrsInfo.offSize, subrRefMaps.global_map, 1); - if (!offsets.localSubrsInfos.resize (orig_fdcount)) - return false; - for (unsigned int i = 0; i < orig_fdcount; i++) - offsets.localSubrsInfos[i].size = acc.privateDicts[i].localSubrs->calculate_serialized_size (offsets.localSubrsInfos[i].offSize, subrRefMaps.local_maps[i], 1); - } + /* global subrs */ offsets.globalSubrsInfo.offset = final_size; final_size += offsets.globalSubrsInfo.size; @@ -686,19 +645,10 @@ struct cff_subset_plan { unsigned int dataSize = 0; for (unsigned int i = 0; i < plan->glyphs.len; i++) { - if (flatten_subrs) - { - ByteStrBuff &flatstr = flat_charstrings[i]; - ByteStr str (&flatstr[0], flatstr.len); - subset_charstrings.push (str); - dataSize += flatstr.len; - } - else - { - const ByteStr str = (*acc.charStrings)[plan->glyphs[i]]; - subset_charstrings.push (str); - dataSize += str.len; - } + ByteStrBuff &flatstr = flat_charstrings[i]; + ByteStr str (&flatstr[0], flatstr.len); + subset_charstrings.push (str); + dataSize += flatstr.len; } offsets.charStringsInfo.offSize = calcOffSize (dataSize + 1); final_size += CFF1CharStrings::calculate_serialized_size (offsets.charStringsInfo.offSize, plan->glyphs.len, dataSize); @@ -710,15 +660,13 @@ struct cff_subset_plan { { if (!fdmap.excludes (i)) { - CFFPrivateDict_OpSerializer privSzr (plan->drop_hints, flatten_subrs); + CFFPrivateDict_OpSerializer privSzr (plan->drop_hints); unsigned int priv_size = PrivateDict::calculate_serialized_size (acc.privateDicts[i], privSzr); TableInfo privInfo = { final_size, priv_size, 0 }; FontDictValuesMod fontdict_mod; fontdict_mod.init ( &acc.fontDicts[i], sidmap[acc.fontDicts[i].fontName], privInfo ); fontdicts_mod.push (fontdict_mod); final_size += privInfo.size; - if (!flatten_subrs) - final_size += offsets.localSubrsInfos[i].size; } } @@ -751,8 +699,6 @@ struct cff_subset_plan { ByteStrBuffArray flat_charstrings; hb_vector_t fontdicts_mod; - SubrRefMaps subrRefMaps; - bool flatten_subrs; bool drop_hints; @@ -836,13 +782,9 @@ static inline bool _write_cff1 (const cff_subset_plan &plan, { assert (plan.offsets.globalSubrsInfo.offset != 0); assert (plan.offsets.globalSubrsInfo.offset == c.head - c.start); - CFF1Subrs *dest = c.start_embed (); + CFF1Subrs *dest = c.allocate_size (HBUINT16::static_size); if (unlikely (dest == nullptr)) return false; - if (unlikely (!dest->serialize (&c, *acc.globalSubrs, plan.offsets.globalSubrsInfo.offSize, plan.subrRefMaps.global_map, NULL_SUBR))) - { - DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF global subrs"); - return false; - } + dest->count.set (0); } /* Encoding */ @@ -941,9 +883,9 @@ static inline bool _write_cff1 (const cff_subset_plan &plan, { PrivateDict *pd = c.start_embed (); if (unlikely (pd == nullptr)) return false; - unsigned int priv_size = plan.flatten_subrs? 0: plan.fontdicts_mod[plan.fdmap[i]].privateDictInfo.size; + unsigned int priv_size = plan.fontdicts_mod[plan.fdmap[i]].privateDictInfo.size; bool result; - CFFPrivateDict_OpSerializer privSzr (plan.drop_hints, plan.flatten_subrs); + CFFPrivateDict_OpSerializer privSzr (plan.drop_hints); /* N.B. local subrs immediately follows its corresponding private dict. i.e., subr offset == private dict size */ result = pd->serialize (&c, acc.privateDicts[i], privSzr, priv_size); if (unlikely (!result)) @@ -951,20 +893,6 @@ static inline bool _write_cff1 (const cff_subset_plan &plan, DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF Private Dict[%d]", i); return false; } - if (!plan.flatten_subrs && (acc.privateDicts[i].subrsOffset != 0)) - { - CFF1Subrs *subrs = c.start_embed (); - if (unlikely (subrs == nullptr) || acc.privateDicts[i].localSubrs == &Null(CFF1Subrs)) - { - DEBUG_MSG (SUBSET, nullptr, "CFF subset: local subrs unexpectedly null [%d]", i); - return false; - } - if (unlikely (!subrs->serialize (&c, *acc.privateDicts[i].localSubrs, plan.offsets.localSubrsInfos[i].offSize, plan.subrRefMaps.local_maps[i], NULL_SUBR))) - { - DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF local subrs [%d]", i); - return false; - } - } } } diff --git a/src/hb-subset-cff2.cc b/src/hb-subset-cff2.cc index 56bba57d0..193b4335d 100644 --- a/src/hb-subset-cff2.cc +++ b/src/hb-subset-cff2.cc @@ -168,38 +168,12 @@ struct CFF2CSOpSet_Flatten : CFF2CSOpSet typedef CSOpSet CSOPSET; }; -struct CFF2CSOpSet_SubsetSubrs : CFF2CSOpSet -{ - static inline bool process_op (OpCode op, CFF2CSInterpEnv &env, SubrRefMapPair& refMapPair) - { - unsigned int subr_num; - switch (op) { - case OpCode_callsubr: - if (!unlikely (env.popSubrNum(env.localSubrs, subr_num))) - return false; - env.argStack.unpop (); - refMapPair.local_map->add (subr_num); - break; - case OpCode_callgsubr: - if (!unlikely (env.popSubrNum(env.globalSubrs, subr_num))) - return false; - env.argStack.unpop (); - refMapPair.global_map->add (subr_num); - break; - default: - break; - } - return CFF2CSOpSet::process_op (op, env, refMapPair); - } -}; - struct cff2_subset_plan { inline cff2_subset_plan (void) : final_size (0), orig_fdcount (0), subset_fdcount(1), subset_fdselect_format (0), - flatten_subrs (true), drop_hints (false) { subset_fdselect_first_glyphs.init (); @@ -207,7 +181,6 @@ struct cff2_subset_plan { subset_charstrings.init (); flat_charstrings.init (); privateDictInfos.init (); - subrRefMaps.init (); } inline ~cff2_subset_plan (void) @@ -217,7 +190,6 @@ struct cff2_subset_plan { subset_charstrings.fini (); flat_charstrings.fini (); privateDictInfos.fini (); - subrRefMaps.fini (); } inline bool create (const OT::cff2::accelerator_subset_t &acc, @@ -238,7 +210,6 @@ struct cff2_subset_plan { final_size += offsets.topDictInfo.size; } - if (flatten_subrs) { /* Flatten global & local subrs */ SubrFlattener @@ -249,19 +220,6 @@ struct cff2_subset_plan { /* no global/local subroutines */ offsets.globalSubrsInfo.size = HBUINT32::static_size; /* count 0 only */ } - else - { - /* Subset global & local subrs */ - SubrSubsetter subsetter(acc, plan->glyphs); - if (!subsetter.collect_refs (subrRefMaps)) - return false; - - offsets.globalSubrsInfo.size = acc.globalSubrs->calculate_serialized_size (offsets.globalSubrsInfo.offSize, subrRefMaps.global_map); - if (!offsets.localSubrsInfos.resize (orig_fdcount)) - return false; - for (unsigned int i = 0; i < orig_fdcount; i++) - offsets.localSubrsInfos[i].size = acc.privateDicts[i].localSubrs->calculate_serialized_size (offsets.localSubrsInfos[i].offSize, subrRefMaps.local_maps[i]); - } /* global subrs */ offsets.globalSubrsInfo.offset = final_size; @@ -306,19 +264,10 @@ struct cff2_subset_plan { unsigned int dataSize = 0; for (unsigned int i = 0; i < plan->glyphs.len; i++) { - if (flatten_subrs) - { - ByteStrBuff &flatstr = flat_charstrings[i]; - ByteStr str (&flatstr[0], flatstr.len); - subset_charstrings.push (str); - dataSize += flatstr.len; - } - else - { - const ByteStr str = (*acc.charStrings)[plan->glyphs[i]]; - subset_charstrings.push (str); - dataSize += str.len; - } + ByteStrBuff &flatstr = flat_charstrings[i]; + ByteStr str (&flatstr[0], flatstr.len); + subset_charstrings.push (str); + dataSize += flatstr.len; } offsets.charStringsInfo.offSize = calcOffSize (dataSize + 1); final_size += CFF2CharStrings::calculate_serialized_size (offsets.charStringsInfo.offSize, plan->glyphs.len, dataSize); @@ -331,13 +280,11 @@ struct cff2_subset_plan { if (!fdmap.excludes (i)) { unsigned int priv_size; - CFFPrivateDict_OpSerializer privSzr (drop_hints, flatten_subrs); + CFFPrivateDict_OpSerializer privSzr (drop_hints); priv_size = PrivateDict::calculate_serialized_size (acc.privateDicts[i], privSzr); TableInfo privInfo = { final_size, priv_size, 0 }; privateDictInfos.push (privInfo); final_size += privInfo.size; - if (!flatten_subrs) - final_size += offsets.localSubrsInfos[i].size; } } @@ -361,9 +308,6 @@ struct cff2_subset_plan { ByteStrBuffArray flat_charstrings; hb_vector_t privateDictInfos; - SubrRefMaps subrRefMaps; - - bool flatten_subrs; bool drop_hints; }; @@ -400,13 +344,9 @@ static inline bool _write_cff2 (const cff2_subset_plan &plan, /* global subrs */ { assert (cff2->topDict + plan.offsets.topDictInfo.size == c.head - c.start); - CFF2Subrs *dest = c.start_embed (); + CFF2Subrs *dest = c.allocate_size (HBUINT32::static_size); if (unlikely (dest == nullptr)) return false; - if (unlikely (!dest->serialize (&c, *acc.globalSubrs, plan.offsets.globalSubrsInfo.offSize, plan.subrRefMaps.global_map))) - { - DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF2 global subrs"); - return false; - } + dest->count.set (0); } /* variation store */ @@ -485,27 +425,13 @@ static inline bool _write_cff2 (const cff2_subset_plan &plan, if (unlikely (pd == nullptr)) return false; unsigned int priv_size = plan.privateDictInfos[plan.fdmap[i]].size; bool result; - CFFPrivateDict_OpSerializer privSzr (plan.drop_hints, plan.flatten_subrs); + CFFPrivateDict_OpSerializer privSzr (plan.drop_hints); result = pd->serialize (&c, acc.privateDicts[i], privSzr, priv_size); if (unlikely (!result)) { DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF2 Private Dict[%d]", i); return false; } - if (!plan.flatten_subrs && (acc.privateDicts[i].subrsOffset != 0)) - { - CFF2Subrs *subrs = c.start_embed (); - if (unlikely (subrs == nullptr) || acc.privateDicts[i].localSubrs == &Null(CFF2Subrs)) - { - DEBUG_MSG (SUBSET, nullptr, "CFF2 subset: local subrs unexpectedly null [%d]", i); - return false; - } - if (unlikely (!subrs->serialize (&c, *acc.privateDicts[i].localSubrs, plan.offsets.localSubrsInfos[i].offSize, plan.subrRefMaps.local_maps[i]))) - { - DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF2 local subrs [%d]", i); - return false; - } - } } }