Imported Upstream version 8.2.2
[platform/upstream/harfbuzz.git] / src / test-item-varstore.cc
1 /*
2  * Copyright © 2020  Google, Inc.
3  *
4  *  This is part of HarfBuzz, a text shaping library.
5  *
6  * Permission is hereby granted, without written agreement and without
7  * license or royalty fees, to use, copy, modify, and distribute this
8  * software and its documentation for any purpose, provided that the
9  * above copyright notice and the following two paragraphs appear in
10  * all copies of this software.
11  *
12  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16  * DAMAGE.
17  *
18  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23  *
24  */
25 #include "hb-ot-var-common.hh"
26 #include "hb-ot-var-hvar-table.hh"
27 // HVAR table data from SourceSerif4Variable-Roman_subset.otf
28 const char hvar_data[] = "\x0\x1\x0\x0\x0\x0\x0\x14\x0\x0\x0\xc4\x0\x0\x0\x0\x0\x0\x0\x0\x0\x1\x0\x0\x0\x10\x0\x2\x0\x0\x0\x74\x0\x0\x0\x7a\x0\x2\x0\x8\xc0\x0\xc0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x40\x0\x40\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\xc0\x0\xc0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x0\x40\x0\x40\x0\xc0\x0\xc0\x0\x0\x0\xc0\x0\xc0\x0\x0\x0\xc0\x0\xc0\x0\x0\x0\x0\x0\x40\x0\x40\x0\x0\x0\x40\x0\x40\x0\xc0\x0\xc0\x0\x0\x0\x0\x0\x40\x0\x40\x0\x0\x0\x40\x0\x40\x0\x0\x1\x0\x0\x0\x0\x0\x4\x0\x0\x0\x8\x0\x0\x0\x1\x0\x2\x0\x3\x0\x4\x0\x5\x0\x6\x0\x7\xf9\xf\x2f\xbf\xfb\xfb\x35\xf9\x4\x4\xf3\xb4\xf2\xfb\x2e\xf3\x4\x4\xe\xad\xfa\x1\x1a\x1\x15\x22\x59\xd6\xe3\xf6\x6\xf5\x0\x1\x0\x5\x0\x4\x7\x5\x6";
29
30 static void
31 test_item_variations ()
32 {
33   const OT::HVAR* hvar_table = reinterpret_cast<const OT::HVAR*> (hvar_data);
34
35   hb_tag_t axis_tag = HB_TAG ('w', 'g', 'h', 't');
36   hb_map_t axis_idx_tag_map;
37   axis_idx_tag_map.set (0, axis_tag);
38
39   axis_tag = HB_TAG ('o', 'p', 's', 'z');
40   axis_idx_tag_map.set (1, axis_tag);
41
42   OT::item_variations_t item_vars;
43   const OT::VariationStore& src_var_store = hvar_table+(hvar_table->varStore);
44   bool result = item_vars.create_from_item_varstore (src_var_store, axis_idx_tag_map);
45       
46   assert (result);
47
48   /* partial instancing wght=300:800 */
49   hb_hashmap_t<hb_tag_t, Triple> normalized_axes_location;
50   normalized_axes_location.set (axis_tag, Triple (-0.512817f, 0.f, 0.700012f));
51
52   hb_hashmap_t<hb_tag_t, TripleDistances> axes_triple_distances;
53   axes_triple_distances.set (axis_tag, TripleDistances (200.f, 500.f));
54
55   result = item_vars.instantiate_tuple_vars (normalized_axes_location, axes_triple_distances);
56   assert (result);
57   result = item_vars.as_item_varstore (false);
58   assert (result);
59   assert (item_vars.get_region_list().length == 8);
60 }
61
62 int
63 main (int argc, char **argv)
64 {
65   test_item_variations ();
66 }