Class/Module Index [+]

Quicksearch

Origami::Object

Parent module representing a PDF Object. PDF specification declares a set of primitive object types :

Attributes

file_offset[RW]
generation[RW]
no[RW]
objstm_offset[RW]
parent[RW]

Public Class Methods

native_type() click to toggle source
# File lib/origami/object.rb, line 611
def self.native_type; Origami::Object end
new(*cons) click to toggle source

Creates a new PDF Object.

# File lib/origami/object.rb, line 272
def initialize(*cons)
  @indirect = false
  @no, @generation = 0, 0
  
  super(*cons) unless cons.empty?
end

Public Instance Methods

<=>(obj) click to toggle source

Compare two objects from their respective numbers.

# File lib/origami/object.rb, line 316
def <=>(obj)
  [@no, @generation] <=> [obj.no, obj.generation]
end
copy() click to toggle source

Deep copy of an object.

# File lib/origami/object.rb, line 330
def copy
  saved_pdf = @pdf
  saved_parent = @parent
  
  saved_xref_cache = @xref_cache
  @pdf = @parent = nil # do not process parent object and document in the copy

  # Perform the recursive copy (quite dirty).
  copyobj = Marshal.load(Marshal.dump(self))

  # restore saved values
  @pdf = saved_pdf
  @parent = saved_parent

  copyobj.set_pdf(saved_pdf) if copyobj.is_indirect?
  copyobj.parent = parent

  copyobj
end
export() click to toggle source

Creates an exportable version of current object. The exportable version is a copy of self with solved references, no owning PDF and no parent. References to Catalog or PageTreeNode objects have been destroyed.

When exported, an object can be moved into another document without hassle.

# File lib/origami/object.rb, line 405
def export
  exported_obj = self.logicalize
  exported_obj.no = exported_obj.generation = 0
  exported_obj.set_pdf(nil) if exported_obj.is_indirect?
  exported_obj.parent = nil
  exported_obj.xref_cache.clear
  
  exported_obj
end
indirect_parent() click to toggle source

Returns the indirect object which contains this object. If the current object is already indirect, returns self.

# File lib/origami/object.rb, line 473
def indirect_parent 
  obj = self
  obj = obj.parent until obj.is_indirect?
    
  obj
end
is_indirect?() click to toggle source

Returns whether the objects is indirect, which means that it is not embedded into another object.

# File lib/origami/object.rb, line 323
def is_indirect?
  @indirect
end
native_type() click to toggle source

Returns the native PDF type of this Object.

# File lib/origami/object.rb, line 616
def native_type
  self.class.native_type
end
output(data) click to toggle source
Alias for: to_s
pdf() click to toggle source

Returns the PDF which the object belongs to.

# File lib/origami/object.rb, line 504
def pdf
  if self.is_indirect? then @pdf
  else
    @parent.pdf if @parent
  end
end
post_build() click to toggle source

Generic method called just after the object is finalized. At this time, any indirect object has its own number and generation identifier.

# File lib/origami/object.rb, line 309
def post_build
  self
end
pre_build() click to toggle source

Generic method called just before the object is finalized. At this time, no number nor generation allocation has yet been done.

# File lib/origami/object.rb, line 301
def pre_build
  self
end
reference() click to toggle source

Returns an indirect reference to this object, or a Null object is this object is not indirect.

# File lib/origami/object.rb, line 353
def reference
  unless self.is_indirect?
    raise InvalidObjectError, "Cannot reference a direct object"
  end

  ref = Reference.new(@no, @generation)
  ref.parent = self

  ref
end
resolve_all_references(obj, browsed = [], ref_cache = {}) click to toggle source
# File lib/origami/object.rb, line 429
def resolve_all_references(obj, browsed = [], ref_cache = {})
  return if browsed.include?(obj)
  browsed.push(obj)

  if obj.is_a?(ObjectStream)
    obj.each do |subobj|
      resolve_all_references(obj, browsed, ref_cache)
    end
  end

  if obj.is_a?(Dictionary) or obj.is_a?(Array)
    obj.map! do |subobj|
      if subobj.is_a?(Reference)
        new_obj = 
          if ref_cache.has_key?(subobj)
            ref_cache[subobj]
          else
            ref_cache[subobj] = subobj.solve.copy  
          end
        new_obj.no = new_obj.generation = 0
        new_obj.parent = obj

        new_obj unless new_obj.is_a?(Catalog) or new_obj.is_a?(PageTreeNode)
      else
        subobj
      end
    end

    obj.each do |subobj|
      resolve_all_references(subobj, browsed, ref_cache)
    end

  elsif obj.is_a?(Stream)
    resolve_all_references(obj.dictionary, browsed, ref_cache)
  end
end
set_indirect(bool) click to toggle source

Sets whether the object is indirect or not. Indirect objects are allocated numbers at build time.

# File lib/origami/object.rb, line 283
def set_indirect(bool)
  unless bool == true or bool == false
    raise TypeError, "The argument must be boolean"
  end

  if not bool
    @no = @generation = 0
    @pdf = nil
  end

  @indirect = bool
  self
end
set_pdf(pdf) click to toggle source
# File lib/origami/object.rb, line 511
def set_pdf(pdf)
  if self.is_indirect? then @pdf = pdf
  else
    raise InvalidObjectError, "You cannot set the PDF parent of a direct object"
  end
end
size() click to toggle source

Returns the size of this object once converted to PDF code.

# File lib/origami/object.rb, line 497
def size
  to_s.size
end
solve() click to toggle source

Returns self.

# File lib/origami/object.rb, line 490
def solve
  self
end
to_o() click to toggle source

Returns self.

# File lib/origami/object.rb, line 483
def to_o
  self
end
to_obfuscated_str(data) click to toggle source
Alias for: to_s
to_s(data) click to toggle source

Outputs this object into PDF code.

data

The object data.

# File lib/origami/object.rb, line 632
def to_s(data)
  
  content = ""
  content << "#{no} #{generation} obj" << EOL if self.is_indirect?
  content << data
  content << EOL << "endobj" << EOL if self.is_indirect?
  
  content
end
Also aliased as: to_obfuscated_str, output
type() click to toggle source

Returns the symbol type of this Object.

# File lib/origami/object.rb, line 607
def type
  self.class.to_s.split("::").last.to_sym
end
xrefs() click to toggle source

Returns an array of references pointing to the current object.

# File lib/origami/object.rb, line 367
def xrefs
  unless self.is_indirect?
    raise InvalidObjectError, "Cannot find xrefs to a direct object"
  end

  if self.pdf.nil?
    raise InvalidObjectError, "Not attached to any PDF"
  end

  xref_cache = Hash.new([])
  @pdf.root_objects.each do |obj|
    case obj
      when Dictionary,Array then
        xref_cache.update(obj.xref_cache) do |ref, cache1, cache2|
          cache1.concat(cache2)
        end

      when Stream then
        obj.dictionary.xref_cache.each do |ref, cache|
          cache.map!{obj}
        end

        xref_cache.update(obj.dictionary.xref_cache) do |ref, cache1, cache2|
          cache1.concat(cache2)
        end
    end
  end

  xref_cache[self.reference]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.