Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Revert "Document bug in cell width calculation."

This reverts commit 2024b97.
  • Loading branch information...
commit 15be513be9863f0e5cff2e21d5ac7c37ee5bf0bf 1 parent aae81ba
@bradediger bradediger authored
View
20 bugs/cell_width_problems.rb
@@ -1,20 +0,0 @@
-# cell attributes aren't taken into account while
-# auto-calculating widths
-
-require 'rubygems'
-require 'prawn'
-require 'prawn/layout'
-
-pdf = Prawn::Document.new
-pdf.font 'Helvetica'
-cell1 = { :text => 'nnnnnnnnnnnnnnnnnnnnnn', :font_style => :normal }
-cell2 = { :text => 'nnnnnnnnnnnnnnnnnnnnnn', :font_style => :bold_italic }
-pdf.table [[cell1]]
-pdf.table [[cell2]]
-
-cell3 = { :text => 'nnnnnnnnnnnnnnnnnnnnnn', :font_size => 8 }
-cell4 = { :text => 'nnnnnnnnnnnnnnnnnnnnnn', :font_size => 24 }
-pdf.table [[cell3]]
-pdf.table [[cell4]]
-
-pdf.render_file("widths.pdf")
View
12 lib/prawn/table.rb
@@ -45,8 +45,7 @@ class Document
def table(data, options={})
if data.nil? || data.empty?
raise Prawn::Errors::EmptyTable,
- "data must be a non-empty, non-nil, two dimensional array of " +
- "Prawn::Table::Cells, Hashes, and Strings"
+ "data must be a non-empty, non-nil, two dimensional array of Prawn::Cells or strings"
end
Prawn::Table.new(data,self,options).draw
end
@@ -128,7 +127,7 @@ def initialize(data, document, options={})
@data = data
@document = document
- Prawn.verify_options [:font_size, :border_style, :border_width,
+ Prawn.verify_options [:font_size,:border_style, :border_width,
:position, :headers, :row_colors, :align, :align_headers,
:header_text_color, :border_color, :horizontal_padding,
:vertical_padding, :padding, :column_widths, :width, :header_color ],
@@ -271,6 +270,7 @@ def generate_table
align = C(:align)
end
+
align ||= e.to_s =~ NUMBER_PATTERN ? :right : :left
case e
@@ -293,9 +293,9 @@ def generate_table
end
cell_options = {
- :document => @document,
- :text => text,
- :width => width,
+ :document => @document,
+ :text => text,
+ :width => width,
:horizontal_padding => C(:horizontal_padding),
:vertical_padding => C(:vertical_padding),
:border_width => C(:border_width),
View
32 spec/table_spec.rb
@@ -10,7 +10,6 @@
table.width.should == 300
end
-
it "should calculate unspecified column widths even " +
"with colspan cells declared" do
pdf = Prawn::Document.new
@@ -31,7 +30,7 @@
col2_width.ceil + 2*columns*hpad
end
- it "should calculate unspecified column widths as " +
+ it "should calculate unspecified column widths as "+
"(max(string_width).ceil + 2*horizontal_padding)" do
pdf = Prawn::Document.new
hpad, fs = 3, 12
@@ -45,29 +44,6 @@
table.width.should == col0_width.ceil + col1_width.ceil + 2*columns*hpad
end
- it "should take font styles into account while autocalculating widths" do
- pdf = Prawn::Document.new
- pdf.font 'Helvetica'
- cell1 = { :text => 'nnnnnnnnnnnnnnnnnnnnnn', :font_style => :normal }
- cell2 = { :text => 'nnnnnnnnnnnnnnnnnnnnnn', :font_style => :bold_italic }
- table1 = Prawn::Table.new([[cell1]], pdf)
- table2 = Prawn::Table.new([[cell2]], pdf)
- table1.width.should.not == table2.width
- end
-
- it "should take font size into account while autocalculating widths" do
- pdf = Prawn::Document.new
- pdf.font 'Helvetica'
- cell1 = { :text => 'nnnnnnnnnnnnnnnnnnnnnn', :font_size => 8 }
- cell2 = { :text => 'nnnnnnnnnnnnnnnnnnnnnn' }
- cell3 = { :text => 'nnnnnnnnnnnnnnnnnnnnnn', :font_size => 24 }
- table1 = Prawn::Table.new([[cell1]], pdf)
- table2 = Prawn::Table.new([[cell2]], pdf)
- table3 = Prawn::Table.new([[cell3]], pdf)
- table1.width.should < table2.width
- table2.width.should < table3.width
- end
-
it "should allow mixing autocalculated and preset"+
"column widths within a single table" do
@@ -108,8 +84,7 @@
end
- it "should not exceed the maximum width of the margin_box " +
- "even with manual widths specified" do
+ it "should not exceed the maximum width of the margin_box even with manual widths specified" do
pdf = Prawn::Document.new
expected_width = pdf.margin_box.width
@@ -202,8 +177,7 @@
describe "A table's content" do
- it "should not cause an error if rendering the very first "+
- "row causes a page break" do
+ it "should not cause an error if rendering the very first row causes a page break" do
Prawn::Document.new( :page_layout => :portrait ) do
arr = Array(1..5).collect{|i| ["cell #{i}"] }
Please sign in to comment.
Something went wrong with that request. Please try again.