mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 06:21:16 +01:00
[subset] de-duplicate features (#5494)
This commit is contained in:
1 parent
6a2453bb20
commit
0952bc0ac2
96 files changed
+68
-8
No files matched your search
@@ -141,6 +141,7 @@ struct hb_subset_layout_context_t :
|
||||
const hb_map_t *lookup_index_map;
|
||||
const hb_hashmap_t<unsigned, hb::unique_ptr<hb_set_t>> *script_langsys_map;
|
||||
const hb_map_t *feature_index_map;
|
||||
const hb_map_t *feature_map_w_duplicates;
|
||||
const hb_hashmap_t<unsigned, const Feature*> *feature_substitutes_map;
|
||||
hb_hashmap_t<unsigned, hb::shared_ptr<hb_set_t>> *feature_record_cond_idx_map;
|
||||
const hb_set_t *catch_all_record_feature_idxes;
|
||||
@@ -165,6 +166,7 @@ struct hb_subset_layout_context_t :
|
||||
lookup_index_map = &c_->plan->gsub_lookups;
|
||||
script_langsys_map = &c_->plan->gsub_langsys;
|
||||
feature_index_map = &c_->plan->gsub_features;
|
||||
feature_map_w_duplicates = &c_->plan->gsub_features_w_duplicates;
|
||||
feature_substitutes_map = &c_->plan->gsub_feature_substitutes_map;
|
||||
feature_record_cond_idx_map = c_->plan->user_axes_location.is_empty () ? nullptr : &c_->plan->gsub_feature_record_cond_idx_map;
|
||||
catch_all_record_feature_idxes = &c_->plan->gsub_old_features;
|
||||
@@ -175,6 +177,7 @@ struct hb_subset_layout_context_t :
|
||||
lookup_index_map = &c_->plan->gpos_lookups;
|
||||
script_langsys_map = &c_->plan->gpos_langsys;
|
||||
feature_index_map = &c_->plan->gpos_features;
|
||||
feature_map_w_duplicates = &c_->plan->gpos_features_w_duplicates;
|
||||
feature_substitutes_map = &c_->plan->gpos_feature_substitutes_map;
|
||||
feature_record_cond_idx_map = c_->plan->user_axes_location.is_empty () ? nullptr : &c_->plan->gpos_feature_record_cond_idx_map;
|
||||
catch_all_record_feature_idxes = &c_->plan->gpos_old_features;
|
||||
@@ -1082,15 +1085,15 @@ struct LangSys
|
||||
if (unlikely (!c->serializer->extend_min (out))) return_trace (false);
|
||||
|
||||
const uint32_t *v;
|
||||
out->reqFeatureIndex = l->feature_index_map->has (reqFeatureIndex, &v) ? *v : 0xFFFFu;
|
||||
out->reqFeatureIndex = l->feature_map_w_duplicates->has (reqFeatureIndex, &v) ? *v : 0xFFFFu;
|
||||
|
||||
if (!l->visitFeatureIndex (featureIndex.len))
|
||||
return_trace (false);
|
||||
|
||||
auto it =
|
||||
+ hb_iter (featureIndex)
|
||||
| hb_filter (l->feature_index_map)
|
||||
| hb_map (l->feature_index_map)
|
||||
| hb_filter (l->feature_map_w_duplicates)
|
||||
| hb_map (l->feature_map_w_duplicates)
|
||||
;
|
||||
|
||||
bool ret = bool (it);
|
||||
@@ -4459,7 +4462,7 @@ struct FeatureTableSubstitutionRecord
|
||||
if (unlikely (!s->extend_min (this))) return_trace (false);
|
||||
|
||||
uint32_t *new_feature_idx;
|
||||
if (!c->feature_index_map->has (feature_index, &new_feature_idx))
|
||||
if (!c->feature_map_w_duplicates->has (feature_index, &new_feature_idx))
|
||||
return_trace (false);
|
||||
|
||||
if (!s->check_assign (featureIndex, *new_feature_idx, HB_SERIALIZE_ERROR_INT_OVERFLOW))
|
||||
@@ -4477,7 +4480,7 @@ struct FeatureTableSubstitutionRecord
|
||||
{
|
||||
TRACE_SUBSET (this);
|
||||
uint32_t *new_feature_index;
|
||||
if (!c->feature_index_map->has (featureIndex, &new_feature_index))
|
||||
if (!c->feature_map_w_duplicates->has (featureIndex, &new_feature_index))
|
||||
return_trace (false);
|
||||
|
||||
auto *out = c->subset_context->serializer->embed (this);
|
||||
@@ -4751,7 +4754,7 @@ struct FeatureVariations
|
||||
|
||||
int keep_up_to = -1;
|
||||
for (int i = varRecords.len - 1; i >= 0; i--) {
|
||||
if (varRecords[i].intersects_features (this, l->feature_index_map)) {
|
||||
if (varRecords[i].intersects_features (this, l->feature_map_w_duplicates)) {
|
||||
keep_up_to = i;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -248,12 +248,48 @@ _GSUBGPOS_find_duplicate_features (const OT::GSUBGPOS &g,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
remap_feature_indices (const hb_set_t &feature_indices,
|
||||
const hb_map_t &duplicate_feature_map,
|
||||
const hb_hashmap_t<unsigned, hb_pair_t<const void*, const void*>>& catch_all_record_idx_feature_map,
|
||||
hb_map_t *mapping, /* OUT */
|
||||
hb_map_t *mapping_w_duplicates /* OUT */)
|
||||
{
|
||||
unsigned i = 0;
|
||||
for (const auto _ : feature_indices)
|
||||
{
|
||||
// retain those features in case we need to insert a catch-all record to reinstate the old features
|
||||
if (catch_all_record_idx_feature_map.has (_))
|
||||
{
|
||||
mapping->set (_, i);
|
||||
mapping_w_duplicates->set (_, i);
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t f_idx = duplicate_feature_map.get (_);
|
||||
uint32_t *new_idx;
|
||||
if (mapping-> has (f_idx, &new_idx))
|
||||
{
|
||||
mapping_w_duplicates->set (_, *new_idx);
|
||||
}
|
||||
else
|
||||
{
|
||||
mapping->set (_, i);
|
||||
mapping_w_duplicates->set (_, i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void
|
||||
_closure_glyphs_lookups_features (hb_subset_plan_t *plan,
|
||||
hb_set_t *gids_to_retain,
|
||||
hb_map_t *lookups,
|
||||
hb_map_t *features,
|
||||
hb_map_t *features_w_duplicates,
|
||||
script_langsys_map *langsys_map,
|
||||
hb_hashmap_t<unsigned, hb::shared_ptr<hb_set_t>> *feature_record_cond_idx_map,
|
||||
hb_hashmap_t<unsigned, const OT::Feature*> *feature_substitutes_map,
|
||||
@@ -291,7 +327,7 @@ _closure_glyphs_lookups_features (hb_subset_plan_t *plan,
|
||||
|
||||
feature_indices.clear ();
|
||||
table->prune_langsys (&duplicate_feature_map, &plan->layout_scripts, langsys_map, &feature_indices);
|
||||
remap_indexes (&feature_indices, features);
|
||||
remap_feature_indices (feature_indices, duplicate_feature_map, catch_all_record_idx_feature_map, features, features_w_duplicates);
|
||||
|
||||
table.destroy ();
|
||||
}
|
||||
@@ -323,6 +359,7 @@ layout_populate_gids_to_retain (hb_subset_plan_t* plan,
|
||||
&plan->_glyphset_gsub,
|
||||
&plan->gsub_lookups,
|
||||
&plan->gsub_features,
|
||||
&plan->gsub_features_w_duplicates,
|
||||
&plan->gsub_langsys,
|
||||
&plan->gsub_feature_record_cond_idx_map,
|
||||
&plan->gsub_feature_substitutes_map,
|
||||
@@ -335,6 +372,7 @@ layout_populate_gids_to_retain (hb_subset_plan_t* plan,
|
||||
&plan->_glyphset_gsub,
|
||||
&plan->gpos_lookups,
|
||||
&plan->gpos_features,
|
||||
&plan->gpos_features_w_duplicates,
|
||||
&plan->gpos_langsys,
|
||||
&plan->gpos_feature_record_cond_idx_map,
|
||||
&plan->gpos_feature_substitutes_map,
|
||||
@@ -379,4 +417,4 @@ collect_layout_variation_indices (hb_subset_plan_t* plan)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -81,6 +81,10 @@ HB_SUBSET_PLAN_MEMBER (hb_hashmap_t E(<unsigned, hb::unique_ptr<hb_set_t>>), gpo
|
||||
HB_SUBSET_PLAN_MEMBER (hb_map_t, gsub_features)
|
||||
HB_SUBSET_PLAN_MEMBER (hb_map_t, gpos_features)
|
||||
|
||||
//active features(with duplicates) old index -> new index mapping
|
||||
HB_SUBSET_PLAN_MEMBER (hb_map_t, gsub_features_w_duplicates)
|
||||
HB_SUBSET_PLAN_MEMBER (hb_map_t, gpos_features_w_duplicates)
|
||||
|
||||
//active feature variation records/condition index with variations
|
||||
HB_SUBSET_PLAN_MEMBER (hb_hashmap_t E(<unsigned, hb::shared_ptr<hb_set_t>>), gsub_feature_record_cond_idx_map)
|
||||
HB_SUBSET_PLAN_MEMBER (hb_hashmap_t E(<unsigned, hb::shared_ptr<hb_set_t>>), gpos_feature_record_cond_idx_map)
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -14,3 +14,8 @@ drop-hints-desubroutinize-retain-gids.txt
|
||||
SUBSETS:
|
||||
明
|
||||
acek
|
||||
|
||||
# TODO temporary until diff with fonttools on FDSelect format is fixed.
|
||||
OPTIONS:
|
||||
# no_fonttools
|
||||
|
||||
@@ -8,3 +8,8 @@ retain-gids-glyph-names.txt
|
||||
SUBSETS:
|
||||
U+0x0,U+0x8,U+0x9,U+0x1d,U+0x20,U+0xb7
|
||||
*
|
||||
|
||||
# diff with fonttools
|
||||
# fonttools still keeps psNames for those retain-gid holes
|
||||
OPTIONS:
|
||||
no_fonttools
|
||||
@@ -8,3 +8,8 @@ retain-base-table-filter-scripts.txt
|
||||
SUBSETS:
|
||||
abc
|
||||
|
||||
# diff with fonttools
|
||||
# BASE table(fonttools doesn't support BASE table)
|
||||
OPTIONS:
|
||||
no_fonttools
|
||||
|
||||
Reference in new issue
Block a user