Class: HexaPDF::XRefSection
- Inherits:
-
Utils::ObjectHash
- Object
- Utils::ObjectHash
- HexaPDF::XRefSection
- Defined in:
- lib/hexapdf/xref_section.rb
Overview
Manages the indirect objects of one cross-reference section or stream.
A PDF file can have more than one cross-reference section or stream which are all daisy-chained together. This allows later sections to override entries in prior ones. This is automatically and transparently done by HexaPDF.
Note that a cross-reference section may contain a single object number only once.
See: HexaPDF::Revision, PDF1.7 s7.5.4, s7.5.8
Defined Under Namespace
Classes: Entry
Instance Attribute Summary
Attributes inherited from Utils::ObjectHash
Class Method Summary collapse
-
.compressed_entry(oid, objstm, pos) ⇒ Object
Creates a compressed cross-reference entry.
-
.free_entry(oid, gen) ⇒ Object
Creates a free cross-reference entry.
-
.in_use_entry(oid, gen, pos) ⇒ Object
Creates an in-use cross-reference entry.
Instance Method Summary collapse
-
#add_compressed_entry(oid, objstm, pos) ⇒ Object
Adds a compressed entry to the cross-reference section.
-
#add_free_entry(oid, gen) ⇒ Object
Adds a free entry to the cross-reference section.
-
#add_in_use_entry(oid, gen, pos) ⇒ Object
Adds an in-use entry to the cross-reference section.
-
#each_subsection {|temp| ... } ⇒ Object
:call-seq: xref_section.each_subsection {|sub| block } -> xref_section xref_section.each_subsection -> Enumerator.
-
#merge!(xref_section) ⇒ Object
Merges the entries from the given cross-reference section into this one.
Methods inherited from Utils::ObjectHash
#[], #[]=, #delete, #each, #entry?, #gen_for_oid, #initialize, #oids
Constructor Details
This class inherits a constructor from HexaPDF::Utils::ObjectHash
Class Method Details
.compressed_entry(oid, objstm, pos) ⇒ Object
Creates a compressed cross-reference entry. See Entry for details on the arguments.
106 107 108 |
# File 'lib/hexapdf/xref_section.rb', line 106 def self.compressed_entry(oid, objstm, pos) Entry.new(:compressed, oid, 0, pos, objstm) end |
Instance Method Details
#add_compressed_entry(oid, objstm, pos) ⇒ Object
Adds a compressed entry to the cross-reference section.
See: ::compressed_entry
131 132 133 |
# File 'lib/hexapdf/xref_section.rb', line 131 def add_compressed_entry(oid, objstm, pos) self[oid, 0] = self.class.compressed_entry(oid, objstm, pos) end |
#add_free_entry(oid, gen) ⇒ Object
Adds a free entry to the cross-reference section.
See: ::free_entry
124 125 126 |
# File 'lib/hexapdf/xref_section.rb', line 124 def add_free_entry(oid, gen) self[oid, gen] = self.class.free_entry(oid, gen) end |
#add_in_use_entry(oid, gen, pos) ⇒ Object
Adds an in-use entry to the cross-reference section.
See: ::in_use_entry
117 118 119 |
# File 'lib/hexapdf/xref_section.rb', line 117 def add_in_use_entry(oid, gen, pos) self[oid, gen] = self.class.in_use_entry(oid, gen, pos) end |
#each_subsection {|temp| ... } ⇒ Object
:call-seq:
xref_section.each_subsection {|sub| block } -> xref_section
xref_section.each_subsection -> Enumerator
Calls the given block once for every subsection of this cross-reference section. Each yielded subsection is a sorted array of cross-reference entries.
If this section contains no objects, a single empty array is yielded (corresponding to a subsection with zero elements).
The subsections are dynamically generated based on the object numbers in this section.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/hexapdf/xref_section.rb', line 151 def each_subsection return to_enum(__method__) unless block_given? temp = [] oids.sort.each do |oid| if !temp.empty? && temp[-1].oid + 1 != oid yield(temp) temp = [] end temp << self[oid] end yield(temp) self end |
#merge!(xref_section) ⇒ Object
Merges the entries from the given cross-reference section into this one.
136 137 138 |
# File 'lib/hexapdf/xref_section.rb', line 136 def merge!(xref_section) xref_section.each {|oid, gen, data| self[oid, gen] = data } end |