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
|
# File 'lib/liquid_code.rb', line 31
def draw_to_canvas(bgcolor, fgcolor, fgcolorwhite, canvas, ox, oy, bs)
image_size=@qr.modules.size * bs
canvas.stroke(bgcolor)
canvas.fill(bgcolor)
canvas.rectangle(ox, oy, ox + image_size, oy + image_size)
canvas.stroke(fgcolor)
canvas.fill(fgcolor)
canvas.fill_opacity(1)
canvas.stroke_width(1)
hbs = bs/2
is_dark = lambda { |x, y|
begin
return ((@qr.is_dark(y, x) and fgcolorwhite) or ((not @qr.is_dark(y, x)) and (not fgcolorwhite)))
rescue IndexError, RQRCode::QRCodeRunTimeError
return (not fgcolorwhite)
end
}
@qr.modules.each_index do |x|
@qr.modules.each_index do |y|
if is_dark.call(x, y)
canvas.roundrectangle(ox+(x * bs), oy+(y * bs), ox+((x+1) * bs), oy+((y+1) * bs), hbs, hbs)
if (is_dark.call(x, y+1))
canvas.rectangle(ox+(x * bs), oy+(y * bs)+hbs, ox+((x+1) * bs), oy+((y+1) * bs)+hbs)
end
if (is_dark.call(x+1, y))
canvas.rectangle(ox+(x * bs)+hbs, oy+(y * bs), ox+((x+1) * bs)+hbs, oy+((y+1) * bs))
end
end
end
end
@qr.modules.each_index do |x|
@qr.modules.each_index do |y|
if (not is_dark.call(x, y))
if (is_dark.call(x+1, y) and is_dark.call(x, y-1) and is_dark.call(x+1, y-1))
canvas.rectangle(ox+(x * bs)+hbs, oy+(y * bs), ox+((x+1) * bs), oy+((y) * bs)+hbs)
end
if (is_dark.call(x+1, y) and is_dark.call(x+1, y+1) and is_dark.call(x, y+1))
canvas.rectangle(ox+(x * bs)+hbs, oy+(y * bs)+hbs, ox+((x+1) * bs), oy+((y+1) * bs))
end
if (is_dark.call(x-1, y) and is_dark.call(x-1, y+1) and is_dark.call(x, y+1))
canvas.rectangle(ox+(x * bs), oy+(y * bs)+hbs, ox+(x * bs)+hbs, oy+((y+1) * bs))
end
if (is_dark.call(x-1, y-1) and is_dark.call(x-1, y) and is_dark.call(x, y-1))
canvas.rectangle(ox+(x * bs), oy+(y * bs), ox+(x * bs)+hbs, oy+(y * bs)+hbs)
end
canvas.fill(bgcolor)
canvas.stroke(bgcolor)
canvas.roundrectangle(ox+(x * bs)+1, oy+(y * bs)+1, ox+((x+1) * bs)-1, oy+((y+1) * bs)-1, hbs, hbs)
canvas.stroke(fgcolor)
canvas.fill(fgcolor)
end
end
end
end
|