Class: JotPDF::Core::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/jot_pdf/core.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Writer

Returns a new instance of Writer.



27
28
29
30
31
32
33
34
# File 'lib/jot_pdf/core.rb', line 27

def initialize(io)
  @objects = [
    CrossReferenceTableEntry.default,
  ]
  @section = [0]
  @io = io
  @offset = 0
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



25
26
27
# File 'lib/jot_pdf/core.rb', line 25

def io
  @io
end

#objectsObject (readonly)

Returns the value of attribute objects.



25
26
27
# File 'lib/jot_pdf/core.rb', line 25

def objects
  @objects
end

#offsetObject (readonly)

Returns the value of attribute offset.



25
26
27
# File 'lib/jot_pdf/core.rb', line 25

def offset
  @offset
end

Instance Method Details

#<<(data) ⇒ Object



57
58
59
60
61
62
# File 'lib/jot_pdf/core.rb', line 57

def <<(data)
  s = data.to_s
  @io << s
  @offset += s.bytesize
  self
end

#finish_sectionObject



51
52
53
54
55
# File 'lib/jot_pdf/core.rb', line 51

def finish_section
  result = @section.dup
  @section.clear
  result
end

#new_objectObject



36
37
38
39
40
# File 'lib/jot_pdf/core.rb', line 36

def new_object
  number = @objects.size
  @objects << CrossReferenceTableEntry.default
  ObjectRef.new(number:, generation: 0)
end

#update_object_entry(object_ref) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/jot_pdf/core.rb', line 42

def update_object_entry(object_ref)
  @section << object_ref.number
  @objects[object_ref.number] = CrossReferenceTableEntry.new(
    generation: object_ref.generation,
    offset: @offset,
    usage: :in_use,
  )
end