Skip to content

Commit b9b75b2

Browse files
committed
backport fix for #1735 and #1949
1 parent a3d1271 commit b9b75b2

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

lib/asciidoctor/pdf/ext/prawn/extensions.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,27 @@ def effective_page_height
7676
reference_bounds.height
7777
end
7878

79+
# workaround for https://github.com/prawnpdf/prawn/issues/1121
80+
def generate_margin_box
81+
page_w, page_h = (page = state.page).dimensions.slice 2, 2
82+
page_m = page.margins
83+
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])
84+
85+
# update bounding box if not flowing from the previous page
86+
unless @bounding_box&.parent
87+
prev_margin_box = @bounding_box
88+
@bounding_box = @margin_box
89+
end
90+
91+
# maintains indentation settings across page breaks
92+
if prev_margin_box
93+
@margin_box.add_left_padding prev_margin_box.total_left_padding
94+
@margin_box.add_right_padding prev_margin_box.total_right_padding
95+
end
96+
97+
nil
98+
end
99+
79100
# Set the margins for the current page.
80101
#
81102
def set_page_margin margin

spec/table_spec.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,45 @@
10941094
(expect a_texts[0][:y]).to eql b_texts[0][:y]
10951095
(expect b_texts[0][:x]).to eql b_texts[1][:x]
10961096
end
1097+
1098+
it 'should preserve left margin on page that follows page containing a table with an AsciiDoc table cell' do
1099+
pdf = to_pdf <<~EOS, analyze: true
1100+
== Section Title
1101+
1102+
[%hardbreaks]
1103+
#{(['filler'] * 20).join ?\n}
1104+
1105+
[cols=2*]
1106+
|===
1107+
|filler
1108+
a| Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna al abcde aaaaaaaaaa bbbbb
1109+
1110+
____
1111+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et
1112+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
1113+
____
1114+
|===
1115+
1116+
terms::
1117+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et doloreata.
1118+
1119+
nested term:::
1120+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore. +
1121+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore. +
1122+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et fin.
1123+
1124+
.list title
1125+
* Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore.
1126+
EOS
1127+
1128+
first_page_text = pdf.text.select {|it| it[:page_number] == 1 }
1129+
second_page_text = pdf.text.select {|it| it[:page_number] == 2 }
1130+
(expect second_page_text[0][:string]).to end_with ' et fin.'
1131+
(expect second_page_text[0][:x]).to be > 48.24
1132+
(expect second_page_text[0][:x]).to eql first_page_text.last[:x]
1133+
(expect second_page_text[1][:string]).to eql 'list title'
1134+
(expect second_page_text[1][:x]).to eql 48.24
1135+
end
10971136
end
10981137

10991138
context 'Verse table cell' do

0 commit comments

Comments
 (0)