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.



498
499
500
501
502
503
504
# File 'lib/podoff.rb', line 498

def initialize(obj=nil)

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

Instance Attribute Details

#objObject

Returns the value of attribute obj.



496
497
498
# File 'lib/podoff.rb', line 496

def obj
  @obj
end

Instance Method Details

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



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

def bt(x, y, text)

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

#rg(red, green, blue) ⇒ Object Also known as: color, rgb



514
515
516
517
# File 'lib/podoff.rb', line 514

def rg(red, green, blue)

  @color = "#{red} #{green} #{blue} rg "
end

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



506
507
508
509
510
511
# File 'lib/podoff.rb', line 506

def tf(font_name, font_size)

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

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

#to_sObject



537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'lib/podoff.rb', line 537

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



532
533
534
535
# File 'lib/podoff.rb', line 532

def write(text)

  @content.write(text)
end