Module: Prawn::Stamp
- Included in:
- Document
- Defined in:
- lib/prawn/stamp.rb
Instance Method Summary collapse
- #create_stamp(user_defined_name = "", &block) ⇒ Object
- #stamp(user_defined_name) ⇒ Object
- #stamp_at(user_defined_name, point) ⇒ Object
Instance Method Details
#create_stamp(user_defined_name = "", &block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/prawn/stamp.rb', line 45 def create_stamp(user_defined_name="", &block) raise Prawn::Errors::InvalidName if user_defined_name.empty? if stamp_dictionary_registry[user_defined_name] raise Prawn::Errors::NameTaken end # BBox origin is the lower left margin of the page, so we need # it to be the full dimension of the page, or else things that # should appear near the top or right margin are invisible stamp_dictionary = ref!(:Type => :XObject, :Subtype => :Form, :BBox => [0, 0, page_dimensions[2], page_dimensions[3]]) stamp_dictionary_name = "Stamp#{next_stamp_dictionary_id}" stamp_dictionary_registry[user_defined_name] = { :stamp_dictionary_name => stamp_dictionary_name, :stamp_dictionary => stamp_dictionary} @active_stamp_stream = "" @active_stamp_dictionary = stamp_dictionary yield if block_given? stamp_dictionary.data[:Length] = @active_stamp_stream.length + 1 stamp_dictionary << @active_stamp_stream @active_stamp_stream = nil @active_stamp_dictionary = nil end |
#stamp(user_defined_name) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/prawn/stamp.rb', line 13 def stamp(user_defined_name) raise Prawn::Errors::InvalidName if user_defined_name.empty? unless stamp_dictionary_registry[user_defined_name] raise Prawn::Errors::UndefinedObjectName end dict = stamp_dictionary_registry[user_defined_name] stamp_dictionary_name = dict[:stamp_dictionary_name] stamp_dictionary = dict[:stamp_dictionary] add_content "/#{stamp_dictionary_name} Do" page_xobjects.merge!(stamp_dictionary_name => stamp_dictionary) end |
#stamp_at(user_defined_name, point) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/prawn/stamp.rb', line 29 def stamp_at(user_defined_name, point) # Save the graphics state add_content "q" # Translate the user space x,y = point translate_position = "1 0 0 1 %.3f %.3f cm" % [x, y] add_content translate_position # Draw the stamp in the now translated user space stamp(user_defined_name) # Restore the graphics state to remove the translation add_content "Q" end |