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, #pdf_version_required, #set_default_value, #set_default_values

Methods inherited from Stream

#[], #[]=, add_type_info, #cast_to, #data, #data=, #decode!, #each_key, #encode!, guess_type, #method_missing, native_type, parse, #post_build, #rawdata, #rawdata=, #set_predictor, #to_obfuscated_str, #to_s, #value

Methods included from Object

#<=>, #cast_to, #copy, #export, #indirect_parent, #is_indirect?, #logicalize, #logicalize!, native_type, #native_type, parse, #pdf, #pdf_version_required, #post_build, #reference, #resolve_all_references, #set_indirect, #set_pdf, #size, skip_until_next_obj, #solve, #to_o, #to_s, #type, typeof, #xrefs

Constructor Details

#initialize(data = "", dictionary = {}) ⇒ XRefStream

Returns a new instance of XRefStream.



337
338
339
340
341
# File 'lib/origami/xreftable.rb', line 337

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.



366
367
368
369
370
# File 'lib/origami/xreftable.rb', line 366

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

  @xrefs << xref  
end

#clearObject



401
402
403
404
405
# File 'lib/origami/xreftable.rb', line 401

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

#each(&b) ⇒ Object

Iterates over each XRef present in the stream.



375
376
377
378
379
# File 'lib/origami/xreftable.rb', line 375

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

  @xrefs.each(&b)
end

#entriesObject



343
344
345
346
347
# File 'lib/origami/xreftable.rb', line 343

def entries
  load! if @xrefs.nil?

  @xrefs
end

#find(no) ⇒ Object

Returns an XRef matching this object number.



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'lib/origami/xreftable.rb', line 384

def find(no)
  load! if @xrefs.nil?

  ranges = self.Index || [ 0, @xrefs.length ]

  index = 0
  (ranges.size / 2).times do |i|
    brange = ranges[i*2].to_i
    size = ranges[i*2+1].to_i
    return @xrefs[index + no - brange] if Range.new(brange, brange + size - 1) === no

    index += size
  end

  nil
end

#pre_buildObject

Returns XRef entries present in this stream.



352
353
354
355
356
357
358
359
360
361
# File 'lib/origami/xreftable.rb', line 352

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