Skip to content

Commit

Permalink
resolves #2538 don't allow AsciiDoc table cell to overrun bottom of p…
Browse files Browse the repository at this point in the history
…age on which it fits (PR #2539)
  • Loading branch information
mojavelinux authored Sep 23, 2024
1 parent 2830860 commit c3e27b1
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 @@ -54,6 +54,7 @@ Bug Fixes::
* prevent special character substitution from interfering with callouts in plain verbatim block (#2390)
* remove deprecated, undocumented `svg-font-family` theme key (the correct key is `svg-fallback-font-family`)
* major improvement to OTF support following release of ttfunk 1.8.0 (automatic transitive dependency of prawn)
* 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)
if @valign != :top && (excess_y = spanned_content_height - natural_content_height) > 0
# QUESTION: could this cause a unexpected page overrun?
pdf.move_down(@valign == :center ? (excess_y.fdiv 2) : excess_y)
Expand Down
59 changes: 59 additions & 0 deletions spec/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2749,6 +2749,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 = <<~END
: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
|===
END

pdf = nil
(expect do
pdf = to_pdf input, pdf_theme: pdf_theme, analyze: true
end).not_to 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 c3e27b1

Please sign in to comment.