Skip to content

Commit

Permalink
Media box (#25)
Browse files Browse the repository at this point in the history
* Handle case where MediaBox is a reference
  • Loading branch information
wkirby authored and Burkhard Vogel-Kreykenbohm committed Nov 21, 2019
1 parent 7109432 commit 087a161
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Binary file added data/pdfs/page_with_mediabox_reference.pdf
Binary file not shown.
6 changes: 5 additions & 1 deletion lib/pdf/core/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ def imported_page?

alias __dimensions dimensions if method_defined? :dimensions
def dimensions
return inherited_dictionary_value(:MediaBox) if imported_page?
if imported_page?
media_box = inherited_dictionary_value(:MediaBox)
return media_box.data if media_box.is_a?(PDF::Core::Reference)
return media_box
end

coords = PDF::Core::PageGeometry::SIZES[size] || size
[0, 0] +
Expand Down
11 changes: 11 additions & 0 deletions spec/prawn/templates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,17 @@
expect(hash[hash.trailer[:Info]].keys.include?(k)).to eq true
end
end

it 'returns correct dimensions when :MediaBox is a reference' do
filename = "#{DATADIR}/pdfs/page_with_mediabox_reference.pdf"
pdf = Prawn::Document.new(template: filename)

# expect the inherited value to be a reference
expect(pdf.state.page.send(:inherited_dictionary_value, :MediaBox)).to be_a PDF::Core::Reference

# expect dimensions to come back as an array
expect(pdf.state.page.dimensions).to be_a Array
end
end

describe 'Document#start_new_page with :template option' do
Expand Down

0 comments on commit 087a161

Please sign in to comment.