From 1de17bdb80b0668f4d4a4700e3f80c8caee3303d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 22 Oct 2018 10:29:01 -0700 Subject: [PATCH] [colr] Add hb_ot_color_layer_t We never return parallel arrays from functions. That's inconvenient and hard to bind. --- src/hb-ot-color.cc | 18 ++++++++---------- src/hb-ot-color.h | 22 ++++++++++++++++------ test/api/test-ot-color.c | 33 +++++++++++++++------------------ 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/src/hb-ot-color.cc b/src/hb-ot-color.cc index 724e67261..2672d0a31 100644 --- a/src/hb-ot-color.cc +++ b/src/hb-ot-color.cc @@ -244,25 +244,23 @@ hb_ot_color_has_layers (hb_face_t *face) } /** - * hb_ot_color_get_color_layers: + * hb_ot_color_glyph_get_layers: * @face: a font face. * @glyph: * @start_offset: * @count: (inout) (optional): - * @glyphs: (array length=count) (out) (optional): - * @color_indices: (array length=count) (out) (optional): + * @layers: (array length=count) (out) (optional): * * Returns: * * Since: REPLACEME */ 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_glyph_get_layers (hb_face_t *face, + hb_codepoint_t glyph, + unsigned int start_offset, + unsigned int *count, /* IN/OUT. May be NULL. */ + hb_ot_color_layer_t *layers /* OUT. May be NULL. */) { const OT::COLR& colr = _get_colr (face); unsigned int num_results = 0; @@ -275,7 +273,7 @@ hb_ot_color_get_color_layers (hb_face_t *face, for (unsigned int i = 0; i < layer_count; i++) { if (colr.get_layer_record (start_layer_index + start_offset + i, - &glyphs[num_results], &color_indices[num_results])) + &layers[num_results].glyph, &layers[num_results].color_index)) ++num_results; } } diff --git a/src/hb-ot-color.h b/src/hb-ot-color.h index ce289e5c7..e01fafac4 100644 --- a/src/hb-ot-color.h +++ b/src/hb-ot-color.h @@ -91,13 +91,23 @@ hb_ot_color_get_palette_flags (hb_face_t *face, unsigned int palette); HB_EXTERN hb_bool_t hb_ot_color_has_layers (hb_face_t *face); +/** + * hb_ot_color_layer_t: + * + * Since: REPLACEME + **/ +typedef struct hb_ot_color_layer_t +{ + hb_codepoint_t glyph; + unsigned int color_index; +} hb_ot_color_layer_t; + 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_glyph_get_layers (hb_face_t *face, + hb_codepoint_t glyph, + unsigned int start_offset, + unsigned int *count, /* IN/OUT. May be NULL. */ + hb_ot_color_layer_t *layers /* OUT. May be NULL. */); HB_END_DECLS diff --git a/test/api/test-ot-color.c b/test/api/test-ot-color.c index 9a2ba4518..5da026315 100644 --- a/test/api/test-ot-color.c +++ b/test/api/test-ot-color.c @@ -317,36 +317,33 @@ test_hb_ot_color_get_palette_entry_name_id (void) static void -test_hb_ot_color_get_color_layers (void) +test_hb_ot_color_glyph_get_layers (void) { - hb_codepoint_t layer_gids[1]; - unsigned int color_indices[1]; + hb_ot_color_layer_t layers[1]; unsigned int count = 1; - g_assert_cmpuint (hb_ot_color_get_color_layers (cpal_v1, 0, 0, - NULL, NULL, NULL), ==, 0); - g_assert_cmpuint (hb_ot_color_get_color_layers (cpal_v1, 1, 0, - NULL, NULL, NULL), ==, 0); - g_assert_cmpuint (hb_ot_color_get_color_layers (cpal_v1, 2, 0, - NULL, NULL, NULL), ==, 2); + g_assert_cmpuint (hb_ot_color_glyph_get_layers (cpal_v1, 0, 0, + NULL, NULL), ==, 0); + g_assert_cmpuint (hb_ot_color_glyph_get_layers (cpal_v1, 1, 0, + NULL, NULL), ==, 0); + g_assert_cmpuint (hb_ot_color_glyph_get_layers (cpal_v1, 2, 0, + NULL, NULL), ==, 2); unsigned int num_layers; - num_layers = hb_ot_color_get_color_layers (cpal_v1, 2, 0, &count, layer_gids, - color_indices); + num_layers = hb_ot_color_glyph_get_layers (cpal_v1, 2, 0, &count, layers); g_assert_cmpuint (num_layers, ==, 2); g_assert_cmpuint (count, ==, 1); - g_assert_cmpuint (layer_gids[0], ==, 3); - g_assert_cmpuint (color_indices[0], ==, 1); + g_assert_cmpuint (layers[0].glyph, ==, 3); + g_assert_cmpuint (layers[0].color_index, ==, 1); count = 1; - hb_ot_color_get_color_layers (cpal_v1, 2, 1, &count, layer_gids, - color_indices); + hb_ot_color_glyph_get_layers (cpal_v1, 2, 1, &count, layers); g_assert_cmpuint (num_layers, ==, 2); g_assert_cmpuint (count, ==, 1); - g_assert_cmpuint (layer_gids[0], ==, 4); - g_assert_cmpuint (color_indices[0], ==, 0); + g_assert_cmpuint (layers[0].glyph, ==, 4); + g_assert_cmpuint (layers[0].color_index, ==, 0); } static void @@ -394,7 +391,7 @@ main (int argc, char **argv) hb_test_add (test_hb_ot_color_get_palette_colors_v0); hb_test_add (test_hb_ot_color_get_palette_colors_v1); hb_test_add (test_hb_ot_color_get_palette_entry_name_id); - hb_test_add (test_hb_ot_color_get_color_layers); + hb_test_add (test_hb_ot_color_glyph_get_layers); hb_test_add (test_hb_ot_color_has_data); status = hb_test_run(); hb_face_destroy (cpal_v0);