Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #403 advance table to next page if rowspan in first row does not fit in space remaining on current page #2201

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co
Bug Fixes::

* use specified column widths to avoid bugs in column width calculation when using colspans (#1368)
* advance table to next page if rowspan in first row does not fit in space remaining on current page (#403)

== 2.0.1 (2022-05-21) - @mojavelinux

Bug Fixes::

* scale inline image to fit within available height of page, accounting for the top padding of the line and the bottom gutter (#2193)
* short-circuit formatted_text routine and log error if fragments in first line cannot fit on a new page
* break and wrap long contiguous text in source block when linenums are enabled (#2198)
* scale inline image to fit within available height of page, accounting for the top padding of the line height and the bottom gutter (#2193)
* short-circuit formatted text routine and log error if fragments in first line cannot fit on an empty page
* break and wrap long contiguous text in source block when linenums is enabled (#2198)

=== Details

Expand Down
1 change: 1 addition & 0 deletions docs/modules/ROOT/pages/features.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* Footnotes are always displayed as endnotes (at the bottom of the last page of a chapter for books; at the bottom of the last page of the document for all other doctypes).
*Footnotes cannot be displayed at the current bottom of the page because the PDF generator does not support content reflows* (see {url-project-issues}/85#issuecomment-577412975[#85^] for reasoning).
* Table cells that exceed the height of a single page are truncated with a warning (see https://github.com/prawnpdf/prawn-table/issues/41[prawn-table#41^]).
* A rowspan in a table that exceeds the height of a single page will be orphaned and the remaining columns will be truncated (see {url-project-issues}/403#issuecomment-1133840210[#403^]).
* A column can't be assigned a `width` of `0%` or a `width` less than the width of a single character.
The converter will skip the table and emit a warning if such a case occurs.
* A column can't be set to `autowidth` if the width of all the other columns in the table meets or exceeds 100%.
Expand Down
11 changes: 11 additions & 0 deletions lib/asciidoctor/pdf/ext/prawn-table.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
# frozen_string_literal: true

require 'prawn/table'

Prawn::Table.prepend (Module.new do
def initial_row_on_initial_page
return 0 if fits_on_page? @pdf.bounds.height
height_required = (row (0..number_of_header_rows)).height_with_span
return -1 if fits_on_page? height_required, true
@pdf.bounds.move_past_bottom
0
end
end)

require_relative 'prawn-table/cell'
require_relative 'prawn-table/cell/asciidoc'
require_relative 'prawn-table/cell/text'
21 changes: 21 additions & 0 deletions spec/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2914,6 +2914,27 @@
(expect big_cell_text[:y]).to be < top_cell_text[:y]
(expect big_cell_text[:y]).to be > bottom_cell_text[:y]
end

it 'should advance table to next page if rowspan in first row does not fit on current page' do
input = <<~EOS
#{(['filler'] * 5).join %(\n\n)}

[cols=2*]
|===
.30+|Group A |Member 1
#{29.times.map {|idx| '|Member ' + idx.next.to_s }.join ?\n}

.30+|Group B |Member 1
#{29.times.map {|idx| '|Member ' + idx.next.to_s }.join ?\n}
|===
EOS

pdf = to_pdf input, analyze: true
(expect pdf.pages).to have_size 3
(expect (pdf.find_text 'filler').map {|it| it[:page_number] }.uniq).to eql [1]
(expect (pdf.find_unique_text 'Group A')[:page_number]).to eql 2
(expect (pdf.find_unique_text 'Group B')[:page_number]).to eql 3
end
end

context 'Arrange block' do
Expand Down