Class: Pdfrb::Source::ObjectReader
- Inherits:
-
Object
- Object
- Pdfrb::Source::ObjectReader
- Defined in:
- lib/pdfrb/source/object_reader.rb
Overview
Resolves Model::Reference values to Model::Object instances by consulting the document's XrefSection. In-use entries seek and parse the indirect object at the recorded offset. Compressed entries defer to ObjectStreamReader.
Caches resolved objects per document.
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#xref ⇒ Object
readonly
Returns the value of attribute xref.
Instance Method Summary collapse
- #clear_cache ⇒ Object
-
#initialize(document, xref) ⇒ ObjectReader
constructor
A new instance of ObjectReader.
- #load(reference) ⇒ Object
- #load_oid(oid) ⇒ Object
Constructor Details
#initialize(document, xref) ⇒ ObjectReader
Returns a new instance of ObjectReader.
14 15 16 17 18 19 |
# File 'lib/pdfrb/source/object_reader.rb', line 14 def initialize(document, xref) @document = document @xref = xref @cache = {} @objstm_cache = {} end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
12 13 14 |
# File 'lib/pdfrb/source/object_reader.rb', line 12 def document @document end |
#xref ⇒ Object (readonly)
Returns the value of attribute xref.
12 13 14 |
# File 'lib/pdfrb/source/object_reader.rb', line 12 def xref @xref end |
Instance Method Details
#clear_cache ⇒ Object
39 40 41 42 |
# File 'lib/pdfrb/source/object_reader.rb', line 39 def clear_cache @cache.clear @objstm_cache.clear end |
#load(reference) ⇒ Object
21 22 23 |
# File 'lib/pdfrb/source/object_reader.rb', line 21 def load(reference) load_oid(reference.oid) end |
#load_oid(oid) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pdfrb/source/object_reader.rb', line 25 def load_oid(oid) return @cache[oid] if @cache.key?(oid) entry = xref[oid] return nil if entry.nil? || entry.free? obj = case entry.type when :in_use then parse_at(entry.offset, oid, entry.gen) when :compressed then load_from_objstm(entry.obj_stm_oid, entry.index, oid) end @cache[oid] = obj obj end |