Removed unused subr subset code
This commit is contained in:
parent
1666b89e30
commit
cc52e53cf0
|
@ -212,8 +212,8 @@ struct CFFFontDict_OpSerializer : OpSerializer
|
||||||
|
|
||||||
struct CFFPrivateDict_OpSerializer : OpSerializer
|
struct CFFPrivateDict_OpSerializer : OpSerializer
|
||||||
{
|
{
|
||||||
inline CFFPrivateDict_OpSerializer (bool drop_hints_=false, bool flatten_subrs_=false)
|
inline CFFPrivateDict_OpSerializer (bool drop_hints_=false)
|
||||||
: drop_hints (drop_hints_), flatten_subrs (flatten_subrs_) {}
|
: drop_hints (drop_hints_) {}
|
||||||
|
|
||||||
inline bool serialize (hb_serialize_context_t *c,
|
inline bool serialize (hb_serialize_context_t *c,
|
||||||
const OpStr &opstr,
|
const OpStr &opstr,
|
||||||
|
@ -224,12 +224,7 @@ struct CFFPrivateDict_OpSerializer : OpSerializer
|
||||||
if (drop_hints && DictOpSet::is_hint_op (opstr.op))
|
if (drop_hints && DictOpSet::is_hint_op (opstr.op))
|
||||||
return true;
|
return true;
|
||||||
if (opstr.op == OpCode_Subrs)
|
if (opstr.op == OpCode_Subrs)
|
||||||
{
|
return_trace (true);
|
||||||
if (flatten_subrs)
|
|
||||||
return_trace (true);
|
|
||||||
else
|
|
||||||
return_trace (FontDict::serialize_offset2_op(c, OpCode_Subrs, subrsOffset));
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
return_trace (copy_opstr (c, opstr));
|
return_trace (copy_opstr (c, opstr));
|
||||||
}
|
}
|
||||||
|
@ -239,19 +234,13 @@ struct CFFPrivateDict_OpSerializer : OpSerializer
|
||||||
if (drop_hints && DictOpSet::is_hint_op (opstr.op))
|
if (drop_hints && DictOpSet::is_hint_op (opstr.op))
|
||||||
return 0;
|
return 0;
|
||||||
if (opstr.op == OpCode_Subrs)
|
if (opstr.op == OpCode_Subrs)
|
||||||
{
|
return 0;
|
||||||
if (flatten_subrs)
|
|
||||||
return 0;
|
|
||||||
else
|
|
||||||
return OpCode_Size (OpCode_shortint) + 2 + OpCode_Size (OpCode_Subrs);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
return opstr.str.len;
|
return opstr.str.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const bool drop_hints;
|
const bool drop_hints;
|
||||||
const bool flatten_subrs;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FlattenParam
|
struct FlattenParam
|
||||||
|
@ -295,85 +284,6 @@ struct SubrFlattener
|
||||||
const hb_vector_t<hb_codepoint_t> &glyphs;
|
const hb_vector_t<hb_codepoint_t> &glyphs;
|
||||||
bool drop_hints;
|
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<hb_set_t *> local_maps;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SubrRefMapPair
|
|
||||||
{
|
|
||||||
inline void init (void) {}
|
|
||||||
|
|
||||||
hb_set_t *global_map;
|
|
||||||
hb_set_t *local_map;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename ACC, typename ENV, typename OPSET>
|
|
||||||
struct SubrSubsetter
|
|
||||||
{
|
|
||||||
inline SubrSubsetter (const ACC &acc_, const hb_vector_t<hb_codepoint_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<ENV, OPSET, SubrRefMapPair> interp;
|
|
||||||
interp.env.init (str, acc, fd);
|
|
||||||
if (unlikely (!interp.interpret (pair)))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ACC &acc;
|
|
||||||
const hb_vector_t<hb_codepoint_t> &glyphs;
|
|
||||||
};
|
|
||||||
|
|
||||||
}; /* namespace CFF */
|
}; /* namespace CFF */
|
||||||
|
|
||||||
HB_INTERNAL bool
|
HB_INTERNAL bool
|
||||||
|
|
|
@ -321,31 +321,6 @@ struct CFF1CSOpSet_Flatten : CFF1CSOpSet<CFF1CSOpSet_Flatten, FlattenParam>
|
||||||
typedef CFF1CSOpSet<CFF1CSOpSet_Flatten, FlattenParam> SUPER;
|
typedef CFF1CSOpSet<CFF1CSOpSet_Flatten, FlattenParam> SUPER;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CFF1CSOpSet_SubsetSubrs : CFF1CSOpSet<CFF1CSOpSet_SubsetSubrs, SubrRefMapPair>
|
|
||||||
{
|
|
||||||
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<CFF1CSOpSet_SubsetSubrs, SubrRefMapPair>::process_op (op, env, refMapPair);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cff_subset_plan {
|
struct cff_subset_plan {
|
||||||
inline cff_subset_plan (void)
|
inline cff_subset_plan (void)
|
||||||
: final_size (0),
|
: final_size (0),
|
||||||
|
@ -353,7 +328,6 @@ struct cff_subset_plan {
|
||||||
subset_fdcount (1),
|
subset_fdcount (1),
|
||||||
subset_fdselect_format (0),
|
subset_fdselect_format (0),
|
||||||
offsets (),
|
offsets (),
|
||||||
flatten_subrs (true),
|
|
||||||
drop_hints (false)
|
drop_hints (false)
|
||||||
{
|
{
|
||||||
topdict_sizes.init ();
|
topdict_sizes.init ();
|
||||||
|
@ -364,7 +338,6 @@ struct cff_subset_plan {
|
||||||
subset_charstrings.init ();
|
subset_charstrings.init ();
|
||||||
flat_charstrings.init ();
|
flat_charstrings.init ();
|
||||||
fontdicts_mod.init ();
|
fontdicts_mod.init ();
|
||||||
subrRefMaps.init ();
|
|
||||||
subset_enc_code_ranges.init ();
|
subset_enc_code_ranges.init ();
|
||||||
subset_enc_supp_codes.init ();
|
subset_enc_supp_codes.init ();
|
||||||
subset_charset_ranges.init ();
|
subset_charset_ranges.init ();
|
||||||
|
@ -382,7 +355,6 @@ struct cff_subset_plan {
|
||||||
subset_charstrings.fini ();
|
subset_charstrings.fini ();
|
||||||
flat_charstrings.fini ();
|
flat_charstrings.fini ();
|
||||||
fontdicts_mod.fini ();
|
fontdicts_mod.fini ();
|
||||||
subrRefMaps.fini ();
|
|
||||||
subset_enc_code_ranges.fini ();
|
subset_enc_code_ranges.fini ();
|
||||||
subset_enc_supp_codes.init ();
|
subset_enc_supp_codes.init ();
|
||||||
subset_charset_ranges.fini ();
|
subset_charset_ranges.fini ();
|
||||||
|
@ -621,7 +593,6 @@ struct cff_subset_plan {
|
||||||
final_size += offsets.stringIndexInfo.size;
|
final_size += offsets.stringIndexInfo.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flatten_subrs)
|
|
||||||
{
|
{
|
||||||
/* Flatten global & local subrs */
|
/* Flatten global & local subrs */
|
||||||
SubrFlattener<const OT::cff1::accelerator_subset_t, CFF1CSInterpEnv, CFF1CSOpSet_Flatten>
|
SubrFlattener<const OT::cff1::accelerator_subset_t, CFF1CSInterpEnv, CFF1CSOpSet_Flatten>
|
||||||
|
@ -632,19 +603,7 @@ struct cff_subset_plan {
|
||||||
/* no global/local subroutines */
|
/* no global/local subroutines */
|
||||||
offsets.globalSubrsInfo.size = HBUINT16::static_size; /* count 0 only */
|
offsets.globalSubrsInfo.size = HBUINT16::static_size; /* count 0 only */
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Subset global & local subrs */
|
|
||||||
SubrSubsetter<const OT::cff1::accelerator_subset_t, CFF1CSInterpEnv, CFF1CSOpSet_SubsetSubrs> 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 */
|
/* global subrs */
|
||||||
offsets.globalSubrsInfo.offset = final_size;
|
offsets.globalSubrsInfo.offset = final_size;
|
||||||
final_size += offsets.globalSubrsInfo.size;
|
final_size += offsets.globalSubrsInfo.size;
|
||||||
|
@ -686,19 +645,10 @@ struct cff_subset_plan {
|
||||||
unsigned int dataSize = 0;
|
unsigned int dataSize = 0;
|
||||||
for (unsigned int i = 0; i < plan->glyphs.len; i++)
|
for (unsigned int i = 0; i < plan->glyphs.len; i++)
|
||||||
{
|
{
|
||||||
if (flatten_subrs)
|
ByteStrBuff &flatstr = flat_charstrings[i];
|
||||||
{
|
ByteStr str (&flatstr[0], flatstr.len);
|
||||||
ByteStrBuff &flatstr = flat_charstrings[i];
|
subset_charstrings.push (str);
|
||||||
ByteStr str (&flatstr[0], flatstr.len);
|
dataSize += 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
offsets.charStringsInfo.offSize = calcOffSize (dataSize + 1);
|
offsets.charStringsInfo.offSize = calcOffSize (dataSize + 1);
|
||||||
final_size += CFF1CharStrings::calculate_serialized_size (offsets.charStringsInfo.offSize, plan->glyphs.len, dataSize);
|
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))
|
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);
|
unsigned int priv_size = PrivateDict::calculate_serialized_size (acc.privateDicts[i], privSzr);
|
||||||
TableInfo privInfo = { final_size, priv_size, 0 };
|
TableInfo privInfo = { final_size, priv_size, 0 };
|
||||||
FontDictValuesMod fontdict_mod;
|
FontDictValuesMod fontdict_mod;
|
||||||
fontdict_mod.init ( &acc.fontDicts[i], sidmap[acc.fontDicts[i].fontName], privInfo );
|
fontdict_mod.init ( &acc.fontDicts[i], sidmap[acc.fontDicts[i].fontName], privInfo );
|
||||||
fontdicts_mod.push (fontdict_mod);
|
fontdicts_mod.push (fontdict_mod);
|
||||||
final_size += privInfo.size;
|
final_size += privInfo.size;
|
||||||
if (!flatten_subrs)
|
|
||||||
final_size += offsets.localSubrsInfos[i].size;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -751,8 +699,6 @@ struct cff_subset_plan {
|
||||||
ByteStrBuffArray flat_charstrings;
|
ByteStrBuffArray flat_charstrings;
|
||||||
hb_vector_t<FontDictValuesMod> fontdicts_mod;
|
hb_vector_t<FontDictValuesMod> fontdicts_mod;
|
||||||
|
|
||||||
SubrRefMaps subrRefMaps;
|
|
||||||
|
|
||||||
bool flatten_subrs;
|
bool flatten_subrs;
|
||||||
bool drop_hints;
|
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 != 0);
|
||||||
assert (plan.offsets.globalSubrsInfo.offset == c.head - c.start);
|
assert (plan.offsets.globalSubrsInfo.offset == c.head - c.start);
|
||||||
CFF1Subrs *dest = c.start_embed<CFF1Subrs> ();
|
CFF1Subrs *dest = c.allocate_size <CFF1Subrs> (HBUINT16::static_size);
|
||||||
if (unlikely (dest == nullptr)) return false;
|
if (unlikely (dest == nullptr)) return false;
|
||||||
if (unlikely (!dest->serialize (&c, *acc.globalSubrs, plan.offsets.globalSubrsInfo.offSize, plan.subrRefMaps.global_map, NULL_SUBR)))
|
dest->count.set (0);
|
||||||
{
|
|
||||||
DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF global subrs");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Encoding */
|
/* Encoding */
|
||||||
|
@ -941,9 +883,9 @@ static inline bool _write_cff1 (const cff_subset_plan &plan,
|
||||||
{
|
{
|
||||||
PrivateDict *pd = c.start_embed<PrivateDict> ();
|
PrivateDict *pd = c.start_embed<PrivateDict> ();
|
||||||
if (unlikely (pd == nullptr)) return false;
|
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;
|
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 */
|
/* 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);
|
result = pd->serialize (&c, acc.privateDicts[i], privSzr, priv_size);
|
||||||
if (unlikely (!result))
|
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);
|
DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF Private Dict[%d]", i);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plan.flatten_subrs && (acc.privateDicts[i].subrsOffset != 0))
|
|
||||||
{
|
|
||||||
CFF1Subrs *subrs = c.start_embed<CFF1Subrs> ();
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,38 +168,12 @@ struct CFF2CSOpSet_Flatten : CFF2CSOpSet<CFF2CSOpSet_Flatten, FlattenParam>
|
||||||
typedef CSOpSet<BlendArg, CFF2CSOpSet_Flatten, CFF2CSInterpEnv, FlattenParam> CSOPSET;
|
typedef CSOpSet<BlendArg, CFF2CSOpSet_Flatten, CFF2CSInterpEnv, FlattenParam> CSOPSET;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CFF2CSOpSet_SubsetSubrs : CFF2CSOpSet<CFF2CSOpSet_SubsetSubrs, SubrRefMapPair>
|
|
||||||
{
|
|
||||||
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<CFF2CSOpSet_SubsetSubrs, SubrRefMapPair>::process_op (op, env, refMapPair);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct cff2_subset_plan {
|
struct cff2_subset_plan {
|
||||||
inline cff2_subset_plan (void)
|
inline cff2_subset_plan (void)
|
||||||
: final_size (0),
|
: final_size (0),
|
||||||
orig_fdcount (0),
|
orig_fdcount (0),
|
||||||
subset_fdcount(1),
|
subset_fdcount(1),
|
||||||
subset_fdselect_format (0),
|
subset_fdselect_format (0),
|
||||||
flatten_subrs (true),
|
|
||||||
drop_hints (false)
|
drop_hints (false)
|
||||||
{
|
{
|
||||||
subset_fdselect_first_glyphs.init ();
|
subset_fdselect_first_glyphs.init ();
|
||||||
|
@ -207,7 +181,6 @@ struct cff2_subset_plan {
|
||||||
subset_charstrings.init ();
|
subset_charstrings.init ();
|
||||||
flat_charstrings.init ();
|
flat_charstrings.init ();
|
||||||
privateDictInfos.init ();
|
privateDictInfos.init ();
|
||||||
subrRefMaps.init ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ~cff2_subset_plan (void)
|
inline ~cff2_subset_plan (void)
|
||||||
|
@ -217,7 +190,6 @@ struct cff2_subset_plan {
|
||||||
subset_charstrings.fini ();
|
subset_charstrings.fini ();
|
||||||
flat_charstrings.fini ();
|
flat_charstrings.fini ();
|
||||||
privateDictInfos.fini ();
|
privateDictInfos.fini ();
|
||||||
subrRefMaps.fini ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool create (const OT::cff2::accelerator_subset_t &acc,
|
inline bool create (const OT::cff2::accelerator_subset_t &acc,
|
||||||
|
@ -238,7 +210,6 @@ struct cff2_subset_plan {
|
||||||
final_size += offsets.topDictInfo.size;
|
final_size += offsets.topDictInfo.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flatten_subrs)
|
|
||||||
{
|
{
|
||||||
/* Flatten global & local subrs */
|
/* Flatten global & local subrs */
|
||||||
SubrFlattener<const OT::cff2::accelerator_subset_t, CFF2CSInterpEnv, CFF2CSOpSet_Flatten>
|
SubrFlattener<const OT::cff2::accelerator_subset_t, CFF2CSInterpEnv, CFF2CSOpSet_Flatten>
|
||||||
|
@ -249,19 +220,6 @@ struct cff2_subset_plan {
|
||||||
/* no global/local subroutines */
|
/* no global/local subroutines */
|
||||||
offsets.globalSubrsInfo.size = HBUINT32::static_size; /* count 0 only */
|
offsets.globalSubrsInfo.size = HBUINT32::static_size; /* count 0 only */
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Subset global & local subrs */
|
|
||||||
SubrSubsetter<const OT::cff2::accelerator_subset_t, CFF2CSInterpEnv, CFF2CSOpSet_SubsetSubrs> 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 */
|
/* global subrs */
|
||||||
offsets.globalSubrsInfo.offset = final_size;
|
offsets.globalSubrsInfo.offset = final_size;
|
||||||
|
@ -306,19 +264,10 @@ struct cff2_subset_plan {
|
||||||
unsigned int dataSize = 0;
|
unsigned int dataSize = 0;
|
||||||
for (unsigned int i = 0; i < plan->glyphs.len; i++)
|
for (unsigned int i = 0; i < plan->glyphs.len; i++)
|
||||||
{
|
{
|
||||||
if (flatten_subrs)
|
ByteStrBuff &flatstr = flat_charstrings[i];
|
||||||
{
|
ByteStr str (&flatstr[0], flatstr.len);
|
||||||
ByteStrBuff &flatstr = flat_charstrings[i];
|
subset_charstrings.push (str);
|
||||||
ByteStr str (&flatstr[0], flatstr.len);
|
dataSize += 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
offsets.charStringsInfo.offSize = calcOffSize (dataSize + 1);
|
offsets.charStringsInfo.offSize = calcOffSize (dataSize + 1);
|
||||||
final_size += CFF2CharStrings::calculate_serialized_size (offsets.charStringsInfo.offSize, plan->glyphs.len, dataSize);
|
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))
|
if (!fdmap.excludes (i))
|
||||||
{
|
{
|
||||||
unsigned int priv_size;
|
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);
|
priv_size = PrivateDict::calculate_serialized_size (acc.privateDicts[i], privSzr);
|
||||||
TableInfo privInfo = { final_size, priv_size, 0 };
|
TableInfo privInfo = { final_size, priv_size, 0 };
|
||||||
privateDictInfos.push (privInfo);
|
privateDictInfos.push (privInfo);
|
||||||
final_size += privInfo.size;
|
final_size += privInfo.size;
|
||||||
if (!flatten_subrs)
|
|
||||||
final_size += offsets.localSubrsInfos[i].size;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,9 +308,6 @@ struct cff2_subset_plan {
|
||||||
ByteStrBuffArray flat_charstrings;
|
ByteStrBuffArray flat_charstrings;
|
||||||
hb_vector_t<TableInfo> privateDictInfos;
|
hb_vector_t<TableInfo> privateDictInfos;
|
||||||
|
|
||||||
SubrRefMaps subrRefMaps;
|
|
||||||
|
|
||||||
bool flatten_subrs;
|
|
||||||
bool drop_hints;
|
bool drop_hints;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -400,13 +344,9 @@ static inline bool _write_cff2 (const cff2_subset_plan &plan,
|
||||||
/* global subrs */
|
/* global subrs */
|
||||||
{
|
{
|
||||||
assert (cff2->topDict + plan.offsets.topDictInfo.size == c.head - c.start);
|
assert (cff2->topDict + plan.offsets.topDictInfo.size == c.head - c.start);
|
||||||
CFF2Subrs *dest = c.start_embed<CFF2Subrs> ();
|
CFF2Subrs *dest = c.allocate_size <CFF2Subrs> (HBUINT32::static_size);
|
||||||
if (unlikely (dest == nullptr)) return false;
|
if (unlikely (dest == nullptr)) return false;
|
||||||
if (unlikely (!dest->serialize (&c, *acc.globalSubrs, plan.offsets.globalSubrsInfo.offSize, plan.subrRefMaps.global_map)))
|
dest->count.set (0);
|
||||||
{
|
|
||||||
DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF2 global subrs");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* variation store */
|
/* variation store */
|
||||||
|
@ -485,27 +425,13 @@ static inline bool _write_cff2 (const cff2_subset_plan &plan,
|
||||||
if (unlikely (pd == nullptr)) return false;
|
if (unlikely (pd == nullptr)) return false;
|
||||||
unsigned int priv_size = plan.privateDictInfos[plan.fdmap[i]].size;
|
unsigned int priv_size = plan.privateDictInfos[plan.fdmap[i]].size;
|
||||||
bool result;
|
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);
|
result = pd->serialize (&c, acc.privateDicts[i], privSzr, priv_size);
|
||||||
if (unlikely (!result))
|
if (unlikely (!result))
|
||||||
{
|
{
|
||||||
DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF2 Private Dict[%d]", i);
|
DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF2 Private Dict[%d]", i);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!plan.flatten_subrs && (acc.privateDicts[i].subrsOffset != 0))
|
|
||||||
{
|
|
||||||
CFF2Subrs *subrs = c.start_embed<CFF2Subrs> ();
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue