135
141
check(not cairo.RecordingSurface:is_type_of(s2))
144
function cairo.pattern_type()
145
local cairo = lgi.cairo
148
pattern = cairo.Pattern.create_rgb(1, 1, 1)
149
check(cairo.SolidPattern:is_type_of(pattern))
150
check(cairo.Pattern:is_type_of(pattern))
151
pattern = cairo.SolidPattern(1, 1, 1)
152
check(cairo.SolidPattern:is_type_of(pattern))
153
pattern = cairo.SolidPattern(1, 1, 1, 1)
154
check(cairo.SolidPattern:is_type_of(pattern))
156
local surface = cairo.ImageSurface('ARGB32', 100, 100)
157
pattern = cairo.Pattern.create_for_surface(surface)
158
check(select(2, pattern:get_surface()) == surface)
159
check(cairo.SurfacePattern:is_type_of(pattern))
160
check(cairo.Pattern:is_type_of(pattern))
161
pattern = cairo.SurfacePattern(surface)
162
check(cairo.SurfacePattern:is_type_of(pattern))
164
pattern = cairo.Pattern.create_linear(0, 0, 10, 10)
165
check(cairo.LinearPattern:is_type_of(pattern))
166
check(cairo.GradientPattern:is_type_of(pattern))
167
check(cairo.Pattern:is_type_of(pattern))
168
pattern = cairo.LinearPattern(0, 0, 10, 10)
169
check(cairo.LinearPattern:is_type_of(pattern))
171
pattern = cairo.Pattern.create_radial(0, 0, 5, 10, 10, 5)
172
check(cairo.RadialPattern:is_type_of(pattern))
173
check(cairo.GradientPattern:is_type_of(pattern))
174
check(cairo.Pattern:is_type_of(pattern))
175
pattern = cairo.RadialPattern(0, 0, 5, 10, 10, 5)
176
check(cairo.RadialPattern:is_type_of(pattern))
178
if cairo.version >= cairo.version_encode(1, 12, 0) then
179
pattern = cairo.Pattern.create_mesh()
180
check(cairo.MeshPattern:is_type_of(pattern))
181
check(not cairo.GradientPattern:is_type_of(pattern))
182
check(cairo.Pattern:is_type_of(pattern))
183
pattern = cairo.MeshPattern()
184
check(cairo.MeshPattern:is_type_of(pattern))
188
function cairo.pattern_mesh()
189
local cairo = lgi.cairo
191
-- Mesh patterns are introduced in cairo 1.12
192
if cairo.version < cairo.version_encode(1, 12, 0) then
196
local mesh = cairo.Pattern.create_mesh()
197
local pattern = cairo.Pattern.create_radial(1, 2, 3, 4, 5, 6)
199
check(cairo.Pattern:is_type_of(mesh))
200
check(cairo.MeshPattern:is_type_of(mesh))
202
check(cairo.Pattern:is_type_of(pattern))
203
check(not cairo.MeshPattern:is_type_of(pattern))
205
local function check_status(status)
206
checkv(status, 'SUCCESS', 'string')
209
-- Taken from cairo's pattern-getters test and slightly adapted to use all
210
-- functions of the mesh pattern API
211
local status, count = mesh:get_patch_count()
213
checkv(count, 0, 'number')
220
mesh:set_corner_color_rgba(0, 1, 1, 1, 1)
223
local status, count = mesh:get_patch_count()
225
checkv(count, 1, 'number')
227
for k, v in pairs({ { 1, 1 }, { 1, 2 }, { 2, 2 }, { 2, 1 } }) do
228
local status, x, y = mesh:get_control_point(0, k - 1)
230
checkv(x, v[1], 'number')
231
checkv(y, v[2], 'number')
237
mesh:curve_to(1, 1, 1, 2, 0, 1)
238
mesh:set_corner_color_rgb(0, 1, 1, 1)
239
mesh:set_control_point(2, 0.5, 0.5)
242
local status, count = mesh:get_patch_count()
244
checkv(count, 2, 'number')
246
for k, v in pairs({ 1, 0, 0, 1 }) do
247
local status, r, g, b, a = mesh:get_corner_color_rgba(1, k - 1)
249
checkv(r, v, 'number')
250
checkv(g, v, 'number')
251
checkv(b, v, 'number')
252
checkv(a, v, 'number')
257
{ { 0, 1 }, { 0, 2 }, { 0, 3 } },
258
{ { 1, 3 }, { 2, 3 }, { 3, 3 } },
259
{ { 3, 2 }, { 3, 1 }, { 3, 0 } },
260
{ { 2, 0 }, { 1, 0 }, { 0, 0 } },
262
for t, pts in mesh:get_path(0):pairs() do
264
checkv(t, 'MOVE_TO', 'string')
265
check(type(pts) == 'table' and #pts == 1)
266
checkv(pts[1].x, 0, 'number')
267
checkv(pts[1].y, 0, 'number')
269
-- Mesh patterns turn everything into curves. :-(
270
checkv(t, 'CURVE_TO', 'string')
271
check(type(pts) == 'table' and #pts == 3)
272
for k, v in pairs(expected[i]) do
273
checkv(pts[k].x, v[1], 'number')
274
checkv(pts[k].y, v[2], 'number')
279
check(i == #expected + 1)
138
282
function cairo.context_transform()
139
283
local cairo = lgi.cairo
140
284
local surface = cairo.ImageSurface('ARGB32', 100, 100)