Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #1121 read padding from correct box when creating new page #1122

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 7 additions & 5 deletions lib/prawn/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions spec/prawn/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down