[subset] collect name_ids for FeratureParams

This commit is contained in:
Qunxin Liu 2023-03-13 15:43:29 -07:00
parent de6533d885
commit 125450d2f2
3 changed files with 74 additions and 15 deletions

View File

@ -529,6 +529,9 @@ struct FeatureParamsSize
return_trace (true); return_trace (true);
} }
void collect_name_ids (hb_set_t *nameids_to_retain /* OUT */) const
{ nameids_to_retain->add (subfamilyNameID); }
bool subset (hb_subset_context_t *c) const bool subset (hb_subset_context_t *c) const
{ {
TRACE_SUBSET (this); TRACE_SUBSET (this);
@ -585,6 +588,9 @@ struct FeatureParamsStylisticSet
return_trace (c->check_struct (this)); return_trace (c->check_struct (this));
} }
void collect_name_ids (hb_set_t *nameids_to_retain /* OUT */) const
{ nameids_to_retain->add (uiNameID); }
bool subset (hb_subset_context_t *c) const bool subset (hb_subset_context_t *c) const
{ {
TRACE_SUBSET (this); TRACE_SUBSET (this);
@ -632,6 +638,20 @@ struct FeatureParamsCharacterVariants
unsigned get_size () const unsigned get_size () const
{ return min_size + characters.len * HBUINT24::static_size; } { return min_size + characters.len * HBUINT24::static_size; }
void collect_name_ids (hb_set_t *nameids_to_retain /* OUT */) const
{
if (featUILableNameID) nameids_to_retain->add (featUILableNameID);
if (featUITooltipTextNameID) nameids_to_retain->add (featUITooltipTextNameID);
if (sampleTextNameID) nameids_to_retain->add (sampleTextNameID);
if (!firstParamUILabelNameID || !numNamedParameters || numNamedParameters >= 0x7FFF)
return;
unsigned last_name_id = (unsigned) firstParamUILabelNameID + (unsigned) numNamedParameters - 1;
if (last_name_id >= 256 && last_name_id <= 32767)
nameids_to_retain->add_range (firstParamUILabelNameID, last_name_id);
}
bool subset (hb_subset_context_t *c) const bool subset (hb_subset_context_t *c) const
{ {
TRACE_SUBSET (this); TRACE_SUBSET (this);
@ -694,6 +714,19 @@ struct FeatureParams
return_trace (true); return_trace (true);
} }
void collect_name_ids (hb_tag_t tag, hb_set_t *nameids_to_retain /* OUT */) const
{
#ifdef HB_NO_LAYOUT_FEATURE_PARAMS
return;
#endif
if (tag == HB_TAG ('s','i','z','e'))
return (u.size.collect_name_ids (nameids_to_retain));
if ((tag & 0xFFFF0000u) == HB_TAG ('s','s','\0','\0')) /* ssXX */
return (u.stylisticSet.collect_name_ids (nameids_to_retain));
if ((tag & 0xFFFF0000u) == HB_TAG ('c','v','\0','\0')) /* cvXX */
return (u.characterVariants.collect_name_ids (nameids_to_retain));
}
bool subset (hb_subset_context_t *c, const Tag* tag) const bool subset (hb_subset_context_t *c, const Tag* tag) const
{ {
TRACE_SUBSET (this); TRACE_SUBSET (this);
@ -762,6 +795,12 @@ struct Feature
bool intersects_lookup_indexes (const hb_map_t *lookup_indexes) const bool intersects_lookup_indexes (const hb_map_t *lookup_indexes) const
{ return lookupIndex.intersects (lookup_indexes); } { return lookupIndex.intersects (lookup_indexes); }
void collect_name_ids (hb_tag_t tag, hb_set_t *nameids_to_retain /* OUT */) const
{
if (featureParams)
get_feature_params ().collect_name_ids (tag, nameids_to_retain);
}
bool subset (hb_subset_context_t *c, bool subset (hb_subset_context_t *c,
hb_subset_layout_context_t *l, hb_subset_layout_context_t *l,
const Tag *tag = nullptr) const const Tag *tag = nullptr) const

View File

@ -4461,6 +4461,18 @@ struct GSUBGPOS
} }
} }
void collect_name_ids (const hb_map_t *feature_index_map,
hb_set_t *nameids_to_retain /* OUT */) const
{
unsigned count = get_feature_count ();
for (unsigned i = 0 ; i < count; i++)
{
if (!feature_index_map->has (i)) continue;
hb_tag_t tag = get_feature_tag (i);
get_feature (i).collect_name_ids (tag, nameids_to_retain);
}
}
template <typename T> template <typename T>
struct accelerator_t struct accelerator_t
{ {

View File

@ -622,23 +622,34 @@ _glyf_add_gid_and_children (const OT::glyf_accelerator_t &glyf,
} }
static void static void
_nameid_closure (hb_face_t *face, _nameid_closure (hb_subset_plan_t* plan,
hb_set_t *nameids, hb_set_t* drop_tables)
bool all_axes_pinned,
hb_hashmap_t<hb_tag_t, float> *user_axes_location,
bool collect_cpal_name_ids,
const hb_map_t *color_index_map)
{ {
#ifndef HB_NO_STYLE #ifndef HB_NO_STYLE
face->table.STAT->collect_name_ids (user_axes_location, nameids); plan->source->table.STAT->collect_name_ids (&plan->user_axes_location, &plan->name_ids);
#endif #endif
#ifndef HB_NO_VAR #ifndef HB_NO_VAR
if (!all_axes_pinned) if (!plan->all_axes_pinned)
face->table.fvar->collect_name_ids (user_axes_location, nameids); plan->source->table.fvar->collect_name_ids (&plan->user_axes_location, &plan->name_ids);
#endif #endif
if (collect_cpal_name_ids) if (!drop_tables->has (HB_OT_TAG_CPAL))
face->table.CPAL->collect_name_ids (color_index_map, nameids); plan->source->table.CPAL->collect_name_ids (&plan->colr_palettes, &plan->name_ids);
#ifndef HB_NO_SUBSET_LAYOUT
if (!drop_tables->has (HB_OT_TAG_GPOS))
{
hb_blob_ptr_t<GPOS> gpos = plan->source_table<GPOS> ();
gpos->collect_name_ids (&plan->gpos_features, &plan->name_ids);
gpos.destroy ();
}
if (!drop_tables->has (HB_OT_TAG_GSUB))
{
hb_blob_ptr_t<GSUB> gsub = plan->source_table<GSUB> ();
gsub->collect_name_ids (&plan->gsub_features, &plan->name_ids);
gsub.destroy ();
}
#endif
} }
static void static void
@ -694,10 +705,7 @@ _populate_gids_to_retain (hb_subset_plan_t* plan,
plan->_glyphset_colred = cur_glyphset; plan->_glyphset_colred = cur_glyphset;
_nameid_closure (plan->source, &(plan->name_ids), _nameid_closure (plan, drop_tables);
plan->all_axes_pinned, &(plan->user_axes_location),
!drop_tables->has (HB_OT_TAG_CPAL),
&(plan->colr_palettes));
/* Populate a full set of glyphs to retain by adding all referenced /* Populate a full set of glyphs to retain by adding all referenced
* composite glyphs. */ * composite glyphs. */
if (glyf.has_data ()) if (glyf.has_data ())