Class: Prawn::Core::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/core/reference.rb,
lib/prawn/security.rb

Overview

:nodoc:

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Reference) initialize(id, data)



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

- (Object) data

Returns the value of attribute data



16
17
18
# File 'lib/prawn/core/reference.rb', line 16

def data
  @data
end

- (Object) gen

Returns the value of attribute gen



16
17
18
# File 'lib/prawn/core/reference.rb', line 16

def gen
  @gen
end

- (Object) identifier

Returns the value of attribute identifier



16
17
18
# File 'lib/prawn/core/reference.rb', line 16

def identifier
  @identifier
end

- (Object) live

Returns the value of attribute live



16
17
18
# File 'lib/prawn/core/reference.rb', line 16

def live
  @live
end

- (Object) offset

Returns the value of attribute offset



16
17
18
# File 'lib/prawn/core/reference.rb', line 16

def offset
  @offset
end

- (Object) stream

Returns the value of attribute stream



16
17
18
# File 'lib/prawn/core/reference.rb', line 16

def stream
  @stream
end

Instance Method Details

- (Object) <<(data)



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

- (Object) compress_stream



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

- (Boolean) compressed?



51
52
53
# File 'lib/prawn/core/reference.rb', line 51

def compressed?
  @compressed
end

- (Object) deep_copy(share = [])

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
73
74
75
# File 'lib/prawn/core/reference.rb', line 58

def deep_copy(share=[])
  r = dup

  case r.data
  when 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
  when Prawn::Core::NameTree::Node
    r.data = r.data.deep_copy
  else
    r.data = Marshal.load(Marshal.dump(r.data))
  end

  r.stream = Marshal.load(Marshal.dump(r.stream))
  r
end

- (Object) encrypted_object(key)

Returns the object definition for the object this references, keyed from key.



253
254
255
256
257
258
259
260
261
262
263
# File 'lib/prawn/security.rb', line 253

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

- (Object) mark_live

Marks this and all referenced objects live, recursively.



86
87
88
89
90
# File 'lib/prawn/core/reference.rb', line 86

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

- (Object) replace(other_ref)

Replaces the data and stream with that of other_ref. Preserves compressed status.



79
80
81
82
83
# File 'lib/prawn/core/reference.rb', line 79

def replace(other_ref)
  @data       = other_ref.data
  @stream     = other_ref.stream
  @compressed = other_ref.compressed?
end

- (Object) to_s



40
41
42
# File 'lib/prawn/core/reference.rb', line 40

def to_s            
  "#{@identifier} #{gen} R"
end