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.
403 404 405 406 407 |
# File 'lib/origami/xreftable.rb', line 403 def initialize(data = "", dictionary = {}) super @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.
432 433 434 435 436 |
# File 'lib/origami/xreftable.rb', line 432 def <<(xref) load! if @xrefs.nil? @xrefs << xref end |
#clear ⇒ Object
485 486 487 488 489 |
# File 'lib/origami/xreftable.rb', line 485 def clear self.data = '' @xrefs = [] self.Index = [] end |
#each(&b) ⇒ Object
Iterates over each XRef present in the stream.
441 442 443 444 445 |
# File 'lib/origami/xreftable.rb', line 441 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.
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/origami/xreftable.rb', line 450 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| yield(xrefs.next, no) rescue StopIteration raise InvalidXRefStreamObjectError, "Range is bigger than number of entries" end end end |
#entries ⇒ Object
409 410 411 412 413 |
# File 'lib/origami/xreftable.rb', line 409 def entries load! if @xrefs.nil? @xrefs end |
#find(no) ⇒ Object
Returns an XRef matching this object number.
470 471 472 473 474 475 476 477 478 479 480 481 482 483 |
# File 'lib/origami/xreftable.rb', line 470 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.
418 419 420 421 422 423 424 425 426 427 |
# File 'lib/origami/xreftable.rb', line 418 def pre_build # :nodoc: load! if @xrefs.nil? self.W = [1, 2, 2] unless key?(:W) self.Size = @xrefs.length + 1 save! super end |