[cairo-commit] rcairo/samples pac.rb,1.8,1.9 pac2.rb,1.8,1.9

Kouhei Sutou commit at pdx.freedesktop.org
Thu Apr 10 22:19:27 PDT 2008


Committed by: kou

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

Modified Files:
	pac.rb pac2.rb 
Log Message:
* samples/pac.rb, samples/pac2.rb: use Cairo::Paper.


Index: pac.rb
===================================================================
RCS file: /cvs/cairo/rcairo/samples/pac.rb,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- pac.rb	16 Apr 2007 07:31:43 -0000	1.8
+++ pac.rb	11 Apr 2008 05:24:14 -0000	1.9
@@ -11,14 +11,13 @@
 
 require "cairo"
 
-WIDTH = 841.889763779528
-HEIGHT = 595.275590551181
+paper = Cairo::Paper::A4_LANDSCAPE
 
 def pac(surface)
   cr = Cairo::Context.new(surface)
 
   cr.set_source_color(:black)
-  cr.rectangle(0, 0, WIDTH, HEIGHT).fill
+  cr.paint
 
   # Wall
   cr.set_source_color(:magenta)
@@ -79,15 +78,15 @@
   cr.show_page
 end
 
-Cairo::ImageSurface.new(WIDTH, HEIGHT) do |surface|
+Cairo::ImageSurface.new(*paper.size("pt")) do |surface|
   cr = pac(surface)
   cr.target.write_to_png("pac.png")
 end
 
-def scalable_surface_output(surface_class_name, suffix)
+def scalable_surface_output(surface_class_name, paper, suffix)
   if Cairo.const_defined?(surface_class_name)
     surface_class = Cairo.const_get(surface_class_name)
-    surface_class.new("pac.#{suffix}", WIDTH, HEIGHT) do |surface|
+    surface_class.new("pac.#{suffix}", paper) do |surface|
       pac(surface)
     end
   else
@@ -95,6 +94,6 @@
   end
 end
 
-scalable_surface_output("PSSurface", "ps")
-scalable_surface_output("PDFSurface", "pdf")
-scalable_surface_output("SVGSurface", "svg")
+scalable_surface_output("PSSurface", paper, "ps")
+scalable_surface_output("PDFSurface", paper, "pdf")
+scalable_surface_output("SVGSurface", paper, "svg")

Index: pac2.rb
===================================================================
RCS file: /cvs/cairo/rcairo/samples/pac2.rb,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- pac2.rb	16 Apr 2007 07:31:43 -0000	1.8
+++ pac2.rb	11 Apr 2008 05:24:14 -0000	1.9
@@ -147,19 +147,19 @@
   cr.show_page
 end
 
-width = 841.889763779528
-height = 595.275590551181
+paper = Cairo::Paper.parse(:a4_landscape)
 
-Cairo::ImageSurface.new(width, height) do |surface|
-  cr = pac(surface, width, height)
+size_in_points = paper.size("pt")
+Cairo::ImageSurface.new(*size_in_points) do |surface|
+  cr = pac(surface, *size_in_points)
   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_class.new("pac2.#{suffix}", width, height) do |surface|
-      pac(surface, width, height)
+    surface_class.new("pac2.#{suffix}", paper) do |surface|
+      pac(surface, *size_in_points)
     end
   else
     puts("#{surface_class_name} isn't supported.")



More information about the cairo-commit mailing list