From 8eb8494e8d3e1e070d477d2545ff62d03fd670bf Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 12 Feb 2021 14:13:11 -0700 Subject: [PATCH] WIP --- src/hb-ot-layout-gpos-table.hh | 6 ---- src/hb-ot-layout-gsub-table.hh | 6 ---- src/hb-ot-layout-gsubgpos.hh | 65 +++++++++++++++++----------------- 3 files changed, 32 insertions(+), 45 deletions(-) diff --git a/src/hb-ot-layout-gpos-table.hh b/src/hb-ot-layout-gpos-table.hh index b2b2f0ef0..0e8fbff53 100644 --- a/src/hb-ot-layout-gpos-table.hh +++ b/src/hb-ot-layout-gpos-table.hh @@ -2556,12 +2556,6 @@ struct PosLookupSubTable } } - bool intersects (const hb_set_t *glyphs, unsigned int lookup_type) const - { - hb_intersects_context_t c (glyphs); - return dispatch (&c, lookup_type); - } - protected: union { SinglePos single; diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index 5f10ecb7e..cfc6c7671 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -1348,12 +1348,6 @@ struct SubstLookupSubTable } } - bool intersects (const hb_set_t *glyphs, unsigned int lookup_type) const - { - hb_intersects_context_t c (glyphs); - return dispatch (&c, lookup_type); - } - protected: union { SingleSubst single; diff --git a/src/hb-ot-layout-gsubgpos.hh b/src/hb-ot-layout-gsubgpos.hh index c8fe9441a..0f1f98deb 100644 --- a/src/hb-ot-layout-gsubgpos.hh +++ b/src/hb-ot-layout-gsubgpos.hh @@ -44,23 +44,24 @@ namespace OT { struct hb_intersects_context_t : hb_dispatch_context_t { - template - return_t dispatch (const T &obj) { return obj.intersects (this->glyphs); } - static return_t default_return_value () { return false; } - bool stop_sublookup_iteration (return_t r) const { return r; } - const hb_set_t *glyphs; hb_intersects_context_t (const hb_set_t *glyphs_) : glyphs (glyphs_) {} + + /* Dispatch interface. */ + template auto + dispatch (const T &obj) HB_RETURN (return_t, obj.intersects (this->glyphs)) + static return_t default_return_value () { return false; } + bool stop_sublookup_iteration (return_t r) const { return r; } }; struct hb_closure_context_t : hb_dispatch_context_t { 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 (); } + template auto + dispatch (const T &obj) HB_RETURN (return_t, (obj.closure (this), hb_empty_t ())) static return_t default_return_value () { return hb_empty_t (); } void recurse (unsigned int lookup_index) { @@ -134,8 +135,8 @@ struct hb_closure_lookups_context_t : hb_dispatch_context_t { 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 (); } + template auto + dispatch (const T &obj) HB_RETURN (return_t, (obj.closure_lookups (this), hb_empty_t ())) static return_t default_return_value () { return hb_empty_t (); } void recurse (unsigned lookup_index) { @@ -200,8 +201,8 @@ struct hb_closure_lookups_context_t : struct hb_would_apply_context_t : hb_dispatch_context_t { - template - return_t dispatch (const T &obj) { return obj.would_apply (this); } + template auto + dispatch (const T &obj) HB_RETURN (return_t, obj.would_apply (this)) static return_t default_return_value () { return false; } bool stop_sublookup_iteration (return_t r) const { return r; } @@ -224,8 +225,8 @@ struct hb_collect_glyphs_context_t : hb_dispatch_context_t { 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 (); } + template auto + dispatch (const T &obj) HB_RETURN (return_t, (obj.collect_glyphs (this), hb_empty_t())) static return_t default_return_value () { return hb_empty_t (); } void recurse (unsigned int lookup_index) { @@ -300,8 +301,8 @@ struct hb_collect_coverage_context_t : hb_dispatch_context_t, const Coverage &> { typedef const Coverage &return_t; // Stoopid that we have to dupe this here. - template - return_t dispatch (const T &obj) { return obj.get_coverage (); } + template auto + dispatch (const T &obj) HB_RETURN (return_t, obj.get_coverage (this)) static return_t default_return_value () { return Null (Coverage); } bool stop_sublookup_iteration (return_t r) const { @@ -505,8 +506,8 @@ struct hb_ot_apply_context_t : const char *get_name () { return "APPLY"; } typedef return_t (*recurse_func_t) (hb_ot_apply_context_t *c, unsigned int lookup_index); - template - return_t dispatch (const T &obj) { return obj.apply (this); } + template auto + dispatch (const T &obj) HB_RETURN (return_t, obj.apply (this)) static return_t default_return_value () { return false; } bool stop_sublookup_iteration (return_t r) const { return r; } return_t recurse (unsigned int sub_lookup_index) @@ -3159,13 +3160,23 @@ struct ExtensionFormat1 const X& get_subtable () const { return this + reinterpret_cast &> (extensionOffset); } - template - typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const + private: + /* If the context accepts dispatching to this object, call it. */ + template auto + _dispatch (context_t *c, hb_priority<1>, Ts&&... ds) const HB_AUTO_RETURN + ( c->dispatch (*this, hb_forward (ds)...) ) + /* Otherwise, dispatch to the referred sublookup. */ + template typename context_t::return_t + _dispatch (context_t *c, Ts&&... ds) const { TRACE_DISPATCH (this, format); if (unlikely (!c->may_dispatch (this, this))) return_trace (c->no_dispatch_return_value ()); return_trace (get_subtable ().dispatch (c, get_type (), hb_forward (ds)...)); } + public: + template auto + dispatch (context_t *c, Ts&&... ds) const HB_AUTO_RETURN + ( _dispatch (c, hb_prioritize, hb_forward (ds)...) ) void collect_variation_indices (hb_collect_variation_indices_context_t *c) const { dispatch (c); } @@ -3226,20 +3237,8 @@ struct Extension } } - // Specialization of dispatch for subset. dispatch() normally just - // dispatches to the sub table this points too, but for subset - // we need to run subset on this subtable too. - template - typename hb_subset_context_t::return_t dispatch (hb_subset_context_t *c, Ts&&... ds) const - { - switch (u.format) { - case 1: return u.format1.subset (c); - default: return c->default_return_value (); - } - } - - template - typename context_t::return_t dispatch (context_t *c, Ts&&... ds) const + template typename context_t::return_t + dispatch (context_t *c, Ts&&... ds) const { TRACE_DISPATCH (this, u.format); if (unlikely (!c->may_dispatch (this, &u.format))) return_trace (c->no_dispatch_return_value ());