提交 7b2ef551 编写于 作者: B Behdad Esfahbod

Templatize Lookup::sanitize()

上级 9c3747c5
...@@ -634,16 +634,16 @@ struct Lookup ...@@ -634,16 +634,16 @@ struct Lookup
{ {
inline unsigned int get_subtable_count (void) const { return subTable.len; } inline unsigned int get_subtable_count (void) const { return subTable.len; }
template <typename SubTableType> template <typename TSubTable>
inline const SubTableType& get_subtable (unsigned int i) const inline const TSubTable& get_subtable (unsigned int i) const
{ return this+CastR<OffsetArrayOf<SubTableType> > (subTable)[i]; } { return this+CastR<OffsetArrayOf<TSubTable> > (subTable)[i]; }
template <typename SubTableType> template <typename TSubTable>
inline const OffsetArrayOf<SubTableType>& get_subtables (void) const inline const OffsetArrayOf<TSubTable>& get_subtables (void) const
{ return CastR<OffsetArrayOf<SubTableType> > (subTable); } { return CastR<OffsetArrayOf<TSubTable> > (subTable); }
template <typename SubTableType> template <typename TSubTable>
inline OffsetArrayOf<SubTableType>& get_subtables (void) inline OffsetArrayOf<TSubTable>& get_subtables (void)
{ return CastR<OffsetArrayOf<SubTableType> > (subTable); } { return CastR<OffsetArrayOf<TSubTable> > (subTable); }
inline unsigned int get_size (void) const inline unsigned int get_size (void) const
{ {
...@@ -669,14 +669,14 @@ struct Lookup ...@@ -669,14 +669,14 @@ struct Lookup
return flag; return flag;
} }
template <typename SubTableType, typename context_t> template <typename TSubTable, typename context_t>
inline typename context_t::return_t dispatch (context_t *c) const inline typename context_t::return_t dispatch (context_t *c) const
{ {
unsigned int lookup_type = get_type (); unsigned int lookup_type = get_type ();
TRACE_DISPATCH (this, lookup_type); TRACE_DISPATCH (this, lookup_type);
unsigned int count = get_subtable_count (); unsigned int count = get_subtable_count ();
for (unsigned int i = 0; i < count; i++) { for (unsigned int i = 0; i < count; i++) {
typename context_t::return_t r = get_subtable<SubTableType> (i).dispatch (c, lookup_type); typename context_t::return_t r = get_subtable<TSubTable> (i).dispatch (c, lookup_type);
if (c->stop_sublookup_iteration (r)) if (c->stop_sublookup_iteration (r))
return_trace (r); return_trace (r);
} }
...@@ -702,16 +702,32 @@ struct Lookup ...@@ -702,16 +702,32 @@ struct Lookup
return_trace (true); return_trace (true);
} }
template <typename TSubTable>
inline bool sanitize (hb_sanitize_context_t *c) const inline bool sanitize (hb_sanitize_context_t *c) const
{ {
TRACE_SANITIZE (this); 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 (!(c->check_struct (this) && subTable.sanitize (c))) return_trace (false);
if (lookupFlag & LookupFlag::UseMarkFilteringSet) if (lookupFlag & LookupFlag::UseMarkFilteringSet)
{ {
const HBUINT16 &markFilteringSet = StructAfter<HBUINT16> (subTable); const HBUINT16 &markFilteringSet = StructAfter<HBUINT16> (subTable);
if (!markFilteringSet.sanitize (c)) return_trace (false); if (!markFilteringSet.sanitize (c)) return_trace (false);
} }
if (unlikely (!dispatch<TSubTable> (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<TSubTable> (0).u.extension.get_type ();
unsigned int count = get_subtable_count ();
for (unsigned int i = 1; i < count; i++)
if (get_subtable<TSubTable> (i).u.extension.get_type () != type)
return_trace (false);
}
return_trace (true);
return_trace (true); return_trace (true);
} }
......
...@@ -1445,6 +1445,7 @@ struct ExtensionPos : Extension<ExtensionPos> ...@@ -1445,6 +1445,7 @@ struct ExtensionPos : Extension<ExtensionPos>
struct PosLookupSubTable struct PosLookupSubTable
{ {
friend struct Lookup;
friend struct PosLookup; friend struct PosLookup;
enum Type { enum Type {
...@@ -1543,11 +1544,7 @@ struct PosLookup : Lookup ...@@ -1543,11 +1544,7 @@ struct PosLookup : Lookup
{ return Lookup::dispatch<SubTable> (c); } { return Lookup::dispatch<SubTable> (c); }
inline bool sanitize (hb_sanitize_context_t *c) const inline bool sanitize (hb_sanitize_context_t *c) const
{ { return Lookup::sanitize<SubTable> (c); }
TRACE_SANITIZE (this);
if (unlikely (!Lookup::sanitize (c))) return_trace (false);
return_trace (dispatch (c));
}
}; };
/* /*
......
...@@ -1161,6 +1161,7 @@ struct ReverseChainSingleSubst ...@@ -1161,6 +1161,7 @@ struct ReverseChainSingleSubst
struct SubstLookupSubTable struct SubstLookupSubTable
{ {
friend struct Lookup;
friend struct SubstLookup; friend struct SubstLookup;
enum Type { enum Type {
...@@ -1366,30 +1367,10 @@ struct SubstLookup : Lookup ...@@ -1366,30 +1367,10 @@ struct SubstLookup : Lookup
{ return Lookup::dispatch<SubTable> (c); } { return Lookup::dispatch<SubTable> (c); }
inline bool subset (hb_subset_context_t *c) const inline bool subset (hb_subset_context_t *c) const
{ { return false; }//XXX Lookup::subset<SubTable> (c); }
return false; //XXX
}
inline bool sanitize (hb_sanitize_context_t *c) const inline bool sanitize (hb_sanitize_context_t *c) const
{ { return Lookup::sanitize<SubTable> (c); }
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);
}
}; };
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册