1 2 3 4 5 6 7 8 9 10 11 12 13 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 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 110 111 112 113 114 115 116
|
#!/usr/bin/env ruby
# This file is copyright 2007 by Vincent Fourmond
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# The goal of this file is to establish a correspondance between
# PNG images used inside the documentation and figures inside the
# files in the sample directory.
# This script creates an images/ directory which should be copied to the
# directory generated by rdoc, so that the images display properly.
require 'optparse'
require 'fileutils'
# Which gs to use
gs = 'gs'
pdftops = false
border = "6"
# Another option: use pdftoppm, which seems to have better aa than gs
opts = OptionParser.new
opts.on("","--gs GS",
"Path for the gs program") do |p|
gs = p
end
opts.on("","--[no-]pdftops [PATH] ",
"Use pdftops") do |p|
if p.is_a? String
pdftops = p
elsif p
pdftops = "pdftops"
else
pdftops = false
end
end
opts.on("","--border BORDER",
"Size of the white border around the image") do |p|
border = p
end
opts.parse!(ARGV)
# The correspondance file:figure -> target.
IMAGES = {
# "samples/plots/plots.rb:Blues" => "blues",
# "samples/plots/plots.rb:Reds" => "reds",
# "samples/plots/plots.rb:Greens" => "greens",
# "samples/figures/figures.rb:Arc" => 'append_arc',
# "samples/figures/figures.rb:Curve" => 'append_curve',
# "samples/figures/figures.rb:Subfigures" => 'subfigures',
}
FIGURES = {}
def get_figure_index(file, figure)
if FIGURES.key?(file)
return FIGURES[file][figure]
else
f = IO.popen("tioga #{file} -l")
h = {}
for l in f
if l =~ /(\d+)\s+(.*)/
h[$2] = $1
end
end
f.close
FIGURES[file] = h
return get_figure_index(file, figure)
end
end
density = 120
for s,t in IMAGES
puts "Creating image #{t}.png from #{s}"
s =~ /(.*):(.*)/
file = $1
figure = $2
idx = get_figure_index(file, figure)
`tioga #{file} -m #{idx}` =~ /\s*(?:\d+\s+)?(.*\.pdf)/
pdf = $1
if pdftops
target = "#{pdf}.temp.ps"
system "#{pdftops} #{pdf} #{target}"
FileUtils.rm pdf
pdf = target
end
system "#{gs} " +
"-q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=png16m " +
" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 " +
" -sOutputFile=images/#{t}.temp.png -r#{density}x#{density} #{pdf}"
# Then, we could have fun with convert and -trim and -border
system "convert images/#{t}.temp.png -trim " +
" -bordercolor white -border #{border} images/#{t}.png"
FileUtils.rm [pdf, "images/#{t}.temp.png"]
end
|