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



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

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

#eachObject



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

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

#is_utf8?(str) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
102
# File 'lib/pdf/core/object_store.rb', line 99

def is_utf8?(str)
  str.force_encoding(::Encoding::UTF_8)
  str.valid_encoding?
end

#object_id_for_page(k) ⇒ 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


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

def object_id_for_page(k)
  k -= 1 if k > 0
  flat_page_ids = get_page_objects(pages).flatten
  flat_page_ids[k]
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
# 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



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

def size
  @identifiers.size
end