Class: PDF::Core::ObjectStore
- Inherits:
-
Object
- Object
- PDF::Core::ObjectStore
- Includes:
- Enumerable
- Defined in:
- lib/pdf/core/object_store.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#min_version ⇒ Object
readonly
Returns the value of attribute min_version.
Instance Method Summary collapse
- #[](id) ⇒ Object
- #each ⇒ Object
- #info ⇒ Object
-
#initialize(opts = {}) ⇒ ObjectStore
constructor
A new instance of ObjectStore.
-
#object_id_for_page(page) ⇒ Object
returns the object ID for a particular page in the document.
- #page_count ⇒ Object
- #pages ⇒ Object
-
#push(*args, &block) ⇒ Object
(also: #<<)
Adds the given reference to the store and returns the reference object.
- #ref(data, &block) ⇒ Object
- #root ⇒ Object
- #size ⇒ Object (also: #length)
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_version ⇒ Object (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 |
#each ⇒ Object
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 |
#info ⇒ Object
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_count ⇒ Object
46 47 48 |
# File 'lib/pdf/core/object_store.rb', line 46 def page_count pages.data[:Count] end |
#pages ⇒ Object
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 |
#root ⇒ Object
38 39 40 |
# File 'lib/pdf/core/object_store.rb', line 38 def root @objects[@root] end |
#size ⇒ Object Also known as: length
79 80 81 |
# File 'lib/pdf/core/object_store.rb', line 79 def size @identifiers.size end |