From b2a1acccd9776beddb25fb4f9e24ca6e272958f4 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 18 Jun 2020 16:41:31 -0700 Subject: [PATCH] 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; }