Skip to content

Commit

Permalink
resolves #403 advance table to next page if rowspan in first row does…
Browse files Browse the repository at this point in the history
… not fit in space remaining on current page
  • Loading branch information
mojavelinux committed May 22, 2022
1 parent 4c03f53 commit 1ed9a89
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
This document provides a high-level view of the changes to the {project-name} by release.
For a detailed view of what has changed, refer to the {url-repo}/commits/main[commit history] on GitHub.

== Unreleased

Bug Fixes::

* 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::
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 @@ -2853,6 +2853,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

0 comments on commit 1ed9a89

Please sign in to comment.