This file is indexed.

/usr/share/doc/lua-lgi-dev/samples/cairo.lua is in lua-lgi-dev 0.7.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#! /usr/bin/env lua

--
-- Sample cairo application, based on http://cairographics.org/samples/
--
-- Renders all samples into separate PNG images
--

local math = require 'math'
local lgi = require 'lgi'
local cairo = lgi.cairo

local dir = arg[0]:sub(1, arg[0]:find('[^%/\\]+$') - 1):gsub('[/\\]$', '')
local imagename = dir .. '/gtk-demo/apple-red.png'

local samples = {}

function samples.arc(cr)
   local xc, yc = 128, 128
   local radius = 100
   local angle1, angle2 = math.rad(45), math.rad(180)

   cr.line_width = 10
   cr:arc(xc, yc, radius, angle1, angle2)
   cr:stroke()

   -- draw helping lines
   cr:set_source_rgba(1, 0.2, 0.2, 0.6)
   cr.line_width = 6

   cr:arc(xc, yc, 10, 0, math.rad(360))
   cr:fill()

   cr:arc(xc, yc, radius, angle1, angle1)
   cr:line_to(xc, yc)
   cr:arc(xc, yc, radius, angle2, angle2)
   cr:line_to(xc, yc)
   cr:stroke()
end

function samples.arc_negative(cr)
   local xc, yc = 128, 128
   local radius = 100
   local angle1, angle2 = math.rad(45), math.rad(180)

   cr.line_width = 10
   cr:arc_negative(xc, yc, radius, angle1, angle2)
   cr:stroke()

   -- draw helping lines
   cr:set_source_rgba(1, 0.2, 0.2, 0.6)
   cr.line_width = 6

   cr:arc(xc, yc, 10, 0, math.rad(360))
   cr:fill()

   cr:arc(xc, yc, radius, angle1, angle1)
   cr:line_to(xc, yc)
   cr:arc(xc, yc, radius, angle2, angle2)
   cr:line_to(xc, yc)
   cr:stroke()
end

function samples.clip(cr)
   cr:arc(128, 128, 76.8, 0, math.rad(360))
   cr:clip()

   -- current path is not consumed by cairo.Context.clip()
   cr:new_path()

   cr:rectangle(0, 0, 256, 256)
   cr:fill()
   cr:set_source_rgb(0, 1, 0)
   cr:move_to(0, 0)
   cr:line_to(256, 256)
   cr:move_to(256, 0)
   cr:line_to(0, 256)
   cr.line_width = 10
   cr:stroke()
end

function samples.clip_image(cr)
   cr:arc(128, 128, 76.8, 0, math.rad(360))
   cr:clip()
   cr:new_path()

   local image = cairo.ImageSurface.create_from_png(imagename)
   cr:scale(256 / image.width, 256 / image.height)
   cr:set_source_surface(image, 0, 0)
   cr:paint()
end

function samples.dash(cr)
   cr:set_dash({ 50, 10, 10, 10 }, -50)

   cr.line_width = 10
   cr:move_to(128, 25.6)
   cr:line_to(230.4, 230.4)
   cr:rel_line_to(-102.4, 0)
   cr:curve_to(51.2, 230.4, 51.2, 128, 128, 128)

   cr:stroke()
end

function samples.curve_to(cr)
   local x, y = 25.6, 128
   local x1, y1 = 102.4, 230.4
   local x2, y2 = 153.6, 25.6
   local x3, y3 = 230.4, 128

   cr:move_to(x, y)
   cr:curve_to(x1, y1, x2, y2, x3, y3)

   cr.line_width = 10
   cr:stroke()

   cr:set_source_rgba(1, 0.2, 0.2, 0.6)
   cr.line_width = 6
   cr:move_to(x, y)
   cr:line_to(x1, y1)
   cr:move_to(x2, y2)
   cr:line_to(x3, y3)
   cr:stroke()
end

function samples.fill_and_stroke(cr)
   cr:move_to(128, 25.6)
   cr:line_to(230.4, 230.4)
   cr:rel_line_to(-102.4, 0)
   cr:curve_to(51.2, 230.4, 51.2, 128, 128, 128)
   cr:close_path()

   cr:move_to(64, 25.6)
   cr:rel_line_to(51.2, 51.2)
   cr:rel_line_to(-51.2, 51.2)
   cr:rel_line_to(-51.2, -51.2)
   cr:close_path()

   cr.line_width = 10
   cr:set_source_rgb(0, 0, 1)
   cr:fill_preserve()
   cr:set_source_rgb(0, 0, 0)
   cr:stroke()
end

function samples.fill_style(cr)
   cr.line_width = 6

   cr:rectangle(12, 12, 232, 70)
   cr:new_sub_path()
   cr:arc(64, 64, 40, 0, math.rad(360))
   cr:new_sub_path()
   cr:arc_negative(192, 64, 40, 0, math.rad(-360))

   cr.fill_rule = 'EVEN_ODD'
   cr:set_source_rgb(0, 0.7, 0)
   cr:fill_preserve()
   cr:set_source_rgb(0, 0, 0)
   cr:stroke()

   cr:translate(0, 128)
   cr:rectangle(12, 12, 232, 70)
   cr:new_sub_path()
   cr:arc(64, 64, 40, 0, math.rad(360))
   cr:new_sub_path()
   cr:arc_negative(192, 64, 40, 0, math.rad(-360))

   cr.fill_rule = 'WINDING'
   cr:set_source_rgb(0, 0, 0.9)
   cr:fill_preserve()
   cr:set_source_rgb(0, 0, 0)
   cr:stroke()
end

function samples.gradient(cr)
   local pat = cairo.Pattern.create_linear(0, 0, 0, 256)
   pat:add_color_stop_rgba(1, 0, 0, 0, 1)
   pat:add_color_stop_rgba(0, 1, 1, 1, 1)
   cr:rectangle(0, 0, 256, 256)
   cr.source = pat
   cr:fill()

   pat = cairo.Pattern.create_radial(115.2, 102.4, 25.6,
				     102.4, 102.4, 128)
   pat:add_color_stop_rgba(0, 1, 1, 1, 1);
   pat:add_color_stop_rgba(1, 0, 0, 0, 0);
   cr.source = pat
   cr:arc(128, 128, 76.8, 0, math.rad(360))
   cr:fill()
end

function samples.image(cr)
   local image = cairo.ImageSurface.create_from_png(imagename)
   
   cr:translate(128, 128)
   cr:rotate(math.rad(45))
   cr:scale(256 / image.width, 256 / image.height)
   cr:translate(-image.width / 2, -image.height / 2)

   cr:set_source_surface(image, 0, 0)
   cr:paint()
end

function samples.imagepattern(cr)
   local image = cairo.ImageSurface.create_from_png(imagename)

   local pattern = cairo.Pattern.create_for_surface(image)
   pattern.extend = 'REPEAT'

   cr:translate(128, 128)
   cr:rotate(math.rad(45))
   cr:scale(1 / math.sqrt(2), 1 / math.sqrt(2))
   cr:translate(-128, -128)

   pattern.matrix = cairo.Matrix.create_scale(image.width / 256 * 5,
					      image.height / 256 * 5)
   cr.source = pattern

   cr:rectangle(0, 0, 256, 256)
   cr:fill()
end

function samples.multisegment_caps(cr)
   cr:move_to(50, 75)
   cr:line_to(200, 75)

   cr:move_to(50, 125)
   cr:line_to(200, 125)

   cr:move_to(50, 175)
   cr:line_to(200, 175)

   cr.line_width = 30
   cr.line_cap = 'ROUND'
   cr:stroke()
end

function samples.rounded_rectangle(cr)
   local x, y, width, height = 25.6, 25.6, 204.8, 204.8
   local aspect = 1
   local corner_radius = height / 10

   local radius = corner_radius / aspect

   cr:new_sub_path()
   cr:arc(x + width - radius, y + radius, radius,
	  math.rad(-90), math.rad(0))
   cr:arc(x + width - radius, y + height - radius, radius,
	  math.rad(0), math.rad(90))
   cr:arc(x + radius, y + height - radius, radius,
	  math.rad(90), math.rad(180))
   cr:arc(x + radius, y + radius, radius,
	  math.rad(180), math.rad(270))
   cr:close_path()

   cr:set_source_rgb(0.5, 0.5, 1)
   cr:fill_preserve()
   cr:set_source_rgba(0.5, 0, 0, 0.5)
   cr.line_width = 10
   cr:stroke()
end

-- Iterate through all samples and create .png files from them
for name, sample in pairs(samples) do
   local surface = cairo.ImageSurface.create('ARGB32', 256, 256)
   local cr = cairo.Context.create(surface)
   sample(cr)
   surface:write_to_png('cairodemo-' .. name .. '.png')
end