[color] Rename / reorder a bit

Implement has_data() for realz.
This commit is contained in:
Behdad Esfahbod 2018-10-21 19:23:11 -07:00
parent 9085a72deb
commit 3b3668acc8
5 changed files with 85 additions and 60 deletions

View File

@ -96,6 +96,8 @@ struct COLR
{
static const hb_tag_t tableTag = HB_OT_TAG_COLR;
inline bool has_data (void) const { return numBaseGlyphs; }
inline bool get_base_glyph_record (hb_codepoint_t glyph_id,
unsigned int *first_layer /* OUT */,
unsigned int *num_layers /* OUT */) const

View File

@ -112,6 +112,8 @@ struct CPAL
{
static const hb_tag_t tableTag = HB_OT_TAG_CPAL;
inline bool has_data (void) const { return numPalettes; }
inline bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);

View File

@ -77,8 +77,13 @@ _get_svg (hb_face_t *face)
}
#endif
/*
* CPAL
*/
/**
* hb_ot_color_has_cpal_data:
* hb_ot_color_has_palettes:
* @face: a font face.
*
* Returns: whether CPAL table is available.
@ -86,23 +91,9 @@ _get_svg (hb_face_t *face)
* Since: REPLACEME
*/
hb_bool_t
hb_ot_color_has_cpal_data (hb_face_t *face)
hb_ot_color_has_palettes (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 is available.
*
* Since: REPLACEME
*/
hb_bool_t
hb_ot_color_has_colr_data (hb_face_t *face)
{
return &_get_colr (face) != &Null(OT::COLR);
return _get_cpal (face).has_data ();
}
/**
@ -215,6 +206,43 @@ hb_ot_color_get_palette_colors (hb_face_t *face,
return cpal.get_palette_entries_count ();
}
/**
* 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: REPLACEME
*/
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);
}
/*
* COLR
*/
/**
* hb_ot_color_has_layers:
* @face: a font face.
*
* Returns: whether COLR table is available.
*
* Since: REPLACEME
*/
hb_bool_t
hb_ot_color_has_layers (hb_face_t *face)
{
return _get_colr (face).has_data ();
}
/**
* hb_ot_color_get_color_layers:
* @face: a font face.
@ -256,21 +284,3 @@ hb_ot_color_get_color_layers (hb_face_t *face,
if (likely (count)) *count = num_results;
return num_layers;
}
/**
* 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: REPLACEME
*/
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);
}

View File

@ -38,11 +38,13 @@
HB_BEGIN_DECLS
HB_EXTERN hb_bool_t
hb_ot_color_has_cpal_data (hb_face_t *face);
/*
* Color palettes.
*/
HB_EXTERN hb_bool_t
hb_ot_color_has_colr_data (hb_face_t *face);
hb_ot_color_has_palettes (hb_face_t *face);
HB_EXTERN unsigned int
hb_ot_color_get_palette_count (hb_face_t *face);
@ -60,14 +62,6 @@ hb_ot_color_get_palette_colors (hb_face_t *face,
unsigned int *color_count, /* IN/OUT. May be NULL. */
hb_color_t *colors /* OUT. May be NULL. */);
HB_EXTERN unsigned int
hb_ot_color_get_color_layers (hb_face_t *face,
hb_codepoint_t glyph,
unsigned int start_offset,
unsigned int *count, /* IN/OUT. May be NULL. */
hb_codepoint_t *glyphs, /* OUT. May be NULL. */
unsigned int *color_indices /* OUT. May be NULL. */);
/**
* hb_ot_color_palette_flags_t:
* @HB_OT_COLOR_PALETTE_FLAG_DEFAULT: default indicating that there is nothing special
@ -89,6 +83,23 @@ HB_EXTERN hb_ot_color_palette_flags_t
hb_ot_color_get_palette_flags (hb_face_t *face, unsigned int palette);
/*
* Color layers.
*/
HB_EXTERN hb_bool_t
hb_ot_color_has_layers (hb_face_t *face);
HB_EXTERN unsigned int
hb_ot_color_get_color_layers (hb_face_t *face,
hb_codepoint_t glyph,
unsigned int start_offset,
unsigned int *count, /* IN/OUT. May be NULL. */
hb_codepoint_t *glyphs, /* OUT. May be NULL. */
unsigned int *color_indices /* OUT. May be NULL. */);
HB_END_DECLS
#endif /* HB_OT_COLOR_H */

View File

@ -354,21 +354,21 @@ test_hb_ot_color_has_data (void)
{
hb_face_t *empty = hb_face_get_empty ();
g_assert (hb_ot_color_has_colr_data (empty) == FALSE);
g_assert (hb_ot_color_has_colr_data (cpal_v0) == TRUE);
g_assert (hb_ot_color_has_colr_data (cpal_v1) == TRUE);
g_assert (hb_ot_color_has_colr_data (cpal) == TRUE);
g_assert (hb_ot_color_has_colr_data (cbdt) == FALSE);
g_assert (hb_ot_color_has_colr_data (sbix) == FALSE);
g_assert (hb_ot_color_has_colr_data (svg) == FALSE);
g_assert (hb_ot_color_has_layers (empty) == FALSE);
g_assert (hb_ot_color_has_layers (cpal_v0) == TRUE);
g_assert (hb_ot_color_has_layers (cpal_v1) == TRUE);
g_assert (hb_ot_color_has_layers (cpal) == TRUE);
g_assert (hb_ot_color_has_layers (cbdt) == FALSE);
g_assert (hb_ot_color_has_layers (sbix) == FALSE);
g_assert (hb_ot_color_has_layers (svg) == FALSE);
g_assert (hb_ot_color_has_cpal_data (empty) == FALSE);
g_assert (hb_ot_color_has_cpal_data (cpal_v0) == TRUE);
g_assert (hb_ot_color_has_cpal_data (cpal_v1) == TRUE);
g_assert (hb_ot_color_has_cpal_data (cpal) == TRUE);
g_assert (hb_ot_color_has_cpal_data (cbdt) == FALSE);
g_assert (hb_ot_color_has_cpal_data (sbix) == FALSE);
g_assert (hb_ot_color_has_cpal_data (svg) == FALSE);
g_assert (hb_ot_color_has_palettes (empty) == FALSE);
g_assert (hb_ot_color_has_palettes (cpal_v0) == TRUE);
g_assert (hb_ot_color_has_palettes (cpal_v1) == TRUE);
g_assert (hb_ot_color_has_palettes (cpal) == TRUE);
g_assert (hb_ot_color_has_palettes (cbdt) == FALSE);
g_assert (hb_ot_color_has_palettes (sbix) == FALSE);
g_assert (hb_ot_color_has_palettes (svg) == FALSE);
}
int