2 * Copyright © 2020 Google, Inc.
4 * This is part of HarfBuzz, a text shaping library.
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.
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
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.
24 * Google Author(s): Calder Kitagawa
28 #include "hb-subset-test.h"
30 /* Unit tests for CBDT/CBLC subsetting */
33 test_subset_cbdt_noop (void)
35 hb_face_t *face = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.ttf");
37 hb_set_t *codepoints = hb_set_create ();
38 hb_face_t *face_subset;
39 hb_set_add (codepoints, 0x38);
40 hb_set_add (codepoints, 0x39);
41 hb_set_add (codepoints, 0xAE);
42 hb_set_add (codepoints, 0x2049);
43 hb_set_add (codepoints, 0x20E3);
44 face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
45 hb_set_destroy (codepoints);
47 hb_subset_test_check (face, face_subset, HB_TAG ('C','B','L','C'));
48 hb_subset_test_check (face, face_subset, HB_TAG ('C','B','D','T'));
50 hb_face_destroy (face_subset);
51 hb_face_destroy (face);
55 test_subset_cbdt_keep_one (void)
57 hb_face_t *face = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.ttf");
58 hb_face_t *face_expected = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.default.39.ttf");
60 hb_set_t *codepoints = hb_set_create ();
61 hb_face_t *face_subset;
62 hb_set_add (codepoints, 0x39);
63 face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
64 hb_set_destroy (codepoints);
66 hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','B','L','C'));
67 hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','B','D','T'));
69 hb_face_destroy (face_subset);
70 hb_face_destroy (face_expected);
71 hb_face_destroy (face);
75 test_subset_cbdt_keep_one_last_subtable (void)
77 hb_face_t *face = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.ttf");
78 hb_face_t *face_expected = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.default.2049.ttf");
80 hb_set_t *codepoints = hb_set_create ();
81 hb_face_t *face_subset;
82 hb_set_add (codepoints, 0x2049);
83 face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
84 hb_set_destroy (codepoints);
86 hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','B','L','C'));
87 hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','B','D','T'));
89 hb_face_destroy (face_subset);
90 hb_face_destroy (face_expected);
91 hb_face_destroy (face);
95 test_subset_cbdt_keep_multiple_subtables (void)
97 hb_face_t *face = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.multiple_size_tables.ttf");
98 hb_face_t *face_expected = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.multiple_size_tables.default.38,AE,2049.ttf");
100 hb_set_t *codepoints = hb_set_create ();
101 hb_face_t *face_subset;
102 hb_set_add (codepoints, 0x38);
103 hb_set_add (codepoints, 0xAE);
104 hb_set_add (codepoints, 0x2049);
105 face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
106 hb_set_destroy (codepoints);
108 hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','B','L','C'));
109 hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','B','D','T'));
111 hb_face_destroy (face_subset);
112 hb_face_destroy (face_expected);
113 hb_face_destroy (face);
117 test_subset_cbdt_index_format_3 (void)
119 hb_face_t *face = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.index_format3.ttf");
120 hb_face_t *face_expected = hb_test_open_font_file ("fonts/NotoColorEmoji.subset.index_format3.default.38,AE,2049.ttf");
122 hb_set_t *codepoints = hb_set_create ();
123 hb_face_t *face_subset;
124 hb_set_add (codepoints, 0x38);
125 hb_set_add (codepoints, 0xAE);
126 hb_set_add (codepoints, 0x2049);
127 face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
128 hb_set_destroy (codepoints);
130 hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','B','L','C'));
131 hb_subset_test_check (face_expected, face_subset, HB_TAG ('C','B','D','T'));
133 hb_face_destroy (face_subset);
134 hb_face_destroy (face_expected);
135 hb_face_destroy (face);
138 // TODO: add support/tests for index formats 2,4,5 (image formats are treated as
139 // opaque blobs when subsetting so don't need to be tested separately).
140 // TODO: add a test that keeps no codepoints.
143 main (int argc, char **argv)
145 hb_test_init (&argc, &argv);
147 hb_test_add (test_subset_cbdt_noop);
148 hb_test_add (test_subset_cbdt_keep_one);
149 hb_test_add (test_subset_cbdt_keep_one_last_subtable);
150 // The following use manually crafted expectation files as they are not
151 // binary compatible with FontTools.
152 hb_test_add (test_subset_cbdt_keep_multiple_subtables);
153 // Can use FontTools after https://github.com/fonttools/fonttools/issues/1817
155 hb_test_add (test_subset_cbdt_index_format_3);
157 return hb_test_run();