cairo 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cairo might be problematic. Click here for more details.

@@ -0,0 +1,36 @@
1
+ #!/USO/bin/env ruby
2
+
3
+ require 'cairo'
4
+
5
+ margin = 10
6
+ rectangle_width = 300
7
+ rectangle_height = 100
8
+
9
+ width = rectangle_width + 2 * margin
10
+ height = (rectangle_height + 2 * margin) * 3
11
+
12
+ surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, width, height)
13
+ context = Cairo::Context.new(surface)
14
+
15
+ context.set_source_rgb(1, 1, 1)
16
+ context.paint
17
+
18
+ context.set_source_rgba(0.3, 0.3, 0.3)
19
+ context.rectangle(margin, margin, rectangle_width, rectangle_height)
20
+ context.fill
21
+
22
+ context.pseudo_blur do
23
+ context.set_source_rgb(0.3, 0.3, 0.3)
24
+ context.rectangle(margin, rectangle_height + 2 * margin + margin / 2,
25
+ rectangle_width, rectangle_height)
26
+ context.fill
27
+ end
28
+
29
+ context.pseudo_blur(5) do
30
+ context.set_source_rgb(0.3, 0.3, 0.3)
31
+ context.rectangle(margin, (rectangle_height + 2 * margin) * 2 + margin / 2,
32
+ rectangle_width, rectangle_height)
33
+ context.fill
34
+ end
35
+
36
+ surface.write_to_png("blur.png")
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ top = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ src = File.join(top, "src")
5
+ $LOAD_PATH.unshift src
6
+ $LOAD_PATH.unshift File.join(src, "lib")
7
+
8
+ require 'cairo'
9
+
10
+ margin = 10
11
+ rectangle_width = 300
12
+ rectangle_height = 100
13
+
14
+ width = rectangle_width + 2 * margin
15
+ height = (rectangle_height + 2 * margin) * 3
16
+
17
+ surface = Cairo::ImageSurface.new(width, height)
18
+ context = Cairo::Context.new(surface)
19
+
20
+ context.set_source_color(:white)
21
+ context.paint
22
+
23
+ module Cairo
24
+ module Color
25
+ GRAY30 = Cairo::Color::RGB.new(0.3, 0.3, 0.3)
26
+ end
27
+ end
28
+
29
+ context.set_source_color(:gray30)
30
+ context.rectangle(margin, margin, rectangle_width, rectangle_height)
31
+ context.fill
32
+
33
+ context.pseudo_blur do
34
+ context.set_source_color(:gray30)
35
+ context.rectangle(margin, rectangle_height + 2 * margin + margin / 2,
36
+ rectangle_width, rectangle_height)
37
+ context.fill
38
+ end
39
+
40
+ context.pseudo_blur(5) do
41
+ context.set_source_color(:gray30)
42
+ context.rectangle(margin, (rectangle_height + 2 * margin) * 2 + margin / 2,
43
+ rectangle_width, rectangle_height)
44
+ context.fill
45
+ end
46
+
47
+ surface.write_to_png("blur.png")
@@ -15,42 +15,35 @@ WIDTH = 841.889763779528
15
15
  HEIGHT = 595.275590551181
16
16
 
17
17
  def pac(surface)
18
- white = [1, 1, 1]
19
- black = [0, 0, 0]
20
- magenta = [1, 0, 1]
21
- cyan = [0, 1, 1]
22
- yellow = [1, 1, 0]
23
- blue = [0, 0, 1]
24
-
25
18
  cr = Cairo::Context.new(surface)
26
19
 
27
- cr.set_source_rgb(*black)
20
+ cr.set_source_color(:black)
28
21
  cr.rectangle(0, 0, WIDTH, HEIGHT).fill
29
22
 
30
23
  # Wall
31
- cr.set_source_rgb(*magenta)
24
+ cr.set_source_color(:magenta)
32
25
  cr.rounded_rectangle(20, 80, 750, 20, 10)
33
26
  cr.fill
34
- cr.set_source_rgb(*cyan)
27
+ cr.set_source_color(:cyan)
35
28
  cr.rounded_rectangle(20, 80, 750, 20, 10)
36
29
  cr.stroke
37
-
38
- cr.set_source_rgb(*magenta)
30
+
31
+ cr.set_source_color(:magenta)
39
32
  cr.rounded_rectangle(20, 380, 750, 20, 10)
40
33
  cr.fill
41
- cr.set_source_rgb(*cyan)
34
+ cr.set_source_color(:cyan)
42
35
  cr.rounded_rectangle(20, 380, 750, 20, 10)
43
36
  cr.stroke
44
-
37
+
45
38
  # Body
46
- cr.set_source_rgb(*yellow)
39
+ cr.set_source_color(:yellow)
47
40
  cr.fill do
48
41
  cr.arc(150, 250, 100, 30 * (Math::PI / 180), 330 * (Math::PI / 180))
49
42
  cr.line_to(150, 250)
50
43
  end
51
44
 
52
45
  # Dot
53
- cr.set_source_rgb(*yellow)
46
+ cr.set_source_color(:yellow)
54
47
  cr.circle(250, 250, 20).fill
55
48
  cr.circle(300, 250, 10).fill
56
49
  cr.circle(350, 250, 10).fill
@@ -69,33 +62,34 @@ def pac(surface)
69
62
  cr.line_to(525, 325)
70
63
  cr.line_to(500, 350)
71
64
 
72
- cr.set_source_rgb(*blue)
65
+ cr.set_source_color(:blue)
73
66
  cr.fill_preserve
74
- cr.set_source_rgb(*cyan)
67
+ cr.set_source_color(:cyan)
75
68
  cr.stroke
76
69
 
77
70
  # Ghost Eyes
78
- cr.set_source_rgb(*white)
71
+ cr.set_source_color(:white)
79
72
  cr.rectangle(525, 200, 25, 25).fill
80
73
  cr.rectangle(575, 200, 25, 25).fill
81
-
82
- cr.set_source_rgb(*black)
74
+
75
+ cr.set_source_color(:black)
83
76
  cr.rectangle(525, 215, 10, 10).fill
84
77
  cr.rectangle(575, 215, 10, 10).fill
85
-
78
+
86
79
  cr.show_page
87
80
  end
88
81
 
89
- surface = Cairo::ImageSurface.new(WIDTH, HEIGHT)
90
- cr = pac(surface)
91
- cr.target.write_to_png("pac.png")
82
+ Cairo::ImageSurface.new(WIDTH, HEIGHT) do |surface|
83
+ cr = pac(surface)
84
+ cr.target.write_to_png("pac.png")
85
+ end
92
86
 
93
87
  def scalable_surface_output(surface_class_name, suffix)
94
88
  if Cairo.const_defined?(surface_class_name)
95
89
  surface_class = Cairo.const_get(surface_class_name)
96
- surface = surface_class.new("pac.#{suffix}", WIDTH, HEIGHT)
97
- cr = pac(surface)
98
- cr.target.finish
90
+ surface_class.new("pac.#{suffix}", WIDTH, HEIGHT) do |surface|
91
+ pac(surface)
92
+ end
99
93
  else
100
94
  puts("#{surface_class_name} isn't supported.")
101
95
  end
@@ -12,22 +12,15 @@ $LOAD_PATH.unshift File.join(src, "lib")
12
12
  require "cairo"
13
13
 
14
14
  def pac(surface, width, height)
15
- white = [1, 1, 1]
16
- black = [0, 0, 0]
17
- magenta = [1, 0, 1]
18
- cyan = [0, 1, 1]
19
- yellow = [1, 1, 0]
20
- blue = [0, 0, 1]
21
-
22
15
  cr = Cairo::Context.new(surface)
23
16
 
24
17
  # NOTE: You may need to set line width when use Cairo::Context#scale
25
18
  cr.set_line_width(cr.line_width / [width, height].max)
26
-
19
+
27
20
  cr.scale(width, height)
28
21
 
29
22
  cr.save do
30
- cr.set_source_rgb(*black)
23
+ cr.set_source_color(:black)
31
24
  cr.rectangle(0, 0, 1, 1)
32
25
  cr.fill
33
26
  end
@@ -40,30 +33,30 @@ def pac(surface, width, height)
40
33
  wall1_y = 1 - 0.86
41
34
  wall2_y = wall1_y + wall_space
42
35
  wall_radius = 0.01
43
-
44
- cr.set_source_rgb(*magenta)
36
+
37
+ cr.set_source_color(:magenta)
45
38
  cr.rounded_rectangle(wall_x, wall1_y, wall_width, wall_height, wall_radius)
46
39
  cr.fill
47
- cr.set_source_rgb(*cyan)
40
+ cr.set_source_color(:cyan)
48
41
  cr.rounded_rectangle(wall_x, wall1_y, wall_width, wall_height, wall_radius)
49
42
  cr.stroke
50
-
51
- cr.set_source_rgb(*magenta)
43
+
44
+ cr.set_source_color(:magenta)
52
45
  cr.rounded_rectangle(wall_x, wall2_y, wall_width, wall_height, wall_radius)
53
46
  cr.fill
54
- cr.set_source_rgb(*cyan)
47
+ cr.set_source_color(:cyan)
55
48
  cr.rounded_rectangle(wall_x, wall2_y, wall_width, wall_height, wall_radius)
56
49
  cr.stroke
57
-
50
+
58
51
  # Body
59
52
  body_x = 0.17
60
53
  body_y = 1 - 0.58
61
54
  body_width = 0.23
62
55
  body_height = 0.33
63
-
56
+
64
57
  cr.save do
65
58
  cr.translate(body_x, body_y)
66
- cr.set_source_rgb(*yellow)
59
+ cr.set_source_color(:yellow)
67
60
  cr.scale(body_width, body_height)
68
61
  cr.arc(0, 0, 0.5, 30 * (Math::PI / 180), 330 * (Math::PI / 180))
69
62
  cr.line_to(0, 0)
@@ -79,9 +72,9 @@ def pac(surface, width, height)
79
72
  dot_x = 0.29
80
73
  dot_y = 1 - 0.58
81
74
  dot_step = 0.05
82
-
75
+
83
76
  cr.save do
84
- cr.set_source_rgb(*yellow)
77
+ cr.set_source_color(:yellow)
85
78
  cr.save do
86
79
  cr.translate(dot_x, dot_y)
87
80
  cr.scale(dot_width, dot_height)
@@ -120,10 +113,10 @@ def pac(surface, width, height)
120
113
  i += 1
121
114
  end
122
115
  cr.close_path
123
-
124
- cr.set_source_rgb(*blue)
116
+
117
+ cr.set_source_color(:blue)
125
118
  cr.fill_preserve
126
- cr.set_source_rgb(*cyan)
119
+ cr.set_source_color(:cyan)
127
120
  cr.stroke
128
121
 
129
122
  # Ghost Eyes
@@ -135,15 +128,15 @@ def pac(surface, width, height)
135
128
  black_eye_width = 0.01
136
129
  black_eye_height = 0.02
137
130
 
138
- cr.set_source_rgb(*white)
131
+ cr.set_source_color(:white)
139
132
  cr.rectangle(eye_x, eye_y - white_eye_height,
140
133
  white_eye_width, white_eye_height)
141
134
  cr.fill
142
135
  cr.rectangle(eye_x + eye_space, eye_y - white_eye_height,
143
136
  white_eye_width, white_eye_height)
144
137
  cr.fill
145
-
146
- cr.set_source_rgb(*black)
138
+
139
+ cr.set_source_color(:black)
147
140
  cr.rectangle(eye_x, eye_y - black_eye_height,
148
141
  black_eye_width, black_eye_height)
149
142
  cr.fill
@@ -157,16 +150,17 @@ end
157
150
  width = 841.889763779528
158
151
  height = 595.275590551181
159
152
 
160
- surface = Cairo::ImageSurface.new(width, height)
161
- cr = pac(surface, width, height)
162
- cr.target.write_to_png("pac2.png")
153
+ Cairo::ImageSurface.new(width, height) do |surface|
154
+ cr = pac(surface, width, height)
155
+ cr.target.write_to_png("pac2.png")
156
+ end
163
157
 
164
158
  scalable_surface_output = Proc.new do |surface_class_name, suffix|
165
159
  if Cairo.const_defined?(surface_class_name)
166
160
  surface_class = Cairo.const_get(surface_class_name)
167
- surface = surface_class.new("pac2.#{suffix}", width, height)
168
- cr = pac(surface, width, height)
169
- cr.target.finish
161
+ surface_class.new("pac2.#{suffix}", width, height) do |surface|
162
+ pac(surface, width, height)
163
+ end
170
164
  else
171
165
  puts("#{surface_class_name} isn't supported.")
172
166
  end
@@ -10,34 +10,37 @@ require 'cairo'
10
10
  width = 200
11
11
  height = 200
12
12
 
13
- surface = Cairo::ImageSurface.new(width, height)
14
- cr = Cairo::Context.new(surface)
15
-
16
- # fill background with white
17
- cr.set_source_rgba(1.0, 1.0, 1.0, 0.8)
18
- cr.paint
19
-
20
- # create shape
21
- cr.move_to(50, 50)
22
- cr.curve_to(100, 25, 100, 75, 150, 50)
23
- cr.line_to(150, 150)
24
- cr.line_to(50, 150)
25
- cr.close_path
26
-
27
- cr.set_source_rgb(0.0, 0.0, 0.0)
28
- cr.fill_preserve
29
- cr.set_source_rgb(1.0, 0.0, 0.0)
30
- cr.set_line_join(Cairo::LINE_JOIN_MITER)
31
- cr.set_line_width(4)
32
- cr.stroke
33
-
34
- cr.target.write_to_png("test.png")
35
-
36
- data = cr.target.data
37
- stride = cr.target.stride
38
-
39
- cr.target.finish
40
-
41
- surface = Cairo::ImageSurface.new(data, Cairo::FORMAT_ARGB32,
42
- width, height, stride)
43
- surface.write_to_png("test-renew.png")
13
+ data = nil
14
+ stride = nil
15
+
16
+ Cairo::ImageSurface.new(width, height) do |surface|
17
+ cr = Cairo::Context.new(surface)
18
+
19
+ # fill background with white
20
+ cr.set_source_color("#fffc")
21
+ cr.paint
22
+
23
+ # create shape
24
+ cr.move_to(50, 50)
25
+ cr.curve_to(100, 25, 100, 75, 150, 50)
26
+ cr.line_to(150, 150)
27
+ cr.line_to(50, 150)
28
+ cr.close_path
29
+
30
+ cr.set_source_color(:black)
31
+ cr.fill_preserve
32
+ cr.set_source_color(:red)
33
+ cr.set_line_join(Cairo::LINE_JOIN_MITER)
34
+ cr.set_line_width(4)
35
+ cr.stroke
36
+
37
+ cr.target.write_to_png("test.png")
38
+
39
+ data = cr.target.data
40
+ stride = cr.target.stride
41
+ end
42
+
43
+ Cairo::ImageSurface.new(data, Cairo::FORMAT_ARGB32,
44
+ width, height, stride) do |surface|
45
+ surface.write_to_png("test-renew.png")
46
+ end
@@ -9,32 +9,30 @@ require 'cairo'
9
9
  require 'stringio'
10
10
 
11
11
  def render(output, surface_class)
12
- surface = surface_class.new(output, 200, 200)
13
- cr = Cairo::Context.new(surface)
14
-
15
- # fill background with white
16
- cr.set_source_rgba(1.0, 1.0, 1.0, 0.8)
17
- cr.paint
18
-
19
- # create shape
20
- cr.move_to(50, 50)
21
- cr.curve_to(100, 25, 100, 75, 150, 50)
22
- cr.line_to(150, 150)
23
- cr.line_to(50, 150)
24
- cr.close_path
25
-
26
- cr.set_source_rgb(0.0, 0.0, 0.0)
27
- cr.fill_preserve
28
- cr.set_source_rgb(1.0, 0.0, 0.0)
29
- cr.set_line_join(Cairo::LINE_JOIN_MITER)
30
- cr.set_line_width(4)
31
- cr.stroke
32
-
33
- cr.show_page
34
-
35
- cr.target.finish
36
-
37
- cr
12
+ surface_class.new(output, 200, 200) do |surface|
13
+ cr = Cairo::Context.new(surface)
14
+
15
+ # fill background with white
16
+ cr.set_source_color("#fffc")
17
+ cr.paint
18
+
19
+ # create shape
20
+ cr.move_to(50, 50)
21
+ cr.curve_to(100, 25, 100, 75, 150, 50)
22
+ cr.line_to(150, 150)
23
+ cr.line_to(50, 150)
24
+ cr.close_path
25
+
26
+ cr.set_source_color(:black)
27
+ cr.fill_preserve
28
+ cr.set_source_color(:red)
29
+ cr.set_line_join(Cairo::LINE_JOIN_MITER)
30
+ cr.set_line_width(4)
31
+ cr.stroke
32
+
33
+ cr.show_page
34
+ surface.finish
35
+ end
38
36
  end
39
37
 
40
38
  def output(surface_class_name, suffix)
@@ -9,7 +9,7 @@ require 'cairo'
9
9
  require 'pango'
10
10
 
11
11
  def render_background(cr)
12
- cr.set_source_rgba(1.0, 1.0, 1.0)
12
+ cr.set_source_color(:white)
13
13
  cr.paint
14
14
  end
15
15
 
@@ -28,7 +28,7 @@ def render(surface)
28
28
 
29
29
  render_background(cr)
30
30
 
31
- cr.set_source_rgba(1, 0, 0, 1)
31
+ cr.set_source_color(:red)
32
32
  cr.move_to(25, 350)
33
33
  cr.line_to(150, 375)
34
34
  cr.curve_to(275, 400, 450, 350, 450, 200)
@@ -48,14 +48,13 @@ def render(surface)
48
48
  cr.stroke
49
49
 
50
50
  cr.show_page
51
-
52
- cr
53
51
  end
54
52
 
55
53
  def output
56
- surface = Cairo::ImageSurface.new(500, 500)
57
- render(surface)
58
- surface.write_to_png("text-on-path.png")
54
+ Cairo::ImageSurface.new(500, 500) do |surface|
55
+ render(surface)
56
+ surface.write_to_png("text-on-path.png")
57
+ end
59
58
  end
60
59
 
61
60
  output