[color/COLR] Clean up
This commit is contained in:
parent
150c53ee96
commit
6418ae4e8a
@ -140,90 +140,6 @@ struct BinSearchArrayOf
|
||||
};
|
||||
|
||||
|
||||
/* TODO Move this to hb-open-type-private.hh and use it in ArrayOf, HeadlessArrayOf,
|
||||
* and other places around the code base?? */
|
||||
template <typename Type>
|
||||
struct UnsizedArrayOf
|
||||
{
|
||||
inline const Type& operator [] (unsigned int i) const { return arrayZ[i]; }
|
||||
inline Type& operator [] (unsigned int i) { return arrayZ[i]; }
|
||||
|
||||
inline bool sanitize (hb_sanitize_context_t *c, unsigned int count) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
if (unlikely (!sanitize_shallow (c, count))) return_trace (false);
|
||||
|
||||
/* Note: for structs that do not reference other structs,
|
||||
* we do not need to call their sanitize() as we already did
|
||||
* a bound check on the aggregate array size. We just include
|
||||
* a small unreachable expression to make sure the structs
|
||||
* pointed to do have a simple sanitize(), ie. they do not
|
||||
* reference other structs via offsets.
|
||||
*/
|
||||
(void) (false && arrayZ[0].sanitize (c));
|
||||
|
||||
return_trace (true);
|
||||
}
|
||||
inline bool sanitize (hb_sanitize_context_t *c, unsigned int count, const void *base) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
if (unlikely (!sanitize_shallow (c, count))) return_trace (false);
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
if (unlikely (!arrayZ[i].sanitize (c, base)))
|
||||
return_trace (false);
|
||||
return_trace (true);
|
||||
}
|
||||
template <typename T>
|
||||
inline bool sanitize (hb_sanitize_context_t *c, unsigned int count, const void *base, T user_data) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
if (unlikely (!sanitize_shallow (c, count))) return_trace (false);
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
if (unlikely (!arrayZ[i].sanitize (c, base, user_data)))
|
||||
return_trace (false);
|
||||
return_trace (true);
|
||||
}
|
||||
|
||||
private:
|
||||
inline bool sanitize_shallow (hb_sanitize_context_t *c, unsigned int count) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace (c->check_array (arrayZ, arrayZ[0].static_size, count));
|
||||
}
|
||||
|
||||
public:
|
||||
Type arrayZ[VAR];
|
||||
public:
|
||||
DEFINE_SIZE_ARRAY (0, arrayZ);
|
||||
};
|
||||
|
||||
/* Unsized array of offset's */
|
||||
template <typename Type, typename OffsetType>
|
||||
struct UnsizedOffsetArrayOf : UnsizedArrayOf<OffsetTo<Type, OffsetType> > {};
|
||||
|
||||
/* Unsized array of offsets relative to the beginning of the array itself. */
|
||||
template <typename Type, typename OffsetType>
|
||||
struct UnsizedOffsetListOf : UnsizedOffsetArrayOf<Type, OffsetType>
|
||||
{
|
||||
inline const Type& operator [] (unsigned int i) const
|
||||
{
|
||||
return this+this->arrayZ[i];
|
||||
}
|
||||
|
||||
inline bool sanitize (hb_sanitize_context_t *c, unsigned int count) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace ((UnsizedOffsetArrayOf<Type, OffsetType>::sanitize (c, count, this)));
|
||||
}
|
||||
template <typename T>
|
||||
inline bool sanitize (hb_sanitize_context_t *c, unsigned int count, T user_data) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace ((UnsizedOffsetArrayOf<Type, OffsetType>::sanitize (c, count, this, user_data)));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Lookup Table
|
||||
*/
|
||||
|
@ -862,6 +862,90 @@ static inline Type& operator + (Base &base, OffsetTo<Type, OffsetType> &offset)
|
||||
* Array Types
|
||||
*/
|
||||
|
||||
|
||||
/* TODO Use it in ArrayOf, HeadlessArrayOf, and other places around the code base?? */
|
||||
template <typename Type>
|
||||
struct UnsizedArrayOf
|
||||
{
|
||||
inline const Type& operator [] (unsigned int i) const { return arrayZ[i]; }
|
||||
inline Type& operator [] (unsigned int i) { return arrayZ[i]; }
|
||||
|
||||
inline bool sanitize (hb_sanitize_context_t *c, unsigned int count) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
if (unlikely (!sanitize_shallow (c, count))) return_trace (false);
|
||||
|
||||
/* Note: for structs that do not reference other structs,
|
||||
* we do not need to call their sanitize() as we already did
|
||||
* a bound check on the aggregate array size. We just include
|
||||
* a small unreachable expression to make sure the structs
|
||||
* pointed to do have a simple sanitize(), ie. they do not
|
||||
* reference other structs via offsets.
|
||||
*/
|
||||
(void) (false && arrayZ[0].sanitize (c));
|
||||
|
||||
return_trace (true);
|
||||
}
|
||||
inline bool sanitize (hb_sanitize_context_t *c, unsigned int count, const void *base) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
if (unlikely (!sanitize_shallow (c, count))) return_trace (false);
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
if (unlikely (!arrayZ[i].sanitize (c, base)))
|
||||
return_trace (false);
|
||||
return_trace (true);
|
||||
}
|
||||
template <typename T>
|
||||
inline bool sanitize (hb_sanitize_context_t *c, unsigned int count, const void *base, T user_data) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
if (unlikely (!sanitize_shallow (c, count))) return_trace (false);
|
||||
for (unsigned int i = 0; i < count; i++)
|
||||
if (unlikely (!arrayZ[i].sanitize (c, base, user_data)))
|
||||
return_trace (false);
|
||||
return_trace (true);
|
||||
}
|
||||
|
||||
private:
|
||||
inline bool sanitize_shallow (hb_sanitize_context_t *c, unsigned int count) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace (c->check_array (arrayZ, arrayZ[0].static_size, count));
|
||||
}
|
||||
|
||||
public:
|
||||
Type arrayZ[VAR];
|
||||
public:
|
||||
DEFINE_SIZE_ARRAY (0, arrayZ);
|
||||
};
|
||||
|
||||
/* Unsized array of offset's */
|
||||
template <typename Type, typename OffsetType>
|
||||
struct UnsizedOffsetArrayOf : UnsizedArrayOf<OffsetTo<Type, OffsetType> > {};
|
||||
|
||||
/* Unsized array of offsets relative to the beginning of the array itself. */
|
||||
template <typename Type, typename OffsetType>
|
||||
struct UnsizedOffsetListOf : UnsizedOffsetArrayOf<Type, OffsetType>
|
||||
{
|
||||
inline const Type& operator [] (unsigned int i) const
|
||||
{
|
||||
return this+this->arrayZ[i];
|
||||
}
|
||||
|
||||
inline bool sanitize (hb_sanitize_context_t *c, unsigned int count) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace ((UnsizedOffsetArrayOf<Type, OffsetType>::sanitize (c, count, this)));
|
||||
}
|
||||
template <typename T>
|
||||
inline bool sanitize (hb_sanitize_context_t *c, unsigned int count, T user_data) const
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
return_trace ((UnsizedOffsetArrayOf<Type, OffsetType>::sanitize (c, count, this, user_data)));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* An array with a number of elements. */
|
||||
template <typename Type, typename LenType=HBUINT16>
|
||||
struct ArrayOf
|
||||
|
@ -80,14 +80,14 @@ struct COLR
|
||||
{
|
||||
TRACE_SANITIZE (this);
|
||||
if (!(c->check_struct (this) &&
|
||||
c->check_array (&(this+layerRecordsOffsetZ), sizeof (LayerRecord), numLayerRecords) &&
|
||||
c->check_array (&(this+baseGlyphRecordsZ), sizeof (BaseGlyphRecord), numBaseGlyphRecords)))
|
||||
c->check_array (&(this+layers), sizeof (LayerRecord), numLayers) &&
|
||||
c->check_array (&(this+baseGlyphs), sizeof (BaseGlyphRecord), numBaseGlyphs)))
|
||||
return_trace (false);
|
||||
|
||||
const BaseGlyphRecord* base_glyph_records = &baseGlyphRecordsZ (this);
|
||||
for (unsigned int i = 0; i < numBaseGlyphRecords; ++i)
|
||||
const BaseGlyphRecord* base_glyph_records = (this+baseGlyphs).arrayZ;
|
||||
for (unsigned int i = 0; i < numBaseGlyphs; ++i)
|
||||
if (base_glyph_records[i].firstLayerIdx +
|
||||
base_glyph_records[i].numLayers > numLayerRecords)
|
||||
base_glyph_records[i].numLayers > numLayers)
|
||||
return_trace (false);
|
||||
|
||||
return_trace (true);
|
||||
@ -97,8 +97,8 @@ struct COLR
|
||||
unsigned int &first_layer,
|
||||
unsigned int &num_layers) const
|
||||
{
|
||||
const BaseGlyphRecord* base_glyph_records = &baseGlyphRecordsZ (this);
|
||||
unsigned int min = 0, max = numBaseGlyphRecords - 1;
|
||||
const BaseGlyphRecord* base_glyph_records = (this+baseGlyphs).arrayZ;
|
||||
unsigned int min = 0, max = numBaseGlyphs - 1;
|
||||
while (min <= max)
|
||||
{
|
||||
unsigned int mid = (min + max) / 2;
|
||||
@ -121,19 +121,19 @@ struct COLR
|
||||
hb_codepoint_t &glyph_id,
|
||||
unsigned int &palette_index) const
|
||||
{
|
||||
const LayerRecord* records = &layerRecordsOffsetZ (this);
|
||||
const LayerRecord* records = (this+layers).arrayZ;
|
||||
glyph_id = records[layer].glyphid;
|
||||
palette_index = records[layer].colorIdx;
|
||||
}
|
||||
|
||||
protected:
|
||||
HBUINT16 version; /* Table version number */
|
||||
HBUINT16 numBaseGlyphRecords; /* Number of Base Glyph Records */
|
||||
LOffsetTo<BaseGlyphRecord>
|
||||
baseGlyphRecordsZ; /* Offset to Base Glyph records. */
|
||||
LOffsetTo<LayerRecord>
|
||||
layerRecordsOffsetZ; /* Offset to Layer Records */
|
||||
HBUINT16 numLayerRecords; /* Number of Layer Records */
|
||||
HBUINT16 version; /* Table version number */
|
||||
HBUINT16 numBaseGlyphs; /* Number of Base Glyph Records */
|
||||
LOffsetTo<UnsizedArrayOf<BaseGlyphRecord> >
|
||||
baseGlyphs; /* Offset to Base Glyph records. */
|
||||
LOffsetTo<UnsizedArrayOf<LayerRecord> >
|
||||
layers; /* Offset to Layer Records */
|
||||
HBUINT16 numLayers; /* Number of Layer Records */
|
||||
public:
|
||||
DEFINE_SIZE_STATIC (14);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user