public
Description: Fast, Nimble PDF Writer for Ruby
Homepage: http://prawn.majesticseacreature.com
Clone URL: git://github.com/sandal/prawn.git
Refactoring of bounding box stuff
sandal (author)
Mon Jul 21 08:04:57 -0700 2008
commit  efe870d121952287184ef3cd8d7b2c023b38cffe
tree    db96a0e0970dd3900a2c533befeaf3eb2b3aa2b1
parent  0fcc3530603a8d3d05e112cff39883038a213ce5
...
83
84
85
86
87
88
89
90
91
92
 
 
 
 
 
 
93
94
95
96
97
98
99
100
 
 
101
102
103
...
107
108
109
110
111
112
113
114
115
 
 
 
 
 
 
 
 
 
 
 
 
 
116
117
 
118
119
 
 
 
120
121
122
 
123
124
 
125
126
127
...
83
84
85
 
 
 
 
 
 
 
86
87
88
89
90
91
92
 
 
 
 
 
 
 
93
94
95
96
97
...
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
0
@@ -83,21 +83,15 @@ module Prawn
0
     # Of course, if you use canvas, you will be responsible for ensuring that
0
     # you remain within the printable area of your document.
0
     #
0
-    def bounding_box(*args, &block)
0
-      parent_box = @bounding_box
0
-      
0
-      # Offset to relative positions
0
-      top_left = args[0]
0
-      top_left[0] += parent_box.absolute_left
0
-      top_left[1] += parent_box.absolute_bottom
0
+    def bounding_box(*args, &block)    
0
+      init_bounding_box(block) do |parent_box|
0
+        # Offset to relative positions
0
+        top_left = args[0]
0
+        top_left[0] += parent_box.absolute_left
0
+        top_left[1] += parent_box.absolute_bottom
0
 
0
-      @bounding_box = BoundingBox.new(self, *args)
0
-      self.y = @bounding_box.absolute_top
0
-     
0
-      block.call
0
-      
0
-      self.y = @bounding_box.absolute_bottom
0
-      @bounding_box = parent_box
0
+        @bounding_box = BoundingBox.new(self, *args)   
0
+      end
0
     end
0
 
0
     # A shortcut to produce a bounding box which is mapped to the document's
0
@@ -107,21 +101,29 @@ module Prawn
0
     #     pdf.line pdf.bounds.bottom_left, pdf.bounds.top_right
0
     #   end
0
     #
0
-    def canvas(&block)
0
-      parent_box = @bounding_box
0
-      @bounding_box = BoundingBox.new(self, [0,page_dimensions[3]], 
0
-        :width => page_dimensions[2], 
0
-        :height => page_dimensions[3] 
0
-      )
0
+    def canvas(&block)     
0
+      init_bounding_box(block) do |_|
0
+        @bounding_box = BoundingBox.new(self, [0,page_dimensions[3]], 
0
+          :width => page_dimensions[2], 
0
+          :height => page_dimensions[3] 
0
+        ) 
0
+      end
0
+    end      
0
+    
0
+    private
0
+    
0
+    def init_bounding_box(user_block, &init_block)
0
+      parent_box = @bounding_box       
0
 
0
-      self.y = @bounding_box.absolute_top
0
+      init_block.call(parent_box)     
0
 
0
-      block.call
0
+      self.y = @bounding_box.absolute_top       
0
+      user_block.call   
0
+      self.y = @bounding_box.absolute_bottom 
0
 
0
-      self.y = @bounding_box.absolute_bottom
0
-      @bounding_box = parent_box
0
+      @bounding_box = parent_box 
0
     end
0
-    
0
+       
0
     class BoundingBox
0
       
0
       def initialize(parent, point, options={}) #:nodoc:

Comments