From 1348a2c865d368a4f6e83add0edfa9945d84914f Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Tue, 16 Jun 2020 21:05:16 -0400 Subject: [PATCH 01/16] [layout] hb_ot_layout_lookup_get_alternates, a new API An API to retrieve one-to-one alternates from a given GSUB lookup index. --- docs/harfbuzz-sections.txt | 1 + src/hb-ot-layout-gsub-table.hh | 30 +++++++++++++++++++ src/hb-ot-layout.cc | 37 ++++++++++++++++++++++++ src/hb-ot-layout.h | 7 +++++ test/api/Makefile.am | 1 + test/api/meson.build | 1 + test/api/test-ot-alternates.c | 53 ++++++++++++++++++++++++++++++++++ 7 files changed, 130 insertions(+) create mode 100644 test/api/test-ot-alternates.c diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index 38b357dd1..ae3038ffa 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -574,6 +574,7 @@ hb_ot_layout_language_get_feature_indexes hb_ot_layout_language_get_feature_tags hb_ot_layout_language_get_required_feature hb_ot_layout_lookup_collect_glyphs +hb_ot_layout_lookup_get_alternates hb_ot_layout_lookup_substitute_closure hb_ot_layout_lookups_substitute_closure hb_ot_layout_lookup_would_substitute diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index fdddca545..b7f5f6446 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -522,6 +522,8 @@ struct MultipleSubst struct AlternateSet { + friend struct AlternateSubstFormat1; + bool intersects (const hb_set_t *glyphs) const { return hb_any (alternates, glyphs); } @@ -628,6 +630,14 @@ struct AlternateSubstFormat1 bool would_apply (hb_would_apply_context_t *c) const { return c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED; } + const ArrayOf &get_alternates (hb_codepoint_t gid) const + { + unsigned index = (this+coverage).get_coverage (gid); + if (index == NOT_COVERED) return Null (ArrayOf); + + return (this+alternateSet[index]).alternates; + } + bool apply (hb_ot_apply_context_t *c) const { TRACE_APPLY (this); @@ -715,6 +725,14 @@ struct AlternateSubst } } + const ArrayOf &get_alternates (hb_codepoint_t gid) const + { + switch (u.format) { + case 1: return u.format1.get_alternates (gid); + default:return Null (ArrayOf); + } + } + template typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const { @@ -1463,6 +1481,18 @@ struct SubstLookup : Lookup substitute_glyphs_list)); } + const ArrayOf &get_alternates (hb_codepoint_t gid) const + { + if (get_type () != SubTable::Alternate) return Null (ArrayOf); + unsigned size = get_subtable_count (); + for (unsigned i = 0; i < size; ++i) + { + const ArrayOf &alternates = get_subtable (i).u.alternate.get_alternates (gid); + if (alternates.len) return alternates; + } + return Null (ArrayOf); + } + bool serialize_alternate (hb_serialize_context_t *c, uint32_t lookup_props, hb_sorted_array_t glyphs, diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 48f4a9315..972d71647 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1969,4 +1969,41 @@ hb_ot_layout_get_baseline (hb_font_t *font, return result; } #endif + +/** + * hb_ot_layout_lookup_get_alternates: + * @face: a face. + * @lookup_index: index of the feature lookup to query. + * @glyph: a glyph id. + * @start_offset: starting offset. + * @alternate_count: (inout) (allow-none): Input = the maximum number of alternate glyphs to return; + * Output = the actual number of alternate glyphs returned (may be zero). + * @alternate_glyphs: (out caller-allocates) (array length=alternate_count): A glyphs buffer. + * Alternate glyphs associated with the glyph id. + * + * Fetches alternates of a glyph from a given GSUB lookup index. + * + * Return value: total number of alternates found in the specific lookup index for the given glyph id. + * + * Since: REPLACEME + **/ +HB_EXTERN unsigned +hb_ot_layout_lookup_get_alternates (hb_face_t *face, + unsigned lookup_index, + hb_codepoint_t glyph, + unsigned start_offset, + unsigned *alternate_count /* IN/OUT */, + hb_codepoint_t *alternate_glyphs) +{ + const OT::SubstLookup &lookup = face->table.GSUB->table->get_lookup (lookup_index); + const OT::ArrayOf &alternates = lookup.get_alternates (glyph); + if (alternate_count) + { + + alternates.sub_array (start_offset, alternate_count) + | hb_sink (hb_array (alternate_glyphs, *alternate_count)) + ; + } + return alternates.len; +} + #endif diff --git a/src/hb-ot-layout.h b/src/hb-ot-layout.h index 363dea89c..fedf32e1e 100644 --- a/src/hb-ot-layout.h +++ b/src/hb-ot-layout.h @@ -449,6 +449,13 @@ hb_ot_layout_get_baseline (hb_font_t *font, hb_tag_t language_tag, hb_position_t *coord /* OUT. May be NULL. */); +HB_EXTERN unsigned +hb_ot_layout_lookup_get_alternates (hb_face_t *face, + unsigned lookup_index, + hb_codepoint_t glyph, + unsigned start_offset, + unsigned *alternate_count /* IN/OUT */, + hb_codepoint_t *alternate_glyphs); HB_END_DECLS diff --git a/test/api/Makefile.am b/test/api/Makefile.am index 01e12c570..bf29d2200 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -40,6 +40,7 @@ TEST_PROGS = \ test-font \ test-map \ test-object \ + test-ot-alternates \ test-ot-color \ test-ot-face \ test-ot-glyphname \ diff --git a/test/api/meson.build b/test/api/meson.build index e824a6c6f..7c9862592 100644 --- a/test/api/meson.build +++ b/test/api/meson.build @@ -16,6 +16,7 @@ tests = [ 'test-font.c', 'test-map.c', 'test-object.c', + 'test-ot-alternates.c', 'test-ot-color.c', 'test-ot-face.c', 'test-ot-glyphname.c', diff --git a/test/api/test-ot-alternates.c b/test/api/test-ot-alternates.c new file mode 100644 index 000000000..f91acecc1 --- /dev/null +++ b/test/api/test-ot-alternates.c @@ -0,0 +1,53 @@ +/* + * Copyright © 2020 Ebrahim Byagowi + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + */ + +#include "hb-test.h" + +#include +#include + +static void +test_ot_layout_lookup_get_alternates (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/SourceSansPro-Regular.otf"); + + hb_codepoint_t alternates[3]; + unsigned alternates_count = 3; + g_assert_cmpuint (7, ==, hb_ot_layout_lookup_get_alternates (face, 1, 1091, 2, &alternates_count, alternates)); + + g_assert_cmpuint (3, ==, alternates_count); + g_assert_cmpuint (1606, ==, alternates[0]); + g_assert_cmpuint (1578, ==, alternates[1]); + g_assert_cmpuint (1592, ==, alternates[2]); + + hb_face_destroy (face); +} + +int +main (int argc, char **argv) +{ + hb_test_init (&argc, &argv); + hb_test_add (test_ot_layout_lookup_get_alternates); + return hb_test_run (); +} From d3c169792ba4771b459c37a4430fab6f2dcbda5e Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Thu, 18 Jun 2020 08:37:21 +0430 Subject: [PATCH 02/16] [layout] move alternate buffer iteration logic to AlternateSet --- src/hb-ot-layout-gsub-table.hh | 72 +++++++++++++++++++++++++--------- src/hb-ot-layout.cc | 13 ++---- 2 files changed, 57 insertions(+), 28 deletions(-) diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index b7f5f6446..688330856 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -522,8 +522,6 @@ struct MultipleSubst struct AlternateSet { - friend struct AlternateSubstFormat1; - bool intersects (const hb_set_t *glyphs) const { return hb_any (alternates, glyphs); } @@ -558,6 +556,20 @@ struct AlternateSet return_trace (true); } + unsigned + get_alternates (unsigned start_offset, + unsigned *alternate_count /* IN/OUT. May be NULL. */, + hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const + { + if (alternate_count) + { + + alternates.sub_array (start_offset, alternate_count) + | hb_sink (hb_array (alternate_glyphs, *alternate_count)) + ; + } + return alternates.len; + } + template bool serialize (hb_serialize_context_t *c, @@ -630,13 +642,15 @@ struct AlternateSubstFormat1 bool would_apply (hb_would_apply_context_t *c) const { return c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED; } - const ArrayOf &get_alternates (hb_codepoint_t gid) const - { - unsigned index = (this+coverage).get_coverage (gid); - if (index == NOT_COVERED) return Null (ArrayOf); + unsigned get_coverage_index (hb_codepoint_t gid) const + { return (this+coverage).get_coverage (gid); } - return (this+alternateSet[index]).alternates; - } + unsigned + get_alternates (unsigned index, + unsigned start_offset, + unsigned *alternate_count /* IN/OUT. May be NULL. */, + hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const + { return (this+alternateSet[index]).get_alternates (start_offset, alternate_count, alternate_glyphs); } bool apply (hb_ot_apply_context_t *c) const { @@ -725,11 +739,24 @@ struct AlternateSubst } } - const ArrayOf &get_alternates (hb_codepoint_t gid) const + unsigned + get_coverage_index (hb_codepoint_t gid) const { switch (u.format) { - case 1: return u.format1.get_alternates (gid); - default:return Null (ArrayOf); + case 1: return u.format1.get_coverage_index (gid); + default:return NOT_COVERED; + } + } + + unsigned + get_alternates (unsigned index, + unsigned start_offset, + unsigned *alternate_count /* IN/OUT. May be NULL. */, + hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const + { + switch (u.format) { + case 1: return u.format1.get_alternates (index, start_offset, alternate_count, alternate_glyphs); + default:assert (0); return 0; } } @@ -1481,16 +1508,25 @@ struct SubstLookup : Lookup substitute_glyphs_list)); } - const ArrayOf &get_alternates (hb_codepoint_t gid) const + unsigned + get_alternates (hb_codepoint_t gid, + unsigned start_offset, + unsigned *alternate_count /* IN/OUT. May be NULL. */, + hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const { - if (get_type () != SubTable::Alternate) return Null (ArrayOf); - unsigned size = get_subtable_count (); - for (unsigned i = 0; i < size; ++i) + if (get_type () == SubTable::Alternate) { - const ArrayOf &alternates = get_subtable (i).u.alternate.get_alternates (gid); - if (alternates.len) return alternates; + unsigned size = get_subtable_count (); + for (unsigned i = 0; i < size; ++i) + { + const AlternateSubst &alternate_subtable = get_subtable (i).u.alternate; + unsigned index = alternate_subtable.get_coverage_index (gid); + if (index != NOT_COVERED) + return alternate_subtable.get_alternates (index, start_offset, alternate_count, alternate_glyphs); + } } - return Null (ArrayOf); + if (alternate_count) *alternate_count = 0; + return 0; } bool serialize_alternate (hb_serialize_context_t *c, diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 972d71647..c58b667af 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1992,18 +1992,11 @@ hb_ot_layout_lookup_get_alternates (hb_face_t *face, unsigned lookup_index, hb_codepoint_t glyph, unsigned start_offset, - unsigned *alternate_count /* IN/OUT */, - hb_codepoint_t *alternate_glyphs) + unsigned *alternate_count /* IN/OUT. May be NULL. */, + hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) { const OT::SubstLookup &lookup = face->table.GSUB->table->get_lookup (lookup_index); - const OT::ArrayOf &alternates = lookup.get_alternates (glyph); - if (alternate_count) - { - + alternates.sub_array (start_offset, alternate_count) - | hb_sink (hb_array (alternate_glyphs, *alternate_count)) - ; - } - return alternates.len; + return lookup.get_alternates (glyph, start_offset, alternate_count, alternate_glyphs); } #endif From 1bac85828c134835ce0a3ecd517aefdcecf43d9a Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Thu, 18 Jun 2020 22:56:07 +0430 Subject: [PATCH 03/16] [layout] Rename _get_alternates to _get_glyph_alternates --- docs/harfbuzz-sections.txt | 2 +- src/hb-ot-layout-gsub-table.hh | 36 +++++++++++++++++----------------- src/hb-ot-layout.cc | 16 +++++++-------- src/hb-ot-layout.h | 12 ++++++------ test/api/test-ot-alternates.c | 6 +++--- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/docs/harfbuzz-sections.txt b/docs/harfbuzz-sections.txt index ae3038ffa..fe9b89c05 100644 --- a/docs/harfbuzz-sections.txt +++ b/docs/harfbuzz-sections.txt @@ -574,7 +574,7 @@ hb_ot_layout_language_get_feature_indexes hb_ot_layout_language_get_feature_tags hb_ot_layout_language_get_required_feature hb_ot_layout_lookup_collect_glyphs -hb_ot_layout_lookup_get_alternates +hb_ot_layout_lookup_get_glyph_alternates hb_ot_layout_lookup_substitute_closure hb_ot_layout_lookups_substitute_closure hb_ot_layout_lookup_would_substitute diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index 688330856..f37676c28 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -557,9 +557,9 @@ struct AlternateSet } unsigned - get_alternates (unsigned start_offset, - unsigned *alternate_count /* IN/OUT. May be NULL. */, - hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const + get_glyph_alternates (unsigned start_offset, + unsigned *alternate_count /* IN/OUT. May be NULL. */, + hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const { if (alternate_count) { @@ -646,11 +646,11 @@ struct AlternateSubstFormat1 { return (this+coverage).get_coverage (gid); } unsigned - get_alternates (unsigned index, - unsigned start_offset, - unsigned *alternate_count /* IN/OUT. May be NULL. */, - hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const - { return (this+alternateSet[index]).get_alternates (start_offset, alternate_count, alternate_glyphs); } + get_glyph_alternates (unsigned index, + unsigned start_offset, + unsigned *alternate_count /* IN/OUT. May be NULL. */, + hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const + { return (this+alternateSet[index]).get_glyph_alternates (start_offset, alternate_count, alternate_glyphs); } bool apply (hb_ot_apply_context_t *c) const { @@ -749,13 +749,13 @@ struct AlternateSubst } unsigned - get_alternates (unsigned index, - unsigned start_offset, - unsigned *alternate_count /* IN/OUT. May be NULL. */, - hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const + get_glyph_alternates (unsigned index, + unsigned start_offset, + unsigned *alternate_count /* IN/OUT. May be NULL. */, + hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const { switch (u.format) { - case 1: return u.format1.get_alternates (index, start_offset, alternate_count, alternate_glyphs); + case 1: return u.format1.get_glyph_alternates (index, start_offset, alternate_count, alternate_glyphs); default:assert (0); return 0; } } @@ -1509,10 +1509,10 @@ struct SubstLookup : Lookup } unsigned - get_alternates (hb_codepoint_t gid, - unsigned start_offset, - unsigned *alternate_count /* IN/OUT. May be NULL. */, - hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const + get_glyph_alternates (hb_codepoint_t gid, + unsigned start_offset, + unsigned *alternate_count /* IN/OUT. May be NULL. */, + hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const { if (get_type () == SubTable::Alternate) { @@ -1522,7 +1522,7 @@ struct SubstLookup : Lookup const AlternateSubst &alternate_subtable = get_subtable (i).u.alternate; unsigned index = alternate_subtable.get_coverage_index (gid); if (index != NOT_COVERED) - return alternate_subtable.get_alternates (index, start_offset, alternate_count, alternate_glyphs); + return alternate_subtable.get_glyph_alternates (index, start_offset, alternate_count, alternate_glyphs); } } if (alternate_count) *alternate_count = 0; diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index c58b667af..82d6f0c8a 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1971,7 +1971,7 @@ hb_ot_layout_get_baseline (hb_font_t *font, #endif /** - * hb_ot_layout_lookup_get_alternates: + * hb_ot_layout_lookup_get_glyph_alternates: * @face: a face. * @lookup_index: index of the feature lookup to query. * @glyph: a glyph id. @@ -1988,15 +1988,15 @@ hb_ot_layout_get_baseline (hb_font_t *font, * Since: REPLACEME **/ HB_EXTERN unsigned -hb_ot_layout_lookup_get_alternates (hb_face_t *face, - unsigned lookup_index, - hb_codepoint_t glyph, - unsigned start_offset, - unsigned *alternate_count /* IN/OUT. May be NULL. */, - hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) +hb_ot_layout_lookup_get_glyph_alternates (hb_face_t *face, + unsigned lookup_index, + hb_codepoint_t glyph, + unsigned start_offset, + unsigned *alternate_count /* IN/OUT. May be NULL. */, + hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) { const OT::SubstLookup &lookup = face->table.GSUB->table->get_lookup (lookup_index); - return lookup.get_alternates (glyph, start_offset, alternate_count, alternate_glyphs); + return lookup.get_glyph_alternates (glyph, start_offset, alternate_count, alternate_glyphs); } #endif diff --git a/src/hb-ot-layout.h b/src/hb-ot-layout.h index fedf32e1e..b23fbf4e1 100644 --- a/src/hb-ot-layout.h +++ b/src/hb-ot-layout.h @@ -450,12 +450,12 @@ hb_ot_layout_get_baseline (hb_font_t *font, hb_position_t *coord /* OUT. May be NULL. */); HB_EXTERN unsigned -hb_ot_layout_lookup_get_alternates (hb_face_t *face, - unsigned lookup_index, - hb_codepoint_t glyph, - unsigned start_offset, - unsigned *alternate_count /* IN/OUT */, - hb_codepoint_t *alternate_glyphs); +hb_ot_layout_lookup_get_glyph_alternates (hb_face_t *face, + unsigned lookup_index, + hb_codepoint_t glyph, + unsigned start_offset, + unsigned *alternate_count /* IN/OUT */, + hb_codepoint_t *alternate_glyphs); HB_END_DECLS diff --git a/test/api/test-ot-alternates.c b/test/api/test-ot-alternates.c index f91acecc1..4db6b1558 100644 --- a/test/api/test-ot-alternates.c +++ b/test/api/test-ot-alternates.c @@ -28,13 +28,13 @@ #include static void -test_ot_layout_lookup_get_alternates (void) +test_ot_layout_lookup_get_glyph_alternates (void) { hb_face_t *face = hb_test_open_font_file ("fonts/SourceSansPro-Regular.otf"); hb_codepoint_t alternates[3]; unsigned alternates_count = 3; - g_assert_cmpuint (7, ==, hb_ot_layout_lookup_get_alternates (face, 1, 1091, 2, &alternates_count, alternates)); + g_assert_cmpuint (7, ==, hb_ot_layout_lookup_get_glyph_alternates (face, 1, 1091, 2, &alternates_count, alternates)); g_assert_cmpuint (3, ==, alternates_count); g_assert_cmpuint (1606, ==, alternates[0]); @@ -48,6 +48,6 @@ int main (int argc, char **argv) { hb_test_init (&argc, &argv); - hb_test_add (test_ot_layout_lookup_get_alternates); + hb_test_add (test_ot_layout_lookup_get_glyph_alternates); return hb_test_run (); } From 26514ad70e4e96b862ff6bd63fb2a03e136e7620 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 18 Jun 2020 15:22:07 -0700 Subject: [PATCH 04/16] Fix API comment --- src/hb-ot-layout.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-ot-layout.h b/src/hb-ot-layout.h index b23fbf4e1..95dffe57a 100644 --- a/src/hb-ot-layout.h +++ b/src/hb-ot-layout.h @@ -455,7 +455,7 @@ hb_ot_layout_lookup_get_glyph_alternates (hb_face_t *face, hb_codepoint_t glyph, unsigned start_offset, unsigned *alternate_count /* IN/OUT */, - hb_codepoint_t *alternate_glyphs); + hb_codepoint_t *alternate_glyphs /* OUT */); HB_END_DECLS From e13aaaaa4566c8aa1a790402b38448713c6621ab Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 18 Jun 2020 15:22:54 -0700 Subject: [PATCH 05/16] Move API to right place in header --- src/hb-ot-layout.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/hb-ot-layout.h b/src/hb-ot-layout.h index 95dffe57a..545d5f7fc 100644 --- a/src/hb-ot-layout.h +++ b/src/hb-ot-layout.h @@ -323,6 +323,14 @@ hb_ot_layout_feature_with_variations_get_lookups (hb_face_t *face, HB_EXTERN hb_bool_t hb_ot_layout_has_substitution (hb_face_t *face); +HB_EXTERN unsigned +hb_ot_layout_lookup_get_glyph_alternates (hb_face_t *face, + unsigned lookup_index, + hb_codepoint_t glyph, + unsigned start_offset, + unsigned *alternate_count /* IN/OUT */, + hb_codepoint_t *alternate_glyphs /* OUT */); + HB_EXTERN hb_bool_t hb_ot_layout_lookup_would_substitute (hb_face_t *face, unsigned int lookup_index, @@ -449,14 +457,6 @@ hb_ot_layout_get_baseline (hb_font_t *font, hb_tag_t language_tag, hb_position_t *coord /* OUT. May be NULL. */); -HB_EXTERN unsigned -hb_ot_layout_lookup_get_glyph_alternates (hb_face_t *face, - unsigned lookup_index, - hb_codepoint_t glyph, - unsigned start_offset, - unsigned *alternate_count /* IN/OUT */, - hb_codepoint_t *alternate_glyphs /* OUT */); - HB_END_DECLS #endif /* HB_OT_LAYOUT_H */ From 5bede33885a5349c05e0724e8ee6948af8a25670 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 18 Jun 2020 15:25:19 -0700 Subject: [PATCH 06/16] Whitespace --- src/hb-ot-layout.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 82d6f0c8a..01587f1df 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1362,7 +1362,6 @@ hb_ot_layout_lookup_would_substitute (hb_face_t *face, OT::hb_would_apply_context_t c (face, glyphs, glyphs_length, (bool) zero_context); const OT::SubstLookup& l = face->table.GSUB->table->get_lookup (lookup_index); - return l.would_apply (&c, &face->table.GSUB->accels[lookup_index]); } @@ -1380,7 +1379,7 @@ void hb_ot_layout_substitute_start (hb_font_t *font, hb_buffer_t *buffer) { -_hb_ot_layout_set_glyph_props (font, buffer); + _hb_ot_layout_set_glyph_props (font, buffer); } void From bedf4171218ef7c64386aa492b574356277fc21f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 18 Jun 2020 15:49:01 -0700 Subject: [PATCH 07/16] Push get_glyph_alternates() work all the way down --- src/hb-ot-layout-gsub-table.hh | 36 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index f37676c28..641bf6182 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -557,11 +557,11 @@ struct AlternateSet } unsigned - get_glyph_alternates (unsigned start_offset, - unsigned *alternate_count /* IN/OUT. May be NULL. */, - hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const + get_alternates (unsigned start_offset, + unsigned *alternate_count /* IN/OUT. May be NULL. */, + hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const { - if (alternate_count) + if (alternates.len && alternate_count) { + alternates.sub_array (start_offset, alternate_count) | hb_sink (hb_array (alternate_glyphs, *alternate_count)) @@ -642,15 +642,13 @@ struct AlternateSubstFormat1 bool would_apply (hb_would_apply_context_t *c) const { return c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED; } - unsigned get_coverage_index (hb_codepoint_t gid) const - { return (this+coverage).get_coverage (gid); } - unsigned - get_glyph_alternates (unsigned index, + get_glyph_alternates (hb_codepoint_t gid, unsigned start_offset, unsigned *alternate_count /* IN/OUT. May be NULL. */, hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const - { return (this+alternateSet[index]).get_glyph_alternates (start_offset, alternate_count, alternate_glyphs); } + { return (this+alternateSet[(this+coverage).get_coverage (gid)]) + .get_alternates (start_offset, alternate_count, alternate_glyphs); } bool apply (hb_ot_apply_context_t *c) const { @@ -740,22 +738,13 @@ struct AlternateSubst } unsigned - get_coverage_index (hb_codepoint_t gid) const - { - switch (u.format) { - case 1: return u.format1.get_coverage_index (gid); - default:return NOT_COVERED; - } - } - - unsigned - get_glyph_alternates (unsigned index, + get_glyph_alternates (hb_codepoint_t gid, unsigned start_offset, unsigned *alternate_count /* IN/OUT. May be NULL. */, hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const { switch (u.format) { - case 1: return u.format1.get_glyph_alternates (index, start_offset, alternate_count, alternate_glyphs); + case 1: return u.format1.get_glyph_alternates (gid, start_offset, alternate_count, alternate_glyphs); default:assert (0); return 0; } } @@ -1519,10 +1508,9 @@ struct SubstLookup : Lookup unsigned size = get_subtable_count (); for (unsigned i = 0; i < size; ++i) { - const AlternateSubst &alternate_subtable = get_subtable (i).u.alternate; - unsigned index = alternate_subtable.get_coverage_index (gid); - if (index != NOT_COVERED) - return alternate_subtable.get_glyph_alternates (index, start_offset, alternate_count, alternate_glyphs); + const AlternateSubst &subtable = get_subtable (i).u.alternate; + auto ret = subtable.get_glyph_alternates (gid, start_offset, alternate_count, alternate_glyphs); + if (ret) return (ret); } } if (alternate_count) *alternate_count = 0; From ffe8d3f39d5a742e51f87b5af66a2a7e63c87037 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 18 Jun 2020 16:31:39 -0700 Subject: [PATCH 08/16] Use dispatch for get_glyph_alternates_t First time we do this in a way that if target object doesn't have the matching function we basically "ignore". Risky but I feel like is the right decision for this case. I'm going to put back the template varargs and use those, which would make the dispatcher be just that: "dispatcher", and wouldn't need to carry the call context. That would be a refreshing change I think. --- src/hb-ot-layout-gsub-table.hh | 41 +++------------------------------- src/hb-ot-layout-gsubgpos.hh | 39 ++++++++++++++++++++++++++++++++ src/hb-ot-layout.cc | 5 ++++- 3 files changed, 46 insertions(+), 39 deletions(-) diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index 641bf6182..11c9bf19e 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -643,12 +643,9 @@ struct AlternateSubstFormat1 { return c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED; } unsigned - get_glyph_alternates (hb_codepoint_t gid, - unsigned start_offset, - unsigned *alternate_count /* IN/OUT. May be NULL. */, - hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const - { return (this+alternateSet[(this+coverage).get_coverage (gid)]) - .get_alternates (start_offset, alternate_count, alternate_glyphs); } + get_glyph_alternates (hb_get_glyph_alternates_context_t *c) const + { return (this+alternateSet[(this+coverage).get_coverage (c->gid)]) + .get_alternates (c->start_offset, c->alternate_count, c->alternate_glyphs); } bool apply (hb_ot_apply_context_t *c) const { @@ -737,18 +734,6 @@ struct AlternateSubst } } - unsigned - get_glyph_alternates (hb_codepoint_t gid, - unsigned start_offset, - unsigned *alternate_count /* IN/OUT. May be NULL. */, - hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const - { - switch (u.format) { - case 1: return u.format1.get_glyph_alternates (gid, start_offset, alternate_count, alternate_glyphs); - default:assert (0); return 0; - } - } - template typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const { @@ -1497,26 +1482,6 @@ struct SubstLookup : Lookup substitute_glyphs_list)); } - unsigned - get_glyph_alternates (hb_codepoint_t gid, - unsigned start_offset, - unsigned *alternate_count /* IN/OUT. May be NULL. */, - hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const - { - if (get_type () == SubTable::Alternate) - { - unsigned size = get_subtable_count (); - for (unsigned i = 0; i < size; ++i) - { - const AlternateSubst &subtable = get_subtable (i).u.alternate; - auto ret = subtable.get_glyph_alternates (gid, start_offset, alternate_count, alternate_glyphs); - if (ret) return (ret); - } - } - if (alternate_count) *alternate_count = 0; - return 0; - } - bool serialize_alternate (hb_serialize_context_t *c, uint32_t lookup_props, hb_sorted_array_t glyphs, diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 0026f83a5..75ef76a4b 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -227,6 +227,45 @@ struct hb_would_apply_context_t : debug_depth (0) {} }; +struct hb_get_glyph_alternates_context_t : + hb_dispatch_context_t +{ + const char *get_name () { return "GET_GLYPH_ALTERNATES"; } + static return_t default_return_value () { return 0; } + bool stop_sublookup_iteration (return_t r) const { return r; } + + hb_face_t *face; + hb_codepoint_t gid; + unsigned start_offset; + unsigned *alternate_count; + hb_codepoint_t *alternate_glyphs; + unsigned int debug_depth; + + hb_get_glyph_alternates_context_t (hb_face_t *face_, + hb_codepoint_t gid_, + unsigned start_offset_, + unsigned *alternate_count_, + hb_codepoint_t *alternate_glyphs_) : + face (face_), + gid (gid_), + start_offset (start_offset_), + alternate_count (alternate_count_), + alternate_glyphs (alternate_glyphs_), + debug_depth (0) {} + + private: + template auto + _dispatch (const T &obj, hb_priority<1>) HB_AUTO_RETURN + ( obj.get_glyph_alternates (this) ) + template auto + _dispatch (const T &obj, hb_priority<0>) HB_AUTO_RETURN + ( default_return_value () ) + public: + template auto + dispatch (const T &obj) HB_AUTO_RETURN + ( _dispatch (obj, hb_prioritize) ) +}; + struct hb_collect_glyphs_context_t : hb_dispatch_context_t diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 01587f1df..c042ce9cc 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1994,8 +1994,11 @@ hb_ot_layout_lookup_get_glyph_alternates (hb_face_t *face, unsigned *alternate_count /* IN/OUT. May be NULL. */, hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) { + OT::hb_get_glyph_alternates_context_t c (face, glyph, start_offset, alternate_count, alternate_glyphs); const OT::SubstLookup &lookup = face->table.GSUB->table->get_lookup (lookup_index); - return lookup.get_glyph_alternates (glyph, start_offset, alternate_count, alternate_glyphs); + auto ret = lookup.dispatch (&c); + if (!ret && alternate_count) *alternate_count = 0; + return ret; } #endif From b2a1acccd9776beddb25fb4f9e24ca6e272958f4 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 18 Jun 2020 16:41:31 -0700 Subject: [PATCH 09/16] Simplify get_glyph_alternates() dispatcher Trying to make it **very simple** to add a specialized dispatcher for one API to be routed to just a few objects (one in this case). --- src/hb-ot-layout-gsub-table.hh | 9 +++++--- src/hb-ot-layout-gsubgpos.hh | 40 ---------------------------------- src/hb-ot-layout.cc | 32 +++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 45 deletions(-) diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index 11c9bf19e..4a9d38a5b 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -643,9 +643,12 @@ struct AlternateSubstFormat1 { return c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED; } unsigned - get_glyph_alternates (hb_get_glyph_alternates_context_t *c) const - { return (this+alternateSet[(this+coverage).get_coverage (c->gid)]) - .get_alternates (c->start_offset, c->alternate_count, c->alternate_glyphs); } + get_glyph_alternates (hb_codepoint_t gid, + unsigned start_offset, + unsigned *alternate_count /* IN/OUT. May be NULL. */, + hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) const + { return (this+alternateSet[(this+coverage).get_coverage (gid)]) + .get_alternates (start_offset, alternate_count, alternate_glyphs); } bool apply (hb_ot_apply_context_t *c) const { diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 75ef76a4b..991fef6bb 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -227,46 +227,6 @@ struct hb_would_apply_context_t : debug_depth (0) {} }; -struct hb_get_glyph_alternates_context_t : - hb_dispatch_context_t -{ - const char *get_name () { return "GET_GLYPH_ALTERNATES"; } - static return_t default_return_value () { return 0; } - bool stop_sublookup_iteration (return_t r) const { return r; } - - hb_face_t *face; - hb_codepoint_t gid; - unsigned start_offset; - unsigned *alternate_count; - hb_codepoint_t *alternate_glyphs; - unsigned int debug_depth; - - hb_get_glyph_alternates_context_t (hb_face_t *face_, - hb_codepoint_t gid_, - unsigned start_offset_, - unsigned *alternate_count_, - hb_codepoint_t *alternate_glyphs_) : - face (face_), - gid (gid_), - start_offset (start_offset_), - alternate_count (alternate_count_), - alternate_glyphs (alternate_glyphs_), - debug_depth (0) {} - - private: - template auto - _dispatch (const T &obj, hb_priority<1>) HB_AUTO_RETURN - ( obj.get_glyph_alternates (this) ) - template auto - _dispatch (const T &obj, hb_priority<0>) HB_AUTO_RETURN - ( default_return_value () ) - public: - template auto - dispatch (const T &obj) HB_AUTO_RETURN - ( _dispatch (obj, hb_prioritize) ) -}; - - struct hb_collect_glyphs_context_t : hb_dispatch_context_t { diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index c042ce9cc..542d059d4 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1969,6 +1969,34 @@ hb_ot_layout_get_baseline (hb_font_t *font, } #endif + +struct hb_get_glyph_alternates_context_t : + hb_dispatch_context_t +{ + const char *get_name () { return "GET_GLYPH_ALTERNATES"; } + static return_t default_return_value () { return 0; } + bool stop_sublookup_iteration (return_t r) const { return r; } + + hb_face_t *face; + unsigned int debug_depth; + + hb_get_glyph_alternates_context_t (hb_face_t *face) : + face (face), + debug_depth (0) {} + + private: + template auto + _dispatch (const T &obj, hb_priority<1>, Ts&&... ds) HB_AUTO_RETURN + ( obj.get_glyph_alternates (hb_forward (ds)...) ) + template auto + _dispatch (const T &obj, hb_priority<0>, Ts&&... ds) HB_AUTO_RETURN + ( default_return_value () ) + public: + template auto + dispatch (const T &obj, Ts&&... ds) HB_AUTO_RETURN + ( _dispatch (obj, hb_prioritize, hb_forward (ds)...) ) +}; + /** * hb_ot_layout_lookup_get_glyph_alternates: * @face: a face. @@ -1994,9 +2022,9 @@ hb_ot_layout_lookup_get_glyph_alternates (hb_face_t *face, unsigned *alternate_count /* IN/OUT. May be NULL. */, hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) { - OT::hb_get_glyph_alternates_context_t c (face, glyph, start_offset, alternate_count, alternate_glyphs); + hb_get_glyph_alternates_context_t c (face); const OT::SubstLookup &lookup = face->table.GSUB->table->get_lookup (lookup_index); - auto ret = lookup.dispatch (&c); + auto ret = lookup.dispatch (&c, glyph, start_offset, alternate_count, alternate_glyphs); if (!ret && alternate_count) *alternate_count = 0; return ret; } From e47a2ab8f8a90d903653a1d0d970c220f0957158 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 18 Jun 2020 16:48:07 -0700 Subject: [PATCH 10/16] Remove unused dispatcher names --- src/hb-dispatch.hh | 1 + src/hb-ot-layout-common.hh | 1 - src/hb-ot-layout-gsubgpos.hh | 5 ----- src/hb-ot-layout.cc | 1 - 4 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/hb-dispatch.hh b/src/hb-dispatch.hh index 1ce3fac93..acbb6e904 100644 --- a/src/hb-dispatch.hh +++ b/src/hb-dispatch.hh @@ -43,6 +43,7 @@ struct hb_dispatch_context_t const Context* thiz () const { return static_cast (this); } Context* thiz () { return static_cast< Context *> (this); } public: + const char *get_name () { return "UNKNOWN"; } static constexpr unsigned max_debug_depth = MaxDebugDepth; typedef Return return_t; template diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index fdd1f31c7..3ea62b15d 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -153,7 +153,6 @@ struct hb_subset_layout_context_t : struct hb_collect_variation_indices_context_t : hb_dispatch_context_t { - const char *get_name () { return "CLOSURE_LAYOUT_VARIATION_IDXES"; } template return_t dispatch (const T &obj) { obj.collect_variation_indices (this); return hb_empty_t (); } static return_t default_return_value () { return hb_empty_t (); } diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 991fef6bb..1722cf870 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -44,7 +44,6 @@ namespace OT { struct hb_intersects_context_t : hb_dispatch_context_t { - const char *get_name () { return "INTERSECTS"; } template return_t dispatch (const T &obj) { return obj.intersects (this->glyphs); } static return_t default_return_value () { return false; } @@ -61,7 +60,6 @@ struct hb_intersects_context_t : struct hb_closure_context_t : hb_dispatch_context_t { - const char *get_name () { return "CLOSURE"; } typedef return_t (*recurse_func_t) (hb_closure_context_t *c, unsigned int lookup_index); template return_t dispatch (const T &obj) { obj.closure (this); return hb_empty_t (); } @@ -136,7 +134,6 @@ struct hb_closure_context_t : struct hb_closure_lookups_context_t : hb_dispatch_context_t { - const char *get_name () { return "CLOSURE_LOOKUPS"; } typedef return_t (*recurse_func_t) (hb_closure_lookups_context_t *c, unsigned lookup_index); template return_t dispatch (const T &obj) { obj.closure_lookups (this); return hb_empty_t (); } @@ -204,7 +201,6 @@ struct hb_closure_lookups_context_t : struct hb_would_apply_context_t : hb_dispatch_context_t { - const char *get_name () { return "WOULD_APPLY"; } template return_t dispatch (const T &obj) { return obj.would_apply (this); } static return_t default_return_value () { return false; } @@ -230,7 +226,6 @@ struct hb_would_apply_context_t : struct hb_collect_glyphs_context_t : hb_dispatch_context_t { - const char *get_name () { return "COLLECT_GLYPHS"; } typedef return_t (*recurse_func_t) (hb_collect_glyphs_context_t *c, unsigned int lookup_index); template return_t dispatch (const T &obj) { obj.collect_glyphs (this); return hb_empty_t (); } diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 542d059d4..18ec4c932 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1973,7 +1973,6 @@ hb_ot_layout_get_baseline (hb_font_t *font, struct hb_get_glyph_alternates_context_t : hb_dispatch_context_t { - const char *get_name () { return "GET_GLYPH_ALTERNATES"; } static return_t default_return_value () { return 0; } bool stop_sublookup_iteration (return_t r) const { return r; } From d7d8604ec8526f96618b4f0f83ed9b3204e7b597 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 18 Jun 2020 16:51:01 -0700 Subject: [PATCH 11/16] Remove excessive trace routes --- src/hb-debug.hh | 4 ---- src/hb-ot-layout-gsubgpos.hh | 6 ++---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/hb-debug.hh b/src/hb-debug.hh index 5c13e5d1a..ec3a1ff21 100644 --- a/src/hb-debug.hh +++ b/src/hb-debug.hh @@ -373,10 +373,6 @@ struct hb_no_trace_t { #define HB_DEBUG_FT (HB_DEBUG+0) #endif -#ifndef HB_DEBUG_GET_COVERAGE -#define HB_DEBUG_GET_COVERAGE (HB_DEBUG+0) -#endif - #ifndef HB_DEBUG_OBJECT #define HB_DEBUG_OBJECT (HB_DEBUG+0) #endif diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 1722cf870..7a759d16f 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -302,9 +302,8 @@ struct hb_collect_glyphs_context_t : template struct hb_collect_coverage_context_t : - hb_dispatch_context_t, const Coverage &, HB_DEBUG_GET_COVERAGE> + hb_dispatch_context_t, const Coverage &, 0> { - const char *get_name () { return "GET_COVERAGE"; } typedef const Coverage &return_t; template return_t dispatch (const T &obj) { return obj.get_coverage (); } @@ -695,7 +694,7 @@ struct hb_ot_apply_context_t : struct hb_get_subtables_context_t : - hb_dispatch_context_t + hb_dispatch_context_t { template static inline bool apply_to (const void *obj, OT::hb_ot_apply_context_t *c) @@ -731,7 +730,6 @@ struct hb_get_subtables_context_t : typedef hb_vector_t array_t; /* Dispatch interface. */ - const char *get_name () { return "GET_SUBTABLES"; } template return_t dispatch (const T &obj) { From 8d0a90ac1bd9f6485d3e0fead7c648caa735eb81 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 18 Jun 2020 16:53:54 -0700 Subject: [PATCH 12/16] [dispatch] Default debug level to 0 --- src/hb-dispatch.hh | 2 +- src/hb-ot-layout-common.hh | 2 +- src/hb-ot-layout-gsubgpos.hh | 14 +++++++------- src/hb-ot-layout.cc | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/hb-dispatch.hh b/src/hb-dispatch.hh index acbb6e904..37b6a8eb8 100644 --- a/src/hb-dispatch.hh +++ b/src/hb-dispatch.hh @@ -35,7 +35,7 @@ * Dispatch */ -template +template struct hb_dispatch_context_t { private: diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 3ea62b15d..b66b63866 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -151,7 +151,7 @@ struct hb_subset_layout_context_t : }; struct hb_collect_variation_indices_context_t : - hb_dispatch_context_t + hb_dispatch_context_t { template return_t dispatch (const T &obj) { obj.collect_variation_indices (this); return hb_empty_t (); } diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 7a759d16f..d296cc66f 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -42,7 +42,7 @@ namespace OT { struct hb_intersects_context_t : - hb_dispatch_context_t + hb_dispatch_context_t { template return_t dispatch (const T &obj) { return obj.intersects (this->glyphs); } @@ -58,7 +58,7 @@ struct hb_intersects_context_t : }; struct hb_closure_context_t : - hb_dispatch_context_t + hb_dispatch_context_t { typedef return_t (*recurse_func_t) (hb_closure_context_t *c, unsigned int lookup_index); template @@ -132,7 +132,7 @@ struct hb_closure_context_t : }; struct hb_closure_lookups_context_t : - hb_dispatch_context_t + hb_dispatch_context_t { typedef return_t (*recurse_func_t) (hb_closure_lookups_context_t *c, unsigned lookup_index); template @@ -199,7 +199,7 @@ struct hb_closure_lookups_context_t : }; struct hb_would_apply_context_t : - hb_dispatch_context_t + hb_dispatch_context_t { template return_t dispatch (const T &obj) { return obj.would_apply (this); } @@ -224,7 +224,7 @@ struct hb_would_apply_context_t : }; struct hb_collect_glyphs_context_t : - hb_dispatch_context_t + hb_dispatch_context_t { typedef return_t (*recurse_func_t) (hb_collect_glyphs_context_t *c, unsigned int lookup_index); template @@ -302,7 +302,7 @@ struct hb_collect_glyphs_context_t : template struct hb_collect_coverage_context_t : - hb_dispatch_context_t, const Coverage &, 0> + hb_dispatch_context_t, const Coverage &> { typedef const Coverage &return_t; template @@ -694,7 +694,7 @@ struct hb_ot_apply_context_t : struct hb_get_subtables_context_t : - hb_dispatch_context_t + hb_dispatch_context_t { template static inline bool apply_to (const void *obj, OT::hb_ot_apply_context_t *c) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 18ec4c932..239a47615 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1971,7 +1971,7 @@ hb_ot_layout_get_baseline (hb_font_t *font, struct hb_get_glyph_alternates_context_t : - hb_dispatch_context_t + hb_dispatch_context_t { static return_t default_return_value () { return 0; } bool stop_sublookup_iteration (return_t r) const { return r; } From 25aec0265c1a1030c7d6453e85b2463589c8688a Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 18 Jun 2020 16:58:01 -0700 Subject: [PATCH 13/16] [dispatch] Default return type to hb_empty_t --- src/hb-dispatch.hh | 2 +- src/hb-ot-layout-common.hh | 2 +- src/hb-ot-layout-gsubgpos.hh | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hb-dispatch.hh b/src/hb-dispatch.hh index 37b6a8eb8..b00267fec 100644 --- a/src/hb-dispatch.hh +++ b/src/hb-dispatch.hh @@ -35,7 +35,7 @@ * Dispatch */ -template +template struct hb_dispatch_context_t { private: diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index b66b63866..3cd3c6ce3 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -151,7 +151,7 @@ struct hb_subset_layout_context_t : }; struct hb_collect_variation_indices_context_t : - hb_dispatch_context_t + hb_dispatch_context_t { template return_t dispatch (const T &obj) { obj.collect_variation_indices (this); return hb_empty_t (); } diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index d296cc66f..2a477d657 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -58,7 +58,7 @@ struct hb_intersects_context_t : }; struct hb_closure_context_t : - hb_dispatch_context_t + hb_dispatch_context_t { typedef return_t (*recurse_func_t) (hb_closure_context_t *c, unsigned int lookup_index); template @@ -132,7 +132,7 @@ struct hb_closure_context_t : }; struct hb_closure_lookups_context_t : - hb_dispatch_context_t + hb_dispatch_context_t { typedef return_t (*recurse_func_t) (hb_closure_lookups_context_t *c, unsigned lookup_index); template @@ -224,7 +224,7 @@ struct hb_would_apply_context_t : }; struct hb_collect_glyphs_context_t : - hb_dispatch_context_t + hb_dispatch_context_t { typedef return_t (*recurse_func_t) (hb_collect_glyphs_context_t *c, unsigned int lookup_index); template @@ -694,7 +694,7 @@ struct hb_ot_apply_context_t : struct hb_get_subtables_context_t : - hb_dispatch_context_t + hb_dispatch_context_t { template static inline bool apply_to (const void *obj, OT::hb_ot_apply_context_t *c) From dc492d7c8a49f0c0322848348d35ac8b818fce57 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 18 Jun 2020 17:03:05 -0700 Subject: [PATCH 14/16] [dispatch] Comment --- src/hb-ot-layout-gsubgpos.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index 2a477d657..da9f4069f 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -304,7 +304,7 @@ template struct hb_collect_coverage_context_t : hb_dispatch_context_t, const Coverage &> { - typedef const Coverage &return_t; + typedef const Coverage &return_t; // Stoopid that we have to dupe this here. template return_t dispatch (const T &obj) { return obj.get_coverage (); } static return_t default_return_value () { return Null (Coverage); } From 5bc4cedde67854ecda72305d839c7e7ad297e83e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 18 Jun 2020 17:04:35 -0700 Subject: [PATCH 15/16] Rename --- src/hb-ot-layout.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 239a47615..05e9fa89d 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1970,8 +1970,8 @@ hb_ot_layout_get_baseline (hb_font_t *font, #endif -struct hb_get_glyph_alternates_context_t : - hb_dispatch_context_t +struct hb_get_glyph_alternates_dispatch_t : + hb_dispatch_context_t { static return_t default_return_value () { return 0; } bool stop_sublookup_iteration (return_t r) const { return r; } @@ -1979,9 +1979,9 @@ struct hb_get_glyph_alternates_context_t : hb_face_t *face; unsigned int debug_depth; - hb_get_glyph_alternates_context_t (hb_face_t *face) : - face (face), - debug_depth (0) {} + hb_get_glyph_alternates_dispatch_t (hb_face_t *face) : + face (face), + debug_depth (0) {} private: template auto @@ -2021,7 +2021,7 @@ hb_ot_layout_lookup_get_glyph_alternates (hb_face_t *face, unsigned *alternate_count /* IN/OUT. May be NULL. */, hb_codepoint_t *alternate_glyphs /* OUT. May be NULL. */) { - hb_get_glyph_alternates_context_t c (face); + hb_get_glyph_alternates_dispatch_t c (face); const OT::SubstLookup &lookup = face->table.GSUB->table->get_lookup (lookup_index); auto ret = lookup.dispatch (&c, glyph, start_offset, alternate_count, alternate_glyphs); if (!ret && alternate_count) *alternate_count = 0; From 70d6696cc6c863673a580b3bfc79d16d3a5d393d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 18 Jun 2020 17:09:39 -0700 Subject: [PATCH 16/16] [dispatch] Don't require debug_depth for untraced objects --- src/hb-dispatch.hh | 1 + src/hb-ot-layout-common.hh | 4 +--- src/hb-ot-layout-gsubgpos.hh | 20 ++++---------------- src/hb-ot-layout.cc | 4 +--- 4 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/hb-dispatch.hh b/src/hb-dispatch.hh index b00267fec..327770a89 100644 --- a/src/hb-dispatch.hh +++ b/src/hb-dispatch.hh @@ -44,6 +44,7 @@ struct hb_dispatch_context_t Context* thiz () { return static_cast< Context *> (this); } public: const char *get_name () { return "UNKNOWN"; } + static constexpr unsigned debug_depth = 0; static constexpr unsigned max_debug_depth = MaxDebugDepth; typedef Return return_t; template diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 3cd3c6ce3..132e9522b 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -160,15 +160,13 @@ struct hb_collect_variation_indices_context_t : hb_set_t *layout_variation_indices; const hb_set_t *glyph_set; const hb_map_t *gpos_lookups; - unsigned int debug_depth; hb_collect_variation_indices_context_t (hb_set_t *layout_variation_indices_, const hb_set_t *glyph_set_, const hb_map_t *gpos_lookups_) : layout_variation_indices (layout_variation_indices_), glyph_set (glyph_set_), - gpos_lookups (gpos_lookups_), - debug_depth (0) {} + gpos_lookups (gpos_lookups_) {} }; template diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index da9f4069f..e935a9505 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -50,11 +50,9 @@ struct hb_intersects_context_t : bool stop_sublookup_iteration (return_t r) const { return r; } const hb_set_t *glyphs; - unsigned int debug_depth; hb_intersects_context_t (const hb_set_t *glyphs_) : - glyphs (glyphs_), - debug_depth (0) {} + glyphs (glyphs_) {} }; struct hb_closure_context_t : @@ -100,7 +98,6 @@ struct hb_closure_context_t : hb_set_t output[1]; recurse_func_t recurse_func; unsigned int nesting_level_left; - unsigned int debug_depth; hb_closure_context_t (hb_face_t *face_, hb_set_t *glyphs_, @@ -110,7 +107,6 @@ struct hb_closure_context_t : glyphs (glyphs_), recurse_func (nullptr), nesting_level_left (nesting_level_left_), - debug_depth (0), done_lookups (done_lookups_), lookup_count (0) {} @@ -174,7 +170,6 @@ struct hb_closure_lookups_context_t : const hb_set_t *glyphs; recurse_func_t recurse_func; unsigned int nesting_level_left; - unsigned int debug_depth; hb_closure_lookups_context_t (hb_face_t *face_, const hb_set_t *glyphs_, @@ -185,7 +180,6 @@ struct hb_closure_lookups_context_t : glyphs (glyphs_), recurse_func (nullptr), nesting_level_left (nesting_level_left_), - debug_depth (0), visited_lookups (visited_lookups_), inactive_lookups (inactive_lookups_), lookup_count (0) {} @@ -210,7 +204,6 @@ struct hb_would_apply_context_t : const hb_codepoint_t *glyphs; unsigned int len; bool zero_context; - unsigned int debug_depth; hb_would_apply_context_t (hb_face_t *face_, const hb_codepoint_t *glyphs_, @@ -219,8 +212,7 @@ struct hb_would_apply_context_t : face (face_), glyphs (glyphs_), len (len_), - zero_context (zero_context_), - debug_depth (0) {} + zero_context (zero_context_) {} }; struct hb_collect_glyphs_context_t : @@ -276,7 +268,6 @@ struct hb_collect_glyphs_context_t : recurse_func_t recurse_func; hb_set_t *recursed_lookups; unsigned int nesting_level_left; - unsigned int debug_depth; hb_collect_glyphs_context_t (hb_face_t *face_, hb_set_t *glyphs_before, /* OUT. May be NULL */ @@ -291,8 +282,7 @@ struct hb_collect_glyphs_context_t : output (glyphs_output ? glyphs_output : hb_set_get_empty ()), recurse_func (nullptr), recursed_lookups (hb_set_create ()), - nesting_level_left (nesting_level_left_), - debug_depth (0) {} + nesting_level_left (nesting_level_left_) {} ~hb_collect_glyphs_context_t () { hb_set_destroy (recursed_lookups); } void set_recurse_func (recurse_func_t func) { recurse_func = func; } @@ -315,11 +305,9 @@ struct hb_collect_coverage_context_t : } hb_collect_coverage_context_t (set_t *set_) : - set (set_), - debug_depth (0) {} + set (set_) {} set_t *set; - unsigned int debug_depth; }; diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 05e9fa89d..b612c1e2f 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -1977,11 +1977,9 @@ struct hb_get_glyph_alternates_dispatch_t : bool stop_sublookup_iteration (return_t r) const { return r; } hb_face_t *face; - unsigned int debug_depth; hb_get_glyph_alternates_dispatch_t (hb_face_t *face) : - face (face), - debug_depth (0) {} + face (face) {} private: template auto