14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/storyboard/generators/sub.rb', line 14
def add_subtitle(image, subtitle, dimensions)
offset = 0
subtitle.lines.reverse.each_with_index {|caption,i|
escaped = caption.gsub("'", "\\\\'")
font_size = 30
text_width = dimensions[0] + 1
while(text_width > (dimensions[0] * 0.9))
font_size -= 1
text_width = @@size_canvas.width_of(caption.encode!("utf-8"), :size => font_size)
end
font = Storyboard.needs_KFhimaji ? "#{Storyboard.path}/fonts/KFhimaji.otf" : "#{Storyboard.path}/fonts/DejaVuSans.ttf"
write_mvg(offset,escaped, 0)
image.combine_options do |c|
c.font font
c.fill "#333333"
c.strokewidth '1'
c.stroke '#000000'
c.pointsize font_size.to_s
c.gravity "south"
c.draw "@#{File.join(@storyboard.options[:save_directory],'tmp.mvg')}"
end
write_mvg(offset,escaped, -2)
image.combine_options do |c|
c.font font
c.fill "#ffffff"
c.strokewidth '1'
c.stroke 'transparent'
c.pointsize font_size.to_s
c.gravity "south"
c.draw "@#{File.join(@storyboard.options[:save_directory],'tmp.mvg')}"
end
offset += (@@size_canvas.height_of(caption.encode!("utf-8"), :size => font_size)).ceil
}
end
|