Class: Prawn::Core::Reference
- Inherits:
-
Object
- Object
- Prawn::Core::Reference
- Defined in:
- lib/prawn/core/reference.rb,
lib/prawn/security.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#gen ⇒ Object
Returns the value of attribute gen.
-
#identifier ⇒ Object
Returns the value of attribute identifier.
-
#live ⇒ Object
Returns the value of attribute live.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#stream ⇒ Object
Returns the value of attribute stream.
Instance Method Summary collapse
- #<<(data) ⇒ Object
- #compress_stream ⇒ Object
- #compressed? ⇒ Boolean
-
#deep_copy(share = []) ⇒ Object
Creates a deep copy of this ref.
-
#encrypted_object(key) ⇒ Object
Returns the object definition for the object this references, keyed from
key
. -
#initialize(id, data) ⇒ Reference
constructor
A new instance of Reference.
-
#mark_live ⇒ Object
Marks this and all referenced objects live, recursively.
- #object ⇒ Object
-
#replace(other_ref) ⇒ Object
Replaces the data and stream with that of other_ref.
- #to_s ⇒ Object
Constructor Details
#initialize(id, data) ⇒ Reference
Returns a new instance of Reference.
18 19 20 21 22 23 24 |
# File 'lib/prawn/core/reference.rb', line 18 def initialize(id, data) @identifier = id @gen = 0 @data = data @compressed = false @stream = nil end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
16 17 18 |
# File 'lib/prawn/core/reference.rb', line 16 def data @data end |
#gen ⇒ Object
Returns the value of attribute gen.
16 17 18 |
# File 'lib/prawn/core/reference.rb', line 16 def gen @gen end |
#identifier ⇒ Object
Returns the value of attribute identifier.
16 17 18 |
# File 'lib/prawn/core/reference.rb', line 16 def identifier @identifier end |
#live ⇒ Object
Returns the value of attribute live.
16 17 18 |
# File 'lib/prawn/core/reference.rb', line 16 def live @live end |
#offset ⇒ Object
Returns the value of attribute offset.
16 17 18 |
# File 'lib/prawn/core/reference.rb', line 16 def offset @offset end |
#stream ⇒ Object
Returns the value of attribute stream.
16 17 18 |
# File 'lib/prawn/core/reference.rb', line 16 def stream @stream end |
Instance Method Details
#<<(data) ⇒ Object
35 36 37 38 |
# File 'lib/prawn/core/reference.rb', line 35 def <<(data) raise 'Cannot add data to a stream that is compressed' if @compressed (@stream ||= "") << data end |
#compress_stream ⇒ Object
44 45 46 47 48 49 |
# File 'lib/prawn/core/reference.rb', line 44 def compress_stream @stream = Zlib::Deflate.deflate(@stream) @data[:Filter] = :FlateDecode @data[:Length] ||= @stream.length @compressed = true end |
#compressed? ⇒ Boolean
51 52 53 |
# File 'lib/prawn/core/reference.rb', line 51 def compressed? @compressed end |
#deep_copy(share = []) ⇒ Object
Creates a deep copy of this ref. If share
is provided, shares the given dictionary entries between the old ref and the new.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/prawn/core/reference.rb', line 58 def deep_copy(share=[]) r = dup if r.data.is_a?(Hash) # Copy each entry not in +share+. (r.data.keys - share).each do |k| r.data[k] = Marshal.load(Marshal.dump(r.data[k])) end else r.data = Marshal.load(Marshal.dump(r.data)) end r.stream = Marshal.load(Marshal.dump(r.stream)) r end |
#encrypted_object(key) ⇒ Object
Returns the object definition for the object this references, keyed from key
.
251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/prawn/security.rb', line 251 def encrypted_object(key) @on_encode.call(self) if @on_encode output = "#{@identifier} #{gen} obj\n" << Prawn::Core::EncryptedPdfObject(data, key, @identifier, gen) << "\n" if @stream output << "stream\n" << Document::Security.encrypt_string(@stream, key, @identifier, gen) << "\nendstream\n" end output << "endobj\n" end |
#mark_live ⇒ Object
Marks this and all referenced objects live, recursively.
83 84 85 86 87 |
# File 'lib/prawn/core/reference.rb', line 83 def mark_live return if @live @live = true referenced_objects.each { |o| o.mark_live } end |
#object ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/prawn/core/reference.rb', line 26 def object output = "#{@identifier} #{gen} obj\n" << Prawn::Core::PdfObject(data) << "\n" if @stream output << "stream\n" << @stream << "\nendstream\n" end output << "endobj\n" end |
#replace(other_ref) ⇒ Object
Replaces the data and stream with that of other_ref. Preserves compressed status.
76 77 78 79 80 |
# File 'lib/prawn/core/reference.rb', line 76 def replace(other_ref) @data = other_ref.data @stream = other_ref.stream @compressed = other_ref.compressed? end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/prawn/core/reference.rb', line 40 def to_s "#{@identifier} #{gen} R" end |