Class: Origami::XRefStream

Inherits:
Stream
  • Object
show all
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::TOKENS

Constants included from Object

Object::TOKENS

Instance Attribute Summary

Attributes inherited from Stream

#dictionary

Attributes included from Object

#file_offset, #generation, #no, #objstm_offset, #parent

Instance Method Summary collapse

Methods included from StandardObject

#do_type_check, #has_field?, included, #set_default_value, #set_default_values, #version_required

Methods inherited from Stream

#[], #[]=, add_type_info, #cast_to, #data, #data=, #decode!, #each_filter, #each_key, #encode!, #encoded_data, #encoded_data=, #filters, guess_type, #key?, native_type, parse, #post_build, #set_predictor, #to_obfuscated_str, #to_s, #value

Methods included from Object

#<=>, #cast_to, #copy, #document, #export, #indirect?, #indirect_parent, #logicalize, #logicalize!, native_type, #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.



391
392
393
394
395
# File 'lib/origami/xreftable.rb', line 391

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::Stream

Instance Method Details

#<<(xref) ⇒ Object

Adds an XRef to this Stream.



420
421
422
423
424
# File 'lib/origami/xreftable.rb', line 420

def <<(xref)
    load! if @xrefs.nil?

    @xrefs << xref
end

#clearObject



475
476
477
478
479
# File 'lib/origami/xreftable.rb', line 475

def clear
    self.data = ''
    @xrefs = []
    self.Index = []
end

#each(&b) ⇒ Object

Iterates over each XRef present in the stream.



429
430
431
432
433
# File 'lib/origami/xreftable.rb', line 429

def each(&b)
    load! if @xrefs.nil?

    @xrefs.each(&b)
end

#each_with_numberObject

Iterates over each XRef present in the stream, passing the XRef and its object number.



438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/origami/xreftable.rb', line 438

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

#entriesObject



397
398
399
400
401
# File 'lib/origami/xreftable.rb', line 397

def entries
    load! if @xrefs.nil?

    @xrefs
end

#find(no) ⇒ Object

Returns an XRef matching this object number.



460
461
462
463
464
465
466
467
468
469
470
471
472
473
# File 'lib/origami/xreftable.rb', line 460

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_buildObject

Returns XRef entries present in this stream.



406
407
408
409
410
411
412
413
414
415
# File 'lib/origami/xreftable.rb', line 406

def pre_build #:nodoc:
    load! if @xrefs.nil?

    self.W = [ 1, 2, 2 ] unless has_field?(:W)
    self.Size = @xrefs.length + 1

    save!

    super
end