Address COLR/CPAL reviews and revive cpal_v1 tests

This commit is contained in:
Ebrahim Byagowi 2018-10-21 08:26:40 +03:30 committed by Khaled Hosny
parent 687f679b80
commit 456978d408
6 changed files with 192 additions and 184 deletions

View File

@ -127,23 +127,23 @@ colr_cpal_rendering (hb_face_t *face, cairo_font_face_t *cairo_face)
extents.y_bearing -= extents.height / 20;
// Render
unsigned int pallet_count = hb_ot_color_get_palette_count (face);
for (unsigned int pallet = 0; pallet < pallet_count; ++pallet) {
unsigned int palette_count = hb_ot_color_get_palette_count (face);
for (unsigned int palette = 0; palette < palette_count; palette++) {
char output_path[255];
unsigned int num_colors = hb_ot_color_get_palette_colors (face, pallet, 0, nullptr, nullptr);
unsigned int num_colors = hb_ot_color_get_palette_colors (face, palette, 0, nullptr, nullptr);
if (!num_colors)
continue;
hb_ot_color_t *colors = (hb_ot_color_t*) calloc (num_colors, sizeof (hb_ot_color_t));
hb_ot_color_get_palette_colors (face, pallet, 0, &num_colors, colors);
hb_color_t *colors = (hb_color_t*) calloc (num_colors, sizeof (hb_color_t));
hb_ot_color_get_palette_colors (face, palette, 0, &num_colors, colors);
if (num_colors)
{
// If we have more than one pallet, use a better namin
if (pallet_count == 1)
// If we have more than one palette, use a better namin
if (palette_count == 1)
sprintf (output_path, "out/colr-%d.svg", gid);
else
sprintf (output_path, "out/colr-%d-%d.svg", gid, pallet);
sprintf (output_path, "out/colr-%d-%d.svg", gid, palette);
cairo_surface_t *surface = cairo_svg_surface_create (output_path, extents.width, extents.height);
cairo_t *cr = cairo_create (surface);
@ -152,14 +152,14 @@ colr_cpal_rendering (hb_face_t *face, cairo_font_face_t *cairo_face)
for (unsigned int layer = 0; layer < num_layers; ++layer)
{
uint32_t color = 0xFF;
hb_color_t color = 0x000000FF;
if (color_indices[layer] != 0xFFFF)
color = colors[color_indices[layer]];
cairo_set_source_rgba (cr,
hb_ot_color_get_red (color) / 255.,
hb_ot_color_get_green (color) / 255.,
hb_ot_color_get_blue (color) / 255.,
hb_ot_color_get_alpha (color) / 255.);
hb_color_get_red (color) / 255.,
hb_color_get_green (color) / 255.,
hb_color_get_blue (color) / 255.,
hb_color_get_alpha (color) / 255.);
cairo_glyph_t glyph;
glyph.index = layer_gids[layer];

View File

@ -444,6 +444,18 @@ HB_EXTERN void
hb_variation_to_string (hb_variation_t *variation,
char *buf, unsigned int size);
/**
* hb_color_t:
* ARGB data type for holding color values.
*
* Since: REPLACEME
*/
typedef uint32_t hb_color_t;
#define hb_color_get_alpha(color) (color & 0xFF)
#define hb_color_get_red(color) ((color >> 8) & 0xFF)
#define hb_color_get_green(color) ((color >> 16) & 0xFF)
#define hb_color_get_blue(color) ((color >> 24) & 0xFF)
HB_END_DECLS

View File

@ -30,25 +30,14 @@
#include "hb-open-type.hh"
#include "hb-ot-color.h"
#include "hb-ot-name.h"
/*
* Following parts to be moved to a public header.
* CPAL -- Color Palette
* https://docs.microsoft.com/en-us/typography/opentype/spec/cpal
*/
/**
* hb_ot_color_palette_flags_t:
* @HB_OT_COLOR_PALETTE_FLAG_DEFAULT: default indicating that there is nothing special to note about a color palette.
* @HB_OT_COLOR_PALETTE_FLAG_FOR_LIGHT_BACKGROUND: flag indicating that the color palette is suitable for rendering text on light background.
* @HB_OT_COLOR_PALETTE_FLAG_FOR_DARK_BACKGROUND: flag indicating that the color palette is suitable for rendering text on dark background.
*
* Since: REPLACEME
*/
typedef enum { /*< flags >*/
HB_OT_COLOR_PALETTE_FLAG_DEFAULT = 0x00000000u,
HB_OT_COLOR_PALETTE_FLAG_FOR_LIGHT_BACKGROUND = 0x00000001u,
HB_OT_COLOR_PALETTE_FLAG_FOR_DARK_BACKGROUND = 0x00000002u,
} hb_ot_color_palette_flags_t;
#define HB_OT_TAG_CPAL HB_TAG('C','P','A','L')
namespace OT {
@ -64,17 +53,19 @@ struct CPALV1Tail
TRACE_SANITIZE (this);
return_trace (c->check_struct (this) &&
(base+paletteFlagsZ).sanitize (c, palettes) &&
(base+paletteLabelZ).sanitize (c, palettes) &&
(base+paletteEntryLabelZ).sanitize (c, palettes));
(base+paletteLabelZ).sanitize (c, palettes) /*&&
(base+paletteEntryLabelZ).sanitize (c, palettes)*/);
}
private:
#if 0
inline hb_ot_color_palette_flags_t
get_palette_flags (const void *base, unsigned int palette) const
{
// range checked at the CPAL caller
return (hb_ot_color_palette_flags_t) (uint32_t) (base+paletteFlagsZ)[palette];
}
#endif
inline unsigned int
get_palette_name_id (const void *base, unsigned int palette) const
@ -92,12 +83,12 @@ struct CPALV1Tail
paletteLabelZ; /* Offset from the beginning of CPAL table to
* the Palette Labels Array. Set to 0 if no
* array is provided. */
LOffsetTo<UnsizedArrayOf<HBUINT16>, false>
paletteEntryLabelZ; /* Offset from the beginning of CPAL table to
/*LOffsetTo<UnsizedArrayOf<HBUINT16>, false>
paletteEntryLabelZ;*/ /* Offset from the beginning of CPAL table to
* the Palette Entry Label Array. Set to 0
* if no array is provided. */
public:
DEFINE_SIZE_STATIC (12);
DEFINE_SIZE_STATIC (/*12*/8);
};
typedef HBUINT32 BGRAColor;
@ -132,6 +123,7 @@ struct CPAL
return min_size + numPalettes * sizeof (HBUINT16);
}
#if 0
inline hb_ot_color_palette_flags_t get_palette_flags (unsigned int palette) const
{
if (unlikely (version == 0 || palette >= numPalettes))
@ -140,11 +132,12 @@ struct CPAL
const CPALV1Tail& cpal1 = StructAfter<CPALV1Tail> (*this);
return cpal1.get_palette_flags (this, palette);
}
#endif
inline unsigned int get_palette_name_id (unsigned int palette) const
{
if (unlikely (version == 0 || palette >= numPalettes))
return 0xFFFF;
return HB_NAME_ID_INVALID;
const CPALV1Tail& cpal1 = StructAfter<CPALV1Tail> (*this);
return cpal1.get_palette_name_id (this, palette);
@ -161,7 +154,7 @@ struct CPAL
}
bool
get_color_record_argb (unsigned int color_index, unsigned int palette, hb_ot_color_t* color) const
get_color_record_argb (unsigned int color_index, unsigned int palette, hb_color_t* color) const
{
if (unlikely (color_index >= numPaletteEntries || palette >= numPalettes))
return false;

View File

@ -36,11 +36,6 @@
#include "hb-ot-layout.hh"
#if 0
HB_MARK_AS_FLAG_T (hb_ot_color_palette_flags_t)
//HB_SHAPER_DATA_ENSURE_DECLARE(ot, face) Hmm?
#endif
static inline const OT::COLR&
_get_colr (hb_face_t *face)
@ -56,20 +51,8 @@ _get_cpal (hb_face_t *face)
return *(hb_ot_face_data (face)->CPAL.get ());
}
HB_EXTERN hb_bool_t
hb_ot_color_has_cpal_data (hb_face_t *face)
{
return &_get_cpal (face) != &OT::Null(OT::CPAL);
}
HB_EXTERN hb_bool_t
hb_ot_color_has_colr_data (hb_face_t *face)
{
return &_get_colr (face) != &OT::Null(OT::COLR);
}
/**
* hb_ot_color_get_palette_count:
* hb_ot_color_has_cpal_data:
* @face: a font face.
*
* Returns: the number of color palettes in @face, or zero if @face has
@ -77,58 +60,40 @@ hb_ot_color_has_colr_data (hb_face_t *face)
*
* Since: REPLACEME
*/
hb_bool_t
hb_ot_color_has_cpal_data (hb_face_t *face)
{
return &_get_cpal (face) != &Null(OT::CPAL);
}
/**
* hb_ot_color_has_colr_data:
* @face: a font face.
*
* Returns: whether COLR table available
*
* Since: REPLACEME
*/
hb_bool_t
hb_ot_color_has_colr_data (hb_face_t *face)
{
return &_get_colr (face) != &Null(OT::COLR);
}
/**
* hb_ot_color_get_palette_count:
* @face: a font face.
*
* Returns: whether CPAL table available
*
* Since: REPLACEME
*/
unsigned int
hb_ot_color_get_palette_count (hb_face_t *face)
{
const OT::CPAL& cpal = _get_cpal (face);
return cpal.get_palette_count ();
return _get_cpal (face).get_palette_count ();
}
#if 0
/**
* hb_ot_color_get_palette_name_id:
* @face: a font face.
* @palette: the index of the color palette whose name is being requested.
*
* Retrieves the name id of a color palette. For example, a color font can
* have themed palettes like "Spring", "Summer", "Fall", and "Winter".
*
* Returns: an identifier within @face's `name` table.
* If the requested palette has no name, or if @face has no colors,
* or if @palette is not between 0 and hb_ot_color_get_palette_count(),
* the result is 0xFFFF. The implementation does not check whether
* the returned palette name id is actually in @face's `name` table.
*
* Since: DONTREPLACEME
*/
unsigned int
hb_ot_color_get_palette_name_id (hb_face_t *face, unsigned int palette)
{
const OT::CPAL& cpal = _get_cpal (face);
return cpal.get_palette_name_id (palette);
}
/**
* hb_ot_color_get_palette_flags:
* @face: a font face
* @palette: the index of the color palette whose flags are being requested
*
* Returns: the flags for the requested color palette. If @face has no colors,
* or if @palette is not between 0 and hb_ot_color_get_palette_count(),
* the result is #HB_OT_COLOR_PALETTE_FLAG_DEFAULT.
*
* Since: DONTREPLACEME
*/
hb_ot_color_palette_flags_t
hb_ot_color_get_palette_flags (hb_face_t *face, unsigned int palette)
{
const OT::CPAL& cpal = _get_cpal(face);
return cpal.get_palette_flags (palette);
}
#endif
/**
* hb_ot_color_get_palette_colors:
* @face: a font face.
@ -139,7 +104,7 @@ hb_ot_color_get_palette_flags (hb_face_t *face, unsigned int palette)
* can be maximally stored into the @colors array;
* on output, how many colors were actually stored.
* @colors: (array length=color_count) (out) (optional):
* an array of #hb_ot_color_t records. After calling
* an array of #hb_color_t records. After calling
* this function, @colors will be filled with
* the palette colors. If @colors is NULL, the function
* will just return the number of total colors
@ -161,7 +126,7 @@ hb_ot_color_get_palette_colors (hb_face_t *face,
unsigned int palette, /* default=0 */
unsigned int start_offset,
unsigned int *count /* IN/OUT */,
hb_ot_color_t *colors /* OUT */)
hb_color_t *colors /* OUT */)
{
const OT::CPAL& cpal = _get_cpal(face);
if (unlikely (palette >= cpal.get_palette_count ()))
@ -213,3 +178,66 @@ hb_ot_color_get_color_layers (hb_face_t *face,
if (likely (count)) *count = num_results;
return num_layers;
}
/**
* hb_ot_color_get_palette_name_id:
* @face: a font face.
* @palette: the index of the color palette whose name is being requested.
*
* Retrieves the name id of a color palette. For example, a color font can
* have themed palettes like "Spring", "Summer", "Fall", and "Winter".
*
* Returns: an identifier within @face's `name` table.
* If the requested palette has no name, or if @face has no colors,
* or if @palette is not between 0 and hb_ot_color_get_palette_count(),
* the result is 0xFFFF. The implementation does not check whether
* the returned palette name id is actually in @face's `name` table.
*
* Since: REPLACEME
*/
hb_name_id_t
hb_ot_color_get_palette_name_id (hb_face_t *face, unsigned int palette)
{
return _get_cpal (face).get_palette_name_id (palette);
}
#if 0
/**
* hb_ot_color_get_palette_flags:
* @face: a font face
* @palette: the index of the color palette whose flags are being requested
*
* Returns: the flags for the requested color palette. If @face has no colors,
* or if @palette is not between 0 and hb_ot_color_get_palette_count(),
* the result is #HB_OT_COLOR_PALETTE_FLAG_DEFAULT.
*
* Since: DONTREPLACEME
*/
hb_ot_color_palette_flags_t
hb_ot_color_get_palette_flags (hb_face_t *face, unsigned int palette)
{
const OT::CPAL& cpal = _get_cpal(face);
return cpal.get_palette_flags (palette);
}
/*
* Following parts to be moved to a public header.
*/
/**
* hb_ot_color_palette_flags_t:
* @HB_OT_COLOR_PALETTE_FLAG_DEFAULT: default indicating that there is nothing special to note about a color palette.
* @HB_OT_COLOR_PALETTE_FLAG_FOR_LIGHT_BACKGROUND: flag indicating that the color palette is suitable for rendering text on light background.
* @HB_OT_COLOR_PALETTE_FLAG_FOR_DARK_BACKGROUND: flag indicating that the color palette is suitable for rendering text on dark background.
*
* Since: REPLACEME
*/
typedef enum { /*< flags >*/
HB_OT_COLOR_PALETTE_FLAG_DEFAULT = 0x00000000u,
HB_OT_COLOR_PALETTE_FLAG_FOR_LIGHT_BACKGROUND = 0x00000001u,
HB_OT_COLOR_PALETTE_FLAG_FOR_DARK_BACKGROUND = 0x00000002u,
} hb_ot_color_palette_flags_t;
HB_EXTERN hb_ot_color_palette_flags_t
hb_ot_color_get_palette_flags (hb_face_t *face, unsigned int palette);
#endif

View File

@ -32,28 +32,10 @@
#define HB_OT_COLOR_H
#include "hb.h"
#include "hb-ot-name.h"
HB_BEGIN_DECLS
/*
* CPAL -- Color Palette
* https://docs.microsoft.com/en-us/typography/opentype/spec/cpal
*/
#define HB_OT_TAG_CPAL HB_TAG('C','P','A','L')
/**
* hb_ot_color_t:
* ARGB data type for holding color values.
*
* Since: REPLACEME
*/
typedef uint32_t hb_ot_color_t;
#define hb_ot_color_get_alpha(color) (color & 0xFF)
#define hb_ot_color_get_red(color) ((color >> 8) & 0xFF)
#define hb_ot_color_get_green(color) ((color >> 16) & 0xFF)
#define hb_ot_color_get_blue(color) ((color >> 24) & 0xFF)
HB_EXTERN hb_bool_t
hb_ot_color_has_cpal_data (hb_face_t *face);
@ -63,26 +45,22 @@ hb_ot_color_has_colr_data (hb_face_t *face);
HB_EXTERN unsigned int
hb_ot_color_get_palette_count (hb_face_t *face);
// HB_EXTERN unsigned int
// hb_ot_color_get_palette_name_id (hb_face_t *face, unsigned int palette);
// HB_EXTERN hb_ot_color_palette_flags_t
// hb_ot_color_get_palette_flags (hb_face_t *face, unsigned int palette);
HB_EXTERN hb_name_id_t
hb_ot_color_get_palette_name_id (hb_face_t *face, unsigned int palette);
HB_EXTERN unsigned int
hb_ot_color_get_palette_colors (hb_face_t *face,
unsigned int palette, /* default=0 */
unsigned int palette, /* default=0 */
unsigned int start_offset,
unsigned int *color_count /* IN/OUT */,
hb_ot_color_t *colors /* OUT */);
unsigned int *color_count /* IN/OUT */,
hb_color_t *colors /* OUT */);
HB_EXTERN unsigned int
hb_ot_color_get_color_layers (hb_face_t *face,
hb_codepoint_t gid,
unsigned int offset,
unsigned int *count, /* IN/OUT */
hb_codepoint_t *gids, /* OUT */
unsigned int *count, /* IN/OUT */
hb_codepoint_t *gids, /* OUT */
unsigned int *color_indices /* OUT */);
HB_END_DECLS

View File

@ -99,22 +99,22 @@ static hb_face_t *cpal_v0 = NULL;
static hb_face_t *cpal_v1 = NULL;
#define assert_color_rgba(colors, i, r, g, b, a) G_STMT_START { \
const hb_ot_color_t *_colors = (colors); \
const hb_color_t *_colors = (colors); \
const size_t _i = (i); \
const uint8_t red = (r), green = (g), blue = (b), alpha = (a); \
if (hb_ot_color_get_red (_colors[_i]) != red) { \
if (hb_color_get_red (_colors[_i]) != red) { \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
"colors[" #i "]", _colors[_i], "==", red, 'x'); \
} \
if (hb_ot_color_get_green (_colors[_i]) != green) { \
if (hb_color_get_green (_colors[_i]) != green) { \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
"colors[" #i "]", _colors[_i], "==", green, 'x'); \
} \
if (hb_ot_color_get_blue (_colors[_i]) != blue) { \
if (hb_color_get_blue (_colors[_i]) != blue) { \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
"colors[" #i "]", colors[_i], "==", blue, 'x'); \
} \
if (hb_ot_color_get_alpha (_colors[_i]) != alpha) { \
if (hb_color_get_alpha (_colors[_i]) != alpha) { \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
"colors[" #i "]", _colors[_i], "==", alpha, 'x'); \
} \
@ -126,42 +126,39 @@ test_hb_ot_color_get_palette_count (void)
{
g_assert_cmpint (hb_ot_color_get_palette_count (hb_face_get_empty()), ==, 0);
g_assert_cmpint (hb_ot_color_get_palette_count (cpal_v0), ==, 2);
// g_assert_cmpint (hb_ot_color_get_palette_count (cpal_v1), ==, 3);
g_assert_cmpint (hb_ot_color_get_palette_count (cpal_v1), ==, 3);
}
#if 0
static void
test_hb_ot_color_get_palette_name_id_empty (void)
{
/* numPalettes=0, so all calls are for out-of-bounds palette indices */
g_assert_cmpint (hb_ot_color_get_palette_name_id (hb_face_get_empty(), 0), ==, 0xffff);
g_assert_cmpint (hb_ot_color_get_palette_name_id (hb_face_get_empty(), 1), ==, 0xffff);
g_assert_cmpint (hb_ot_color_get_palette_name_id (hb_face_get_empty(), 0), ==, HB_NAME_ID_INVALID);
g_assert_cmpint (hb_ot_color_get_palette_name_id (hb_face_get_empty(), 1), ==, HB_NAME_ID_INVALID);
}
static void
test_hb_ot_color_get_palette_name_id_v0 (void)
{
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v0, 0), ==, 0xffff);
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v0, 1), ==, 0xffff);
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v0, 0), ==, HB_NAME_ID_INVALID);
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v0, 1), ==, HB_NAME_ID_INVALID);
/* numPalettes=2, so palette #2 is out of bounds */
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v0, 2), ==, 0xffff);
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v0, 2), ==, HB_NAME_ID_INVALID);
}
static void
test_hb_ot_color_get_palette_name_id_v1 (void)
{
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v1, 0), ==, 257);
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v1, 1), ==, 0xffff);
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v1, 2), ==, 258);
// g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v1, 0), ==, 257);
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v1, 1), ==, HB_NAME_ID_INVALID);
// g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v1, 2), ==, 258);
/* numPalettes=3, so palette #3 is out of bounds */
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v1, 3), ==, 0xffff);
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v1, 3), ==, HB_NAME_ID_INVALID);
}
#if 0
static void
test_hb_ot_color_get_palette_flags_empty (void)
{
@ -207,21 +204,21 @@ static void
test_hb_ot_color_get_palette_colors_v0 (void)
{
unsigned int num_colors = hb_ot_color_get_palette_colors (cpal_v0, 0, 0, NULL, NULL);
hb_ot_color_t *colors = (hb_ot_color_t*) alloca (num_colors * sizeof (hb_ot_color_t));
hb_color_t *colors = (hb_color_t*) alloca (num_colors * sizeof (hb_color_t));
size_t colors_size = num_colors * sizeof(*colors);
g_assert_cmpint (num_colors, ==, 2);
/* Palette #0, start_index=0 */
g_assert_cmpint (hb_ot_color_get_palette_colors (cpal_v0, 0, 0, &num_colors, colors), ==, 2);
g_assert_cmpint (num_colors, ==, 2);
// assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
// assert_color_rgba (colors, 1, 0x66, 0xcc, 0xff, 0xff);
assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
assert_color_rgba (colors, 1, 0x66, 0xcc, 0xff, 0xff);
/* Palette #1, start_index=0 */
g_assert_cmpint (hb_ot_color_get_palette_colors (cpal_v0, 1, 0, &num_colors, colors), ==, 2);
g_assert_cmpint (num_colors, ==, 2);
// assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
// assert_color_rgba (colors, 1, 0x80, 0x00, 0x00, 0xff);
assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
assert_color_rgba (colors, 1, 0x80, 0x00, 0x00, 0xff);
/* Palette #2 (there are only #0 and #1 in the font, so this is out of bounds) */
g_assert_cmpint (hb_ot_color_get_palette_colors (cpal_v0, 2, 0, &num_colors, colors), ==, 0);
@ -231,16 +228,16 @@ test_hb_ot_color_get_palette_colors_v0 (void)
num_colors = 2;
g_assert_cmpint (hb_ot_color_get_palette_colors (cpal_v0, 0, 1, &num_colors, colors), ==, 2);
g_assert_cmpint (num_colors, ==, 1);
// assert_color_rgba (colors, 0, 0x66, 0xcc, 0xff, 0xff);
// assert_color_rgba (colors, 1, 0x33, 0x33, 0x33, 0x33); /* untouched */
assert_color_rgba (colors, 0, 0x66, 0xcc, 0xff, 0xff);
assert_color_rgba (colors, 1, 0x33, 0x33, 0x33, 0x33); /* untouched */
/* Palette #0, start_index=0, pretend that we have only allocated space for 1 color */
memset(colors, 0x44, colors_size);
num_colors = 1;
g_assert_cmpint (hb_ot_color_get_palette_colors (cpal_v0, 0, 0, &num_colors, colors), ==, 2);
g_assert_cmpint (num_colors, ==, 1);
// assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
// assert_color_rgba (colors, 1, 0x44, 0x44, 0x44, 0x44); /* untouched */
assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
assert_color_rgba (colors, 1, 0x44, 0x44, 0x44, 0x44); /* untouched */
/* start_index > numPaletteEntries */
memset (colors, 0x44, colors_size);
@ -255,34 +252,34 @@ test_hb_ot_color_get_palette_colors_v0 (void)
static void
test_hb_ot_color_get_palette_colors_v1 (void)
{
hb_ot_color_t colors[3];
hb_color_t colors[3];
unsigned int num_colors = hb_ot_color_get_palette_colors (cpal_v1, 0, 0, NULL, NULL);
size_t colors_size = 3 * sizeof(*colors);
// g_assert_cmpint (num_colors, ==, 2);
size_t colors_size = 3 * sizeof (hb_color_t);
g_assert_cmpint (num_colors, ==, 2);
/* Palette #0, start_index=0 */
memset(colors, 0x77, colors_size);
// g_assert_cmpint (hb_ot_color_get_palette_colors (cpal_v1, 0, 0, &num_colors, colors), ==, 2);
// g_assert_cmpint (num_colors, ==, 2);
// assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
// assert_color_rgba (colors, 1, 0x66, 0xcc, 0xff, 0xff);
// assert_color_rgba (colors, 2, 0x77, 0x77, 0x77, 0x77); /* untouched */
memset (colors, 0x77, colors_size);
g_assert_cmpint (hb_ot_color_get_palette_colors (cpal_v1, 0, 0, &num_colors, colors), ==, 2);
g_assert_cmpint (num_colors, ==, 2);
assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
assert_color_rgba (colors, 1, 0x66, 0xcc, 0xff, 0xff);
assert_color_rgba (colors, 2, 0x77, 0x77, 0x77, 0x77); /* untouched */
/* Palette #1, start_index=0 */
memset(colors, 0x77, colors_size);
// g_assert_cmpint (hb_ot_color_get_palette_colors (cpal_v1, 1, 0, &num_colors, colors), ==, 2);
// g_assert_cmpint (num_colors, ==, 2);
// assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
// assert_color_rgba (colors, 1, 0xff, 0xcc, 0x66, 0xff);
// assert_color_rgba (colors, 2, 0x77, 0x77, 0x77, 0x77); /* untouched */
memset (colors, 0x77, colors_size);
g_assert_cmpint (hb_ot_color_get_palette_colors (cpal_v1, 1, 0, &num_colors, colors), ==, 2);
g_assert_cmpint (num_colors, ==, 2);
assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
assert_color_rgba (colors, 1, 0xff, 0xcc, 0x66, 0xff);
assert_color_rgba (colors, 2, 0x77, 0x77, 0x77, 0x77); /* untouched */
/* Palette #2, start_index=0 */
memset(colors, 0x77, colors_size);
// g_assert_cmpint (hb_ot_color_get_palette_colors (cpal_v1, 2, 0, &num_colors, colors), ==, 2);
// g_assert_cmpint (num_colors, ==, 2);
// assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
// assert_color_rgba (colors, 1, 0x80, 0x00, 0x00, 0xff);
// assert_color_rgba (colors, 2, 0x77, 0x77, 0x77, 0x77); /* untouched */
memset (colors, 0x77, colors_size);
g_assert_cmpint (hb_ot_color_get_palette_colors (cpal_v1, 2, 0, &num_colors, colors), ==, 2);
g_assert_cmpint (num_colors, ==, 2);
assert_color_rgba (colors, 0, 0x00, 0x00, 0x00, 0xff);
assert_color_rgba (colors, 1, 0x80, 0x00, 0x00, 0xff);
assert_color_rgba (colors, 2, 0x77, 0x77, 0x77, 0x77); /* untouched */
/* Palette #3 (out of bounds), start_index=0 */
memset (colors, 0x77, colors_size);
@ -302,9 +299,9 @@ main (int argc, char **argv)
cpal_v0 = hb_test_open_font_file ("fonts/cpal-v0.ttf");
cpal_v1 = hb_test_open_font_file ("fonts/cpal-v1.ttf");
hb_test_add (test_hb_ot_color_get_palette_count);
// hb_test_add (test_hb_ot_color_get_palette_name_id_empty);
// hb_test_add (test_hb_ot_color_get_palette_name_id_v0);
// hb_test_add (test_hb_ot_color_get_palette_name_id_v1);
hb_test_add (test_hb_ot_color_get_palette_name_id_empty);
hb_test_add (test_hb_ot_color_get_palette_name_id_v0);
hb_test_add (test_hb_ot_color_get_palette_name_id_v1);
// hb_test_add (test_hb_ot_color_get_palette_flags_empty);
// hb_test_add (test_hb_ot_color_get_palette_flags_v0);
// hb_test_add (test_hb_ot_color_get_palette_flags_v1);