[color] More CPAL rename

This commit is contained in:
Behdad Esfahbod 2018-10-22 14:51:40 -07:00
parent 0befb06c46
commit 69ab72e4aa
2 changed files with 54 additions and 56 deletions

View File

@ -47,46 +47,49 @@ struct CPALV1Tail
{
friend struct CPAL;
inline bool
sanitize (hb_sanitize_context_t *c, const void *base,
unsigned int palette_count, unsigned int color_count) const
{
TRACE_SANITIZE (this);
return_trace (c->check_struct (this) &&
(base+paletteFlagsZ).sanitize (c, palette_count) &&
(base+paletteLabelZ).sanitize (c, palette_count) &&
(base+paletteEntryLabelZ).sanitize (c, color_count));
}
private:
inline hb_ot_color_palette_flags_t
get_palette_flags (const void *base, unsigned int palette_index,
unsigned int palettes_count) const
get_palette_flags (const void *base,
unsigned int palette_index,
unsigned int palette_count) const
{
if (unlikely (palette_index >= palettes_count))
if (unlikely (palette_index >= palette_count))
return HB_OT_COLOR_PALETTE_FLAG_DEFAULT;
return (hb_ot_color_palette_flags_t) (uint32_t) (base+paletteFlagsZ)[palette_index];
}
inline unsigned int
get_palette_name_id (const void *base, unsigned int palette_index,
unsigned int palettes_count) const
get_palette_name_id (const void *base,
unsigned int palette_index,
unsigned int palette_count) const
{
if (unlikely (palette_index >= palettes_count))
if (unlikely (palette_index >= palette_count))
return HB_NAME_ID_INVALID;
return (base+paletteLabelZ)[palette_index];
}
inline unsigned int
get_palette_entry_name_id (const void *base, unsigned int palette_entry,
unsigned int palettes_entries_count) const
get_color_name_id (const void *base,
unsigned int color_index,
unsigned int color_count) const
{
if (unlikely (palette_entry >= palettes_entries_count))
if (unlikely (color_index >= color_count))
return HB_NAME_ID_INVALID;
return (base+paletteEntryLabelZ)[palette_entry];
return (base+paletteEntryLabelZ)[color_index];
}
public:
inline bool sanitize (hb_sanitize_context_t *c, const void *base,
unsigned int palette_count, unsigned int color_count) const
{
TRACE_SANITIZE (this);
return_trace (c->check_struct (this) &&
(base+paletteFlagsZ).sanitize (c, palette_count) &&
(base+paletteLabelZ).sanitize (c, palette_count) &&
(base+paletteEntryLabelZ).sanitize (c, color_count));
}
protected:
@ -114,31 +117,11 @@ struct CPAL
inline bool has_data (void) const { return numPalettes; }
inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
if (unlikely (!(c->check_struct (this) && /* it checks colorRecordIndices also
* See #get_size */
(this+colorRecordsZ).sanitize (c, numColorRecords))))
return_trace (false);
/* Check for indices sanity so no need for doing it runtime */
for (unsigned int i = 0; i < numPalettes; ++i)
if (unlikely (colorRecordIndicesZ[i] + numColors > 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 (likely (v1.sanitize (c, this, numPalettes, numColors)));
}
inline unsigned int get_size (void) const
{
return min_size + numPalettes * sizeof (HBUINT16);
}
{ return min_size + numPalettes * sizeof (colorRecordIndicesZ[0]); }
inline unsigned int get_palette_count () const { return numPalettes; }
inline unsigned int get_color_count () const { return numColors; }
inline hb_ot_color_palette_flags_t get_palette_flags (unsigned int palette_index) const
{
@ -158,21 +141,15 @@ struct CPAL
return cpal1.get_palette_name_id (this, palette_index, numPalettes);
}
inline unsigned int get_palette_entry_name_id (unsigned int palette_entry) const
inline unsigned int get_color_name_id (unsigned int color_index) const
{
if (unlikely (version == 0))
return HB_NAME_ID_INVALID;
const CPALV1Tail& cpal1 = StructAfter<CPALV1Tail> (*this);
return cpal1.get_palette_entry_name_id (this, palette_entry, numColors);
return cpal1.get_color_name_id (this, color_index, numColors);
}
inline unsigned int get_palette_count () const
{ return numPalettes; }
inline unsigned int get_palette_entries_count () const
{ return numColors; }
bool
get_color_record_argb (unsigned int color_index, unsigned int palette_index, hb_color_t* color) const
{
@ -186,6 +163,27 @@ struct CPAL
return true;
}
inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
if (unlikely (!(c->check_struct (this) && /* it checks colorRecordIndices also
* See #get_size */
(this+colorRecordsZ).sanitize (c, numColorRecords))))
return_trace (false);
/* Check for indices sanity so no need for doing it runtime */
for (unsigned int i = 0; i < numPalettes; ++i)
if (unlikely (colorRecordIndicesZ[i] + numColors > 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 (likely (v1.sanitize (c, this, numPalettes, numColors)));
}
protected:
HBUINT16 version; /* Table version number */
/* Version 0 */

View File

@ -145,7 +145,7 @@ hb_name_id_t
hb_ot_color_palette_color_get_name_id (hb_face_t *face,
unsigned int color_index)
{
return _get_cpal (face).get_palette_entry_name_id (color_index);
return _get_cpal (face).get_color_name_id (color_index);
}
/**
@ -208,7 +208,7 @@ hb_ot_color_palette_get_colors (hb_face_t *face,
{
unsigned int platte_count;
platte_count = MIN<unsigned int>(*colors_count,
cpal.get_palette_entries_count () - start_offset);
cpal.get_color_count () - start_offset);
for (unsigned int i = 0; i < platte_count; i++)
{
if (cpal.get_color_record_argb(start_offset + i, palette_index, &colors[num_results]))
@ -217,7 +217,7 @@ hb_ot_color_palette_get_colors (hb_face_t *face,
}
if (likely (colors_count)) *colors_count = num_results;
return cpal.get_palette_entries_count ();
return cpal.get_color_count ();
}