Class: Storyboard::PDFRenderer

Inherits:
Renderer show all
Defined in:
lib/storyboard/generators/pdf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Renderer

#add_subtitle, #write_mvg

Constructor Details

#initialize(parent) ⇒ PDFRenderer

Returns a new instance of PDFRenderer.



8
9
10
11
# File 'lib/storyboard/generators/pdf.rb', line 8

def initialize(parent)
  @dimensions = []
  @storyboard = parent
end

Instance Attribute Details

#dimensionsObject

Returns the value of attribute dimensions.



7
8
9
# File 'lib/storyboard/generators/pdf.rb', line 7

def dimensions
  @dimensions
end

#pdfObject

Returns the value of attribute pdf.



7
8
9
# File 'lib/storyboard/generators/pdf.rb', line 7

def pdf
  @pdf
end

#storyboardObject

Returns the value of attribute storyboard.



7
8
9
# File 'lib/storyboard/generators/pdf.rb', line 7

def storyboard
  @storyboard
end

Instance Method Details

#render_frame(frame_name, subtitle = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/storyboard/generators/pdf.rb', line 23

def render_frame(frame_name, subtitle = nil)
  output_filename = File.join(@storyboard.options[:save_directory], "sub-#{File.basename(frame_name)}")
  image = MiniMagick::Image.open(frame_name)

  if(@dimensions.empty?)
    resize_height = (image[:height] * (@storyboard.options[:max_width].to_f/image[:width])).ceil
    set_dimensions(storyboard.options[:max_width], resize_height)
  end

  image.resize "#{@dimensions[0]}x#{@dimensions[1]}"
  image.quality("60")

  self.add_subtitle(image, subtitle, @dimensions) if subtitle
  image.format 'jpeg'
  image.write(output_filename)
  image.destroy!

  @pdf.image output_filename, :width => @dimensions[0], :height => @dimensions[1]


end

#set_dimensions(w, h) ⇒ Object



13
14
15
16
# File 'lib/storyboard/generators/pdf.rb', line 13

def set_dimensions(w,h)
  @dimensions = [w,h]
  @pdf = Prawn::Document.new(:page_size => [w, h], :margin => 0)
end

#writeObject



18
19
20
21
# File 'lib/storyboard/generators/pdf.rb', line 18

def write
  @pdf.render_file "#{@storyboard.options[:write_to]}/#{@storyboard.options[:basename]}.pdf"
  LOG.info("Wrote #{@storyboard.options[:write_to]}/#{@storyboard.options[:basename]}.pdf")
end