[subset] Convert subset plan to use a flags bit set.
This commit is contained in:
parent
3d534b146c
commit
46d4a5e673
|
@ -213,13 +213,15 @@ struct glyf
|
|||
if (!plan->old_gid_for_new_gid (new_gid, &subset_glyph.old_gid))
|
||||
return subset_glyph;
|
||||
|
||||
if (new_gid == 0 && !plan->notdef_outline)
|
||||
if (new_gid == 0 &&
|
||||
!(plan->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE))
|
||||
subset_glyph.source_glyph = Glyph ();
|
||||
else
|
||||
subset_glyph.source_glyph = glyf.glyph_for_gid (subset_glyph.old_gid, true);
|
||||
if (plan->drop_hints) subset_glyph.drop_hints_bytes ();
|
||||
else subset_glyph.dest_start = subset_glyph.source_glyph.get_bytes ();
|
||||
|
||||
if (plan->flags & HB_SUBSET_FLAGS_NO_HINTING)
|
||||
subset_glyph.drop_hints_bytes ();
|
||||
else
|
||||
subset_glyph.dest_start = subset_glyph.source_glyph.get_bytes ();
|
||||
return subset_glyph;
|
||||
})
|
||||
| hb_sink (glyphs)
|
||||
|
@ -1274,9 +1276,10 @@ struct glyf
|
|||
const_cast<CompositeGlyphChain &> (_).set_glyph_index (new_gid);
|
||||
}
|
||||
|
||||
if (plan->drop_hints) Glyph (dest_glyph).drop_hints ();
|
||||
if (plan->flags & HB_SUBSET_FLAGS_NO_HINTING)
|
||||
Glyph (dest_glyph).drop_hints ();
|
||||
|
||||
if (plan->overlaps_flag)
|
||||
if (plan->flags & HB_SUBSET_FLAGS_SET_OVERLAPS_FLAG)
|
||||
Glyph (dest_glyph).set_overlaps_flag ();
|
||||
|
||||
return_trace (true);
|
||||
|
|
|
@ -538,7 +538,7 @@ struct Anchor
|
|||
switch (u.format) {
|
||||
case 1: return_trace (bool (reinterpret_cast<Anchor *> (u.format1.copy (c->serializer))));
|
||||
case 2:
|
||||
if (c->plan->drop_hints)
|
||||
if (c->plan->flags & HB_SUBSET_FLAGS_NO_HINTING)
|
||||
{
|
||||
// AnchorFormat 2 just containins extra hinting information, so
|
||||
// if hints are being dropped convert to format 1.
|
||||
|
@ -1373,7 +1373,7 @@ struct PairPosFormat1
|
|||
out->format = format;
|
||||
out->valueFormat[0] = valueFormat[0];
|
||||
out->valueFormat[1] = valueFormat[1];
|
||||
if (c->plan->drop_hints)
|
||||
if (c->plan->flags & HB_SUBSET_FLAGS_NO_HINTING)
|
||||
{
|
||||
hb_pair_t<unsigned, unsigned> newFormats = compute_effective_value_formats (glyphset);
|
||||
out->valueFormat[0] = newFormats.first;
|
||||
|
@ -1591,7 +1591,7 @@ struct PairPosFormat2
|
|||
unsigned len2 = valueFormat2.get_len ();
|
||||
|
||||
hb_pair_t<unsigned, unsigned> newFormats = hb_pair (valueFormat1, valueFormat2);
|
||||
if (c->plan->drop_hints)
|
||||
if (c->plan->flags & HB_SUBSET_FLAGS_NO_HINTING)
|
||||
newFormats = compute_effective_value_formats (klass1_map, klass2_map);
|
||||
|
||||
out->valueFormat1 = newFormats.first;
|
||||
|
|
|
@ -107,7 +107,7 @@ struct maxp
|
|||
maxpV1Tail *dest_v1 = c->serializer->embed<maxpV1Tail> (src_v1);
|
||||
if (unlikely (!dest_v1)) return_trace (false);
|
||||
|
||||
if (c->plan->drop_hints)
|
||||
if (c->plan->flags & HB_SUBSET_FLAGS_NO_HINTING)
|
||||
drop_hint_fields (dest_v1);
|
||||
}
|
||||
|
||||
|
|
|
@ -249,7 +249,11 @@ struct name
|
|||
+ nameRecordZ.as_array (count)
|
||||
| hb_filter (c->plan->name_ids, &NameRecord::nameID)
|
||||
| hb_filter (c->plan->name_languages, &NameRecord::languageID)
|
||||
| hb_filter ([&] (const NameRecord& namerecord) { return c->plan->name_legacy || namerecord.isUnicode (); })
|
||||
| hb_filter ([&] (const NameRecord& namerecord) {
|
||||
return
|
||||
(c->plan->flags & HB_SUBSET_FLAGS_NAME_LEGACY)
|
||||
|| namerecord.isUnicode ();
|
||||
})
|
||||
;
|
||||
|
||||
name_prime->serialize (c->serializer, it, hb_addressof (this + stringOffset));
|
||||
|
|
|
@ -171,7 +171,8 @@ struct OS2
|
|||
TRACE_SUBSET (this);
|
||||
OS2 *os2_prime = c->serializer->embed (this);
|
||||
if (unlikely (!os2_prime)) return_trace (false);
|
||||
if (!c->plan->prune_unicode_ranges) return_trace (true);
|
||||
if (c->plan->flags & HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES)
|
||||
return_trace (true);
|
||||
|
||||
/* when --gids option is not used, no need to do collect_mapping that is
|
||||
* iterating all codepoints in each subtable, which is not efficient */
|
||||
|
|
|
@ -98,10 +98,11 @@ struct post
|
|||
post *post_prime = c->serializer->start_embed<post> ();
|
||||
if (unlikely (!post_prime)) return_trace (false);
|
||||
|
||||
if (!serialize (c->serializer, c->plan->glyph_names))
|
||||
bool glyph_names = c->plan->flags & HB_SUBSET_FLAGS_GLYPH_NAMES;
|
||||
if (!serialize (c->serializer, glyph_names))
|
||||
return_trace (false);
|
||||
|
||||
if (c->plan->glyph_names && version.major == 2)
|
||||
if (glyph_names && version.major == 2)
|
||||
return_trace (v2X.subset (c));
|
||||
|
||||
return_trace (true);
|
||||
|
|
|
@ -419,7 +419,9 @@ struct gvar
|
|||
out->glyphCount = num_glyphs;
|
||||
|
||||
unsigned int subset_data_size = 0;
|
||||
for (hb_codepoint_t gid = c->plan->notdef_outline ? 0 : 1; gid < num_glyphs; gid++)
|
||||
for (hb_codepoint_t gid = (c->plan->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE) ? 0 : 1;
|
||||
gid < num_glyphs;
|
||||
gid++)
|
||||
{
|
||||
hb_codepoint_t old_gid;
|
||||
if (!c->plan->old_gid_for_new_gid (gid, &old_gid)) continue;
|
||||
|
@ -449,7 +451,9 @@ struct gvar
|
|||
out->dataZ = subset_data - (char *) out;
|
||||
|
||||
unsigned int glyph_offset = 0;
|
||||
for (hb_codepoint_t gid = c->plan->notdef_outline ? 0 : 1; gid < num_glyphs; gid++)
|
||||
for (hb_codepoint_t gid = (c->plan->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE) ? 0 : 1;
|
||||
gid < num_glyphs;
|
||||
gid++)
|
||||
{
|
||||
hb_codepoint_t old_gid;
|
||||
hb_bytes_t var_data_bytes = c->plan->old_gid_for_new_gid (gid, &old_gid)
|
||||
|
|
|
@ -272,7 +272,7 @@ struct hvarvvar_subset_plan_t
|
|||
index_map_plans[0].init (*index_maps[0], outer_map, inner_sets, plan);
|
||||
if (index_maps[0] == &Null (DeltaSetIndexMap))
|
||||
{
|
||||
retain_adv_map = plan->retain_gids;
|
||||
retain_adv_map = plan->flags & HB_SUBSET_FLAGS_RETAIN_GIDS;
|
||||
outer_map.add (0);
|
||||
for (hb_codepoint_t gid = 0; gid < plan->num_output_glyphs (); gid++)
|
||||
{
|
||||
|
|
|
@ -259,7 +259,10 @@ struct subr_flattener_t
|
|||
return false;
|
||||
cs_interpreter_t<ENV, OPSET, flatten_param_t> interp;
|
||||
interp.env.init (str, acc, fd);
|
||||
flatten_param_t param = { flat_charstrings[i], plan->drop_hints };
|
||||
flatten_param_t param = {
|
||||
flat_charstrings[i],
|
||||
(bool) (plan->flags & HB_SUBSET_FLAGS_NO_HINTING)
|
||||
};
|
||||
if (unlikely (!interp.interpret (param)))
|
||||
return false;
|
||||
}
|
||||
|
@ -636,7 +639,7 @@ struct subr_subsetter_t
|
|||
param.init (&parsed_charstrings[i],
|
||||
&parsed_global_subrs, &parsed_local_subrs[fd],
|
||||
closures.global_closure, closures.local_closures[fd],
|
||||
plan->drop_hints);
|
||||
plan->flags & HB_SUBSET_FLAGS_NO_HINTING);
|
||||
|
||||
if (unlikely (!interp.interpret (param)))
|
||||
return false;
|
||||
|
@ -645,7 +648,7 @@ struct subr_subsetter_t
|
|||
SUBSETTER::complete_parsed_str (interp.env, param, parsed_charstrings[i]);
|
||||
}
|
||||
|
||||
if (plan->drop_hints)
|
||||
if (plan->flags & HB_SUBSET_FLAGS_NO_HINTING)
|
||||
{
|
||||
/* mark hint ops and arguments for drop */
|
||||
for (unsigned int i = 0; i < plan->num_output_glyphs (); i++)
|
||||
|
@ -660,7 +663,7 @@ struct subr_subsetter_t
|
|||
param.init (&parsed_charstrings[i],
|
||||
&parsed_global_subrs, &parsed_local_subrs[fd],
|
||||
closures.global_closure, closures.local_closures[fd],
|
||||
plan->drop_hints);
|
||||
plan->flags & HB_SUBSET_FLAGS_NO_HINTING);
|
||||
|
||||
drop_hints_param_t drop;
|
||||
if (drop_hints_in_str (parsed_charstrings[i], param, drop))
|
||||
|
@ -685,7 +688,7 @@ struct subr_subsetter_t
|
|||
param.init (&parsed_charstrings[i],
|
||||
&parsed_global_subrs, &parsed_local_subrs[fd],
|
||||
closures.global_closure, closures.local_closures[fd],
|
||||
plan->drop_hints);
|
||||
plan->flags & HB_SUBSET_FLAGS_NO_HINTING);
|
||||
collect_subr_refs_in_str (parsed_charstrings[i], param);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -543,8 +543,8 @@ struct cff_subset_plan {
|
|||
|
||||
num_glyphs = plan->num_output_glyphs ();
|
||||
orig_fdcount = acc.fdCount;
|
||||
drop_hints = plan->drop_hints;
|
||||
desubroutinize = plan->desubroutinize;
|
||||
drop_hints = plan->flags & HB_SUBSET_FLAGS_NO_HINTING;
|
||||
desubroutinize = plan->flags & HB_SUBSET_FLAGS_DESUBROUTINIZE;
|
||||
|
||||
/* check whether the subset renumbers any glyph IDs */
|
||||
gid_renum = false;
|
||||
|
|
|
@ -262,8 +262,8 @@ struct cff2_subset_plan {
|
|||
{
|
||||
orig_fdcount = acc.fdArray->count;
|
||||
|
||||
drop_hints = plan->drop_hints;
|
||||
desubroutinize = plan->desubroutinize;
|
||||
drop_hints = plan->flags & HB_SUBSET_FLAGS_NO_HINTING;
|
||||
desubroutinize = plan->flags & HB_SUBSET_FLAGS_DESUBROUTINIZE;
|
||||
|
||||
if (desubroutinize)
|
||||
{
|
||||
|
|
|
@ -296,10 +296,24 @@ _populate_gids_to_retain (hb_subset_plan_t* plan,
|
|||
#ifndef HB_NO_SUBSET_LAYOUT
|
||||
if (close_over_gsub)
|
||||
// closure all glyphs/lookups/features needed for GSUB substitutions.
|
||||
_closure_glyphs_lookups_features<OT::GSUB> (plan->source, plan->_glyphset_gsub, plan->layout_features, plan->retain_all_layout_features, plan->gsub_lookups, plan->gsub_features, plan->gsub_langsys);
|
||||
_closure_glyphs_lookups_features<OT::GSUB> (
|
||||
plan->source,
|
||||
plan->_glyphset_gsub,
|
||||
plan->layout_features,
|
||||
plan->flags & HB_SUBSET_FLAGS_RETAIN_ALL_FEATURES,
|
||||
plan->gsub_lookups,
|
||||
plan->gsub_features,
|
||||
plan->gsub_langsys);
|
||||
|
||||
if (close_over_gpos)
|
||||
_closure_glyphs_lookups_features<OT::GPOS> (plan->source, plan->_glyphset_gsub, plan->layout_features, plan->retain_all_layout_features, plan->gpos_lookups, plan->gpos_features, plan->gpos_langsys);
|
||||
_closure_glyphs_lookups_features<OT::GPOS> (
|
||||
plan->source,
|
||||
plan->_glyphset_gsub,
|
||||
plan->layout_features,
|
||||
plan->flags & HB_SUBSET_FLAGS_RETAIN_ALL_FEATURES,
|
||||
plan->gpos_lookups,
|
||||
plan->gpos_features,
|
||||
plan->gpos_langsys);
|
||||
#endif
|
||||
_remove_invalid_gids (plan->_glyphset_gsub, plan->source->get_num_glyphs ());
|
||||
|
||||
|
@ -423,16 +437,7 @@ hb_subset_plan_create (hb_face_t *face,
|
|||
return const_cast<hb_subset_plan_t *> (&Null (hb_subset_plan_t));
|
||||
|
||||
plan->successful = true;
|
||||
plan->drop_hints = input->flags & HB_SUBSET_FLAGS_NO_HINTING;
|
||||
plan->desubroutinize = input->flags & HB_SUBSET_FLAGS_DESUBROUTINIZE;
|
||||
plan->retain_gids = input->flags & HB_SUBSET_FLAGS_RETAIN_GIDS;
|
||||
plan->name_legacy = input->flags & HB_SUBSET_FLAGS_NAME_LEGACY;
|
||||
plan->overlaps_flag = input->flags & HB_SUBSET_FLAGS_SET_OVERLAPS_FLAG;
|
||||
plan->notdef_outline = input->flags & HB_SUBSET_FLAGS_NOTDEF_OUTLINE;
|
||||
plan->glyph_names = input->flags & HB_SUBSET_FLAGS_GLYPH_NAMES;
|
||||
plan->prune_unicode_ranges = !(input->flags & HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES);
|
||||
plan->retain_all_layout_features = input->flags & HB_SUBSET_FLAGS_RETAIN_ALL_FEATURES;
|
||||
plan->passthrough_unrecognized = input->flags & HB_SUBSET_FLAGS_PASSTHROUGH_UNRECOGNIZED;
|
||||
plan->flags = input->flags;
|
||||
plan->unicodes = hb_set_create ();
|
||||
plan->name_ids = hb_set_copy (input->name_ids);
|
||||
_nameid_closure (face, plan->name_ids);
|
||||
|
|
|
@ -39,17 +39,8 @@ struct hb_subset_plan_t
|
|||
{
|
||||
hb_object_header_t header;
|
||||
|
||||
bool successful : 1;
|
||||
bool drop_hints : 1;
|
||||
bool desubroutinize : 1;
|
||||
bool retain_gids : 1;
|
||||
bool name_legacy : 1;
|
||||
bool overlaps_flag : 1;
|
||||
bool notdef_outline : 1;
|
||||
bool glyph_names : 1;
|
||||
bool prune_unicode_ranges : 1;
|
||||
bool retain_all_layout_features : 1;
|
||||
bool passthrough_unrecognized : 1;
|
||||
bool successful;
|
||||
hb_subset_flags_t flags;
|
||||
|
||||
// For each cp that we'd like to retain maps to the corresponding gid.
|
||||
hb_set_t *unicodes;
|
||||
|
|
|
@ -246,7 +246,7 @@ _should_drop_table (hb_subset_plan_t *plan, hb_tag_t tag)
|
|||
case HB_TAG ('p','r','e','p'): /* hint table, fallthrough */
|
||||
case HB_TAG ('h','d','m','x'): /* hint table, fallthrough */
|
||||
case HB_TAG ('V','D','M','X'): /* hint table, fallthrough */
|
||||
return plan->drop_hints;
|
||||
return plan->flags & HB_SUBSET_FLAGS_NO_HINTING;
|
||||
|
||||
#ifdef HB_NO_SUBSET_LAYOUT
|
||||
// Drop Layout Tables if requested.
|
||||
|
@ -322,7 +322,7 @@ _subset_table (hb_subset_plan_t *plan, hb_tag_t tag)
|
|||
#endif
|
||||
|
||||
default:
|
||||
if (plan->passthrough_unrecognized)
|
||||
if (plan->flags & HB_SUBSET_FLAGS_PASSTHROUGH_UNRECOGNIZED)
|
||||
return _passthrough (plan, tag);
|
||||
|
||||
// Drop table
|
||||
|
|
Loading…
Reference in New Issue