public
Description: Fast, Nimble PDF Writer for Ruby
Homepage: http://prawn.majesticseacreature.com
Clone URL: git://github.com/sandal/prawn.git
Accidentally implemented cell by cell colour support
sandal (author)
Thu Jul 24 14:04:21 -0700 2008
commit  6397aa2d3dc5f5f38c9634b5946af310e6ad4e7e
tree    df65f158cf38fc5299cfae5cfc98a7d29002adc3
parent  c18d829968451c63da3c3b2fb86c783edfdebe8c
...
12
13
14
15
 
 
 
16
17
18
...
12
13
14
 
15
16
17
18
19
20
0
@@ -12,7 +12,9 @@ Prawn::Document.generate("fancy_table.pdf", :page_layout => :landscape) do
0
   mask(:y) { table body, :headers => headers }
0
 
0
   table [["This is",   "A Test"    ],
0
-         ["Of tables", "Drawn Side"],
0
+         [  Prawn::Graphics::Cell.new( :text => "Of tables",
0
+                                       :background_color => "ffccff" ),
0
+            "Drawn Side"],
0
          ["By side",   "and stuff" ]], 
0
     :position         => 600, 
0
     :headers          => ["Col A", "Col B"],
...
171
172
173
174
175
176
177
178
179
180
181
182
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
184
185
...
171
172
173
 
 
 
 
 
 
 
 
 
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
0
@@ -171,15 +171,26 @@ module Prawn
0
         @document.font_size(@font_size) do
0
           renderable_data.each_with_index do |row,index|
0
             c = Prawn::Graphics::CellBlock.new(@document)
0
-            row.each_with_index do |e,i|
0
-              c << Prawn::Graphics::Cell.new(
0
-                :document => @document, 
0
-                :text     => e.to_s, 
0
-                :width    => @col_widths[i],
0
-                :horizontal_padding => @horizontal_padding,
0
-                :vertical_padding => @vertical_padding,
0
-                :border   => @border,
0
-                :border_style => :sides )    
0
+            row.each_with_index do |e,i| 
0
+              case(e)
0
+              when Prawn::Graphics::Cell
0
+                e.document = @document
0
+                e.width    = @col_widths[i]
0
+                e.horizontal_padding = @horizontal_padding
0
+                e.vertical_padding   = @vertical_padding    
0
+                e.border             = @border
0
+                e.border_style       = :sides
0
+                c << e
0
+              else
0
+                c << Prawn::Graphics::Cell.new(
0
+                  :document => @document, 
0
+                  :text     => e.to_s, 
0
+                  :width    => @col_widths[i],
0
+                  :horizontal_padding => @horizontal_padding,
0
+                  :vertical_padding => @vertical_padding,
0
+                  :border   => @border,
0
+                  :border_style => :sides ) 
0
+              end   
0
             end
0
 
0
             if c.height > y_pos - @document.margin_box.absolute_bottom
...
45
46
47
48
 
49
50
51
...
59
60
61
62
63
 
 
 
 
 
 
 
64
65
66
...
190
191
192
193
 
194
195
196
...
45
46
47
 
48
49
50
51
...
59
60
61
 
 
62
63
64
65
66
67
68
69
70
71
...
195
196
197
 
198
199
200
201
0
@@ -45,7 +45,7 @@ module Prawn
0
       def initialize(options={})
0
         @point        = options[:point]
0
         @document     = options[:document]
0
-        @text         = options[:text]
0
+        @text         = options[:text].to_s
0
         @width        = options[:width]
0
         @border       = options[:border]
0
         @border_style = options[:border_style] || :all               
0
@@ -59,8 +59,13 @@ module Prawn
0
         end
0
       end
0
 
0
-      attr_accessor :point, :border_style, :border, :background_color
0
-      attr_writer   :height #:nodoc:
0
+      attr_accessor :point, :border_style, :border, :background_color,
0
+                    :document, :horizontal_padding, :vertical_padding
0
+      attr_writer   :height, :width #:nodoc:   
0
+      
0
+      def to_s
0
+        @text
0
+      end
0
 
0
       # The width of the text area excluding the horizonal padding
0
       #
0
@@ -190,7 +195,7 @@ module Prawn
0
           e.point  = [x - @document.bounds.absolute_left, 
0
                       y - @document.bounds.absolute_bottom]
0
           e.height = @height
0
-          e.background_color = @background_color
0
+          e.background_color ||= @background_color
0
           e.draw
0
           x += e.width
0
         end

Comments