Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 927192
Collapse All | Expand All

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

Return to bug 927192