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
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
#[], #[]=, add_type_signature, #cast_to, #data, #data=, #decode!, #each_filter, #each_key, #encode!, #encoded_data, #encoded_data=, #filters, guess_type, #key?, parse, #post_build, #set_predictor, #to_obfuscated_str, #to_s, #value
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, 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.
387 388 389 390 391 |
# File 'lib/origami/xreftable.rb', line 387 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.
416 417 418 419 420 |
# File 'lib/origami/xreftable.rb', line 416 def <<(xref) load! if @xrefs.nil? @xrefs << xref end |
#clear ⇒ Object
471 472 473 474 475 |
# File 'lib/origami/xreftable.rb', line 471 def clear self.data = '' @xrefs = [] self.Index = [] end |
#each(&b) ⇒ Object
Iterates over each XRef present in the stream.
425 426 427 428 429 |
# File 'lib/origami/xreftable.rb', line 425 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.
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'lib/origami/xreftable.rb', line 434 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
393 394 395 396 397 |
# File 'lib/origami/xreftable.rb', line 393 def entries load! if @xrefs.nil? @xrefs end |
#find(no) ⇒ Object
Returns an XRef matching this object number.
456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/origami/xreftable.rb', line 456 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.
402 403 404 405 406 407 408 409 410 411 |
# File 'lib/origami/xreftable.rb', line 402 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 |