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, PDF2.0 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.
-
#mark_as_initial_section! ⇒ Object
Marks this XRefSection object as being the first cross-reference section in a PDF file.
-
#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
138 139 140 |
# File 'lib/hexapdf/xref_section.rb', line 138 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
131 132 133 |
# File 'lib/hexapdf/xref_section.rb', line 131 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
124 125 126 |
# File 'lib/hexapdf/xref_section.rb', line 124 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. In case the section was marked as the initial section (see #mark_as_initial_section!) only a single subsection is yielded.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/hexapdf/xref_section.rb', line 160 def each_subsection return to_enum(__method__) unless block_given? temp = [] oids.sort.each do |oid| expected_next_oid = !temp.empty? && temp[-1].oid + 1 if expected_next_oid && expected_next_oid != oid if @initial_section expected_next_oid.upto(oid - 1) do |free_oid| temp << self.class.free_entry(free_oid, 0) end else yield(temp) temp = [] end end temp << self[oid] end yield(temp) self end |
#mark_as_initial_section! ⇒ Object
Marks this XRefSection object as being the first cross-reference section in a PDF file.
This has the consequence that only a single sub-section is created.
117 118 119 |
# File 'lib/hexapdf/xref_section.rb', line 117 def mark_as_initial_section! @initial_section = true end |
#merge!(xref_section) ⇒ Object
Merges the entries from the given cross-reference section into this one.
143 144 145 |
# File 'lib/hexapdf/xref_section.rb', line 143 def merge!(xref_section) xref_section.each {|oid, gen, data| self[oid, gen] = data } end |