Class: Podoff::Stream

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj = nil) ⇒ Stream

Returns a new instance of Stream.



522
523
524
525
526
527
# File 'lib/podoff.rb', line 522

def initialize(obj=nil)

  @obj = obj
  @font = nil
  @content = StringIO.new
end

Instance Attribute Details

#objObject

Returns the value of attribute obj.



520
521
522
# File 'lib/podoff.rb', line 520

def obj
  @obj
end

Instance Method Details

#bt(x, y, text) ⇒ Object Also known as: text



537
538
539
540
541
542
543
544
# File 'lib/podoff.rb', line 537

def bt(x, y, text)

  @content.write "\n" if @content.size > 0
  @content.write "BT "
  @content.write @font if @font
  @content.write "#{x} #{y} Td (#{escape(text)}) Tj"
  @content.write " ET"
end

#tf(font_name, font_size) ⇒ Object Also known as: font



529
530
531
532
533
534
# File 'lib/podoff.rb', line 529

def tf(font_name, font_size)

  n = font_name[0] == '/' ? font_name[1..-1] : font_name

  @font = "/#{n} #{font_size} Tf "
end

#to_sObject



552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'lib/podoff.rb', line 552

def to_s

  s = @content.string
  f = ''
  if s.length > 98
    f = ' /Filter /FlateDecode'
    s = Zlib::Deflate.deflate(s)
  end

  "#{obj.ref} obj\n" +
  "<</Length #{s.size}#{f}>>\nstream\n#{s}\nendstream\n" +
  "endobj"
end

#write(text) ⇒ Object



547
548
549
550
# File 'lib/podoff.rb', line 547

def write(text)

  @content.write(text)
end