[cairo-commit] rcairo/samples pac.rb, 1.6, 1.7 pac2.rb, 1.6, 1.7 png.rb, 1.12, 1.13 scalable.rb, 1.3, 1.4 text-on-path.rb, 1.3, 1.4 text2.rb, 1.6, 1.7

Kouhei Sutou commit at pdx.freedesktop.org
Sat Apr 7 23:04:11 PDT 2007


Committed by: kou

Update of /cvs/cairo/rcairo/samples
In directory kemper:/tmp/cvs-serv13606/samples

Modified Files:
	pac.rb pac2.rb png.rb scalable.rb text-on-path.rb text2.rb 
Log Message:
* src/rb_cairo_surface.c (ensure_finish_proc): supported
  Cairo::Surface.new with block. If block is exited, a surface is
  finished automatically.
* sample/*.rb: followed the above change.


Index: pac.rb
===================================================================
RCS file: /cvs/cairo/rcairo/samples/pac.rb,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- pac.rb	6 Mar 2007 12:17:34 -0000	1.6
+++ pac.rb	8 Apr 2007 06:04:02 -0000	1.7
@@ -86,16 +86,17 @@
   cr.show_page
 end
 
-surface = Cairo::ImageSurface.new(WIDTH, HEIGHT)
-cr = pac(surface)
-cr.target.write_to_png("pac.png")
+Cairo::ImageSurface.new(WIDTH, HEIGHT) do |surface|
+  cr = pac(surface)
+  cr.target.write_to_png("pac.png")
+end
 
 def scalable_surface_output(surface_class_name, suffix)
   if Cairo.const_defined?(surface_class_name)
     surface_class = Cairo.const_get(surface_class_name)
-    surface = surface_class.new("pac.#{suffix}", WIDTH, HEIGHT)
-    cr = pac(surface)
-    cr.target.finish
+    surface_class.new("pac.#{suffix}", WIDTH, HEIGHT) do |surface|
+      pac(surface)
+    end
   else
     puts("#{surface_class_name} isn't supported.")
   end

Index: pac2.rb
===================================================================
RCS file: /cvs/cairo/rcairo/samples/pac2.rb,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- pac2.rb	6 Mar 2007 12:17:34 -0000	1.6
+++ pac2.rb	8 Apr 2007 06:04:02 -0000	1.7
@@ -157,16 +157,17 @@
 width = 841.889763779528
 height = 595.275590551181
 
-surface = Cairo::ImageSurface.new(width, height)
-cr = pac(surface, width, height)
-cr.target.write_to_png("pac2.png")
+Cairo::ImageSurface.new(width, height) do |surface|
+  cr = pac(surface, width, height)
+  cr.target.write_to_png("pac2.png")
+end
 
 scalable_surface_output = Proc.new do |surface_class_name, suffix|
   if Cairo.const_defined?(surface_class_name)
     surface_class = Cairo.const_get(surface_class_name)
-    surface = surface_class.new("pac2.#{suffix}", width, height)
-    cr = pac(surface, width, height)
-    cr.target.finish
+    surface_class.new("pac2.#{suffix}", width, height) do |surface|
+      pac(surface, width, height)
+    end
   else
     puts("#{surface_class_name} isn't supported.")
   end

Index: png.rb
===================================================================
RCS file: /cvs/cairo/rcairo/samples/png.rb,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- png.rb	6 Mar 2007 12:17:34 -0000	1.12
+++ png.rb	8 Apr 2007 06:04:02 -0000	1.13
@@ -10,34 +10,37 @@
 width = 200
 height = 200
 
-surface = Cairo::ImageSurface.new(width, height)
-cr = Cairo::Context.new(surface)
+data = nil
+stride = nil
 
-# fill background with white
-cr.set_source_rgba(1.0, 1.0, 1.0, 0.8)
-cr.paint
+Cairo::ImageSurface.new(width, height) do |surface|
+  cr = Cairo::Context.new(surface)
 
-# create shape
-cr.move_to(50, 50)
-cr.curve_to(100, 25, 100, 75, 150, 50)
-cr.line_to(150, 150)
-cr.line_to(50, 150)
-cr.close_path
+  # fill background with white
+  cr.set_source_rgba(1.0, 1.0, 1.0, 0.8)
+  cr.paint
 
-cr.set_source_rgb(0.0, 0.0, 0.0)
-cr.fill_preserve
-cr.set_source_rgb(1.0, 0.0, 0.0)
-cr.set_line_join(Cairo::LINE_JOIN_MITER)
-cr.set_line_width(4)
-cr.stroke
+  # create shape
+  cr.move_to(50, 50)
+  cr.curve_to(100, 25, 100, 75, 150, 50)
+  cr.line_to(150, 150)
+  cr.line_to(50, 150)
+  cr.close_path
 
-cr.target.write_to_png("test.png")
+  cr.set_source_rgb(0.0, 0.0, 0.0)
+  cr.fill_preserve
+  cr.set_source_rgb(1.0, 0.0, 0.0)
+  cr.set_line_join(Cairo::LINE_JOIN_MITER)
+  cr.set_line_width(4)
+  cr.stroke
 
-data = cr.target.data
-stride = cr.target.stride
+  cr.target.write_to_png("test.png")
 
-cr.target.finish
+  data = cr.target.data
+  stride = cr.target.stride
+end
 
-surface = Cairo::ImageSurface.new(data, Cairo::FORMAT_ARGB32,
-                                  width, height, stride)
-surface.write_to_png("test-renew.png")
+Cairo::ImageSurface.new(data, Cairo::FORMAT_ARGB32,
+                        width, height, stride) do |surface|
+  surface.write_to_png("test-renew.png")
+end

Index: scalable.rb
===================================================================
RCS file: /cvs/cairo/rcairo/samples/scalable.rb,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- scalable.rb	6 Mar 2007 12:28:38 -0000	1.3
+++ scalable.rb	8 Apr 2007 06:04:02 -0000	1.4
@@ -9,32 +9,29 @@
 require 'stringio'
 
 def render(output, surface_class)
-  surface = surface_class.new(output, 200, 200)
-  cr = Cairo::Context.new(surface)
-
-  # fill background with white
-  cr.set_source_rgba(1.0, 1.0, 1.0, 0.8)
-  cr.paint
-
-  # create shape
-  cr.move_to(50, 50)
-  cr.curve_to(100, 25, 100, 75, 150, 50)
-  cr.line_to(150, 150)
-  cr.line_to(50, 150)
-  cr.close_path
+  surface_class.new(output, 200, 200) do |surface|
+    cr = Cairo::Context.new(surface)
 
-  cr.set_source_rgb(0.0, 0.0, 0.0)
-  cr.fill_preserve
-  cr.set_source_rgb(1.0, 0.0, 0.0)
-  cr.set_line_join(Cairo::LINE_JOIN_MITER)
-  cr.set_line_width(4)
-  cr.stroke
+    # fill background with white
+    cr.set_source_rgba(1.0, 1.0, 1.0, 0.8)
+    cr.paint
 
-  cr.show_page
+    # create shape
+    cr.move_to(50, 50)
+    cr.curve_to(100, 25, 100, 75, 150, 50)
+    cr.line_to(150, 150)
+    cr.line_to(50, 150)
+    cr.close_path
 
-  cr.target.finish
+    cr.set_source_rgb(0.0, 0.0, 0.0)
+    cr.fill_preserve
+    cr.set_source_rgb(1.0, 0.0, 0.0)
+    cr.set_line_join(Cairo::LINE_JOIN_MITER)
+    cr.set_line_width(4)
+    cr.stroke
 
-  cr
+    cr.show_page
+  end
 end
 
 def output(surface_class_name, suffix)

Index: text-on-path.rb
===================================================================
RCS file: /cvs/cairo/rcairo/samples/text-on-path.rb,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- text-on-path.rb	6 Mar 2007 12:17:34 -0000	1.3
+++ text-on-path.rb	8 Apr 2007 06:04:02 -0000	1.4
@@ -48,14 +48,13 @@
   cr.stroke
 
   cr.show_page
-
-  cr
 end
 
 def output
-  surface = Cairo::ImageSurface.new(500, 500)
-  render(surface)
-  surface.write_to_png("text-on-path.png")
+  Cairo::ImageSurface.new(500, 500) do |surface|
+    render(surface)
+    surface.write_to_png("text-on-path.png")
+  end
 end
 
 output

Index: text2.rb
===================================================================
RCS file: /cvs/cairo/rcairo/samples/text2.rb,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- text2.rb	6 Mar 2007 12:17:34 -0000	1.6
+++ text2.rb	8 Apr 2007 06:04:02 -0000	1.7
@@ -93,22 +93,20 @@
   body_width = width - margin_left - margin_right
   body_height = height - margin_top - margin_bottom
 
-  surface = surface_class.new(output, width, height)
-  cr = Cairo::Context.new(surface)
-
-  render_background(cr)
-  layout = make_layout(cr, text, body_width, font_description)
-  if fade_out
-    setup_fade_out(cr, body_width)
-  else
-    cr.set_source_rgba(0, 0, 0, 1)
-  end
-  render_layout(cr, layout, margin_left, margin_top, body_height)
+  surface_class.new(output, width, height) do |surface|
+    cr = Cairo::Context.new(surface)
 
-  cr.show_page
+    render_background(cr)
+    layout = make_layout(cr, text, body_width, font_description)
+    if fade_out
+      setup_fade_out(cr, body_width)
+    else
+      cr.set_source_rgba(0, 0, 0, 1)
+    end
+    render_layout(cr, layout, margin_left, margin_top, body_height)
 
-  cr.target.finish
-  cr
+    cr.show_page
+  end
 end
 
 def output(options, surface_class_name, suffix)



More information about the cairo-commit mailing list