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   pdf   post_build   pre_build   real_type   reference   set_indirect   set_pdf   size   to_o   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(indirect, *cons)
260:       
261:       set_indirect(indirect)
262:       @no, @generation = 0, 0
263:       
264:       super(*cons) unless cons.empty?
265:       
266:     end

Public Instance methods

Compare two objects from their respective numbers.

[Source]

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

Deep copy of an object.

[Source]

     # File sources/parser/object.rb, line 314
314:     def copy
315:       Marshal.load(Marshal.dump(self))
316:     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 352
352:     def indirect_parent 
353:       obj = self
354:       obj = obj.parent until obj.is_indirect?
355:         
356:       obj
357:     end

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

[Source]

     # File sources/parser/object.rb, line 307
307:     def is_indirect?
308:       @indirect
309:     end

Returns the PDF which the object belongs to.

[Source]

     # File sources/parser/object.rb, line 376
376:     def pdf
377:       if self.is_indirect? then @pdf
378:       else
379:         @parent.pdf
380:       end
381:     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 293
293:     def post_build
294:       self
295:     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 285
285:     def pre_build
286:       self
287:     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 321
321:     def reference
322:       unless self.is_indirect?
323:         raise InvalidObject, "Cannot reference a direct object"
324:       end
325: 
326:       ref = Reference.new(@no, @generation)
327:       ref.parent = self
328: 
329:       ref
330:     end

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

[Source]

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

[Source]

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

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

[Source]

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

Returns self.

[Source]

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

Returns the symbol type of this Object.

[Source]

     # File sources/parser/object.rb, line 464
464:     def type
465:       self.class.to_s.split("::").last.to_sym
466:     end

Returns an array of references pointing to the current object.

[Source]

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

[Validate]