diff --git a/lib/asciidoctor/pdf/ext/prawn/extensions.rb b/lib/asciidoctor/pdf/ext/prawn/extensions.rb index e6a4971b0..fc565f128 100644 --- a/lib/asciidoctor/pdf/ext/prawn/extensions.rb +++ b/lib/asciidoctor/pdf/ext/prawn/extensions.rb @@ -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 diff --git a/spec/table_spec.rb b/spec/table_spec.rb index 7eb0d1efa..05776b4b7 100644 --- a/spec/table_spec.rb +++ b/spec/table_spec.rb @@ -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