Skip to content

Commit

Permalink
backport fix for #1735 and #1949
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Jul 21, 2021
1 parent a3d1271 commit b9b75b2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/asciidoctor/pdf/ext/prawn/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ def effective_page_height
reference_bounds.height
end

# workaround for https://github.com/prawnpdf/prawn/issues/1121
def generate_margin_box
page_w, page_h = (page = state.page).dimensions.slice 2, 2
page_m = page.margins
prev_margin_box, @margin_box = @margin_box, (::Prawn::Document::BoundingBox.new self, nil, [page_m[:left], page_h - page_m[:top]], width: page_w - page_m[:left] - page_m[:right], height: page_h - page_m[:top] - page_m[:bottom])

# update bounding box if not flowing from the previous page
unless @bounding_box&.parent
prev_margin_box = @bounding_box
@bounding_box = @margin_box
end

# maintains indentation settings across page breaks
if prev_margin_box
@margin_box.add_left_padding prev_margin_box.total_left_padding
@margin_box.add_right_padding prev_margin_box.total_right_padding
end

nil
end

# Set the margins for the current page.
#
def set_page_margin margin
Expand Down
39 changes: 39 additions & 0 deletions spec/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,45 @@
(expect a_texts[0][:y]).to eql b_texts[0][:y]
(expect b_texts[0][:x]).to eql b_texts[1][:x]
end

it 'should preserve left margin on page that follows page containing a table with an AsciiDoc table cell' do
pdf = to_pdf <<~EOS, analyze: true
== Section Title
[%hardbreaks]
#{(['filler'] * 20).join ?\n}
[cols=2*]
|===
|filler
a| Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna al abcde aaaaaaaaaa bbbbb
____
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
____
|===
terms::
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et doloreata.
nested term:::
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore. +
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore. +
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et fin.
.list title
* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore.
EOS

first_page_text = pdf.text.select {|it| it[:page_number] == 1 }
second_page_text = pdf.text.select {|it| it[:page_number] == 2 }
(expect second_page_text[0][:string]).to end_with ' et fin.'
(expect second_page_text[0][:x]).to be > 48.24
(expect second_page_text[0][:x]).to eql first_page_text.last[:x]
(expect second_page_text[1][:string]).to eql 'list title'
(expect second_page_text[1][:x]).to eql 48.24
end
end

context 'Verse table cell' do
Expand Down

0 comments on commit b9b75b2

Please sign in to comment.