-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_context.py
More file actions
143 lines (132 loc) · 4.59 KB
/
Copy pathtest_context.py
File metadata and controls
143 lines (132 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import pixie
def test_fields():
context = pixie.Context(100, 100)
assert context.image is not None
fill = pixie.Paint(pixie.SOLID_PAINT)
fill.color = pixie.Color(1, 0, 0, 1)
context.fill_style = fill
assert context.fill_style == fill
stroke = pixie.Paint(pixie.SOLID_PAINT)
stroke.color = pixie.Color(0, 1, 1, 1)
context.stroke = stroke
assert context.stroke == stroke
context.global_alpha = 0.5
assert context.global_alpha == 0.5
context.line_width = 2
assert context.line_width == 2
context.miter_limit = 2
assert context.miter_limit == 2
context.line_cap = pixie.ROUND_CAP
assert context.line_cap == pixie.ROUND_CAP
context.line_join = pixie.BEVEL_JOIN
assert context.line_join == pixie.BEVEL_JOIN
context.font = "tests/fonts/Roboto-Regular_1.ttf"
assert context.font == "tests/fonts/Roboto-Regular_1.ttf"
context.font_size = 18
assert context.font_size == 18
context.text_align = pixie.CENTER_ALIGN
assert context.text_align == pixie.CENTER_ALIGN
def test_save_restore():
context = pixie.Context(100, 100)
paint1 = pixie.Paint(pixie.SOLID_PAINT)
paint1.color = pixie.Color(1, 0, 0, 1)
context.fill_style = paint1
context.save()
paint2 = pixie.Paint(pixie.SOLID_PAINT)
paint2.color = pixie.Color(1, 1, 0, 1)
context.fill_style = paint2
context.restore()
context.fill_style == paint1
def test_transform():
context = pixie.Context(100, 100)
context.get_transform() == pixie.Matrix3()
mat3 = pixie.Matrix3()
mat3.values[1] = 1
context.set_transform(mat3)
context.get_transform().values[1] == 1
mat3.values[0] = 0
mat3.values[1] = 0
mat3.values[4] = 0
mat3.values[8] = 0
context.transform(mat3) # All 0 matrix
assert context.get_transform() == mat3
context.reset_transform()
context.get_transform() == pixie.Matrix3()
context.translate(10, 20)
assert context.get_transform().values[6] == 10
assert context.get_transform().values[7] == 20
context.scale(2, 2)
assert context.get_transform().values[0] == 2
context.reset_transform()
context.rotate(180)
assert context.get_transform().values[0] != 1
def test_fill():
context = pixie.Context(100, 100)
paint = pixie.Paint(pixie.SOLID_PAINT)
paint.color = pixie.Color(1, 0, 0, 1)
context.fill_style = paint
context.begin_path()
context.rect(0, 0, 100, 100)
context.fill()
assert context.image.get_color(10, 10) == paint.color
def test_stroke():
context = pixie.Context(100, 100)
paint = pixie.Paint(pixie.SOLID_PAINT)
paint.color = pixie.Color(1, 0, 0, 1)
context.stroke_style = paint
context.line_width = 10
context.begin_path()
context.rect(0, 0, 100, 100)
context.stroke()
assert context.image.get_color(0, 0) == paint.color
assert context.image.get_color(50, 50) == pixie.Color(0, 0, 0, 0)
def test_clip():
context = pixie.Context(100, 100)
paint = pixie.Paint(pixie.SOLID_PAINT)
paint.color = pixie.Color(1, 0, 0, 1)
context.fill_style = paint
context.begin_path()
context.rect(0, 0, 50, 50)
context.clip()
context.begin_path()
context.rect(0, 0, 100, 100)
context.fill()
assert context.image.get_color(10, 10) == paint.color
assert context.image.get_color(60, 60) == pixie.Color(0, 0, 0, 0)
def test_paths():
context = pixie.Context(100, 100)
context.begin_path()
context.move_to(0, 0)
context.line_to(0, 0)
context.bezier_curve_to(0, 0, 0, 0, 0, 0)
context.quadratic_curve_to(0, 0, 0, 0)
context.arc(0, 0, 0, 0, 0)
context.arc_to(0, 0, 0, 0, 0)
context.rect(0, 0, 0, 0)
context.rounded_rect(0, 0, 0, 0, 0, 0, 0, 0)
context.ellipse(0, 0, 0, 0)
context.circle(0, 0, 0)
context.polygon(0, 0, 0, 3)
context.close_path()
assert not context.is_point_in_path(1, 1)
assert not context.is_point_in_stroke(1, 1)
def test_text():
context = pixie.Context(100, 100)
context.font = "tests/fonts/Roboto-Regular_1.ttf"
# metrics = context.measure_text("Hello world")
# assert metrics.width == 61
context.fill_text("test", 0, 0)
context.stroke_text("text", 0, 0)
def test_line_dash():
context = pixie.Context(100, 100)
line_dash = pixie.SeqFloat32()
line_dash.append(1)
line_dash.append(0)
line_dash.append(2)
line_dash.append(3)
context.set_line_dash(line_dash)
retrieved_line_dash = context.get_line_dash()
assert len(line_dash) == len(retrieved_line_dash)
for i in range(0, len(line_dash)):
print(line_dash[i])
assert line_dash[i] == retrieved_line_dash[i]