[subset] More

This commit is contained in:
Behdad Esfahbod 2018-09-03 16:53:03 -07:00
parent 6d618522d6
commit 9c3747c5e5
3 changed files with 45 additions and 35 deletions

View File

@ -1433,7 +1433,7 @@ struct ChainContextPos : ChainContext {};
struct ExtensionPos : Extension<ExtensionPos>
{
typedef struct PosLookupSubTable LookupSubTable;
typedef struct PosLookupSubTable SubTable;
};
@ -1498,8 +1498,10 @@ struct PosLookupSubTable
struct PosLookup : Lookup
{
inline const PosLookupSubTable& get_subtable (unsigned int i) const
{ return Lookup::get_subtable<PosLookupSubTable> (i); }
typedef struct PosLookupSubTable SubTable;
inline const SubTable& get_subtable (unsigned int i) const
{ return Lookup::get_subtable<SubTable> (i); }
inline bool is_reverse (void) const
{
@ -1538,7 +1540,7 @@ struct PosLookup : Lookup
template <typename context_t>
inline typename context_t::return_t dispatch (context_t *c) const
{ return Lookup::dispatch<PosLookupSubTable> (c); }
{ return Lookup::dispatch<SubTable> (c); }
inline bool sanitize (hb_sanitize_context_t *c) const
{

View File

@ -980,7 +980,7 @@ struct ChainContextSubst : ChainContext {};
struct ExtensionSubst : Extension<ExtensionSubst>
{
typedef struct SubstLookupSubTable LookupSubTable;
typedef struct SubstLookupSubTable SubTable;
inline bool is_reverse (void) const;
};
@ -1211,16 +1211,18 @@ struct SubstLookupSubTable
struct SubstLookup : Lookup
{
inline const SubstLookupSubTable& get_subtable (unsigned int i) const
{ return Lookup::get_subtable<SubstLookupSubTable> (i); }
typedef SubstLookupSubTable SubTable;
inline const SubTable& get_subtable (unsigned int i) const
{ return Lookup::get_subtable<SubTable> (i); }
inline static bool lookup_type_is_reverse (unsigned int lookup_type)
{ return lookup_type == SubstLookupSubTable::ReverseChainSingle; }
{ return lookup_type == SubTable::ReverseChainSingle; }
inline bool is_reverse (void) const
{
unsigned int type = get_type ();
if (unlikely (type == SubstLookupSubTable::Extension))
if (unlikely (type == SubTable::Extension))
return CastR<ExtensionSubst> (get_subtable(0)).is_reverse ();
return lookup_type_is_reverse (type);
}
@ -1277,9 +1279,9 @@ struct SubstLookup : Lookup
static bool apply_recurse_func (hb_ot_apply_context_t *c, unsigned int lookup_index);
inline SubstLookupSubTable& serialize_subtable (hb_serialize_context_t *c,
unsigned int i)
{ return get_subtables<SubstLookupSubTable> ()[i].serialize (c, this); }
inline SubTable& serialize_subtable (hb_serialize_context_t *c,
unsigned int i)
{ return get_subtables<SubTable> ()[i].serialize (c, this); }
inline bool serialize_single (hb_serialize_context_t *c,
uint32_t lookup_props,
@ -1288,7 +1290,7 @@ struct SubstLookup : Lookup
unsigned int num_glyphs)
{
TRACE_SERIALIZE (this);
if (unlikely (!Lookup::serialize (c, SubstLookupSubTable::Single, lookup_props, 1))) return_trace (false);
if (unlikely (!Lookup::serialize (c, SubTable::Single, lookup_props, 1))) return_trace (false);
return_trace (serialize_subtable (c, 0).u.single.serialize (c, glyphs, substitutes, num_glyphs));
}
@ -1300,7 +1302,7 @@ struct SubstLookup : Lookup
Supplier<GlyphID> &substitute_glyphs_list)
{
TRACE_SERIALIZE (this);
if (unlikely (!Lookup::serialize (c, SubstLookupSubTable::Multiple, lookup_props, 1))) return_trace (false);
if (unlikely (!Lookup::serialize (c, SubTable::Multiple, lookup_props, 1))) return_trace (false);
return_trace (serialize_subtable (c, 0).u.multiple.serialize (c,
glyphs,
substitute_len_list,
@ -1316,7 +1318,7 @@ struct SubstLookup : Lookup
Supplier<GlyphID> &alternate_glyphs_list)
{
TRACE_SERIALIZE (this);
if (unlikely (!Lookup::serialize (c, SubstLookupSubTable::Alternate, lookup_props, 1))) return_trace (false);
if (unlikely (!Lookup::serialize (c, SubTable::Alternate, lookup_props, 1))) return_trace (false);
return_trace (serialize_subtable (c, 0).u.alternate.serialize (c,
glyphs,
alternate_len_list,
@ -1334,7 +1336,7 @@ struct SubstLookup : Lookup
Supplier<GlyphID> &component_list /* Starting from second for each ligature */)
{
TRACE_SERIALIZE (this);
if (unlikely (!Lookup::serialize (c, SubstLookupSubTable::Ligature, lookup_props, 1))) return_trace (false);
if (unlikely (!Lookup::serialize (c, SubTable::Ligature, lookup_props, 1))) return_trace (false);
return_trace (serialize_subtable (c, 0).u.ligature.serialize (c,
first_glyphs,
ligature_per_first_glyph_count_list,
@ -1361,7 +1363,12 @@ struct SubstLookup : Lookup
template <typename context_t>
inline typename context_t::return_t dispatch (context_t *c) const
{ return Lookup::dispatch<SubstLookupSubTable> (c); }
{ return Lookup::dispatch<SubTable> (c); }
inline bool subset (hb_subset_context_t *c) const
{
return false; //XXX
}
inline bool sanitize (hb_sanitize_context_t *c) const
{
@ -1369,7 +1376,7 @@ struct SubstLookup : Lookup
if (unlikely (!Lookup::sanitize (c))) return_trace (false);
if (unlikely (!dispatch (c))) return_trace (false);
if (unlikely (get_type () == SubstLookupSubTable::Extension))
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
@ -1400,14 +1407,7 @@ struct GSUB : GSUBGPOS
inline bool subset (hb_subset_context_t *c) const
{
TRACE_SUBSET (this);
//struct GSUB *out = c->serializer->start_embed<GSUB> ();
if (unlikely (!GSUBGPOS::subset (c))) return_trace (false);
//const OffsetTo<SubstLookupList> &list = CastR<const OffsetTo<SubstLookupList> > (lookupList);
//OffsetTo<SubstLookupList> &outList = CastR<OffsetTo<SubstLookupList> > (out->lookupList);
//outList.set (0);
//outList.serialize_subset (c, this+list, out);
/* TODO Use intersects() to count how many subtables survive? */
return_trace (true);
return_trace (GSUBGPOS::subset<SubstLookup> (c));
}
inline bool sanitize (hb_sanitize_context_t *c) const
@ -1425,8 +1425,8 @@ struct GSUB : GSUBGPOS
/*static*/ inline bool ExtensionSubst::is_reverse (void) const
{
unsigned int type = get_type ();
if (unlikely (type == SubstLookupSubTable::Extension))
return CastR<ExtensionSubst> (get_subtable<LookupSubTable>()).is_reverse ();
if (unlikely (type == SubTable::Extension))
return CastR<ExtensionSubst> (get_subtable<SubTable>()).is_reverse ();
return SubstLookup::lookup_type_is_reverse (type);
}

View File

@ -2420,8 +2420,8 @@ struct ExtensionFormat1
inline const X& get_subtable (void) const
{
unsigned int offset = extensionOffset;
if (unlikely (!offset)) return Null(typename T::LookupSubTable);
return StructAtOffset<typename T::LookupSubTable> (this, offset);
if (unlikely (!offset)) return Null(typename T::SubTable);
return StructAtOffset<typename T::SubTable> (this, offset);
}
template <typename context_t>
@ -2429,7 +2429,7 @@ struct ExtensionFormat1
{
TRACE_DISPATCH (this, format);
if (unlikely (!c->may_dispatch (this, this))) return_trace (c->no_dispatch_return_value ());
return_trace (get_subtable<typename T::LookupSubTable> ().dispatch (c, get_type ()));
return_trace (get_subtable<typename T::SubTable> ().dispatch (c, get_type ()));
}
/* This is called from may_dispatch() above with hb_sanitize_context_t. */
@ -2438,7 +2438,7 @@ struct ExtensionFormat1
TRACE_SANITIZE (this);
return_trace (c->check_struct (this) &&
extensionOffset != 0 &&
extensionLookupType != T::LookupSubTable::Extension);
extensionLookupType != T::SubTable::Extension);
}
protected:
@ -2466,8 +2466,8 @@ struct Extension
inline const X& get_subtable (void) const
{
switch (u.format) {
case 1: return u.format1.template get_subtable<typename T::LookupSubTable> ();
default:return Null(typename T::LookupSubTable);
case 1: return u.format1.template get_subtable<typename T::SubTable> ();
default:return Null(typename T::SubTable);
}
}
@ -2546,6 +2546,7 @@ struct GSUBGPOS
return get_feature (feature_index);
}
template <typename TLookup>
inline bool subset (hb_subset_context_t *c) const
{
TRACE_SUBSET (this);
@ -2553,7 +2554,14 @@ struct GSUBGPOS
if (unlikely (!out)) return_trace (false);
out->scriptList.serialize_subset (c, this+scriptList, out);
out->featureList.serialize_subset (c, this+featureList, out);
out->lookupList.set (0); /* GSUB/GPOS fill this one in. */
typedef OffsetListOf<TLookup> TLookupList;
/* TODO Use intersects() to count how many subtables survive? */
CastR<OffsetTo<TLookupList> > (out->lookupList)
.serialize_subset (c,
this+CastR<const OffsetTo<TLookupList> > (lookupList),
out);
if (version.to_int () >= 0x00010001u)
out->featureVars.serialize_subset (c, this+featureVars, out);
return_trace (true);