4 # This file is part of LyX, the document processor.
5 # Licence details can be found in the file COPYING.
9 # Full author contact details are available in file CREDITS
12 # This script converts an XFIG image to something that pdflatex can process
13 # into high quality PDF.
15 # Usage: sh fig2pdf.sh ${base}.xfig
16 # to generate ${base}.pdftex_t
17 # Thereafter, you need only '\input{${base}.pdftex_t}' in your latex document.
19 # modern_xfig() and legacy_xfig() are the functions that do all the work.
21 # Modern versions of xfig can output the image without "special" text as
22 # a PDF file ${base}.pdf and place the text in a LaTeX file
23 # ${base}.pdftex_t for typesetting by pdflatex itself.
29 fig2dev -Lpdftex ${input} ${pdftex}
30 fig2dev -Lpdftex_t -p$1 ${input} ${pdftex_t}
35 # Older versions of xfig cannot do this, so we emulate the behaviour using
36 # pstex and pstex_t output.
43 fig2dev -Lpstex ${input} ${pstex}
44 fig2dev -Lpstex_t -p$1 ${input} ${pdftex_t}
46 # Convert the ${pstex} EPS file (free of "special" text) to PDF format
49 # gs is extremely fussy about the EPS files it converts, so ensure it is
52 eps2eps ${pstex} ${clean}
55 # Extract the width and height of the image using gs' bbox device.
56 # Ie, take output that includes line "%%BoundingBox: 0 0 <width> <height>"
57 # and rewrite it as "-g<width>x<height>"
58 geometry=`gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox ${clean} 2>&1 | \
59 sed '/^%%BoundingBox/! d' | cut -d' ' -f4,5 | \
60 sed 's/^\([0-9]\{1,\}\) \([0-9]\{1,\}\)$/-g\1x\2/'`
62 # Generate a PNG file using the -g option to ensure the size is the same
64 # If we're using a version of gs that does not have a bbox device, then
65 # ${geometry} = "", so there are no unwanted side effects.
66 gs -q -dSAFER -dBATCH -dNOPAUSE ${geometry} -sDEVICE=png16m \
67 -sOutputFile=${png} ${clean}
73 # The main logic of the script is below.
74 # All it does is ascertain which of the two functions above to call.
76 # We expect a single arg, the name of the input file.
77 test $# -eq 1 || exit 1
79 # Remove the .fig extension
81 base=`echo ${input} | sed 's/\.fig$//'`
83 # Ascertain whether fig2dev is "modern enough".
84 # Here "modern" means "fig2dev Version 3.2 Patchlevel 4"
85 version_info=`fig2dev -h | sed '/^fig2dev/! d'`
86 # If no line begins "fig2dev" then default to legacy_xfig
87 test "x${version_info}" = "x" && legacy_xfig ${base}
89 version=`echo ${version_info} | cut -d' ' -f3`
90 patchlevel=`echo ${version_info} | cut -d' ' -f5`
91 # If we cannot extract the version of patchlevel info
92 # then default to legacy_xfig
93 test "x${version}" = "x" -o "x${patchlevel}" = "x" && legacy_xfig ${base}
94 echo ${version} ${patchlevel} | grep '[0-9]!' -o && legacy_xfig ${base}
96 # So, is it am old version?
97 test ${version} != "3.2" -o ${patchlevel} -lt 4 && legacy_xfig ${base}