summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/context/perl/pdftrimwhite.pl24
-rw-r--r--scripts/context/ruby/base/ctx.rb18
-rw-r--r--scripts/context/ruby/base/tex.rb18
-rw-r--r--scripts/context/ruby/graphics/gs.rb83
-rw-r--r--scripts/context/ruby/pstopdf.rb2
-rw-r--r--scripts/context/ruby/texmfstart.rb21
6 files changed, 116 insertions, 50 deletions
diff --git a/scripts/context/perl/pdftrimwhite.pl b/scripts/context/perl/pdftrimwhite.pl
index 08c1de5d7..6ac4f70c5 100644
--- a/scripts/context/perl/pdftrimwhite.pl
+++ b/scripts/context/perl/pdftrimwhite.pl
@@ -61,7 +61,7 @@ eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $
#D \stopuseMPgraphic
#D
#D \placefigure
-#D [here][fig:cropcrap]
+#D [here][fig:pdftrimwhite]
#D {Crops and offsets.}
#D {\useMPgraphic{original}}
#D
@@ -72,40 +72,40 @@ eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $
#D The script is executed as follows:
#D
#D \starttyping
-#D cropcrap <original> [<result>] [<switches>]
+#D pdftrimwhite <original> [<result>] [<switches>]
#D \stoptyping
#D
#D The next call crops \type {test.pdf} to its natural
#D boundingbox.
#D
#D \starttyping
-#D cropcrap test
+#D pdftrimwhite test
#D \stoptyping
#D
#D If the file has some crap at the bottom, you can say:
#D
#D \starttyping
-#D cropcrap test --bottomcrop=2cm
+#D pdftrimwhite test --bottomcrop=2cm
#D \stoptyping
#D
#D This clips 2cm from the bottom. You can clip on all sides
#D individually, in combination or at once, like in:
#D
#D \starttyping
-#D cropcrap test --bottomcrop=2cm --crop=1cm
+#D pdftrimwhite test --bottomcrop=2cm --crop=1cm
#D \stoptyping
#D
#D The final result is a tightly cropped image. In order to get
#D a 5mm margin around this image, you can say:
#D
#D \starttyping
-#D cropcrap test --bottomcrop=2cm --offset=5mm
+#D pdftrimwhite test --bottomcrop=2cm --offset=5mm
#D \stoptyping
#D
#D By default, the script intercepts logging messages and
#D writes them to a logfile with the same name as the
#D resulting image and the prefix \type {log}. If no name is
-#D given, the name \type {cropcrap} is used for all resulting
+#D given, the name \type {pdftrimwhite} is used for all resulting
#D files.
#D
#D By default, \CONTEXT\ is used. When installed properly, you
@@ -114,14 +114,14 @@ eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $
#D is valid:
#D
#D \starttyping
-#D cropcrap test result --bot=2cm --off=5mm --plain
+#D pdftrimwhite test result --bot=2cm --off=5mm --plain
#D \stoptyping
#D
#D The current implementation uses an intermediate \POSTSCRIPT\
#D file. This may change as \GHOSTSCRIPT\ gets more clever with
#D \PDF\ files.
#D
-#D In \in {figure} [fig:cropcrap] the green rectangle is the
+#D In \in {figure} [fig:pdftrimwhite] the green rectangle is the
#D picture we want to keep. Around this picture, we want a
#D margin, represented by the black rectangle, and specified by
#D \type {--offset}. The white rectangle is the cropbox
@@ -175,14 +175,14 @@ my $gs = "gs" ;
my $thisisunix = $Config{'osname'} !~ /dos|mswin/i ;
-#D When no resulting file is given, we use \type {cropcrap}
+#D When no resulting file is given, we use \type {pdftrimwhite}
#D as name (checked later).
my $figurefile = "" ;
my $resultfile = "" ;
my $tempfile = "" ;
-my $programname = "cropcrap" ;
+my $programname = "pdftrimwhite" ;
#D Messages are temporarily saved and written to a log file
#D afterwards.
@@ -227,7 +227,7 @@ my $width = my $height = my $llx = my $lly = my $urx = my $ury = 0 ;
sub PrintHelp
{ print "This is PdfTrimWhite\n\n" .
"usage:\n\n" .
- "cropcrap [switches] filename result\n\n" .
+ "pdftrimwhite [switches] filename result\n\n" .
"switches:\n\n" .
"--crop=<dimen>\n" .
"--offset=<dimen>\n" .
diff --git a/scripts/context/ruby/base/ctx.rb b/scripts/context/ruby/base/ctx.rb
index dff9570d8..4ee2715b8 100644
--- a/scripts/context/ruby/base/ctx.rb
+++ b/scripts/context/ruby/base/ctx.rb
@@ -21,7 +21,7 @@ require 'rexml/document'
class CtxRunner
- attr_reader :environments, :modules, :filters
+ attr_reader :environments, :modules, :filters, :flags
@@suffix = 'prep'
@@ -42,6 +42,7 @@ class CtxRunner
@environments = Array.new
@modules = Array.new
@filters = Array.new
+ @flags = Array.new
end
def manipulate(ctxname=nil,defaultname=nil)
@@ -116,6 +117,18 @@ class CtxRunner
variables['job'] = @jobname
end
root = @xmldata.root
+REXML::XPath.each(root,"/ctx:job//ctx:flags/ctx:flag") do |flg|
+ @flags << justtext(flg)
+end
+REXML::XPath.each(root,"/ctx:job//ctx:resources/ctx:environment") do |sty|
+ @environments << justtext(sty)
+end
+REXML::XPath.each(root,"/ctx:job//ctx:resources/ctx:module") do |mod|
+ @modules << justtext(mod)
+end
+REXML::XPath.each(root,"/ctx:job//ctx:resources/ctx:filter") do |fil|
+ @filters << justtext(fil)
+end
begin
REXML::XPath.each(root,"//ctx:block") do |blk|
if @jobname && blk.attributes['pattern'] then
@@ -141,6 +154,9 @@ class CtxRunner
REXML::XPath.each(root,"/ctx:job//ctx:process/ctx:resources/ctx:filter") do |fil|
@filters << justtext(fil)
end
+REXML::XPath.each(root,"/ctx:job//ctx:process/ctx:flags/ctx:flag") do |flg|
+ @flags << justtext(flg)
+end
commands = Hash.new
REXML::XPath.each(root,"/ctx:job//ctx:preprocess/ctx:processors/ctx:processor") do |pre|
begin
diff --git a/scripts/context/ruby/base/tex.rb b/scripts/context/ruby/base/tex.rb
index ddf1706dc..1b526f6e5 100644
--- a/scripts/context/ruby/base/tex.rb
+++ b/scripts/context/ruby/base/tex.rb
@@ -180,7 +180,7 @@ class TEX
'nomapfiles', 'local',
'arrange', 'noarrange',
'forcexml', 'foxet',
- 'alpha', 'beta',
+ 'alpha', 'beta', 'luatex',
'mpyforce', 'forcempy',
'forcetexutil', 'texutil',
'globalfile', 'autopath',
@@ -1777,8 +1777,20 @@ end
end
ctx.savelog(File.suffixed(rawbase,'ctl'))
- envs = ctx.environments
- mods = ctx.modules
+ envs = ctx.environments
+ mods = ctx.modules
+ flags = ctx.flags
+
+ flags.each do |f|
+ f.sub!(/^\-+/,'')
+ if f =~ /^(.*?)=(.*)$/ then
+ setvariable($1,$2)
+ else
+ setvariable(f,true)
+ end
+ end
+
+ report("using flags #{flags.join(' ')}") if flags.size > 0
# merge environment and module specs
diff --git a/scripts/context/ruby/graphics/gs.rb b/scripts/context/ruby/graphics/gs.rb
index 2c1079d1a..070fd1be8 100644
--- a/scripts/context/ruby/graphics/gs.rb
+++ b/scripts/context/ruby/graphics/gs.rb
@@ -243,7 +243,7 @@ class GhostScript
def pdfmethod? (str)
case method(str).to_i
- when 4, 5 then return true
+ when 3, 4, 5 then return true
end
return false
end
@@ -367,7 +367,13 @@ class GhostScript
@rs = Tool.line_separator(inpfile)
debug("platform mac") if @rs == "\r"
- return false unless tmp = open(inpfile, 'rb')
+ if FileTest.file?(outfile) and not File.writable?(outfile) then
+ report("output file cannot be written")
+ return false
+ elsif not tmp = open(inpfile, 'rb') then
+ report("input file cannot be opened")
+ return false
+ end
debug('opening pipe/file')
@@ -458,35 +464,50 @@ class GhostScript
end
- def convertcropped (inpfile, outfile)
+ # def convertcropped (inpfile, outfile)
+ # report("converting #{inpfile} cropped")
+ # do_convertbounded(inpfile, @@pdftempfile)
+ # return unless test(?e,@@pdftempfile)
+ # arguments = " --offset=#{@offset} #{@@pdftempfile} #{outfile}"
+ # report("calling #{@@pdftrimwhite}")
+ # unless ok = System.run(@@pdftrimwhite,arguments) then
+ # report('cropping failed')
+ # begin
+ # File.delete(outfile)
+ # rescue
+ # end
+ # begin
+ # File.move(@@pdftempfile,outfile)
+ # rescue
+ # File.copy(@@pdftempfile,outfile)
+ # File.delete(@@pdftempfile)
+ # end
+ # end
+ # return ok
+ # end
+ def convertcropped (inpfile, outfile)
report("converting #{inpfile} cropped")
-
- do_convertbounded(inpfile, @@pdftempfile)
-
- return unless test(?e,@@pdftempfile)
-
- arguments = " --offset=#{@offset} #{@@pdftempfile} #{outfile}"
-
- report("calling #{@@pdftrimwhite}")
- unless ok = System.run(@@pdftrimwhite,arguments) then
- report('cropping failed')
- begin
- File.delete(outfile)
- rescue
+ if File.expand_path(inpfile) == File.expand_path(outfile) then
+ report("output filename must be different")
+ elsif inpfile =~ /\.pdf$/io then
+ System.run("pdftops -eps #{inpfile} #{@@pstempfile}")
+ if getdimensions(@@pstempfile) then
+ report("tight boundingbox found")
end
- begin
- File.move(@@pdftempfile,outfile)
- rescue
- File.copy(@@pdftempfile,outfile)
- File.delete(@@pdftempfile)
+ do_convertbounded(@@pstempfile, outfile)
+ File.delete(@@pstempfile) if FileTest.file?(@@pstempfile)
+ else
+ if getdimensions(inpfile) then
+ report("tight boundingbox found")
end
+ do_convertbounded(inpfile, outfile)
end
-
- return ok
-
+ resetdimensions
+ return true
end
+
def pipebounded (eps, out)
epsbbox, skip, buffer = false, false, ''
@@ -501,12 +522,17 @@ class GhostScript
end
end
- debug('locating boundingbox')
-
# why no BeginData check
eps.rewind
+if dimensions? then
+
+ debug('using found boundingbox')
+
+else
+
+ debug('locating boundingbox')
while str = eps.gets(rs=@rs) do
case str
when /^%%Page:/io then
@@ -520,9 +546,10 @@ class GhostScript
setdimensions($1,$2,$3,$4)
end
end
-
debug('no boundingbox found') if @width == 0
+end
+
eps.rewind
while str = eps.gets(rs=@rs) do
@@ -595,6 +622,8 @@ class GhostScript
# report('process aborted, broken pipe, fatal error') unless ok
# return ok
+resetdimensions
+
return true
end
diff --git a/scripts/context/ruby/pstopdf.rb b/scripts/context/ruby/pstopdf.rb
index a677cb617..55bfa3365 100644
--- a/scripts/context/ruby/pstopdf.rb
+++ b/scripts/context/ruby/pstopdf.rb
@@ -343,6 +343,8 @@ class Commands
elsif magick.supported?(filename) then
# report("processing non ps/pdf file #{filename}")
handle_magick(magick,filename)
+ else
+ report("option not suported for #{filename}")
end
end
diff --git a/scripts/context/ruby/texmfstart.rb b/scripts/context/ruby/texmfstart.rb
index a886b2aa1..de4a18d2e 100644
--- a/scripts/context/ruby/texmfstart.rb
+++ b/scripts/context/ruby/texmfstart.rb
@@ -1429,7 +1429,7 @@ end
$mswindows = Config::CONFIG['host_os'] =~ /mswin/
$separator = File::PATH_SEPARATOR
-$version = "2.0.2"
+$version = "2.0.3"
$ownpath = File.dirname($0)
if $mswindows then
@@ -1804,14 +1804,16 @@ def changeddir?(path)
if path.empty? then
return true
else
+ oldpath = File.expand_path(path)
begin
- Dir.chdir(path) if ! path.empty?
+ Dir.chdir(path) if not path.empty?
rescue
report("unable to change to directory: #{path}")
else
report("changed to directory: #{path}")
end
- return File.expand_path(Dir.getwd) == File.expand_path(path)
+ newpath = File.expand_path(Dir.getwd)
+ return oldpath == newpath
end
end
@@ -1971,10 +1973,15 @@ def find(filename,program)
end
filename.sub!(/^.*[\\\/]/, '')
# next we look at the current path and the callerpath
- [ ['.','current'],
- [$ownpath,'caller'], ["#{$ownpath}/../#{suffixlist[0]}",'caller'],
- [registered("THREAD"),'thread'], ["#{registered("THREAD")}/../#{suffixlist[0]}",'thread'],
- ].each do |p|
+ pathlist = [ ]
+ progpath = $applications[suffixlist[0]]
+ threadok = registered("THREAD") !~ /unknown/
+ pathlist << ['.','current']
+ pathlist << [$ownpath,'caller'] if $ownpath != '.'
+ pathlist << ["#{$ownpath}/../#{progpath}",'caller'] if progpath
+ pathlist << [registered("THREAD"),'thread'] if threadok
+ pathlist << ["#{registered("THREAD")}/../#{progpath}",'thread'] if progpath && threadok
+ pathlist.each do |p|
if p && ! p.empty? && ! (p[0] == 'unknown') then
suffixlist.each do |suffix|
fname = "#{filename}.#{suffix}"