Class: CTioga2::PostProcess
- Inherits:
-
Object
- Object
- CTioga2::PostProcess
- Includes:
- Log
- Defined in:
- lib/ctioga2/postprocess.rb
Overview
What happens to generated PDF files ?
todo
-
handle movie generation ? That would be fun !
Instance Attribute Summary collapse
-
#eps ⇒ Object
Are we converting to EPS using pdftops ?.
-
#png_oversampling ⇒ Object
PNG oversampling: how many pixels are rendered for one target linear pixel (take that squared for the real number).
-
#png_res ⇒ Object
PNG resolution.
-
#png_scale ⇒ Object
PNG scale: how many pixels for one postscript point ?.
-
#processed_files ⇒ Object
All files processed so far..
-
#svg ⇒ Object
Are we converting to SVG using pdf2svg ?.
-
#view_all ⇒ Object
View all produced files – or only the last one ?.
-
#viewer ⇒ Object
The viewer command.
Instance Method Summary collapse
-
#initialize ⇒ PostProcess
constructor
Settings up default postprocessing.
-
#process_file(file, last = false) ⇒ Object
Process the given file.
Methods included from Log
debug, error, fatal, #format_exception, #identify, info, init_logger, logger, set_level, #spawn, warn
Constructor Details
#initialize ⇒ PostProcess
Settings up default postprocessing
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ctioga2/postprocess.rb', line 59 def initialize @view_all = false @viewer = false @svg = false @png_res = nil @png_oversampling = 2 @png_scale = 1 @processed_files = [] end |
Instance Attribute Details
#eps ⇒ Object
Are we converting to EPS using pdftops ?
46 47 48 |
# File 'lib/ctioga2/postprocess.rb', line 46 def eps @eps end |
#png_oversampling ⇒ Object
PNG oversampling: how many pixels are rendered for one target linear pixel (take that squared for the real number).
53 54 55 |
# File 'lib/ctioga2/postprocess.rb', line 53 def png_oversampling @png_oversampling end |
#png_res ⇒ Object
PNG resolution
49 50 51 |
# File 'lib/ctioga2/postprocess.rb', line 49 def png_res @png_res end |
#png_scale ⇒ Object
PNG scale: how many pixels for one postscript point ?
56 57 58 |
# File 'lib/ctioga2/postprocess.rb', line 56 def png_scale @png_scale end |
#processed_files ⇒ Object
All files processed so far..
40 41 42 |
# File 'lib/ctioga2/postprocess.rb', line 40 def processed_files @processed_files end |
#svg ⇒ Object
Are we converting to SVG using pdf2svg ?
43 44 45 |
# File 'lib/ctioga2/postprocess.rb', line 43 def svg @svg end |
#view_all ⇒ Object
View all produced files – or only the last one ?
32 33 34 |
# File 'lib/ctioga2/postprocess.rb', line 32 def view_all @view_all end |
#viewer ⇒ Object
The viewer command. If not nil, automatically spawn a viewer after the final figure, or for each produced file if view_all is on.
37 38 39 |
# File 'lib/ctioga2/postprocess.rb', line 37 def viewer @viewer end |
Instance Method Details
#process_file(file, last = false) ⇒ Object
Process the given file. If last is true, things that should only happen last happen.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ctioga2/postprocess.rb', line 74 def process_file(file, last = false) @processed_files << file # Converts to SVG if applicable if @svg target = file.sub(/(\.pdf)?$/,'.svg') info { "Converting #{file} to SVG" } spawn("pdf2svg #{file} #{target}") end if @eps target = file.sub(/(\.pdf)?$/,'.eps') info { "Converting #{file} to EPS" } ## \todo provide some facility to pass options to pdftops ? spawn("pdftops -eps -level2 -paper match #{file} #{target}") end # Converts to PNG if applicable if @png_res target = file.sub(/(\.pdf)?$/,'.png') info { "Converting #{file} to PNG" } spawn "convert -density #{(@png_oversampling * @png_scale * 72).to_i} #{file} -resize #{@png_res.join('x')} #{target}" end # View produced PDF or PNG files... if (last || @view_all) && @viewer if @png_res cmd = "display #{target}" elsif @viewer =~ /%s/ cmd = @viewer % file else cmd = "#{@viewer} #{file}" end info { "Spawning the viewer as requested for #{file}" } spawn(cmd) end end |