From 7b2ef551da0d53cd94106035b1f065a759cf3cd5 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 3 Sep 2018 17:16:09 -0700 Subject: [PATCH] Templatize Lookup::sanitize() --- src/hb-ot-layout-common.hh | 40 ++++++++++++++++++++++++++++------------ src/hb-ot-layout-gpos-table.hh | 7 ++----- src/hb-ot-layout-gsub-table.hh | 25 +++---------------------- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/src/hb-ot-layout-common.hh b/src/hb-ot-layout-common.hh index 343b62d..850ea96 100644 --- a/src/hb-ot-layout-common.hh +++ b/src/hb-ot-layout-common.hh @@ -634,16 +634,16 @@ struct Lookup { inline unsigned int get_subtable_count (void) const { return subTable.len; } - template - inline const SubTableType& get_subtable (unsigned int i) const - { return this+CastR > (subTable)[i]; } + template + inline const TSubTable& get_subtable (unsigned int i) const + { return this+CastR > (subTable)[i]; } - template - inline const OffsetArrayOf& get_subtables (void) const - { return CastR > (subTable); } - template - inline OffsetArrayOf& get_subtables (void) - { return CastR > (subTable); } + template + inline const OffsetArrayOf& get_subtables (void) const + { return CastR > (subTable); } + template + inline OffsetArrayOf& get_subtables (void) + { return CastR > (subTable); } inline unsigned int get_size (void) const { @@ -669,14 +669,14 @@ struct Lookup return flag; } - template + template inline typename context_t::return_t dispatch (context_t *c) const { unsigned int lookup_type = get_type (); TRACE_DISPATCH (this, lookup_type); unsigned int count = get_subtable_count (); for (unsigned int i = 0; i < count; i++) { - typename context_t::return_t r = get_subtable (i).dispatch (c, lookup_type); + typename context_t::return_t r = get_subtable (i).dispatch (c, lookup_type); if (c->stop_sublookup_iteration (r)) return_trace (r); } @@ -702,16 +702,32 @@ struct Lookup return_trace (true); } + template inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); - /* Real sanitize of the subtables is done by GSUB/GPOS/... */ if (!(c->check_struct (this) && subTable.sanitize (c))) return_trace (false); if (lookupFlag & LookupFlag::UseMarkFilteringSet) { const HBUINT16 &markFilteringSet = StructAfter (subTable); if (!markFilteringSet.sanitize (c)) return_trace (false); } + + if (unlikely (!dispatch (c))) return_trace (false); + + if (unlikely (get_type () == TSubTable::Extension)) + { + /* The spec says all subtables of an Extension lookup should + * have the same type, which shall not be the Extension type + * itself (but we already checked for that). + * This is specially important if one has a reverse type! */ + unsigned int type = get_subtable (0).u.extension.get_type (); + unsigned int count = get_subtable_count (); + for (unsigned int i = 1; i < count; i++) + if (get_subtable (i).u.extension.get_type () != type) + return_trace (false); + } + return_trace (true); return_trace (true); } diff --git a/src/hb-ot-layout-gpos-table.hh b/src/hb-ot-layout-gpos-table.hh index 3ff72e3..912bf85 100644 --- a/src/hb-ot-layout-gpos-table.hh +++ b/src/hb-ot-layout-gpos-table.hh @@ -1445,6 +1445,7 @@ struct ExtensionPos : Extension struct PosLookupSubTable { + friend struct Lookup; friend struct PosLookup; enum Type { @@ -1543,11 +1544,7 @@ struct PosLookup : Lookup { return Lookup::dispatch (c); } inline bool sanitize (hb_sanitize_context_t *c) const - { - TRACE_SANITIZE (this); - if (unlikely (!Lookup::sanitize (c))) return_trace (false); - return_trace (dispatch (c)); - } + { return Lookup::sanitize (c); } }; /* diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index a77ab4c..d2a7209 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -1161,6 +1161,7 @@ struct ReverseChainSingleSubst struct SubstLookupSubTable { + friend struct Lookup; friend struct SubstLookup; enum Type { @@ -1366,30 +1367,10 @@ struct SubstLookup : Lookup { return Lookup::dispatch (c); } inline bool subset (hb_subset_context_t *c) const - { - return false; //XXX - } + { return false; }//XXX Lookup::subset (c); } inline bool sanitize (hb_sanitize_context_t *c) const - { - TRACE_SANITIZE (this); - if (unlikely (!Lookup::sanitize (c))) return_trace (false); - if (unlikely (!dispatch (c))) return_trace (false); - - if (unlikely (get_type () == SubTable::Extension)) - { - /* The spec says all subtables of an Extension lookup should - * have the same type, which shall not be the Extension type - * itself (but we already checked for that). - * This is specially important if one has a reverse type! */ - unsigned int type = get_subtable (0).u.extension.get_type (); - unsigned int count = get_subtable_count (); - for (unsigned int i = 1; i < count; i++) - if (get_subtable (i).u.extension.get_type () != type) - return_trace (false); - } - return_trace (true); - } + { return Lookup::sanitize (c); } }; /* -- 2.7.4