diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2022-05-22 14:03:47 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-22 14:03:47 -0600 |
| commit | 2e0af62373b1dc4a593d45688958c8d61d251167 (patch) | |
| tree | 034503d5f530864e9df0211a4cd16b249e2dcf66 | |
| parent | a2a2508d6c5d973072675d4732a75eda3ecb6f12 (diff) | |
resolves #403 advance table to next page if rowspan in first row does not fit in space remaining on current page (PR #2201)
| -rw-r--r-- | CHANGELOG.adoc | 7 | ||||
| -rw-r--r-- | docs/modules/ROOT/pages/features.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/ext/prawn-table.rb | 11 | ||||
| -rw-r--r-- | spec/table_spec.rb | 21 |
4 files changed, 37 insertions, 3 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 4487cc6e..b568ef97 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -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 diff --git a/docs/modules/ROOT/pages/features.adoc b/docs/modules/ROOT/pages/features.adoc index d170da1b..f30e4f57 100644 --- a/docs/modules/ROOT/pages/features.adoc +++ b/docs/modules/ROOT/pages/features.adoc @@ -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%. diff --git a/lib/asciidoctor/pdf/ext/prawn-table.rb b/lib/asciidoctor/pdf/ext/prawn-table.rb index 4faa0df3..219bf97c 100644 --- a/lib/asciidoctor/pdf/ext/prawn-table.rb +++ b/lib/asciidoctor/pdf/ext/prawn-table.rb @@ -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' diff --git a/spec/table_spec.rb b/spec/table_spec.rb index 70d45614..15fe7bdc 100644 --- a/spec/table_spec.rb +++ b/spec/table_spec.rb @@ -2914,6 +2914,27 @@ describe 'Asciidoctor::PDF::Converter - Table' do (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 |
