lib/prawn/table.rb in prawn-0.13.1 vs lib/prawn/table.rb in prawn-0.13.2
- old
+ new
@@ -4,17 +4,18 @@
#
# Copyright December 2009, Brad Ediger. All rights reserved.
#
# This is free software. Please see the LICENSE and COPYING files for details.
-require 'prawn/table/cells'
-require 'prawn/table/cell'
-require 'prawn/table/cell/in_table'
-require 'prawn/table/cell/text'
-require 'prawn/table/cell/subtable'
-require 'prawn/table/cell/image'
-require 'prawn/table/cell/span_dummy'
+require_relative 'table/column_width_calculator'
+require_relative 'table/cells'
+require_relative 'table/cell'
+require_relative 'table/cell/in_table'
+require_relative 'table/cell/text'
+require_relative 'table/cell/subtable'
+require_relative 'table/cell/image'
+require_relative 'table/cell/span_dummy'
module Prawn
class Document
@@ -547,24 +548,10 @@
end
# Returns an array of each column's natural (unconstrained) width.
#
def natural_column_widths
- @natural_column_widths ||=
- begin
- widths_by_column = Hash.new(0)
- cells.each do |cell|
- next if cell.is_a?(Cell::SpanDummy)
-
- # Split the width of colspanned cells evenly by columns
- width_per_column = cell.width.to_f / cell.colspan
- cell.colspan.times do |i|
- widths_by_column[cell.column + i] =
- [widths_by_column[cell.column + i], width_per_column].max
- end
- end
- widths_by_column.sort_by { |col, _| col }.map { |_, w| w }
- end
+ @natural_column_widths ||= ColumnWidthCalculator.new(cells).natural_widths
end
# Returns the "natural" (unconstrained) width of the table. This may be
# extremely silly; for example, the unconstrained width of a paragraph of
# text is the width it would assume if it were not wrapped at all. Could be