Skip to content

Commit

Permalink
Content streams must have balanced q/Q operators or some readers comp…
Browse files Browse the repository at this point in the history
…lain

* evince crashes, acrobat displays an error dialog
* This was an issue on fresh content streams added to pages imported via
  a template
* Thanks to Omar Garcia for reporting
  • Loading branch information
yob committed Apr 6, 2010
1 parent b28be85 commit a238b51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/prawn/document/internals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,15 @@ def fresh_content_streams
go_to_page i
state.page.new_content_stream
use_graphic_settings
save_graphics_state
end
end

def finalize_all_page_contents
(1..page_count).each do |i|
go_to_page i
repeaters.each { |r| r.run(i) }
restore_graphics_state if state.page.content.stream.strip[-1,1] != "Q"
restore_graphics_state
state.page.finalize
end
end
Expand Down
16 changes: 16 additions & 0 deletions spec/template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@
streams.size.should == 2
end

it "should have balance q/Q operators on all content streams" do
filename = "#{Prawn::BASEDIR}/data/pdfs/hexagon.pdf"

@pdf = Prawn::Document.new(:template => filename)
output = StringIO.new(@pdf.render)
hash = PDF::Hash.new(output)

streams = hash.values.select { |obj| obj.kind_of?(PDF::Reader::Stream) }

streams.each do |stream|
data = stream.unfiltered_data
data.scan("q").size.should == 1
data.scan("Q").size.should == 1
end
end

it "should allow text to be added to a single page template" do
filename = "#{Prawn::BASEDIR}/data/pdfs/hexagon.pdf"

Expand Down

0 comments on commit a238b51

Please sign in to comment.