Class: Origami::XRefStream
- Includes:
- Enumerable, StandardObject
- Defined in:
- lib/origami/xreftable.rb
Overview
Class representing a XRef Stream.
Constant Summary collapse
- XREF_FREE =
0
- XREF_USED =
1
- XREF_COMPRESSED =
2
Constants included from StandardObject
StandardObject::DEFAULT_ATTRIBUTES
Constants inherited from Stream
Stream::DEFINED_FILTERS, Stream::TOKENS
Constants included from Object
Instance Attribute Summary
Attributes inherited from Stream
Attributes included from Object
#file_offset, #generation, #no, #objstm_offset, #parent
Instance Method Summary collapse
-
#<<(xref) ⇒ Object
Adds an XRef to this Stream.
- #clear ⇒ Object
-
#each(&b) ⇒ Object
Iterates over each XRef present in the stream.
-
#each_with_number ⇒ Object
Iterates over each XRef present in the stream, passing the XRef and its object number.
- #entries ⇒ Object
-
#find(no) ⇒ Object
Returns an XRef matching this object number.
-
#initialize(data = "", dictionary = {}) ⇒ XRefStream
constructor
A new instance of XRefStream.
-
#pre_build ⇒ Object
Returns XRef entries present in this stream.
Methods included from StandardObject
Methods inherited from Stream
#[], #[]=, #cast_to, #data, #data=, #decode!, #each_filter, #each_key, #each_pair, #encode!, #encoded_data, #encoded_data=, #filters, #key?, #keys, parse, #post_build, #set_predictor, #to_obfuscated_str, #to_s, #value
Methods included from TypeGuessing
Methods included from FieldAccessor
#method_missing, #respond_to_missing?
Methods included from Object
#cast_to, #copy, #document, #export, included, #indirect?, #indirect_parent, #logicalize, #logicalize!, #native_type, #numbered?, parse, #post_build, #reference, #set_document, #set_indirect, skip_until_next_obj, #solve, #to_o, #to_s, #type, typeof, #version_required, #xrefs
Constructor Details
#initialize(data = "", dictionary = {}) ⇒ XRefStream
Returns a new instance of XRefStream.
400 401 402 403 404 |
# File 'lib/origami/xreftable.rb', line 400 def initialize(data = "", dictionary = {}) super(data, dictionary) @xrefs = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Origami::FieldAccessor
Instance Method Details
#<<(xref) ⇒ Object
Adds an XRef to this Stream.
429 430 431 432 433 |
# File 'lib/origami/xreftable.rb', line 429 def <<(xref) load! if @xrefs.nil? @xrefs << xref end |
#clear ⇒ Object
484 485 486 487 488 |
# File 'lib/origami/xreftable.rb', line 484 def clear self.data = '' @xrefs = [] self.Index = [] end |
#each(&b) ⇒ Object
Iterates over each XRef present in the stream.
438 439 440 441 442 |
# File 'lib/origami/xreftable.rb', line 438 def each(&b) load! if @xrefs.nil? @xrefs.each(&b) end |
#each_with_number ⇒ Object
Iterates over each XRef present in the stream, passing the XRef and its object number.
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/origami/xreftable.rb', line 447 def each_with_number return enum_for(__method__) unless block_given? load! if @xrefs.nil? ranges = object_ranges xrefs = @xrefs.to_enum ranges.each do |range| range.each do |no| begin yield(xrefs.next, no) rescue StopIteration raise InvalidXRefStreamObjectError, "Range is bigger than number of entries" end end end end |
#entries ⇒ Object
406 407 408 409 410 |
# File 'lib/origami/xreftable.rb', line 406 def entries load! if @xrefs.nil? @xrefs end |
#find(no) ⇒ Object
Returns an XRef matching this object number.
469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
# File 'lib/origami/xreftable.rb', line 469 def find(no) load! if @xrefs.nil? ranges = object_ranges index = 0 ranges.each do |range| return @xrefs[index + no - range.begin] if range.cover?(no) index += range.size end nil end |
#pre_build ⇒ Object
Returns XRef entries present in this stream.
415 416 417 418 419 420 421 422 423 424 |
# File 'lib/origami/xreftable.rb', line 415 def pre_build #:nodoc: load! if @xrefs.nil? self.W = [ 1, 2, 2 ] unless self.key?(:W) self.Size = @xrefs.length + 1 save! super end |