From c180f93766cbeec4e516800e9cbf956b740e4779 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 26 Jan 2022 08:22:40 -0700 Subject: [PATCH] [reorg] Move sanitize/dispatch and size macros to top --- src/OT/Layout/GSUB/SingleSubst.hh | 39 ++++++++++++------------ src/OT/Layout/GSUB/SingleSubstFormat1.hh | 16 +++++----- src/OT/Layout/GSUB/SingleSubstFormat2.hh | 16 +++++----- 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/OT/Layout/GSUB/SingleSubst.hh b/src/OT/Layout/GSUB/SingleSubst.hh index c30d860c1..786428fe4 100644 --- a/src/OT/Layout/GSUB/SingleSubst.hh +++ b/src/OT/Layout/GSUB/SingleSubst.hh @@ -11,6 +11,26 @@ namespace GSUB { struct SingleSubst { + protected: + union { + HBUINT16 format; /* Format identifier */ + SingleSubstFormat1 format1; + SingleSubstFormat2 format2; + } u; + + public: + + 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 ()); + switch (u.format) { + case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); + case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); + default:return_trace (c->default_return_value ()); + } + } 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 ()); - switch (u.format) { - case 1: return_trace (c->dispatch (u.format1, std::forward (ds)...)); - case 2: return_trace (c->dispatch (u.format2, std::forward (ds)...)); - default:return_trace (c->default_return_value ()); - } - } - - protected: - union { - HBUINT16 format; /* Format identifier */ - SingleSubstFormat1 format1; - SingleSubstFormat2 format2; - } u; }; template diff --git a/src/OT/Layout/GSUB/SingleSubstFormat1.hh b/src/OT/Layout/GSUB/SingleSubstFormat1.hh index 4528094ca..59feb5575 100644 --- a/src/OT/Layout/GSUB/SingleSubstFormat1.hh +++ b/src/OT/Layout/GSUB/SingleSubstFormat1.hh @@ -19,6 +19,13 @@ struct SingleSubstFormat1 * substitute GlyphID, modulo 0x10000 */ public: + DEFINE_SIZE_STATIC (6); + + bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (coverage.sanitize (c, this) && deltaGlyphID.sanitize (c)); + } bool intersects (const hb_set_t *glyphs) const { return (this+coverage).intersects (glyphs); } @@ -106,15 +113,6 @@ struct SingleSubstFormat1 SingleSubst_serialize (c->serializer, it); return_trace (ret); } - - bool sanitize (hb_sanitize_context_t *c) const - { - TRACE_SANITIZE (this); - return_trace (coverage.sanitize (c, this) && deltaGlyphID.sanitize (c)); - } - - public: - DEFINE_SIZE_STATIC (6); }; } diff --git a/src/OT/Layout/GSUB/SingleSubstFormat2.hh b/src/OT/Layout/GSUB/SingleSubstFormat2.hh index a82753599..470a1bade 100644 --- a/src/OT/Layout/GSUB/SingleSubstFormat2.hh +++ b/src/OT/Layout/GSUB/SingleSubstFormat2.hh @@ -20,6 +20,13 @@ struct SingleSubstFormat2 * GlyphIDs--ordered by Coverage Index */ public: + DEFINE_SIZE_ARRAY (6, substitute); + + bool sanitize (hb_sanitize_context_t *c) const + { + TRACE_SANITIZE (this); + return_trace (coverage.sanitize (c, this) && substitute.sanitize (c)); + } bool intersects (const hb_set_t *glyphs) const { return (this+coverage).intersects (glyphs); } @@ -105,15 +112,6 @@ struct SingleSubstFormat2 SingleSubst_serialize (c->serializer, it); return_trace (ret); } - - bool sanitize (hb_sanitize_context_t *c) const - { - TRACE_SANITIZE (this); - return_trace (coverage.sanitize (c, this) && substitute.sanitize (c)); - } - - public: - DEFINE_SIZE_ARRAY (6, substitute); }; }