From 3a01dcf3b593e05aac5c26cbe531fc0af7ff50f4 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Tue, 25 Aug 2020 01:10:12 -0600 Subject: [PATCH 1/2] read padding from correct box when creating new page resolves #1121 --- CHANGELOG.md | 6 ++++++ lib/prawn/document.rb | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5a12aafa..e9d264fa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +### Apply correct margin box when creating or switching pages + +When creating a new page or returning to a page previously created, compute the margin box correctly. + +(Dan Allen, [#1122](https://github.com/prawnpdf/prawn/pull/1022)) + ### Look for glyph in correct font Take the font style into account when looking for a glyph and fallback fonts are enabled. diff --git a/lib/prawn/document.rb b/lib/prawn/document.rb index 439667d5a..4c25c9959 100644 --- a/lib/prawn/document.rb +++ b/lib/prawn/document.rb @@ -723,15 +723,17 @@ def generate_margin_box (page.margins[:top] + page.margins[:bottom]) ) - # This check maintains indentation settings across page breaks + # update bounding box if not flowing from the previous page + unless @bounding_box&.parent + old_margin_box = @bounding_box + @bounding_box = @margin_box + end + + # maintains indentation settings across page breaks if old_margin_box @margin_box.add_left_padding(old_margin_box.total_left_padding) @margin_box.add_right_padding(old_margin_box.total_right_padding) end - - # we must update bounding box if not flowing from the previous page - # - @bounding_box = @margin_box unless @bounding_box&.parent end def apply_margin_options(options) From ad86699763fd9f723b41d302c29177027f02a684 Mon Sep 17 00:00:00 2001 From: Tomify Date: Thu, 13 Jan 2022 13:48:58 -0500 Subject: [PATCH 2/2] add test for #1121 --- spec/prawn/document_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec/prawn/document_spec.rb b/spec/prawn/document_spec.rb index 3b649629e..029c044c7 100644 --- a/spec/prawn/document_spec.rb +++ b/spec/prawn/document_spec.rb @@ -126,6 +126,19 @@ def self.format(string) expect(pdf.instance_variable_get(:@background)).to eq(filename) end end + + it 'retains the current margin and padding' do + initial_absolute_left = pdf.bounds.absolute_left + + pdf.bounding_box [0, pdf.cursor], width: pdf.bounds.width do + pdf.bounds.move_past_bottom + end + pdf.indent 20 do + pdf.bounds.move_past_bottom + end + + expect(pdf.bounds.absolute_left).to eq(initial_absolute_left) + end end describe '#float' do