Skip to content

Commit

Permalink
Merge pull request #24 from prawnpdf/hb_issue_22
Browse files Browse the repository at this point in the history
fixes #22 - unnecessary page break with centered tables
  • Loading branch information
hbrandl committed Sep 16, 2014
2 parents 530c34c + 7f203dd commit 4caf775
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## 0.1.2 (not released yet)

...
* fixed unnecessary page breaks with centered tables (#22, #23)

## 0.1.1

Expand Down
12 changes: 9 additions & 3 deletions lib/prawn/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ def initial_row_on_initial_page
needed_height = row(0..number_of_header_rows).height

# have we got enough room to fit the first row (including header row(s))
return -1 if fits_on_page?(needed_height)
use_reference_bounds = true
return -1 if fits_on_page?(needed_height, use_reference_bounds)

# If there isn't enough room left on the page to fit the first data row
# (including the header), start the table on the next page.
Expand All @@ -484,8 +485,13 @@ def initial_row_on_initial_page
end

# do we have enough room to fit a given height on to the current page?
def fits_on_page?(needed_height)
needed_height < @pdf.y - (@pdf.bounds.absolute_bottom - Prawn::FLOAT_PRECISION)
def fits_on_page?(needed_height, use_reference_bounds = false)
if use_reference_bounds
bounds = @pdf.reference_bounds
else
bounds = @pdf.bounds
end
needed_height < @pdf.y - (bounds.absolute_bottom - Prawn::FLOAT_PRECISION)
end

# return the header rows
Expand Down
8 changes: 8 additions & 0 deletions spec/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1593,4 +1593,12 @@
end
pdf.render
end

it 'illustrates issue #20 (2) and #22', issue: 22 do
pdf = Prawn::Document.new
pdf.table [['one', 'two']], position: :center
pdf.table [['three', 'four']], position: :center
pdf.render
pdf.page_count.should == 1
end
end

0 comments on commit 4caf775

Please sign in to comment.