Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[Issue #200] Using Page Graphic State Stack For Stamps

 - Ironically there doesn't seem to be any reason to avoid using the page graphic stack
 - Got rid of several checks for stamp stream
 - Ensures that hanging graphic states get closed in stamps and pages
 - Finally moving resolved bugs to correct folder
  • Loading branch information...
commit 7e17b6c2d9755a0ae49c3e79ffadfd1759b510aa 1 parent 533261c
Jonathan Greenberg authored
View
0  bugs/color_space_issues.rb → bugs/resolved/color_space_issues.rb
File renamed without changes
View
20 bugs/resolved/dash_stamp_issue.rb
@@ -0,0 +1,20 @@
+# encoding: utf-8
+#
+#
+$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
+require 'rubygems'
+require 'prawn'
+
+
+##
+# When resolved the second page circle should not be dashed
+pdf = Prawn::Document.generate("stamp_dash_issues.pdf", :margin => [40, 45, 50, 45]) do
+ text "The stamped circle might be dashed"
+ create_stamp("stamp_circle") do
+ dash(5)
+ stroke_circle [0, 0], 10
+ end
+ stamp("stamp_circle")
+ text "but the nonstamped circle should not"
+ stroke_circle [10, 10], 10
+end
View
0  bugs/looks_blank.rb → bugs/resolved/looks_blank.rb
File renamed without changes
View
0  bugs/multiple_rendering.rb → bugs/resolved/multiple_rendering.rb
File renamed without changes
View
0  bugs/save_graphics_state.rb → bugs/resolved/save_graphics_state.rb
File renamed without changes
View
0  bugs/stamp_color_issues.rb → bugs/resolved/stamp_color_issues.rb
File renamed without changes
View
20 lib/prawn/core/page.rb
@@ -12,9 +12,9 @@
module Prawn
module Core
class Page #:nodoc:
-
+
include Prawn::Core::Page::GraphicsState
-
+
attr_accessor :document, :content, :dictionary, :margins, :stack
def initialize(document, options={})
@@ -53,11 +53,15 @@ def in_stamp_stream?
def stamp_stream(dictionary)
@stamp_stream = ""
@stamp_dictionary = dictionary
+ graphic_stack_size = stack.stack.size
- document.open_graphics_state
+ document.save_graphics_state
document.send(:freeze_stamp_graphics)
yield if block_given?
- document.close_graphics_state
+
+ until graphic_stack_size == stack.stack.size
+ document.restore_graphics_state
+ end
@stamp_dictionary.data[:Length] = @stamp_stream.length + 1
@stamp_dictionary << @stamp_stream
@@ -166,9 +170,9 @@ def init_from_object(options)
end
def init_new_page(options)
- @size = options[:size] || "LETTER"
- @layout = options[:layout] || :portrait
-
+ @size = options[:size] || "LETTER"
+ @layout = options[:layout] || :portrait
+
@content = document.ref(:Length => 0)
content << "q" << "\n"
@dictionary = document.ref(:Type => :Page,
@@ -203,7 +207,7 @@ def inherited_dictionary_value(key, local_dict = nil)
end
end
-
+
end
end
View
4 lib/prawn/document/graphics_state.rb
@@ -103,7 +103,7 @@ def close_graphics_state
end
def save_graphics_state(graphic_state = nil)
- graphic_stack.save_graphic_state(graphic_state) unless state.page.in_stamp_stream?
+ graphic_stack.save_graphic_state(graphic_state)
open_graphics_state
if block_given?
yield
@@ -119,7 +119,7 @@ def restore_graphics_state
"\n You have reached the end of the graphic state stack"
end
close_graphics_state
- graphic_stack.restore_graphic_state unless state.page.in_stamp_stream?
+ graphic_stack.restore_graphic_state
end
def graphic_stack
View
4 lib/prawn/document/internals.rb
@@ -106,7 +106,9 @@ 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 graphic_stack.present?
+ while graphic_stack.present?
+ restore_graphics_state
+ end
state.page.finalize
end
end
View
8 lib/prawn/graphics/color.rb
@@ -26,9 +26,8 @@ module Color
#
def fill_color(*color)
return current_fill_color if color.empty?
- color = process_color(*color)
- self.current_fill_color = color
- set_fill_color(color)
+ self.current_fill_color = process_color(*color)
+ set_fill_color
end
alias_method :fill_color=, :fill_color
@@ -187,7 +186,6 @@ def current_color_space(type)
end
def set_current_color_space(color_space, type)
- return if state.page.in_stamp_stream?
save_graphics_state if graphic_state.nil?
graphic_state.color_space[type] = color_space
end
@@ -197,7 +195,6 @@ def current_fill_color
end
def current_fill_color=(color)
- return if state.page.in_stamp_stream?
graphic_state.fill_color = color
end
@@ -206,7 +203,6 @@ def current_stroke_color
end
def current_stroke_color=(color)
- return if state.page.in_stamp_stream?
graphic_state.stroke_color = color
end
View
1  spec/repeater_spec.rb
@@ -131,7 +131,6 @@ def repeater(*args, &b)
@pdf.fill_color "666666"
@pdf.cap_style :round
text = PDF::Inspector::Text.analyze(@pdf.render)
- #puts text.strings
text.strings.include?("fill_color: 666666").should == false
text.strings.include?("fill_color: 000000").should == true
text.strings.include?("cap_style: round").should == false
View
3  spec/stamp_spec.rb
@@ -122,7 +122,10 @@
@pdf.create_stamp("MyStamp") do
@pdf.save_graphics_state
+ @pdf.save_graphics_state
+ @pdf.save_graphics_state
@pdf.text "This should have a 'q' before it and a 'Q' after it"
+ @pdf.restore_graphics_state
end
@pdf.state.page.stack.stack.size.should == 1
end
Please sign in to comment.
Something went wrong with that request. Please try again.