mirror of
https://github.com/harfbuzz/harfbuzz.git
synced 2025-04-10 07:18:39 +00:00
[subset/cff] Move serialize to accelerator
This commit is contained in:
parent
7344411cc2
commit
97d63e8d1d
4 changed files with 41 additions and 31 deletions
|
@ -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<cff1_private_dict_opset_subset_t, cff1_private_dict_values_subset_t> SUPER;
|
||||
};
|
||||
|
|
|
@ -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<int> normalized_coords) const;
|
||||
|
||||
typedef accelerator_templ_t<cff2_private_dict_opset_subset_t, cff2_private_dict_values_subset_t> SUPER;
|
||||
};
|
||||
|
|
|
@ -399,8 +399,10 @@ struct cff1_subr_subsetter_t : subr_subsetter_t<cff1_subr_subsetter_t, CFF1Subrs
|
|||
}
|
||||
};
|
||||
|
||||
struct cff_subset_plan {
|
||||
cff_subset_plan ()
|
||||
namespace OT {
|
||||
struct cff1_subset_plan
|
||||
{
|
||||
cff1_subset_plan ()
|
||||
{
|
||||
for (unsigned int i = 0; i < name_dict_values_t::ValCount; i++)
|
||||
topDictModSIDs[i] = CFF_UNDEF_SID;
|
||||
|
@ -754,13 +756,14 @@ struct cff_subset_plan {
|
|||
|
||||
bool desubroutinize = false;
|
||||
};
|
||||
} // namespace OT
|
||||
|
||||
static bool _serialize_cff1 (hb_serialize_context_t *c,
|
||||
cff_subset_plan &plan,
|
||||
const OT::cff1::accelerator_subset_t &acc)
|
||||
bool
|
||||
OT::cff1::accelerator_subset_t::serialize (hb_serialize_context_t *c,
|
||||
struct OT::cff1_subset_plan &plan) const
|
||||
{
|
||||
/* private dicts & local subrs */
|
||||
for (int i = (int)acc.privateDicts.length; --i >= 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<PrivateDict> ();
|
||||
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<CFF1FDArray> ();
|
||||
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<CFF1StringIndex> ();
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<int> normalized_coords)
|
||||
bool
|
||||
OT::cff2::accelerator_subset_t::serialize (hb_serialize_context_t *c,
|
||||
struct cff2_subset_plan &plan,
|
||||
hb_array_t<int> normalized_coords) const
|
||||
{
|
||||
/* 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))
|
||||
{
|
||||
|
@ -539,8 +541,8 @@ static bool _serialize_cff2 (hb_serialize_context_t *c,
|
|||
}
|
||||
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 ();
|
||||
|
@ -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<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)))
|
||||
|
@ -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<CFF2VariationStore> ();
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue