diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index 062eea6ff..943acf5ad 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -1274,11 +1274,80 @@ struct ReverseChainSingleSubstFormat1 return_trace (false); } + template + bool serialize_coverage_offset_array (hb_subset_context_t *c, Iterator it) const + { + TRACE_SERIALIZE (this); + auto *out = c->serializer->start_embed> (); + + if (unlikely (!c->serializer->allocate_size (HBUINT16::static_size))) + return_trace (false); + + for (auto& offset : it) { + auto *o = out->serialize_append (c->serializer); + if (unlikely (!o) || !o->serialize_subset (c, offset, this)) + return_trace (false); + } + + return_trace (true); + } + + template + bool serialize (hb_subset_context_t *c, + Iterator coverage_subst_iter, + BacktrackIterator backtrack_iter, + LookaheadIterator lookahead_iter) const + { + TRACE_SERIALIZE (this); + + auto *out = c->serializer->start_embed (this); + if (unlikely (!c->serializer->check_success (out))) return_trace (false); + if (unlikely (!c->serializer->embed (this->format))) return_trace (false); + if (unlikely (!c->serializer->embed (this->coverage))) return_trace (false); + + if (!serialize_coverage_offset_array (c, backtrack_iter)) return_trace (false); + if (!serialize_coverage_offset_array (c, lookahead_iter)) return_trace (false); + + auto *substitute_out = c->serializer->start_embed> (); + auto substitutes = + + coverage_subst_iter + | hb_map (hb_second) + ; + + auto glyphs = + + coverage_subst_iter + | hb_map_retains_sorting (hb_first) + ; + if (unlikely (! c->serializer->check_success (substitute_out->serialize (c->serializer, substitutes)))) + return_trace (false); + + if (unlikely (!out->coverage.serialize (c->serializer, out).serialize (c->serializer, glyphs))) + return_trace (false); + return_trace (true); + } + bool subset (hb_subset_context_t *c) const { TRACE_SUBSET (this); - // TODO(subset) - return_trace (false); + const hb_set_t &glyphset = *c->plan->glyphset_gsub (); + const hb_map_t &glyph_map = *c->plan->glyph_map; + + const OffsetArrayOf &lookahead = StructAfter> (backtrack); + const ArrayOf &substitute = StructAfter> (lookahead); + + auto it = + + hb_zip (this+coverage, substitute) + | hb_filter (glyphset, hb_first) + | hb_filter (glyphset, hb_second) + | hb_map_retains_sorting ([&] (hb_pair_t p) -> hb_codepoint_pair_t + { return hb_pair (glyph_map[p.first], glyph_map[p.second]); }) + ; + + return_trace (bool (it) && serialize (c, it, backtrack.iter (), lookahead.iter ())); } bool sanitize (hb_sanitize_context_t *c) const diff --git a/test/subset/data/Makefile.am b/test/subset/data/Makefile.am index 73585f85c..6239adb8b 100644 --- a/test/subset/data/Makefile.am +++ b/test/subset/data/Makefile.am @@ -25,6 +25,7 @@ EXTRA_DIST += \ expected/layout.gsub3 \ expected/layout.gsub5 \ expected/layout.gsub6 \ + expected/layout.gsub8 \ expected/layout.gdef \ expected/layout.context \ expected/layout.gdef-varstore \ diff --git a/test/subset/data/Makefile.sources b/test/subset/data/Makefile.sources index 6275bfda8..433eeac03 100644 --- a/test/subset/data/Makefile.sources +++ b/test/subset/data/Makefile.sources @@ -24,6 +24,7 @@ TESTS = \ tests/layout.gsub3.tests \ tests/layout.gsub5.tests \ tests/layout.gsub6.tests \ + tests/layout.gsub8.tests \ tests/layout.tests \ tests/sbix.tests \ $(NULL) diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43,44,45,46,47,48,49.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43,44,45,46,47,48,49.otf new file mode 100644 index 000000000..8495a4a16 Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43,44,45,46,47,48,49.otf differ diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43,44,45,46,47.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43,44,45,46,47.otf new file mode 100644 index 000000000..4838600e2 Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43,44,45,46,47.otf differ diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43,44,45,46,4D.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43,44,45,46,4D.otf new file mode 100644 index 000000000..27982fd91 Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43,44,45,46,4D.otf differ diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43,44,45,46,51.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43,44,45,46,51.otf new file mode 100644 index 000000000..87a06c034 Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43,44,45,46,51.otf differ diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43,44,45,46.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43,44,45,46.otf new file mode 100644 index 000000000..eea44642b Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43,44,45,46.otf differ diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43.otf new file mode 100644 index 000000000..89553364d Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41,42,43.otf differ diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41.otf new file mode 100644 index 000000000..1a29bbe47 Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.41.otf differ diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.61.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.61.otf new file mode 100644 index 000000000..eebf28c87 Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.61.otf differ diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.retain-all-codepoint.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.retain-all-codepoint.otf new file mode 100644 index 000000000..aae2b269c Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout-retain-gids.retain-all-codepoint.otf differ diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43,44,45,46,47,48,49.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43,44,45,46,47,48,49.otf new file mode 100644 index 000000000..4e30f4718 Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43,44,45,46,47,48,49.otf differ diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43,44,45,46,47.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43,44,45,46,47.otf new file mode 100644 index 000000000..0f8ef5ac3 Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43,44,45,46,47.otf differ diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43,44,45,46,4D.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43,44,45,46,4D.otf new file mode 100644 index 000000000..7b18952d6 Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43,44,45,46,4D.otf differ diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43,44,45,46,51.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43,44,45,46,51.otf new file mode 100644 index 000000000..f96a05aa8 Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43,44,45,46,51.otf differ diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43,44,45,46.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43,44,45,46.otf new file mode 100644 index 000000000..97dd96d4e Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43,44,45,46.otf differ diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43.otf new file mode 100644 index 000000000..d4783b351 Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41,42,43.otf differ diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41.otf new file mode 100644 index 000000000..b442889e1 Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.41.otf differ diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.61.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.61.otf new file mode 100644 index 000000000..627649815 Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.61.otf differ diff --git a/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.retain-all-codepoint.otf b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.retain-all-codepoint.otf new file mode 100644 index 000000000..aae2b269c Binary files /dev/null and b/test/subset/data/expected/layout.gsub8/gsub8_manually_created.keep-layout.retain-all-codepoint.otf differ diff --git a/test/subset/data/fonts/gsub8_manually_created.otf b/test/subset/data/fonts/gsub8_manually_created.otf new file mode 100644 index 000000000..00cbb4bb3 Binary files /dev/null and b/test/subset/data/fonts/gsub8_manually_created.otf differ diff --git a/test/subset/data/tests/layout.gsub8.tests b/test/subset/data/tests/layout.gsub8.tests new file mode 100644 index 000000000..fdff43f8a --- /dev/null +++ b/test/subset/data/tests/layout.gsub8.tests @@ -0,0 +1,17 @@ +FONTS: +gsub8_manually_created.otf + +PROFILES: +keep-layout.txt +keep-layout-retain-gids.txt + +SUBSETS: +a +A +ABC +ABCDEF +ABCDEFG +ABCDEFGHI +ABCDEFM +ABCDEFQ +* diff --git a/test/subset/meson.build b/test/subset/meson.build index 5da61a9e0..fa04117c2 100644 --- a/test/subset/meson.build +++ b/test/subset/meson.build @@ -17,6 +17,7 @@ tests = [ 'layout.gsub3', 'layout.gsub5', 'layout.gsub6', + 'layout.gsub8', 'layout.gdef', 'layout.context', 'layout.gdef-varstore',