diff --git a/src/hb-ot-color-colr-table.hh b/src/hb-ot-color-colr-table.hh index 0e7f6ef23..acad25720 100644 --- a/src/hb-ot-color-colr-table.hh +++ b/src/hb-ot-color-colr-table.hh @@ -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 diff --git a/src/hb-ot-color-cpal-table.hh b/src/hb-ot-color-cpal-table.hh index 300f2cb44..94c5a3c37 100644 --- a/src/hb-ot-color-cpal-table.hh +++ b/src/hb-ot-color-cpal-table.hh @@ -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); diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc index 7588bef87..724e67261 100644 --- a/src/hb-ot-color.cc +++ b/src/hb-ot-color.cc @@ -77,32 +77,23 @@ _get_svg (hb_face_t *face) } #endif -/** - * hb_ot_color_has_cpal_data: - * @face: a font face. - * - * Returns: whether CPAL table is available. - * - * Since: REPLACEME +/* + * CPAL */ -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: + * hb_ot_color_has_palettes: * @face: a font face. * - * Returns: whether COLR table is available. + * Returns: whether CPAL table is available. * * Since: REPLACEME */ hb_bool_t -hb_ot_color_has_colr_data (hb_face_t *face) +hb_ot_color_has_palettes (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); -} diff --git a/src/hb-ot-color.h b/src/hb-ot-color.h index ab2cec981..ce289e5c7 100644 --- a/src/hb-ot-color.h +++ b/src/hb-ot-color.h @@ -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 */ diff --git a/test/api/test-ot-color.c b/test/api/test-ot-color.c index 018b47d1f..9a2ba4518 100644 --- a/test/api/test-ot-color.c +++ b/test/api/test-ot-color.c @@ -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_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_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_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