diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 626abc557..513a4a61d 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -3678,55 +3678,57 @@ struct GSUBGPOS const hb_set_t *feature_indices, hb_map_t *duplicate_feature_map /* OUT */) const { + hb_set_t unique_features; + hb_tag_t prev_t = get_feature_tag (feature_indices->get_min ()); //find out duplicate features after subset - unsigned prev = 0xFFFFu; for (unsigned i : feature_indices->iter ()) { - if (prev == 0xFFFFu) - { - duplicate_feature_map->set (i, i); - prev = i; - continue; - } - hb_tag_t t = get_feature_tag (i); - hb_tag_t prev_t = get_feature_tag (prev); if (t != prev_t) { + prev_t = t; + unique_features.clear (); + unique_features.add (i); duplicate_feature_map->set (i, i); - prev = i; continue; } - const Feature& f = get_feature (i); - const Feature& prev_f = get_feature (prev); + bool found = false; - auto f_iter = - + hb_iter (f.lookupIndex) - | hb_filter (lookup_indices) - ; - - auto prev_iter = - + hb_iter (prev_f.lookupIndex) - | hb_filter (lookup_indices) - ; - - if (f_iter.len () != prev_iter.len ()) + for (unsigned other_f_index : unique_features.iter ()) { - duplicate_feature_map->set (i, i); - prev = i; - continue; + const Feature& f = get_feature (i); + const Feature& other_f = get_feature (other_f_index); + + auto f_iter = + + hb_iter (f.lookupIndex) + | hb_filter (lookup_indices) + ; + + auto other_f_iter = + + hb_iter (other_f.lookupIndex) + | hb_filter (lookup_indices) + ; + + bool is_equal = true; + for (; f_iter && other_f_iter; f_iter++, other_f_iter++) + { + unsigned a = *f_iter; + unsigned b = *other_f_iter; + if (a != b) { is_equal = false; break; } + } + + if (is_equal == false || f_iter || other_f_iter) continue; + + found = true; + duplicate_feature_map->set (i, other_f_index); + break; } - - bool is_equal = true; - for (auto _ : + hb_zip (f_iter, prev_iter)) - if (_.first != _.second) { is_equal = false; break; } - - if (is_equal == true) duplicate_feature_map->set (i, prev); - else + + if (found == false) { + unique_features.add (i); duplicate_feature_map->set (i, i); - prev = i; } } } diff --git a/test/subset/data/Makefile.am b/test/subset/data/Makefile.am index d7b05f4ce..3f521fb79 100644 --- a/test/subset/data/Makefile.am +++ b/test/subset/data/Makefile.am @@ -35,6 +35,7 @@ EXTRA_DIST += \ expected/layout.gdef-attachlist \ expected/layout.notonastaliqurdu \ expected/layout.tinos \ + expected/layout.duplicate_features \ expected/cmap \ expected/cmap14 \ expected/sbix \ diff --git a/test/subset/data/Makefile.sources b/test/subset/data/Makefile.sources index 74b70799d..ad9458912 100644 --- a/test/subset/data/Makefile.sources +++ b/test/subset/data/Makefile.sources @@ -32,6 +32,7 @@ TESTS = \ tests/layout.notonastaliqurdu.tests \ tests/layout.tests \ tests/layout.tinos.tests \ + tests/layout.duplicate_features.tests \ tests/sbix.tests \ tests/variable.tests \ tests/glyph_names.tests \ diff --git a/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.default.20,2f,38,49,4c,51,53,66,67,6f,b4,2044.ttf b/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.default.20,2f,38,49,4c,51,53,66,67,6f,b4,2044.ttf new file mode 100644 index 000000000..d53abcbd8 Binary files /dev/null and b/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.default.20,2f,38,49,4c,51,53,66,67,6f,b4,2044.ttf differ diff --git a/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.default.retain-all-codepoint.ttf b/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.default.retain-all-codepoint.ttf new file mode 100644 index 000000000..4f27a6ca9 Binary files /dev/null and b/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.default.retain-all-codepoint.ttf differ diff --git a/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.glyph-names.20,2f,38,49,4c,51,53,66,67,6f,b4,2044.ttf b/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.glyph-names.20,2f,38,49,4c,51,53,66,67,6f,b4,2044.ttf new file mode 100644 index 000000000..f3ca7d8df Binary files /dev/null and b/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.glyph-names.20,2f,38,49,4c,51,53,66,67,6f,b4,2044.ttf differ diff --git a/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.glyph-names.retain-all-codepoint.ttf b/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.glyph-names.retain-all-codepoint.ttf new file mode 100644 index 000000000..69e63eace Binary files /dev/null and b/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.glyph-names.retain-all-codepoint.ttf differ diff --git a/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.notdef-outline.20,2f,38,49,4c,51,53,66,67,6f,b4,2044.ttf b/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.notdef-outline.20,2f,38,49,4c,51,53,66,67,6f,b4,2044.ttf new file mode 100644 index 000000000..d53abcbd8 Binary files /dev/null and b/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.notdef-outline.20,2f,38,49,4c,51,53,66,67,6f,b4,2044.ttf differ diff --git a/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.notdef-outline.retain-all-codepoint.ttf b/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.notdef-outline.retain-all-codepoint.ttf new file mode 100644 index 000000000..4f27a6ca9 Binary files /dev/null and b/test/subset/data/expected/layout.duplicate_features/AlegreyaSans-BlackItalic.notdef-outline.retain-all-codepoint.ttf differ diff --git a/test/subset/data/fonts/AlegreyaSans-BlackItalic.ttf b/test/subset/data/fonts/AlegreyaSans-BlackItalic.ttf new file mode 100644 index 000000000..76a389d8e Binary files /dev/null and b/test/subset/data/fonts/AlegreyaSans-BlackItalic.ttf differ diff --git a/test/subset/data/tests/layout.duplicate_features.tests b/test/subset/data/tests/layout.duplicate_features.tests new file mode 100644 index 000000000..d6bc9a289 --- /dev/null +++ b/test/subset/data/tests/layout.duplicate_features.tests @@ -0,0 +1,11 @@ +FONTS: +AlegreyaSans-BlackItalic.ttf + +PROFILES: +default.txt +glyph-names.txt +notdef-outline.txt + +SUBSETS: +U+20,U+2f,U+38,U+49,U+4c,U+51,U+53,U+66,U+67,U+6f,U+b4,U+2044 +* diff --git a/test/subset/meson.build b/test/subset/meson.build index 4ed2fdd7f..083ab09ea 100644 --- a/test/subset/meson.build +++ b/test/subset/meson.build @@ -27,6 +27,7 @@ tests = [ 'layout.gdef-attachlist', 'layout.notonastaliqurdu', 'layout.tinos', + 'layout.duplicate_features', 'cmap', 'cmap14', 'sbix',