Class: HexaPDF::XRefSection

Inherits:
Utils::ObjectHash show all
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

#max_oid

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Utils::ObjectHash

#[], #[]=, #delete, #each, #entry?, #gen_for_oid, #initialize

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.



95
96
97
# File 'lib/hexapdf/xref_section.rb', line 95

def self.compressed_entry(oid, objstm, pos)
  Entry.new(:compressed, oid, 0, pos, objstm)
end

.free_entry(oid, gen) ⇒ Object

Creates a free cross-reference entry. See Entry for details on the arguments.



90
91
92
# File 'lib/hexapdf/xref_section.rb', line 90

def self.free_entry(oid, gen)
  Entry.new(:free, oid, gen)
end

.in_use_entry(oid, gen, pos) ⇒ Object

Creates an in-use cross-reference entry. See Entry for details on the arguments.



85
86
87
# File 'lib/hexapdf/xref_section.rb', line 85

def self.in_use_entry(oid, gen, pos)
  Entry.new(:in_use, oid, gen, pos)
end

Instance Method Details

#add_compressed_entry(oid, objstm, pos) ⇒ Object

Adds a compressed entry to the cross-reference section.

See: ::compressed_entry



120
121
122
# File 'lib/hexapdf/xref_section.rb', line 120

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



113
114
115
# File 'lib/hexapdf/xref_section.rb', line 113

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



106
107
108
# File 'lib/hexapdf/xref_section.rb', line 106

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.

Yields:

  • (temp)


135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/hexapdf/xref_section.rb', line 135

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