Class: PDF::Core::ObjectStore

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/pdf/core/object_store.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ ObjectStore

Returns a new instance of ObjectStore.



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pdf/core/object_store.rb', line 16

def initialize(opts = {})
  @objects = {}
  @identifiers = []

  @info  ||= ref(opts[:info] || {}).identifier
  @root  ||= ref(Type: :Catalog).identifier
  if opts[:print_scaling] == :none
    root.data[:ViewerPreferences] = { PrintScaling: :None }
  end
  if pages.nil?
    root.data[:Pages] = ref(Type: :Pages, Count: 0, Kids: [])
  end
end

Instance Attribute Details

#min_versionObject (readonly)

Returns the value of attribute min_version.



14
15
16
# File 'lib/pdf/core/object_store.rb', line 14

def min_version
  @min_version
end

Instance Method Details

#[](id) ⇒ Object



75
76
77
# File 'lib/pdf/core/object_store.rb', line 75

def [](id)
  @objects[id]
end

#eachObject



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

def each
  @identifiers.each do |id|
    yield @objects[id]
  end
end

#infoObject



34
35
36
# File 'lib/pdf/core/object_store.rb', line 34

def info
  @objects[@info]
end

#object_id_for_page(page) ⇒ Object

returns the object ID for a particular page in the document. Pages are indexed starting at 1 (not 0!).

object_id_for_page(1)
=> 5
object_id_for_page(10)
=> 87
object_id_for_page(-11)
=> 17


94
95
96
97
98
# File 'lib/pdf/core/object_store.rb', line 94

def object_id_for_page(page)
  page -= 1 if page.positive?
  flat_page_ids = get_page_objects(pages).flatten
  flat_page_ids[page]
end

#page_countObject



46
47
48
# File 'lib/pdf/core/object_store.rb', line 46

def page_count
  pages.data[:Count]
end

#pagesObject



42
43
44
# File 'lib/pdf/core/object_store.rb', line 42

def pages
  root.data[:Pages]
end

#push(*args, &block) ⇒ Object Also known as: <<

Adds the given reference to the store and returns the reference object. If the object provided is not a PDF::Core::Reference, one is created from the arguments provided.



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pdf/core/object_store.rb', line 54

def push(*args, &block)
  reference =
    if args.first.is_a?(PDF::Core::Reference)
      args.first
    else
      PDF::Core::Reference.new(*args, &block)
    end

  @objects[reference.identifier] = reference
  @identifiers << reference.identifier
  reference
end

#ref(data, &block) ⇒ Object



30
31
32
# File 'lib/pdf/core/object_store.rb', line 30

def ref(data, &block)
  push(size + 1, data, &block)
end

#rootObject



38
39
40
# File 'lib/pdf/core/object_store.rb', line 38

def root
  @objects[@root]
end

#sizeObject Also known as: length



79
80
81
# File 'lib/pdf/core/object_store.rb', line 79

def size
  @identifiers.size
end