Skip to content

Commit

Permalink
Merge c63b856 into a3e29fd
Browse files Browse the repository at this point in the history
  • Loading branch information
ebraminio committed Mar 4, 2018
2 parents a3e29fd + c63b856 commit 5708d20
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 58 deletions.
16 changes: 7 additions & 9 deletions src/hb-ot-color-colr-table.hh
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,24 @@ struct COLR
{
TRACE_SANITIZE (this);
if (!(c->check_struct (this) &&
c->check_array ((const void*) &layerRecordsOffset, sizeof (LayerRecord), numLayerRecords) &&
c->check_array ((const void*) &baseGlyphRecords, sizeof (BaseGlyphRecord), numBaseGlyphRecords)))
c->check_array ((const void*) &layerRecordsOffsetZ, sizeof (LayerRecord), numLayerRecords) &&
c->check_array ((const void*) &baseGlyphRecordsZ, sizeof (BaseGlyphRecord), numBaseGlyphRecords)))
return_trace (false);

const BaseGlyphRecord* base_glyph_records = &baseGlyphRecords (this);
const BaseGlyphRecord* base_glyph_records = &baseGlyphRecordsZ (this);
for (unsigned int i = 0; i < numBaseGlyphRecords; ++i)
if (base_glyph_records[i].firstLayerIndex +
base_glyph_records[i].numLayers > numLayerRecords)
return_trace (false);

/* XXX values of LayerRecord structs should be sanitized */

return_trace (true);
}

inline const bool get_base_glyph_record (
hb_codepoint_t glyph_id, unsigned int &first_layer, unsigned int &num_layers) const
{
/* TODO replace with bsearch */
const BaseGlyphRecord* base_glyph_records = &baseGlyphRecords (this);
const BaseGlyphRecord* base_glyph_records = &baseGlyphRecordsZ (this);
unsigned int records = numBaseGlyphRecords;
for (unsigned int i = 0; i < records; ++i)
if (base_glyph_records[i].gID == glyph_id)
Expand All @@ -114,7 +112,7 @@ struct COLR
inline void get_layer_record (int layer,
hb_codepoint_t &glyph_id, unsigned int &palette_index) const
{
const LayerRecord* records = &layerRecordsOffset (this);
const LayerRecord* records = &layerRecordsOffsetZ (this);
glyph_id = records[layer].gID;
palette_index = records[layer].paletteIndex;
}
Expand All @@ -123,9 +121,9 @@ struct COLR
HBUINT16 version; /* Table version number */
HBUINT16 numBaseGlyphRecords; /* Number of Base Glyph Records */
LOffsetTo<BaseGlyphRecord>
baseGlyphRecords; /* Offset to Base Glyph records. */
baseGlyphRecordsZ; /* Offset to Base Glyph records. */
LOffsetTo<LayerRecord>
layerRecordsOffset; /* Offset to Layer Records */
layerRecordsOffsetZ; /* Offset to Layer Records */
HBUINT16 numLayerRecords; /* Number of Layer Records */
public:
DEFINE_SIZE_STATIC (14);
Expand Down
59 changes: 20 additions & 39 deletions src/hb-ot-color-cpal-table.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,6 @@
namespace OT {


struct ColorRecord
{
friend struct CPAL;

inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
return_trace (true);
}

protected:
HBUINT8 blue;
HBUINT8 green;
HBUINT8 red;
HBUINT8 alpha;
public:
DEFINE_SIZE_STATIC (4);
};

struct CPALV1Tail
{
friend struct CPAL;
Expand Down Expand Up @@ -96,36 +77,35 @@ struct CPALV1Tail
DEFINE_SIZE_STATIC (12);
};

typedef HBUINT32 BGRAColor;

struct CPAL
{
static const hb_tag_t tableTag = HB_OT_TAG_CPAL;

inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
if (!(c->check_struct (this) &&
colorRecords.sanitize (c)))
return_trace (false);

unsigned int palettes = numPalettes;
if (!c->check_array (colorRecordIndices, sizeof (HBUINT16), palettes))
if (!(c->check_struct (this) && // This checks colorRecordIndicesX sanity also, see #get_size
c->check_array ((const void*) &colorRecordsZ, sizeof (BGRAColor), numColorRecords)))
return_trace (false);

for (unsigned int i = 0; i < palettes; ++i)
if (colorRecordIndices[i] + numPaletteEntries > colorRecords.get_size ())
// Check for indices sanity so no need for doing it runtime
for (unsigned int i = 0; i < numPalettes; ++i)
if (colorRecordIndicesX[i] + numPaletteEntries > numColorRecords)
return_trace (false);

// If version is zero, we are done here; otherwise we need to check tail also
if (version == 0)
return_trace (true);

const CPALV1Tail &v1 = StructAfter<CPALV1Tail> (*this);
return_trace (v1.sanitize (c, palettes));
return_trace (v1.sanitize (c, numPalettes));
}

inline unsigned int get_size (void) const
{
return min_size + numPalettes * 2;
return min_size + numPalettes * sizeof (HBUINT16);
}

inline hb_ot_color_palette_flags_t get_palette_flags (unsigned int palette) const
Expand All @@ -151,26 +131,27 @@ struct CPAL
return numPalettes;
}

inline void get_color_record (int palette_index, uint8_t &r, uint8_t &g,
uint8_t &b, uint8_t &a) const
inline hb_ot_color_t get_color_record_argb (unsigned int color_index, unsigned int palette) const
{
// We should check if palette_index is in range as it is not done on COLR sanitization
r = colorRecords[palette_index].red;
g = colorRecords[palette_index].green;
b = colorRecords[palette_index].blue;
a = colorRecords[palette_index].alpha;
if (color_index >= numPaletteEntries || palette >= numPalettes)
return 0;

const BGRAColor* records = &colorRecordsZ(this);
// No need for more range check as it is already done on #sanitize
return records[colorRecordIndicesX[palette] + color_index];
}

protected:
HBUINT16 version;
/* Version 0 */
HBUINT16 numPaletteEntries;
HBUINT16 numPalettes;
ArrayOf<ColorRecord> colorRecords;
HBUINT16 colorRecordIndices[VAR]; // VAR=numPalettes
HBUINT16 numColorRecords;
LOffsetTo<HBUINT32> colorRecordsZ;
HBUINT16 colorRecordIndicesX[VAR]; // VAR=numPalettes
/*CPALV1Tail v1[VAR];*/
public:
DEFINE_SIZE_ARRAY (12, colorRecordIndices);
DEFINE_SIZE_ARRAY (12, colorRecordIndicesX);
};

} /* namespace OT */
Expand Down
12 changes: 2 additions & 10 deletions src/hb-ot-color.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,11 @@ HB_BEGIN_DECLS

/**
* hb_ot_color_t:
* @red: the intensity of the red channel
* @green: the intensity of the green channel
* @blue: the intensity of the blue channel
* @alpha: the transparency
*
* Structure for holding color values.
* ARGB data type for holding color values.
*
* Since: REPLACEME
*/
typedef struct
{
uint8_t red, green, blue, alpha;
} hb_ot_color_t;
typedef uint32_t hb_ot_color_t;


/**
Expand Down

0 comments on commit 5708d20

Please sign in to comment.