Skip to content

Commit

Permalink
backport fix for #2538 don't allow AsciiDoc table cell to overrun bot…
Browse files Browse the repository at this point in the history
…tom of page on which it fits
  • Loading branch information
mojavelinux committed Sep 23, 2024
1 parent ea290ed commit bcbad0f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Improvements::
Bug Fixes::

* support horizontal alignment on AsciiDoc table cell that only contains paragraphs (#2358)
* don't allow AsciiDoc table cell to overrun bottom of page on which it fits (#2538)

== 2.3.18 (2024-07-27) - @mojavelinux

Expand Down
5 changes: 2 additions & 3 deletions lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ def draw_content
end
# NOTE: draw_bounded_content automatically adds FPTolerance to width and height
pdf.bounds.instance_variable_set :@width, spanned_content_width
padding_adjustment = content.context == :document ? padding_bottom : 0
# NOTE: we've already reserved the space, so just let the box stretch to bottom of the content area
pdf.bounds.instance_variable_set :@height, (pdf.y - pdf.page.margins[:bottom] - padding_adjustment)
# NOTE: we've already reserved the space, so just let the box stretch to the maximum that could fit on a page
pdf.bounds.instance_variable_set :@height, (pdf.margin_box.height - padding_top - padding_bottom)
pdf.bounds.instance_variable_set :@table_cell, true
if @valign != :top && (excess_y = spanned_content_height - natural_content_height) > 0
# QUESTION: could this cause a unexpected page overrun?
Expand Down
59 changes: 59 additions & 0 deletions spec/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2747,6 +2747,65 @@ def add_header(*)
end).to log_message severity: :ERROR, message: 'the table cell on page 1 has been truncated; Asciidoctor PDF does not support table cell content that exceeds the height of a single page'
end
end

it 'should reserve remaining space on page once cell is determined to fit' do
pdf_theme = {
extends: 'default',
page_layout: 'landscape',
page_margin: 56,
base_font_size: 10.5,
base_line_height: 1.5,
list_item_spacing: 0,
prose_margin_bottom: 6,
table_cell_padding: [3, 5],
}

input = <<~EOS
:pdf-page-layout: landscape
:nofooter:
.Table 1
[cols=a]
|===
| Row 1
| * 1
* 2
* 3
* 4
|===
.Table 2
[cols=a]
|===
| Row 1
| * 1
* 2
* 3
* 4
|===
.Table 3
[cols=a]
|===
| Row 1
| * 1
* 2
* 3
* 4
* 5
* second to last line
* last line
|===
EOS

pdf = nil
(expect do
pdf = to_pdf input, pdf_theme: pdf_theme, analyze: true
end).to not_log_message
last_line_text = pdf.find_unique_text 'last line'
(expect last_line_text).not_to be_nil
(expect last_line_text[:page_number]).to eql 1
end
end

context 'Caption' do
Expand Down

0 comments on commit bcbad0f

Please sign in to comment.