xref: /aosp_15_r20/external/harfbuzz_ng/test/api/test-aat-layout.c (revision 2d1272b857b1f7575e6e246373e1cb218663db8a)
1 /*
2  * Copyright © 2018  Ebrahim Byagowi
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-test.h"
26 
27 #include <hb.h>
28 #include <hb-ot.h>
29 #include <hb-aat.h>
30 
31 /* Unit tests for hb-aat.h */
32 
33 static hb_face_t *face;
34 static hb_face_t *sbix;
35 
36 #ifndef HB_NO_AAT
37 
38 static void
test_aat_get_feature_types(void)39 test_aat_get_feature_types (void)
40 {
41   hb_aat_layout_feature_type_t features[3];
42   unsigned int count = 3;
43   g_assert_cmpuint (11, ==, hb_aat_layout_get_feature_types (face, 0, &count, features));
44 
45   g_assert_cmpuint (1, ==, features[0]);
46   g_assert_cmpuint (3, ==, features[1]);
47   g_assert_cmpuint (6, ==, features[2]);
48 
49   g_assert_cmpuint (258, ==, hb_aat_layout_feature_type_get_name_id (face, features[0]));
50   g_assert_cmpuint (261, ==, hb_aat_layout_feature_type_get_name_id (face, features[1]));
51   g_assert_cmpuint (265, ==, hb_aat_layout_feature_type_get_name_id (face, features[2]));
52 }
53 
54 static void
test_aat_get_feature_selectors(void)55 test_aat_get_feature_selectors (void)
56 {
57   unsigned int default_index;
58   hb_aat_layout_feature_selector_info_t settings[3];
59   unsigned int count = 3;
60 
61   g_assert_cmpuint (4, ==, hb_aat_layout_feature_type_get_selector_infos (face,
62 									  HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE,
63 									  0, &count, settings,
64 									  &default_index));
65   g_assert_cmpuint (3, ==, count);
66   g_assert_cmpuint (0, ==, default_index);
67 
68   g_assert_cmpuint (0, ==, settings[0].enable);
69   g_assert_cmpuint (294, ==, settings[0].name_id);
70 
71   g_assert_cmpuint (1, ==, settings[1].enable);
72   g_assert_cmpuint (295, ==, settings[1].name_id);
73 
74   g_assert_cmpuint (2, ==, settings[2].enable);
75   g_assert_cmpuint (296, ==, settings[2].name_id);
76 
77   count = 3;
78   g_assert_cmpuint (4, ==, hb_aat_layout_feature_type_get_selector_infos (face,
79 									  HB_AAT_LAYOUT_FEATURE_TYPE_DESIGN_COMPLEXITY_TYPE,
80 									  3, &count, settings,
81 									  &default_index));
82   g_assert_cmpuint (1, ==, count);
83   g_assert_cmpuint (0, ==, default_index);
84 
85   g_assert_cmpuint (3, ==, settings[0].enable);
86   g_assert_cmpuint (297, ==, settings[0].name_id);
87 
88   count = 1;
89   g_assert_cmpuint (1, ==, hb_aat_layout_feature_type_get_selector_infos (face,
90 									  HB_AAT_LAYOUT_FEATURE_TYPE_TYPOGRAPHIC_EXTRAS,
91 									  0, &count, settings,
92 									  &default_index));
93   g_assert_cmpuint (1, ==, count);
94   g_assert_cmpuint (HB_AAT_LAYOUT_NO_SELECTOR_INDEX, ==, default_index);
95 
96   g_assert_cmpuint (8, ==, settings[0].enable);
97   g_assert_cmpuint (308, ==, settings[0].name_id);
98 
99   count = 100;
100   g_assert_cmpuint (0, ==, hb_aat_layout_feature_type_get_selector_infos (face, HB_AAT_LAYOUT_FEATURE_TYPE_INVALID,
101 									  0, &count, settings,
102 									  NULL));
103   g_assert_cmpuint (0, ==, count);
104 }
105 
106 static void
test_aat_has(void)107 test_aat_has (void)
108 {
109   hb_face_t *morx = hb_test_open_font_file ("fonts/aat-morx.ttf");
110   hb_face_t *trak;
111   g_assert (hb_aat_layout_has_substitution (morx));
112   hb_face_destroy (morx);
113 
114   trak = hb_test_open_font_file ("fonts/aat-trak.ttf");
115   g_assert (hb_aat_layout_has_tracking (trak));
116   hb_face_destroy (trak);
117 }
118 
119 #endif
120 
121 int
main(int argc,char ** argv)122 main (int argc, char **argv)
123 {
124   unsigned int status;
125   hb_test_init (&argc, &argv);
126 
127 #ifndef HB_NO_AAT
128   hb_test_add (test_aat_get_feature_types);
129   hb_test_add (test_aat_get_feature_selectors);
130   hb_test_add (test_aat_has);
131 #endif
132 
133   face = hb_test_open_font_file ("fonts/aat-feat.ttf");
134   sbix = hb_test_open_font_file ("fonts/chromacheck-sbix.ttf");
135   status = hb_test_run ();
136   hb_face_destroy (sbix);
137   hb_face_destroy (face);
138   return status;
139 }
140