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.
- #is_utf8?(str) ⇒ Boolean
-
#object_id_for_page(k) ⇒ 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 29 30 |
# File 'lib/pdf/core/object_store.rb', line 16 def initialize(opts = {}) @objects = {} @identifiers = [] load_file(opts[:template]) if opts[:template] @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
76 77 78 |
# File 'lib/pdf/core/object_store.rb', line 76 def [](id) @objects[id] end |
#each ⇒ Object
70 71 72 73 74 |
# File 'lib/pdf/core/object_store.rb', line 70 def each @identifiers.each do |id| yield @objects[id] end end |
#info ⇒ Object
36 37 38 |
# File 'lib/pdf/core/object_store.rb', line 36 def info @objects[@info] end |
#is_utf8?(str) ⇒ Boolean
101 102 103 104 |
# File 'lib/pdf/core/object_store.rb', line 101 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
95 96 97 98 99 |
# File 'lib/pdf/core/object_store.rb', line 95 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_count ⇒ Object
48 49 50 |
# File 'lib/pdf/core/object_store.rb', line 48 def page_count pages.data[:Count] end |
#pages ⇒ Object
44 45 46 |
# File 'lib/pdf/core/object_store.rb', line 44 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.
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/pdf/core/object_store.rb', line 56 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
32 33 34 |
# File 'lib/pdf/core/object_store.rb', line 32 def ref(data, &block) push(size + 1, data, &block) end |
#root ⇒ Object
40 41 42 |
# File 'lib/pdf/core/object_store.rb', line 40 def root @objects[@root] end |
#size ⇒ Object Also known as: length
80 81 82 |
# File 'lib/pdf/core/object_store.rb', line 80 def size @identifiers.size end |