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