diff --git a/src/Makefile.am b/src/Makefile.am index dd039300c..f2e7a3a9d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -457,6 +457,7 @@ COMPILED_TESTS = \ test-repacker \ test-classdef-graph \ test-instancer-solver \ + test-decompile-tuple-varstore \ $(NULL) COMPILED_TESTS_CPPFLAGS = $(HBCFLAGS) -DMAIN -UNDEBUG COMPILED_TESTS_LDADD = libharfbuzz.la $(HBLIBS) @@ -531,6 +532,10 @@ 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_decompile_tuple_varstore_SOURCES = test-decompile-tuple-varstore.cc hb-static.cc +test_decompile_tuple_varstore_CPPFLAGS = $(COMPILED_TESTS_CPPFLAGS) +test_decompile_tuple_varstore_LDADD = $(COMPILED_TESTS_LDADD) + dist_check_SCRIPTS = \ check-c-linkage-decls.py \ check-externs.py \ diff --git a/src/meson.build b/src/meson.build index 539d92495..6f10612d3 100644 --- a/src/meson.build +++ b/src/meson.build @@ -723,6 +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-decompile-tuple-varstore': ['test-decompile-tuple-varstore.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-decompile-tuple-varstore.cc b/src/test-decompile-tuple-varstore.cc new file mode 100644 index 000000000..569189677 --- /dev/null +++ b/src/test-decompile-tuple-varstore.cc @@ -0,0 +1,79 @@ +/* + * Copyright © 2020 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + */ +#include "hb-ot-var-cvar-table.hh" + +// cvar table data from Multi-ABC.ttf +const char cvar_data[] = "\x0\x1\x0\x0\x0\x2\x0\x14\x0\x51\xa0\x0\xc0\x0\x0\x54\xa0\x0\x40\x0\x2a\x29\x17\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\xd\xff\x0\xfd\x1\x0\xff\x0\xfd\x1\x0\xdb\xdb\xe6\xe6\x82\x0\xfd\x84\x6\xfd\x0\x2\xe3\xe3\xec\xec\x82\x4\x1\xe3\xe3\xec\xec\x82\x0\x1\x2a\x29\x17\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1\xd\x1\x0\x5\xfd\x0\x1\x0\x5\xfd\x0\x61\x61\x44\x44\x82\x0\x5\x81\x9\x1\xff\x1\x7\xff\xfb\x49\x49\x35\x35\x82\x4\xff\x49\x49\x35\x35\x82\x0\xff"; + +static void +test_decompile_cvar () +{ + const OT::cvar* cvar_table = reinterpret_cast (cvar_data); + unsigned point_count = 65; + unsigned axis_count = 1; + OT::TupleVariationData::tuple_variations_t tuple_variations; + bool result = cvar_table->decompile_tuple_variations (axis_count, point_count, false, tuple_variations); + assert (result); + assert (tuple_variations.tuple_vars.length == 2); + for (unsigned i = 0; i < 2; i++) + { + assert (tuple_variations.tuple_vars[i].axis_tuples.get_population () == 1); + assert (!tuple_variations.tuple_vars[i].deltas_y); + assert (tuple_variations.tuple_vars[i].indices.length == 65); + assert (tuple_variations.tuple_vars[i].indices.length == tuple_variations.tuple_vars[i].deltas_x.length); + } + assert (tuple_variations.tuple_vars[0].axis_tuples.get (0) == Triple (-1.f, -1.f, 0.f)); + assert (tuple_variations.tuple_vars[1].axis_tuples.get (0) == Triple (0.f, 1.f, 1.f)); + + hb_vector_t 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.f, 0.f, -3.f, 1.f, 0.f, -1.f, 0.f, -3.f, 1.f, 0.f, -37.f, -37.f, -26.f, -26.f, 0.f, 0.f, 0.f, -3.f, 0.f, 0.f, 0.f, 0.f, 0.f, -3.f, 0.f, 2.f, -29.f, -29.f, -20.f, -20.f, 0.f, 0.f, 0.f, 1.f, -29.f, -29.f, -20.f, -20.f, 0.f, 0.f, 0.f, 1.f}; + for (unsigned i = 0; i < 65; i++) + { + if (i < 23) + assert (tuple_variations.tuple_vars[0].indices[i] == 0); + else + { + assert (tuple_variations.tuple_vars[0].indices[i] == 1); + assert (tuple_variations.tuple_vars[0].deltas_x[i] == deltas_1[i]); + } + } + + hb_vector_t 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.f, 0.f, 5.f, -3.f, 0.f, 1.f, 0.f, 5.f, -3.f, 0.f, 97.f, 97.f, 68.f, 68.f, 0.f, 0.f, 0.f, 5.f, 0.f, 0.f, 1.f, -1.f, 1.f, 7.f, -1.f, -5.f, 73.f, 73.f, 53.f, 53.f, 0.f, 0.f, 0.f, -1.f, 73.f, 73.f, 53.f, 53.f, 0.f, 0.f, 0.f, -1.f}; + for (unsigned i = 0 ; i < 65; i++) + { + if (i < 23) + assert (tuple_variations.tuple_vars[1].indices[i] == 0); + else + { + assert (tuple_variations.tuple_vars[1].indices[i] == 1); + assert (tuple_variations.tuple_vars[1].deltas_x[i] == deltas_2[i]); + } + } +} + +int +main (int argc, char **argv) +{ + test_decompile_cvar (); +}