Module Origami::Object
In: sources/parser/object.rb

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

Methods

<=>   copy   indirect_parent   is_indirect?   new   output   pdf   post_build   pre_build   real_type   reference   set_indirect   set_pdf   size   to_o   to_s   type   xrefs  

Attributes

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

Public Class methods

Creates a new PDF Object.

[Source]

     # File sources/parser/object.rb, line 259
259:     def initialize(*cons)
260:       @indirect = false
261:       @no, @generation = 0, 0
262:       
263:       super(*cons) unless cons.empty?
264:     end

Public Instance methods

Compare two objects from their respective numbers.

[Source]

     # File sources/parser/object.rb, line 298
298:     def <=>(obj)
299:       [@no, @generation] <=> [obj.no, obj.generation]
300:     end

Deep copy of an object.

[Source]

     # File sources/parser/object.rb, line 312
312:     def copy
313:       Marshal.load(Marshal.dump(self))
314:     end

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

[Source]

     # File sources/parser/object.rb, line 350
350:     def indirect_parent 
351:       obj = self
352:       obj = obj.parent until obj.is_indirect?
353:         
354:       obj
355:     end

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

[Source]

     # File sources/parser/object.rb, line 305
305:     def is_indirect?
306:       @indirect
307:     end
output(data)

Alias for to_s

Returns the PDF which the object belongs to.

[Source]

     # File sources/parser/object.rb, line 374
374:     def pdf
375:       if self.is_indirect? then @pdf
376:       else
377:         @parent.pdf
378:       end
379:     end

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

[Source]

     # File sources/parser/object.rb, line 291
291:     def post_build
292:       self
293:     end

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

[Source]

     # File sources/parser/object.rb, line 283
283:     def pre_build
284:       self
285:     end
real_type()

Alias for type

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

[Source]

     # File sources/parser/object.rb, line 319
319:     def reference
320:       unless self.is_indirect?
321:         raise InvalidObject, "Cannot reference a direct object"
322:       end
323: 
324:       ref = Reference.new(@no, @generation)
325:       ref.parent = self
326: 
327:       ref
328:     end

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

[Source]

     # File sources/parser/object.rb, line 270
270:     def set_indirect(dir)
271:       unless dir == true  or dir == false
272:         raise TypeError, "The argument must be boolean"
273:       end
274:       
275:       @indirect = dir
276:       self
277:     end

[Source]

     # File sources/parser/object.rb, line 381
381:     def set_pdf(pdf)
382:       if self.is_indirect? then @pdf = pdf
383:       else
384:         raise InvalidObject, "You cannot set the PDF parent of a direct object"
385:       end
386:     end

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

[Source]

     # File sources/parser/object.rb, line 367
367:     def size
368:       to_s.size
369:     end

Returns self.

[Source]

     # File sources/parser/object.rb, line 360
360:     def to_o
361:       self
362:     end

Outputs this object into PDF code.

data:The object data.

[Source]

     # File sources/parser/object.rb, line 470
470:     def to_s(data)
471:       
472:       content = ""
473:       content << "#{no} #{generation} obj" << EOL if self.is_indirect?
474:       content << data
475:       content << EOL << "endobj" << EOL if self.is_indirect?
476:       
477:       content
478:     end

Returns the symbol type of this Object.

[Source]

     # File sources/parser/object.rb, line 460
460:     def type
461:       self.class.to_s.split("::").last.to_sym
462:     end

Returns an array of references pointing to the current object.

[Source]

     # File sources/parser/object.rb, line 333
333:     def xrefs
334:       unless self.is_indirect?
335:         raise InvalidObject, "Cannot find xrefs to a direct object"
336:       end
337: 
338:       if self.pdf.nil?
339:         raise InvalidObject, "Not attached to any PDF"
340:       end
341: 
342:       thisref = self.reference
343:       @pdf.objects.find_all{|obj| obj.is_a?(Reference) and obj.eql?(thisref)}
344:     end

[Validate]