mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-24 21:55:29 +00:00
Replace lib/scriptsfig2pdftex.sh and fig2pstex.sh by their python version
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14265 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
9bf01f2b34
commit
ad3a07c4f2
@ -882,8 +882,8 @@ dist_scripts_DATA = \
|
||||
scripts/clean_dvi.py \
|
||||
scripts/convertDefault.py \
|
||||
scripts/fen2ascii.py \
|
||||
scripts/fig2pdftex.sh \
|
||||
scripts/fig2pstex.sh \
|
||||
scripts/fig2pdftex.py \
|
||||
scripts/fig2pstex.py \
|
||||
scripts/fig_copy.py \
|
||||
scripts/layout2layout.py \
|
||||
scripts/legacy_lyxpreview2ppm.py \
|
||||
|
@ -391,8 +391,8 @@ def checkConverterEntries():
|
||||
\converter date dateout "date +%d-%m-%Y > $$o" ""
|
||||
\converter docbook docbook-xml "cp $$i $$o" "xml"
|
||||
\converter fen asciichess "python $$s/scripts/fen2ascii.py $$i $$o" ""
|
||||
\converter fig pdftex "sh $$s/scripts/fig2pdftex.sh $$i $$o" ""
|
||||
\converter fig pstex "sh $$s/scripts/fig2pstex.sh $$i $$o" ""
|
||||
\converter fig pdftex "python $$s/scripts/fig2pdftex.py $$i $$o" ""
|
||||
\converter fig pstex "python $$s/scripts/fig2pstex.py $$i $$o" ""
|
||||
\converter lyx lyx13x "python $$s/lyx2lyx/lyx2lyx -t 221 $$i > $$o" ""
|
||||
''')
|
||||
|
||||
|
105
lib/scripts/fig2pdftex.py
Normal file
105
lib/scripts/fig2pdftex.py
Normal file
@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: iso-8859-15 -*-
|
||||
|
||||
# file fig2pdf.py
|
||||
# This file is part of LyX, the document processor.
|
||||
# Licence details can be found in the file COPYING.
|
||||
#
|
||||
# \author Angus Leeming
|
||||
# \author Bo Peng
|
||||
#
|
||||
# Full author contact details are available in file CREDITS
|
||||
|
||||
|
||||
# This script converts an XFIG image to something that pdflatex can process
|
||||
# into high quality PDF.
|
||||
|
||||
# Usage:
|
||||
# python fig2pdftex.py ${base}.fig ${base}.pdft
|
||||
# This command generates
|
||||
# ${base}.pdf the converted pdf file
|
||||
# ${base}.pdft a tex file that can be included in your latex document
|
||||
# using '\input{${base}.pdft}'
|
||||
#
|
||||
# Note:
|
||||
# Do not use this command as
|
||||
# python fig2pdftex.py file.fig file.pdf
|
||||
# the real pdf file will be overwritten by a tex file named file.pdf.
|
||||
#
|
||||
|
||||
|
||||
import os, sys, re
|
||||
|
||||
|
||||
def runCommand(cmd):
|
||||
''' Utility function:
|
||||
run a command, quit if fails
|
||||
'''
|
||||
if os.system(cmd) != 0:
|
||||
print "Command '%s' fails." % cmd
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# We expect two args, the names of the input and output files.
|
||||
if len(sys.argv) != 3:
|
||||
sys.exit(1)
|
||||
|
||||
input, output = sys.argv[1:]
|
||||
|
||||
# Fail silently if the file doesn't exist
|
||||
if not os.path.isfile(input):
|
||||
sys.exit(0)
|
||||
|
||||
# Strip the extension from ${output}
|
||||
outbase = os.path.splitext(output)[0]
|
||||
|
||||
# Ascertain whether fig2dev is "modern enough".
|
||||
# If it is, then the help info will mention "pdftex_t" as one of the
|
||||
# available outputs.
|
||||
fout = os.popen('fig2dev -h')
|
||||
help_msg = fout.read()
|
||||
fout.close()
|
||||
|
||||
|
||||
if 'pdftex_t' in help_msg:
|
||||
# Modern versions of xfig can output the image without "special" text as
|
||||
# a PDF file ${base}.pdf and place the text in a LaTeX file
|
||||
# ${base}.pdftex_t for typesetting by pdflatex itself.
|
||||
runCommand('fig2dev -Lpdftex -p1 %s %s.pdf' % (input, outbase))
|
||||
runCommand('fig2dev -Lpdftex_t -p%s %s %s' % (outbase, input, output))
|
||||
else:
|
||||
# Older versions of xfig cannot do this, so we emulate the behaviour using
|
||||
# pstex and pstex_t output.
|
||||
runCommand('fig2dev -Lpstex %s %s.pstex' % (input, outbase))
|
||||
runCommand('fig2dev -Lpstex_t -p %s %s %s' % (outbase, input, output))
|
||||
|
||||
# manipulates the Bounding Box info to enable gs to produce
|
||||
# the appropriate PDF file from an EPS one.
|
||||
# The generated PostScript commands are extracted from epstopdf, distributed
|
||||
# with tetex.
|
||||
epsfile = outbase + '.pstex'
|
||||
tmp = open(epsfile + '.??', 'w')
|
||||
boundingboxline = re.compile('%%BoundingBox:\s+(\d*)\s+(\d*)\s+(\d*)\s+(\d*)')
|
||||
for line in open(epsfile).xreadlines():
|
||||
if line[:13] == '%%BoundingBox':
|
||||
(llx, lly, urx, ury) = map(int, boundingboxline.search(line).groups())
|
||||
width = urx - llx
|
||||
height = ury - lly
|
||||
xoffset = - llx
|
||||
yoffset = - lly
|
||||
tmp.write('''%%%%BoundingBox: 0 0 %d %d
|
||||
<< /PageSize [%d %d] >> setpagedevice
|
||||
gsave %d %d translate
|
||||
''' % (width, height, width, height, xoffset, yoffset))
|
||||
else:
|
||||
tmp.write(line)
|
||||
tmp.close()
|
||||
# direct move(rename) may fail under windows
|
||||
os.unlink(epsfile)
|
||||
os.rename(epsfile + '.??', epsfile)
|
||||
|
||||
# Convert the ${pstex} EPS file (free of "special" text) to PDF format
|
||||
# using gs
|
||||
runCommand('gs -q -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -sOutputFile=%s.pdf %s.pstex'\
|
||||
% (outbase, outbase))
|
||||
os.unlink(epsfile)
|
@ -1,134 +0,0 @@
|
||||
#! /bin/sh
|
||||
|
||||
# file fig2pdf.sh
|
||||
# This file is part of LyX, the document processor.
|
||||
# Licence details can be found in the file COPYING.
|
||||
#
|
||||
# author Angus Leeming
|
||||
#
|
||||
# Full author contact details are available in file CREDITS
|
||||
|
||||
|
||||
# This script converts an XFIG image to something that pdflatex can process
|
||||
# into high quality PDF.
|
||||
|
||||
# Usage: sh fig2pdf.sh ${base}.xfig
|
||||
# to generate ${base}.pdftex_t
|
||||
# Thereafter, you need only '\input{${base}.pdftex_t}' in your latex document.
|
||||
|
||||
# The external programs
|
||||
FIG2DEV=fig2dev
|
||||
# Used only by legacy_xfig
|
||||
GS=gs
|
||||
|
||||
find_exe() {
|
||||
test $# -eq 1 || exit 1
|
||||
|
||||
type $1 > /dev/null || {
|
||||
echo "Unable to find \"$1\". Please install."
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
# modern_xfig() and legacy_xfig() are the functions that do all the work.
|
||||
|
||||
# Modern versions of xfig can output the image without "special" text as
|
||||
# a PDF file ${base}.pdf and place the text in a LaTeX file
|
||||
# ${base}.pdftex_t for typesetting by pdflatex itself.
|
||||
modern_xfig() {
|
||||
# Can we find fig2dev?
|
||||
find_exe ${FIG2DEV}
|
||||
|
||||
input=$1
|
||||
pdftex_t=$2
|
||||
pdftex=$3.pdf
|
||||
|
||||
${FIG2DEV} -Lpdftex -p1 ${input} ${pdftex}
|
||||
${FIG2DEV} -Lpdftex_t -p${outbase} ${input} ${pdftex_t}
|
||||
|
||||
exit 0;
|
||||
}
|
||||
|
||||
|
||||
# This function is used only by legacy_xfig.
|
||||
# It manipulates the Bounding Box info to enable gs to produce
|
||||
# the appropriate PDF file from an EPS one.
|
||||
# The generated PostScript commands are extracted from epstopdf, distributed
|
||||
# with tetex.
|
||||
clean_epsfile() {
|
||||
test $# -eq 1 || exit 1
|
||||
|
||||
# No bounding box info
|
||||
grep '%%BoundingBox' $1 > /dev/null || return 1;
|
||||
|
||||
bbox=`sed -n '/^%%BoundingBox/p' $1`
|
||||
llx=`echo ${bbox} | cut -d' ' -f2`
|
||||
lly=`echo ${bbox} | cut -d' ' -f3`
|
||||
urx=`echo ${bbox} | cut -d' ' -f4`
|
||||
ury=`echo ${bbox} | cut -d' ' -f5`
|
||||
|
||||
width=`expr $urx - $llx`
|
||||
height=`expr $ury - $lly`
|
||||
xoffset=`expr 0 - $llx`
|
||||
yoffset=`expr 0 - $lly`
|
||||
|
||||
temp=$1.??
|
||||
sed "/^%%BoundingBox/{
|
||||
s/^\(%%BoundingBox:\).*/\1 0 0 ${width} ${height}\\
|
||||
<< \/PageSize [${width} ${height}] >> setpagedevice\\
|
||||
gsave ${xoffset} ${yoffset} translate/
|
||||
}" $1 > $temp
|
||||
|
||||
mv -f $temp $1
|
||||
}
|
||||
|
||||
|
||||
# Older versions of xfig cannot do this, so we emulate the behaviour using
|
||||
# pstex and pstex_t output.
|
||||
legacy_xfig() {
|
||||
# Can we find fig2dev and epstopdf?
|
||||
find_exe ${FIG2DEV}
|
||||
find_exe ${GS}
|
||||
|
||||
input=$1
|
||||
pdftex_t=$2
|
||||
pdf=$3.pdf
|
||||
pstex=$3.pstex
|
||||
|
||||
${FIG2DEV} -Lpstex ${input} ${pstex}
|
||||
${FIG2DEV} -Lpstex_t -p${outbase} ${input} ${pdftex_t}
|
||||
|
||||
# Convert the ${pstex} EPS file (free of "special" text) to PDF format
|
||||
# using gs
|
||||
clean_epsfile ${pstex}
|
||||
${GS} -q -dNOPAUSE -dBATCH -dSAFER \
|
||||
-sDEVICE=pdfwrite -sOutputFile=${pdf} ${pstex}
|
||||
rm -f ${pstex}
|
||||
|
||||
exit 0;
|
||||
}
|
||||
|
||||
# The main logic of the script is below.
|
||||
# All it does is ascertain which of the two functions above to call.
|
||||
|
||||
# We expect two args, the names of the input and output files.
|
||||
test $# -eq 2 || exit 1
|
||||
|
||||
input=$1
|
||||
output=$2
|
||||
|
||||
# Fail silently if the file doesn't exist
|
||||
test -r $input || exit 0
|
||||
|
||||
# Strip the extension from ${output}
|
||||
outbase=`echo ${output} | sed 's/[.][^.]*$//'`
|
||||
|
||||
# Ascertain whether fig2dev is "modern enough".
|
||||
# If it is, then the help info will mention "pdftex_t" as one of the
|
||||
# available outputs.
|
||||
CONVERT_IT=modern_xfig
|
||||
${FIG2DEV} -h | grep 'pdftex_t' > /dev/null || CONVERT_IT=legacy_xfig
|
||||
|
||||
${CONVERT_IT} ${input} ${output} ${outbase}
|
||||
|
||||
# The end
|
50
lib/scripts/fig2pstex.py
Normal file
50
lib/scripts/fig2pstex.py
Normal file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: iso-8859-15 -*-
|
||||
|
||||
# file fig2pstex.py
|
||||
# This file is part of LyX, the document processor.
|
||||
# Licence details can be found in the file COPYING.
|
||||
#
|
||||
# \author Angus Leeming
|
||||
# \author Bo Peng
|
||||
#
|
||||
# Full author contact details are available in file CREDITS
|
||||
|
||||
|
||||
# This script converts an XFIG image to something that latex can process
|
||||
# into high quality PostScript.
|
||||
|
||||
# Usage:
|
||||
# python fig2pstex.py ${base}.fig ${base}.pstex
|
||||
# This command generates
|
||||
# ${base}.eps the converted eps file
|
||||
# ${base}.pstex a tex file that can be included in your latex document
|
||||
# using '\input{${output}}'.
|
||||
#
|
||||
# Note:
|
||||
# Do not use this command as
|
||||
# python fig2pstex.py file.fig file.eps
|
||||
# the real eps file will be overwritten by a tex file named file.eps.
|
||||
#
|
||||
|
||||
import os, sys
|
||||
|
||||
# We expect two args, the names of the input and output files.
|
||||
if len(sys.argv) != 3:
|
||||
sys.exit(1)
|
||||
|
||||
input, output = sys.argv[1:]
|
||||
|
||||
# Fail silently if the file doesn't exist
|
||||
if not os.path.isfile(input):
|
||||
sys.exit(0)
|
||||
|
||||
# Strip the extension from ${output}
|
||||
outbase = os.path.splitext(output)[0]
|
||||
|
||||
# Generate the EPS file
|
||||
# Generate the PSTEX_T file
|
||||
if os.system('fig2dev -Lpstex %s %s.eps' % (input, outbase)) != 0 or \
|
||||
os.system('fig2dev -Lpstex_t -p%s %s %s' % (outbase, input, output)) != 0:
|
||||
print 'fig2dev fails'
|
||||
sys.exit(1)
|
@ -1,44 +0,0 @@
|
||||
#! /bin/sh
|
||||
|
||||
# file fig2pstex.sh
|
||||
# This file is part of LyX, the document processor.
|
||||
# Licence details can be found in the file COPYING.
|
||||
#
|
||||
# author Angus Leeming
|
||||
#
|
||||
# Full author contact details are available in file CREDITS
|
||||
|
||||
|
||||
# This script converts an XFIG image to something that latex can process
|
||||
# into high quality PostScript.
|
||||
|
||||
# Usage: sh fig2pstex.sh ${input} ${output}
|
||||
# to generate the pstex_t file ${output}.
|
||||
# In turn this file will \includegraphics{${output_base}}.
|
||||
# The necessary ${output_base}.eps is also generated by this script.
|
||||
#
|
||||
# Thereafter, you need only '\input{${output}}' in your latex document.
|
||||
|
||||
# We expect two args, the names of the input and output files.
|
||||
test $# -eq 2 || exit 1
|
||||
|
||||
# Can we find fig2dev?
|
||||
type fig2dev > /dev/null || exit 1
|
||||
|
||||
input=$1
|
||||
output=$2
|
||||
|
||||
# Fail silently if the file doesn't exist
|
||||
test -r $input || exit 0
|
||||
|
||||
# Strip the extension from ${output}
|
||||
outbase=`echo ${output} | sed 's/[.][^.]*$//'`
|
||||
|
||||
# Generate the EPS file
|
||||
outeps=${outbase}.eps
|
||||
fig2dev -Lpstex ${input} ${outeps}
|
||||
|
||||
# Generate the PSTEX_T file
|
||||
fig2dev -Lpstex_t -p${outbase} ${input} ${output}
|
||||
|
||||
# The end
|
Loading…
Reference in New Issue
Block a user