1
# postprocess.rb: what happens to generated PDF files ?
2
# copyright (c) 2009 by Vincent Fourmond
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful, but
10
# WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
# General Public License for more details (in the COPYING file).
15
require 'ctioga2/utils'
20
Version::register_svn_info('$Revision: 155 $', '$Date: 2010-06-21 21:41:32 +0200 (Mon, 21 Jun 2010) $')
22
# What happens to generated PDF files ?
25
# * handle movie generation ? That would be fun !
28
# Include logging facilities for ctioga2
31
# View all produced files -- or only the last one ?
32
attr_accessor :view_all
34
# The viewer command. If not _nil_, automatically spawn a viewer
35
# after the final figure, or for each produced file if view_all is
39
# All files processed so far..
40
attr_accessor :processed_files
42
# Are we converting to SVG using pdf2svg ?
45
# Are we converting to EPS using pdftops ?
49
attr_accessor :png_res
51
# PNG oversampling: how many pixels are rendered for one target
52
# linear pixel (take that squared for the real number).
53
attr_accessor :png_oversampling
55
# PNG scale: how many pixels for one postscript point ?
56
attr_accessor :png_scale
58
# Settings up default postprocessing
72
# Process the given _file_. If _last_ is true, things that should
73
# only happen last happen.
74
def process_file(file, last = false)
75
@processed_files << file
76
# Converts to SVG if applicable
78
target = file.sub(/(\.pdf)?$/,'.svg')
79
info { "Converting #{file} to SVG" }
80
spawn("pdf2svg #{file} #{target}")
84
target = file.sub(/(\.pdf)?$/,'.eps')
85
info { "Converting #{file} to EPS" }
86
## \todo provide some facility to pass options to pdftops ?
87
spawn("pdftops -eps -level2 -paper match #{file} #{target}")
90
# Converts to PNG if applicable
92
target = file.sub(/(\.pdf)?$/,'.png')
93
info { "Converting #{file} to PNG" }
94
spawn "convert -density #{(@png_oversampling * @png_scale * 72).to_i} #{file} -resize #{@png_res.join('x')} #{target}"
97
# View produced PDF or PNG files...
98
if (last || @view_all) && @viewer
100
cmd = "display #{target}"
101
elsif @viewer =~ /%s/
104
cmd = "#{@viewer} #{file}"
106
info { "Spawning the viewer as requested for #{file}" }