Changeset 883
- Timestamp:
- 05/02/07 11:03:47 (2 years ago)
- Files:
-
- ruport/trunk/lib/ruport/formatter/pdf.rb (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
ruport/trunk/lib/ruport/formatter/pdf.rb
r873 r883 40 40 # * style (:inline,:justified,:separated,:offset) 41 41 # 42 class Formatter::PDF < Formatter 42 class Formatter::PDF < Formatter 43 44 ## THESE ARE WHY YOU SHOULD NEVER USE PDF::Writer 45 46 module PDFWriterMemoryPatch #:nodoc: 47 unless self.class.instance_methods.include?("_post_transaction_rewind") 48 def _post_transaction_rewind 49 @objects.each { |e| e.instance_variable_set(:@parent,self) } 50 end 51 end 52 end 53 54 module PDFSimpleTableOrderingPatch #:nodoc: 55 def __find_table_max_width__(pdf) 56 #p "this actually gets called" 57 max_width = PDF::Writer::OHash.new(-1) 58 59 # Find the maximum cell widths based on the data and the headings. 60 # Passing through the data multiple times is unavoidable as we must do 61 # some analysis first. 62 @data.each do |row| 63 @cols.each do |name, column| 64 w = pdf.text_width(row[name].to_s, @font_size) 65 w *= PDF::SimpleTable::WIDTH_FACTOR 66 67 max_width[name] = w if w > max_width[name] 68 end 69 end 70 71 @cols.each do |name, column| 72 title = column.heading.title if column.heading 73 title ||= column.name 74 w = pdf.text_width(title, @heading_font_size) 75 w *= PDF::SimpleTable::WIDTH_FACTOR 76 max_width[name] = w if w > max_width[name] 77 end 78 max_width 79 end 80 end 43 81 44 82 renders :pdf, :for => [ Renderer::Row, Renderer::Table, … … 55 93 56 94 def initialize 57 quiet do 95 quiet do 58 96 require "pdf/writer" 59 97 require "pdf/simpletable" … … 275 313 format_opts = table_format.merge(format_opts) if table_format 276 314 277 ::PDF::SimpleTable.new do |table| 278 table. data = table_data315 ::PDF::SimpleTable.new do |table| 316 table.extend(PDFSimpleTableOrderingPatch) 279 317 table.maximum_width = 500 280 table.column_order = table_data.column_names 281 318 table.column_order = table_data.column_names 319 table.data = table_data 282 320 apply_pdf_table_column_opts(table,table_data,format_opts) 283 321 284 format_opts.each {|k,v| table.send("#{k}=", v) } 285 322 format_opts.each {|k,v| table.send("#{k}=", v) } 286 323 table.render_on(pdf_writer) 287 324 end … … 344 381 345 382 include DrawingHelpers 346 347 module PDFWriterMemoryPatch #:nodoc:348 unless self.class.instance_methods.include?("_post_transaction_rewind")349 def _post_transaction_rewind350 @objects.each { |e| e.instance_variable_set(:@parent,self) }351 end352 end353 end354 383 355 384 private
