From 6924e29f62a320c91d987a91d4efa752d13c7660 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Tue, 3 Mar 2020 13:11:11 +0330 Subject: [PATCH] [var] Fix hb_ot_var_get_axis_infos's offset semantic The API was adding offset to input's infos buffer index also which is unusual between our APIs and wrong. --- src/hb-ot-var-fvar-table.hh | 26 ++++---------------------- test/api/test-var-coords.c | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/hb-ot-var-fvar-table.hh b/src/hb-ot-var-fvar-table.hh index 9b8d169ed..627e4325a 100644 --- a/src/hb-ot-var-fvar-table.hh +++ b/src/hb-ot-var-fvar-table.hh @@ -150,17 +150,8 @@ struct fvar { if (axes_count) { - /* TODO Rewrite as hb_array_t<>::sub-array() */ - unsigned int count = axisCount; - start_offset = hb_min (start_offset, count); - - count -= start_offset; - axes_array += start_offset; - - count = hb_min (count, *axes_count); - *axes_count = count; - - for (unsigned int i = 0; i < count; i++) + hb_array_t arr = hb_array (&(this+firstAxis), axisCount).sub_array (start_offset, axes_count); + for (unsigned i = 0; i < arr.length; ++i) get_axis_deprecated (start_offset + i, axes_array + i); } return axisCount; @@ -173,17 +164,8 @@ struct fvar { if (axes_count) { - /* TODO Rewrite as hb_array_t<>::sub-array() */ - unsigned int count = axisCount; - start_offset = hb_min (start_offset, count); - - count -= start_offset; - axes_array += start_offset; - - count = hb_min (count, *axes_count); - *axes_count = count; - - for (unsigned int i = 0; i < count; i++) + hb_array_t arr = hb_array (&(this+firstAxis), axisCount).sub_array (start_offset, axes_count); + for (unsigned i = 0; i < arr.length; ++i) get_axis_info (start_offset + i, axes_array + i); } return axisCount; diff --git a/test/api/test-var-coords.c b/test/api/test-var-coords.c index ff75c1575..b3aef09e8 100644 --- a/test/api/test-var-coords.c +++ b/test/api/test-var-coords.c @@ -67,10 +67,35 @@ test_get_var_coords (void) hb_face_destroy (face); } +static void +test_get_var_get_axis_infos (void) +{ + hb_face_t *face = hb_test_open_font_file ("fonts/Estedad-VF.ttf"); + + g_assert_cmpint (hb_ot_var_get_axis_count (face), ==, 2); + + hb_ot_var_axis_info_t info; + unsigned c = 1; + + g_assert_cmpint (hb_ot_var_get_axis_infos (face, 0, &c, &info), ==, 2); + g_assert (info.tag == HB_TAG ('w','g','h','t')); + g_assert_cmpint (c, ==, 1); + + hb_ot_var_get_axis_infos (face, 1, &c, &info); + g_assert (info.tag == HB_TAG ('w','d','t','h')); + g_assert_cmpint (c, ==, 1); + + hb_ot_var_get_axis_infos (face, 2, &c, &info); + g_assert_cmpint (c, ==, 0); + + hb_face_destroy (face); +} + int main (int argc, char **argv) { hb_test_init (&argc, &argv); hb_test_add (test_get_var_coords); + hb_test_add (test_get_var_get_axis_infos); return hb_test_run (); }