1*2d1272b8SAndroid Build Coastguard Worker #include <assert.h>
2*2d1272b8SAndroid Build Coastguard Worker #include <stdio.h>
3*2d1272b8SAndroid Build Coastguard Worker #include "glib.h"
4*2d1272b8SAndroid Build Coastguard Worker #include "hb-subset.h"
5*2d1272b8SAndroid Build Coastguard Worker #include "helper-subset.hh"
6*2d1272b8SAndroid Build Coastguard Worker
7*2d1272b8SAndroid Build Coastguard Worker static
open_font(const char * path)8*2d1272b8SAndroid Build Coastguard Worker hb_face_t* open_font(const char* path)
9*2d1272b8SAndroid Build Coastguard Worker {
10*2d1272b8SAndroid Build Coastguard Worker hb_face_t *face = hb_face_create_from_file_or_fail (path, 0);
11*2d1272b8SAndroid Build Coastguard Worker g_assert (face);
12*2d1272b8SAndroid Build Coastguard Worker return face;
13*2d1272b8SAndroid Build Coastguard Worker }
14*2d1272b8SAndroid Build Coastguard Worker
15*2d1272b8SAndroid Build Coastguard Worker static
check_parsing(hb_face_t * face,const char * spec,hb_tag_t axis,float exp_min,float exp_def,float exp_max)16*2d1272b8SAndroid Build Coastguard Worker gboolean check_parsing(hb_face_t* face, const char* spec, hb_tag_t axis, float exp_min, float exp_def, float exp_max)
17*2d1272b8SAndroid Build Coastguard Worker {
18*2d1272b8SAndroid Build Coastguard Worker printf(">> testing spec: %s\n", spec);
19*2d1272b8SAndroid Build Coastguard Worker hb_subset_input_t* input = hb_subset_input_create_or_fail();
20*2d1272b8SAndroid Build Coastguard Worker g_assert(input);
21*2d1272b8SAndroid Build Coastguard Worker
22*2d1272b8SAndroid Build Coastguard Worker {
23*2d1272b8SAndroid Build Coastguard Worker GError* error;
24*2d1272b8SAndroid Build Coastguard Worker char *spec_copy = g_strdup (spec);
25*2d1272b8SAndroid Build Coastguard Worker gboolean res = parse_instancing_spec(spec_copy, face, input, &error);
26*2d1272b8SAndroid Build Coastguard Worker g_free(spec_copy);
27*2d1272b8SAndroid Build Coastguard Worker if (!res) {
28*2d1272b8SAndroid Build Coastguard Worker hb_subset_input_destroy(input);
29*2d1272b8SAndroid Build Coastguard Worker return res;
30*2d1272b8SAndroid Build Coastguard Worker }
31*2d1272b8SAndroid Build Coastguard Worker }
32*2d1272b8SAndroid Build Coastguard Worker
33*2d1272b8SAndroid Build Coastguard Worker float act_min = 0.0, act_def = 0.0, act_max = 0.0;
34*2d1272b8SAndroid Build Coastguard Worker hb_bool_t res = hb_subset_input_get_axis_range(input, axis, &act_min, &act_max, &act_def);
35*2d1272b8SAndroid Build Coastguard Worker if (!res) {
36*2d1272b8SAndroid Build Coastguard Worker hb_subset_input_destroy(input);
37*2d1272b8SAndroid Build Coastguard Worker return false;
38*2d1272b8SAndroid Build Coastguard Worker
39*2d1272b8SAndroid Build Coastguard Worker }
40*2d1272b8SAndroid Build Coastguard Worker
41*2d1272b8SAndroid Build Coastguard Worker g_assert_cmpuint(exp_min, ==, act_min);
42*2d1272b8SAndroid Build Coastguard Worker g_assert_cmpuint(exp_def, ==, act_def);
43*2d1272b8SAndroid Build Coastguard Worker g_assert_cmpuint(exp_max, ==, act_max);
44*2d1272b8SAndroid Build Coastguard Worker
45*2d1272b8SAndroid Build Coastguard Worker hb_subset_input_destroy(input);
46*2d1272b8SAndroid Build Coastguard Worker return true;
47*2d1272b8SAndroid Build Coastguard Worker }
48*2d1272b8SAndroid Build Coastguard Worker
49*2d1272b8SAndroid Build Coastguard Worker static hb_tag_t wght = HB_TAG('w', 'g', 'h', 't');
50*2d1272b8SAndroid Build Coastguard Worker static hb_tag_t xxxx = HB_TAG('x', 'x', 'x', 'x');
51*2d1272b8SAndroid Build Coastguard Worker
52*2d1272b8SAndroid Build Coastguard Worker static void
test_parse_instancing_spec(void)53*2d1272b8SAndroid Build Coastguard Worker test_parse_instancing_spec (void)
54*2d1272b8SAndroid Build Coastguard Worker {
55*2d1272b8SAndroid Build Coastguard Worker hb_face_t* face = open_font("../test/api/fonts/AdobeVFPrototype-Subset.otf");
56*2d1272b8SAndroid Build Coastguard Worker hb_face_t* roboto = open_font("../test/api/fonts/Roboto-Variable.abc.ttf");
57*2d1272b8SAndroid Build Coastguard Worker
58*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "wght=300", wght, 300, 300, 300));
59*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "wght=100:200:300", wght, 100, 200, 300));
60*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "wght=:500:", wght, 0, 500, 1000));
61*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "wght=::700", wght, 0, 700, 700));
62*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "wght=200::", wght, 200, 1000, 1000));
63*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "wght=200:300:", wght, 200, 300, 1000));
64*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "wght=:300:500", wght, 0, 300, 500));
65*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "wght=300::700", wght, 300, 700, 700));
66*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "wght=300:700", wght, 300, 700, 700));
67*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "wght=:700", wght, 0, 700, 700));
68*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "wght=200:", wght, 200, 1000, 1000));
69*2d1272b8SAndroid Build Coastguard Worker
70*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "wght=200: xxxx=50", wght, 200, 1000, 1000));
71*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "wght=200: xxxx=50", xxxx, 50, 50, 50));
72*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "wght=200:,xxxx=50", wght, 200, 1000, 1000));
73*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "wght=200:,xxxx=50", xxxx, 50, 50, 50));
74*2d1272b8SAndroid Build Coastguard Worker
75*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "wght=200,*=drop", wght, 1000, 1000, 1000));
76*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "wght=200,*=drop", xxxx, 0, 0, 0));
77*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "*=drop,wght=200", wght, 200, 200, 200));
78*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "*=drop,wght=200", xxxx, 0, 0, 0));
79*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "*=drop,wght=200,xxxx=50", wght, 200, 200, 200));
80*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "*=drop,wght=200,xxxx=50", xxxx, 50, 50, 50));
81*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "xxxx=50,*=drop,wght=200", wght, 200, 200, 200));
82*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "xxxx=50,*=drop,wght=200", xxxx, 0, 0, 0));
83*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "*=drop", wght, 1000, 1000, 1000));
84*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(face, "*=drop", xxxx, 0, 0, 0));
85*2d1272b8SAndroid Build Coastguard Worker
86*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(roboto, "wght=300", wght, 300, 300, 300));
87*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(roboto, "wght=100:200:300", wght, 100, 200, 300));
88*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(roboto, "wght=:500:", wght, 100, 500, 900));
89*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(roboto, "wght=::850", wght, 100, 400, 850));
90*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(roboto, "wght=200::", wght, 200, 400, 900));
91*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(roboto, "wght=200:300:", wght, 200, 300, 900));
92*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(roboto, "wght=:300:500", wght, 100, 300, 500));
93*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(roboto, "wght=300::700", wght, 300, 400, 700));
94*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(roboto, "wght=300:700", wght, 300, 400, 700));
95*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(roboto, "wght=:700", wght, 100, 400, 700));
96*2d1272b8SAndroid Build Coastguard Worker g_assert(check_parsing(roboto, "wght=200:", wght, 200, 400, 900));
97*2d1272b8SAndroid Build Coastguard Worker
98*2d1272b8SAndroid Build Coastguard Worker hb_face_destroy(face);
99*2d1272b8SAndroid Build Coastguard Worker hb_face_destroy(roboto);
100*2d1272b8SAndroid Build Coastguard Worker }
101*2d1272b8SAndroid Build Coastguard Worker
102*2d1272b8SAndroid Build Coastguard Worker
103*2d1272b8SAndroid Build Coastguard Worker int
main(int argc,char ** argv)104*2d1272b8SAndroid Build Coastguard Worker main (int argc, char **argv)
105*2d1272b8SAndroid Build Coastguard Worker {
106*2d1272b8SAndroid Build Coastguard Worker test_parse_instancing_spec();
107*2d1272b8SAndroid Build Coastguard Worker
108*2d1272b8SAndroid Build Coastguard Worker return 0;
109*2d1272b8SAndroid Build Coastguard Worker }
110