Class: Prawn::Reference
- Inherits:
-
Object
- Object
- Prawn::Reference
- Defined in:
- lib/prawn/reference.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
-
#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.
17 18 19 20 21 22 23 |
# File 'lib/prawn/reference.rb', line 17 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.
15 16 17 |
# File 'lib/prawn/reference.rb', line 15 def data @data end |
#gen ⇒ Object
Returns the value of attribute gen.
15 16 17 |
# File 'lib/prawn/reference.rb', line 15 def gen @gen end |
#identifier ⇒ Object
Returns the value of attribute identifier.
15 16 17 |
# File 'lib/prawn/reference.rb', line 15 def identifier @identifier end |
#live ⇒ Object
Returns the value of attribute live.
15 16 17 |
# File 'lib/prawn/reference.rb', line 15 def live @live end |
#offset ⇒ Object
Returns the value of attribute offset.
15 16 17 |
# File 'lib/prawn/reference.rb', line 15 def offset @offset end |
#stream ⇒ Object
Returns the value of attribute stream.
15 16 17 |
# File 'lib/prawn/reference.rb', line 15 def stream @stream end |
Instance Method Details
#<<(data) ⇒ Object
34 35 36 37 |
# File 'lib/prawn/reference.rb', line 34 def <<(data) raise 'Cannot add data to a stream that is compressed' if @compressed (@stream ||= "") << data end |
#compress_stream ⇒ Object
43 44 45 46 47 48 |
# File 'lib/prawn/reference.rb', line 43 def compress_stream @stream = Zlib::Deflate.deflate(@stream) @data[:Filter] = :FlateDecode @data[:Length] ||= @stream.length @compressed = true end |
#compressed? ⇒ Boolean
50 51 52 |
# File 'lib/prawn/reference.rb', line 50 def compressed? @compressed end |
#mark_live ⇒ Object
Marks this and all referenced objects live, recursively.
63 64 65 66 67 |
# File 'lib/prawn/reference.rb', line 63 def mark_live return if @live @live = true referenced_objects.each { |o| o.mark_live } end |
#object ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/prawn/reference.rb', line 25 def object output = "#{@identifier} #{gen} obj\n" << Prawn::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.
56 57 58 59 60 |
# File 'lib/prawn/reference.rb', line 56 def replace(other_ref) @data = other_ref.data @stream = other_ref.stream @compressed = other_ref.compressed? end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/prawn/reference.rb', line 39 def to_s "#{@identifier} #{gen} R" end |