From b1c0b9da2ff105d3476fed411e1d7010decb394e Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Thu, 2 Apr 2020 14:39:13 +0100 Subject: [PATCH] [AAT] Don't map OT tags to AAT feature types that are not exposed. If an AAT feature type is not exposed in the 'feat' table, we assume it is not intended to be user-controllable and so we should not map any OT feature tag requests to it. Fixes #2285. --- src/hb-aat-layout-feat-table.hh | 6 ++++++ src/hb-aat-map.cc | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/hb-aat-layout-feat-table.hh b/src/hb-aat-layout-feat-table.hh index 8de7873e4..14f91bf9a 100644 --- a/src/hb-aat-layout-feat-table.hh +++ b/src/hb-aat-layout-feat-table.hh @@ -129,6 +129,9 @@ struct FeatureName hb_ot_name_id_t get_feature_name_id () const { return nameIndex; } + /* A FeatureName with no settings is meaningless */ + bool has_data () const { return nSettings > 0; } + bool sanitize (hb_sanitize_context_t *c, const void *base) const { TRACE_SANITIZE (this); @@ -172,6 +175,9 @@ struct feat return featureNameCount; } + bool exposes_feature (hb_aat_layout_feature_type_t feature_type) const + { return get_feature (feature_type).has_data (); } + const FeatureName& get_feature (hb_aat_layout_feature_type_t feature_type) const { return namesZ.bsearch (featureNameCount, feature_type); } diff --git a/src/hb-aat-map.cc b/src/hb-aat-map.cc index bc879359a..fc1dcbd2d 100644 --- a/src/hb-aat-map.cc +++ b/src/hb-aat-map.cc @@ -33,13 +33,19 @@ #include "hb-aat-map.hh" #include "hb-aat-layout.hh" +#include "hb-aat-layout-feat-table.hh" void hb_aat_map_builder_t::add_feature (hb_tag_t tag, unsigned int value) { + hb_blob_t *feat_blob = face->table.feat.get_blob (); + const AAT::feat& feat = *feat_blob->as (); + if (!feat.has_data ()) return; + if (tag == HB_TAG ('a','a','l','t')) { + if (!feat.exposes_feature (HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_ALTERNATIVES)) return; feature_info_t *info = features.push(); info->type = HB_AAT_LAYOUT_FEATURE_TYPE_CHARACTER_ALTERNATIVES; info->setting = (hb_aat_layout_feature_selector_t) value; @@ -48,6 +54,7 @@ void hb_aat_map_builder_t::add_feature (hb_tag_t tag, const hb_aat_feature_mapping_t *mapping = hb_aat_layout_find_feature_mapping (tag); if (!mapping) return; + if (!feat.exposes_feature (mapping->aatFeatureType)) return; feature_info_t *info = features.push(); info->type = mapping->aatFeatureType;