Skip to content

Commit

Permalink
update to use Document#width_of instead of Font#width_of
Browse files Browse the repository at this point in the history
  • Loading branch information
jamis committed Jan 28, 2009
1 parent 516f928 commit 36be334
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/prawn/table.rb
Expand Up @@ -193,7 +193,7 @@ def calculate_column_widths(manual_widths=nil, width=nil)
renderable_data.each do |row|
row.each_with_index do |cell,i|
length = cell.to_s.lines.map { |e|
@document.font.width_of(e, :size => C(:font_size)) }.max.to_f +
@document.width_of(e, :size => C(:font_size)) }.max.to_f +
2*C(:horizontal_padding)
@column_widths[i] = length.ceil if length > @column_widths[i]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/prawn/table/cell.rb
Expand Up @@ -97,7 +97,7 @@ def text_area_width
# The width of the cell in PDF points
#
def width
@width || (@document.font.width_of(@text, :size => @font_size)) + 2*@horizontal_padding
@width || (@document.width_of(@text, :size => @font_size)) + 2*@horizontal_padding
end

# The height of the cell in PDF points
Expand Down
8 changes: 4 additions & 4 deletions spec/table_spec.rb
Expand Up @@ -19,8 +19,8 @@
table = Prawn::Table.new( [%w[ foo b ], %w[d foobar]], pdf,
:horizontal_padding => hpad, :font_size => fs)

col0_width = pdf.font.width_of("foo", :size => fs)
col1_width = pdf.font.width_of("foobar", :size => fs)
col0_width = pdf.width_of("foo", :size => fs)
col1_width = pdf.width_of("foobar", :size => fs)

table.width.should == col0_width.ceil + col1_width.ceil + 2*columns*hpad
end
Expand All @@ -33,8 +33,8 @@
stretchy_columns = 2

col0_width = 50
col1_width = pdf.font.width_of("foo", :size => fs)
col2_width = pdf.font.width_of("foobar", :size => fs)
col1_width = pdf.width_of("foo", :size => fs)
col2_width = pdf.width_of("foobar", :size => fs)
col3_width = 150

table = Prawn::Table.new( [%w[snake foo b apple],
Expand Down

0 comments on commit 36be334

Please sign in to comment.