Class: PDF::Core::Reference Private

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/core/reference.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

PDF indirect objects

Defined Under Namespace

Classes: CannotAttachStream

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, data) ⇒ Reference

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Reference.

Parameters:

  • id (Integer)

    Object identifier

  • data (any)

    Object data



42
43
44
45
46
47
# File 'lib/pdf/core/reference.rb', line 42

def initialize(id, data)
  @identifier = id
  @gen = 0
  @data = data
  @stream = Stream.new
end

Instance Attribute Details

#dataany

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Object data

Returns:

  • (any)


21
22
23
# File 'lib/pdf/core/reference.rb', line 21

def data
  @data
end

#genInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Object generation

Returns:

  • (Integer)


17
18
19
# File 'lib/pdf/core/reference.rb', line 17

def gen
  @gen
end

#identifierInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Object identifier

Returns:

  • (Integer)


13
14
15
# File 'lib/pdf/core/reference.rb', line 13

def identifier
  @identifier
end

#offsetInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Offset of the serialized object in the document

Returns:

  • (Integer)


25
26
27
# File 'lib/pdf/core/reference.rb', line 25

def offset
  @offset
end

#streamStream

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Object stream

Returns:



29
30
31
# File 'lib/pdf/core/reference.rb', line 29

def stream
  @stream
end

Instance Method Details

#<<(io) ⇒ io

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Appends data to object stream

Parameters:

  • io (String)

    data

Returns:

  • (io)

Raises:



69
70
71
72
73
74
75
# File 'lib/pdf/core/reference.rb', line 69

def <<(io)
  unless @data.is_a?(::Hash)
    raise CannotAttachStream
  end

  (@stream ||= Stream.new) << io
end

#deep_copy(share = []) ⇒ Reference

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a deep copy of this ref.

Parameters:

  • share (Array<Symbol>) (defaults to: [])

    a list of dictionary entries to share between the old ref and the new

Returns:



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/pdf/core/reference.rb', line 89

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] = Utils.deep_clone(r.data[k])
    end
  when PDF::Core::NameTree::Node
    r.data = r.data.deep_copy
  else
    r.data = Utils.deep_clone(r.data)
  end

  r.stream = Utils.deep_clone(r.stream)
  r
end

#objectString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Serialized PDF object

Returns:

  • (String)


52
53
54
55
56
57
58
59
60
61
62
# File 'lib/pdf/core/reference.rb', line 52

def object
  output = +"#{@identifier} #{gen} obj\n"
  if @stream.empty?
    output << PDF::Core.pdf_object(data) << "\n"
  else
    output << PDF::Core.pdf_object(data.merge(@stream.data)) <<
      "\n" << @stream.object
  end

  output << "endobj\n"
end

#replace(other_ref) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Replaces the data and stream with that of other_ref.

Parameters:



112
113
114
115
# File 'lib/pdf/core/reference.rb', line 112

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

#to_sString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Object reference in PDF format

Returns:

  • (String)


80
81
82
# File 'lib/pdf/core/reference.rb', line 80

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