diff options
author | Reinhard Kotucha <reinhard.kotucha@web.de> | 2015-05-05 21:26:28 +0000 |
---|---|---|
committer | Reinhard Kotucha <reinhard.kotucha@web.de> | 2015-05-05 21:26:28 +0000 |
commit | c51296e843e35a3d133557000409674baae01b54 (patch) | |
tree | 571fdfb2f2660b3c7d6bd5d522a1268a776f8ab4 /Master/texmf-dist/scripts/tlgs/gswin32/ps2pdf13.tlu | |
parent | fe576e3d01b31dbc35e1bc4008052c06c47d3cf3 (diff) |
texlua scripts revised
pdfopt.tlu is using -dFastWebView now instead of pdfopt.ps
git-svn-id: svn://tug.org/texlive/trunk@37204 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/tlgs/gswin32/ps2pdf13.tlu')
-rwxr-xr-x | Master/texmf-dist/scripts/tlgs/gswin32/ps2pdf13.tlu | 163 |
1 files changed, 108 insertions, 55 deletions
diff --git a/Master/texmf-dist/scripts/tlgs/gswin32/ps2pdf13.tlu b/Master/texmf-dist/scripts/tlgs/gswin32/ps2pdf13.tlu index a35e3b0912a..d694047cfff 100755 --- a/Master/texmf-dist/scripts/tlgs/gswin32/ps2pdf13.tlu +++ b/Master/texmf-dist/scripts/tlgs/gswin32/ps2pdf13.tlu @@ -2,13 +2,24 @@ --*-Lua-*- -- $Id$ --- Copyright (C) 2008 Reinhard Kotucha. +-- Copyright (C) 2008-2015 Reinhard Kotucha. -- You may freely use, modify and/or distribute this file. --- Replacement for ps2pdf*.bat. --- Convert PS to PDF +-- Generic wrapper for ps2pdf{,12,13,14} and pdfopt. -function fixwin (args_unix) + +local function usage (progname) + local message= + 'Usage: '..progname..' [options] <inputfile> <outputfile>\n\n'.. + ' <inputfile> can be either a PS, EPS, or PDF file.\n'.. + ' A single hyphen (-) denotes stdin.\n\n'.. + ' <outputfile> is required if <inputfile> is a PDF file\n'.. + ' or input is read from stdin.\n' + return message +end + + +local function fixwin (args_unix) if os.type == 'windows' then local args_win={} -- new table args_win[0]=args_unix[1] @@ -21,7 +32,23 @@ function fixwin (args_unix) end end -function filename (file) + +local function push (t, ...) + local args={...} + for _,v in ipairs(args) do + if type(v) == 'table' then + for _,x in ipairs(v) do + t[#t+1]=x + end + else + t[#t+1]=v + end + end +end + + +local function filename (file) + -- strip path if string.find(file, '[/\\]') then return string.match(file, '.*[/\\](.*)$') else @@ -29,75 +56,101 @@ function filename (file) end end -function basename (file) - return string.match(filename(file), '(.*)[%.].*') -end -if os.type == 'windows' then - gs='gswin32c' -else - gs='gs' +local function basename (file) + -- strip extension + return string.match(filename(file), '(.*)%..*') end -command={gs} -files={} -options={} - -PDF_level='1.4' -if string.find(filename(arg[0]), 'ps2pdf12') then - PDF_level='1.2' -elseif string.find(filename(arg[0]), 'ps2pdf13') then - PDF_level='1.3' -elseif string.find(filename(arg[0]), 'ps2pdf14') then - PDF_level='1.4' + +local function extension (file) + -- return extension if available, false otherwise. + local fn=filename(file) + if fn:find('%.') then + return string.match(fn, '.*%.(.*)') + end end -options[#options+1]='-dCompatibilityLevel='..PDF_level -for i=1, #arg do - if arg[i] == '-' then - files[#files+1]=arg[i] - elseif string.find(arg[i], '^%-') then - options[#options+1]=arg[i] +local function parse_cmdline () + local files={} + local options={} + + local progname + local basename=filename(arg[0]) + if basename:find('%.') then + progname=basename:match('(.*)%..*') else - files[#files+1]=arg[i] + progname=basename end -end -if #files < 1 or #files > 2 then - io.stderr:write('Usage: ps2pdf [options] (input.[e]ps|-) [output.pdf]\n') - os.exit(1) + for i=1, #arg do + if string.find(arg[i], '^%-.+') then + push(options, arg[i]) + else + push(files, arg[i]) + end + end + files.input =files[1] + files.output=files[2] + return progname, options, files end -if #files == 1 then - if files[1] == '-' then - outfile='-' - elseif string.find(filename(files[1]), '%.[eE]?[pP][sS]$') then - outfile=basename(files[1])..'.pdf' - else - outfile=filename(files[1])..'.pdf' + +local function check_files (progname, files, default_output_ext) + if #files < 1 then + io.stderr:write(usage(progname)) + os.exit(1) end -else - outfile=files[2] -end -for i=1, #options do - command[#command+1]=options[i] + if #files < 2 then + if extension(files.input) then + local ext=string.lower(extension(files.input)) + if ext:match(default_output_ext..'$') then + io.stderr:write('!Error: no output file specified.\n\n') + io.stderr:write(usage(progname)) + os.exit(1) + else + files.output=basename(files.input)..'.'..default_output_ext + end + else -- the input file has no extension + files.output=files.input..'.'..default_output_ext + end + end end -other_opts={'-q', '-dSAFER', '-dNOPAUSE', '-dBATCH', '-sDEVICE=pdfwrite'} +-- main -- + +-- parse command line +local progname, options, file=parse_cmdline() + +check_files(progname, file, 'pdf') -for i=1, #other_opts do - command[#command+1]=other_opts[i] +-- determine PDF level +local PDF_level='1.4' -- default, may be changed in the future +if progname == 'ps2pdf12' then PDF_level='1.2' +elseif progname == 'ps2pdf13' then PDF_level='1.3' +elseif progname == 'ps2pdf14' then PDF_level='1.4' end -command[#command+1]='-sOutputFile='..outfile +-- setup command -other_opts={'-c', '.setpdfwrite', '-f', files[1]} +local command={} +if os.type == 'unix' then command={'gs'} else command={'gswin32c'} end -for i=1, #other_opts do - command[#command+1]=other_opts[i] -end +push(command, '-P-', '-dSAFER', options, '-dCompatibilityLevel='..PDF_level) + +if progname == 'pdfopt' then push(command, '-dFastWebView=true') end + +push(command, '-q', '-P-', '-dNOPAUSE', '-dBATCH', '-sDEVICE=pdfwrite') + +if os.type == 'unix' then push(command, '-sstdout=%stderr') end + +push(command, '-sOutputFile='..file.output, '-P-', '-dSAFER') + +-- We have to include the options twice because -I only takes effect +-- if it appears before other options [see ps2pdfwr]. +push(command, options, '-c', '.setpdfwrite', '-f', file.input) command=fixwin(command) @@ -105,7 +158,7 @@ command=fixwin(command) for i=0, #command do print (command[i]) end -os.exit(ret) +os.exit(0) --]] ret=os.spawn(command) |