From 9fd367663a25bbcdcdff958ebc3665ddf8017077 Mon Sep 17 00:00:00 2001 From: Qunxin Liu Date: Thu, 8 Jun 2023 12:27:36 -0700 Subject: [PATCH] [instancer] add testing code for change_tuple_variation_axis_limits() Also fixed a small bug --- src/Makefile.am | 2 +- src/hb-ot-var-common.hh | 2 +- src/meson.build | 2 +- src/test-tuple-varstore.cc | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 11f4c8cf1..430d44a45 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -532,7 +532,7 @@ test_instancer_solver_SOURCES = test-subset-instancer-solver.cc hb-subset-instan test_instancer_solver_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) test_instancer_solver_LDADD = $(COMPILED_TESTS_LDADD) -test_tuple_varstore_SOURCES = test-tuple-varstore.cc hb-static.cc +test_tuple_varstore_SOURCES = test-tuple-varstore.cc hb-subset-instancer-solver.cc hb-static.cc test_tuple_varstore_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) test_tuple_varstore_LDADD = $(COMPILED_TESTS_LDADD) diff --git a/src/hb-ot-var-common.hh b/src/hb-ot-var-common.hh index 9a33af299..f28073cf7 100644 --- a/src/hb-ot-var-common.hh +++ b/src/hb-ot-var-common.hh @@ -642,7 +642,7 @@ struct TupleVariationData if (!out) continue; unsigned new_len = new_vars.length + out.length; - if (unlikely (!new_vars.resize (new_len, false))) + if (unlikely (!new_vars.alloc (new_len, false))) { fini (); return;} for (unsigned i = 0; i < out.length; i++) diff --git a/src/meson.build b/src/meson.build index 81ad125e4..d14c3c09e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -723,7 +723,7 @@ if get_option('tests').enabled() 'test-vector': ['test-vector.cc', 'hb-static.cc'], 'test-bimap': ['test-bimap.cc', 'hb-static.cc'], 'test-instancer-solver': ['test-subset-instancer-solver.cc', 'hb-subset-instancer-solver.cc', 'hb-static.cc'], - 'test-tuple-varstore': ['test-tuple-varstore.cc', 'hb-static.cc'], + 'test-tuple-varstore': ['test-tuple-varstore.cc', 'hb-subset-instancer-solver.cc', 'hb-static.cc'], } foreach name, source : compiled_tests if cpp.get_argument_syntax() == 'msvc' and source.contains('hb-static.cc') diff --git a/src/test-tuple-varstore.cc b/src/test-tuple-varstore.cc index 8387d1e88..85cccbfba 100644 --- a/src/test-tuple-varstore.cc +++ b/src/test-tuple-varstore.cc @@ -75,6 +75,41 @@ test_decompile_cvar () assert (tuple_variations.tuple_vars[1].deltas_x[i] == deltas_2[i]); } } + + /* partial instancing wght=300:800 */ + hb_hashmap_t normalized_axes_location; + normalized_axes_location.set (axis_tag, Triple (-0.512817f, 0.f, 0.700012f)); + + tuple_variations.change_tuple_variations_axis_limits (&normalized_axes_location); + tuple_variations.merge_tuple_variations (); + + assert (tuple_variations.tuple_vars[0].indices.length == 65); + assert (tuple_variations.tuple_vars[1].indices.length == 65); + assert (!tuple_variations.tuple_vars[0].deltas_y); + assert (!tuple_variations.tuple_vars[1].deltas_y); + assert (tuple_variations.tuple_vars[0].axis_tuples.get (axis_tag) == Triple (-1.f, -1.f, 0.f)); + assert (tuple_variations.tuple_vars[1].axis_tuples.get (axis_tag) == Triple (0.f, 1.f, 1.f)); + + hb_vector_t rounded_deltas_1 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, -1, 0.f, -2, 1, 0.f, -1, 0.f, -2, 1, 0.f, -19, -19, -13, -13, 0.f, 0.f, 0.f, -2, 0.f, 0.f, 0.f, 0.f, 0.f, -2, 0.f, 1, -15, -15, -10.f, -10.f, 0.f, 0.f, 0.f, 1, -15, -15, -10.f, -10.f, 0.f, 0.f, 0.f, 1}; + + hb_vector_t rounded_deltas_2 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 1, 0.f, 4, -2, 0.f, 1, 0.f, 4, -2, 0.f, 68, 68, 48, 48, 0.f, 0.f, 0.f, 4, 0.f, 0.f, 1, -1, 1, 5, -1, -4, 51, 51, 37, 37, 0.f, 0.f, 0.f, -1, 51, 51, 37, 37, 0.f, 0.f, 0.f, -1}; + + for (unsigned i = 0; i < 65; i++) + { + if (i < 23) + { + assert (tuple_variations.tuple_vars[0].indices[i] == 0); + assert (tuple_variations.tuple_vars[1].indices[i] == 0); + } + else + { + assert (tuple_variations.tuple_vars[0].indices[i] == 1); + assert (tuple_variations.tuple_vars[1].indices[i] == 1); + assert (roundf (tuple_variations.tuple_vars[0].deltas_x[i]) == rounded_deltas_1[i]); + assert (roundf (tuple_variations.tuple_vars[1].deltas_x[i]) == rounded_deltas_2[i]); + } + } + } int