[CPAL] Return 0xFFFF as name id for unnamed palettes
The name id 0 is used as Copyright notice. It's quite unlikely that a font supplies a color palette with the exact same name as the font's copyright notice, but the API should not prevent this. Also, try to fix a problem with GObject introspection, where the auto-generated Python bindings could not return palette colors.
This commit is contained in:
parent
d34d3ac985
commit
5967eaba72
|
@ -82,7 +82,8 @@ hb_ot_color_get_palette_count (hb_face_t *face)
|
||||||
* Returns: an identifier within @face's `name` table.
|
* Returns: an identifier within @face's `name` table.
|
||||||
* If the requested palette has no name, or if @face has no colors,
|
* 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(),
|
* or if @palette is not between 0 and hb_ot_color_get_palette_count(),
|
||||||
* the result is zero.
|
* the result is 0xFFFF. The implementation does not check whether
|
||||||
|
* the returned palette name id is actually in @face's `name` table.
|
||||||
*
|
*
|
||||||
* Since: 1.2.8
|
* Since: 1.2.8
|
||||||
*/
|
*/
|
||||||
|
@ -92,22 +93,20 @@ hb_ot_color_get_palette_name_id (hb_face_t *face, unsigned int palette)
|
||||||
const OT::CPAL& cpal = _get_cpal(face);
|
const OT::CPAL& cpal = _get_cpal(face);
|
||||||
if (unlikely (&cpal == &OT::Null(OT::CPAL) || cpal.version == 0 ||
|
if (unlikely (&cpal == &OT::Null(OT::CPAL) || cpal.version == 0 ||
|
||||||
palette >= cpal.numPalettes)) {
|
palette >= cpal.numPalettes)) {
|
||||||
return 0;
|
return 0xFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
const OT::CPALV1Tail& cpal1 = OT::StructAfter<OT::CPALV1Tail>(cpal);
|
const OT::CPALV1Tail& cpal1 = OT::StructAfter<OT::CPALV1Tail>(cpal);
|
||||||
if (unlikely (&cpal1 == &OT::Null(OT::CPALV1Tail) ||
|
if (unlikely (&cpal1 == &OT::Null(OT::CPALV1Tail) ||
|
||||||
cpal1.paletteLabel.is_null())) {
|
cpal1.paletteLabel.is_null())) {
|
||||||
return 0;
|
return 0xFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
const OT::USHORT* name_ids = &cpal1.paletteLabel (&cpal);
|
const OT::USHORT* name_ids = &cpal1.paletteLabel (&cpal);
|
||||||
const OT::USHORT name_id = name_ids [palette];
|
const OT::USHORT name_id = name_ids [palette];
|
||||||
|
|
||||||
// According to the OpenType CPAL specification, 0xFFFF means name-less.
|
// According to the OpenType CPAL specification, 0xFFFF means name-less.
|
||||||
// We map 0xFFFF to 0 because zero is far more commonly used to indicate
|
return name_id;
|
||||||
// "no value".
|
|
||||||
return likely (name_id != 0xffff) ? name_id : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -152,7 +151,7 @@ hb_ot_color_get_palette_flags (hb_face_t *face, unsigned int palette)
|
||||||
* @color_count: (inout) (optional): on input, how many colors
|
* @color_count: (inout) (optional): on input, how many colors
|
||||||
* can be maximally stored into the @colors array;
|
* can be maximally stored into the @colors array;
|
||||||
* on output, how many colors were actually stored.
|
* on output, how many colors were actually stored.
|
||||||
* @colors: (out caller-allocates) (array length=color_count) (optional):
|
* @colors: (array length=color_count) (optional):
|
||||||
* an array of #hb_ot_color_t records. After calling
|
* an array of #hb_ot_color_t records. After calling
|
||||||
* this function, @colors will be filled with
|
* this function, @colors will be filled with
|
||||||
* the palette colors. If @colors is NULL, the function
|
* the palette colors. If @colors is NULL, the function
|
||||||
|
|
|
@ -135,19 +135,19 @@ static void
|
||||||
test_hb_ot_color_get_palette_name_id_empty (void)
|
test_hb_ot_color_get_palette_name_id_empty (void)
|
||||||
{
|
{
|
||||||
/* numPalettes=0, so all calls are for out-of-bounds palette indices */
|
/* 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), ==, 0);
|
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), ==, 0);
|
g_assert_cmpint (hb_ot_color_get_palette_name_id (hb_face_get_empty(), 1), ==, 0xffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_hb_ot_color_get_palette_name_id_v0 (void)
|
test_hb_ot_color_get_palette_name_id_v0 (void)
|
||||||
{
|
{
|
||||||
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v0, 0), ==, 0);
|
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), ==, 0);
|
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v0, 1), ==, 0xffff);
|
||||||
|
|
||||||
/* numPalettes=2, so palette #2 is out of bounds */
|
/* numPalettes=2, so palette #2 is out of bounds */
|
||||||
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v0, 2), ==, 0);
|
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v0, 2), ==, 0xffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -155,11 +155,11 @@ static void
|
||||||
test_hb_ot_color_get_palette_name_id_v1 (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, 0), ==, 257);
|
||||||
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v1, 1), ==, 0);
|
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, 2), ==, 258);
|
||||||
|
|
||||||
/* numPalettes=3, so palette #3 is out of bounds */
|
/* numPalettes=3, so palette #3 is out of bounds */
|
||||||
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v1, 3), ==, 0);
|
g_assert_cmpint (hb_ot_color_get_palette_name_id (cpal_v1, 3), ==, 0xffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue