+2003-05-23 Angus Leeming <leeming@lyx.org>
+
+ * external_templates: add a PDFLaTeX flavour to the xfig outputs.
+ * scripts/fig2png.py: a new and very simple script.
+ * scripts/fig2png.sh: another new and rather more sophisticated scriot.
+
2003-05-22 Alfredo Braunstein <abraunst@libero.it>
* ui/stdmenus.ui:
EditCommand "xfig $$FName"
AutomaticProduction true
Format LaTeX
- Product "\\begin{picture}(0,0)\\includegraphics{$$Basename.eps}\\end{picture}\\input{$$Basename.pstex_t}"
+ Product "\\input{$$Basename.pstex_t}"
UpdateCommand "python $$Sysdir/scripts/fig2pstex.py $$FName $$Parameters"
- UpdateResult "$$Basename.eps"
+ UpdateResult "$$Basename.pstex_t"
+ Requirement "graphicx"
+ FormatEnd
+ Format PDFLaTeX
+ Product "\\begin{picture}(0,0)\\includegraphics{$$Basename}\\end{picture}"
+ UpdateCommand "python $$Sysdir/scripts/fig2png.py $$FName $$Parameters"
+ UpdateResult "$$Basename.png"
Requirement "graphicx"
FormatEnd
Format Ascii
--- /dev/null
+#! /usr/bin/env python
+# This script converts a xfig file into PNG files
+
+import sys
+import os
+
+filename = sys.argv[1]
+basename = os.path.splitext(filename)[0]
+parameters = sys.argv[2:]
+
+pid = os.fork()
+if pid == 0:
+ os.execvp("fig2dev", ["fig2dev", "-Lpng"] + parameters + [filename, basename + ".png"])
+ print "fig2dev did not work"
+ os.exit(1)
+os.wait()
--- /dev/null
+#! /bin/sh
+# converts an image from XFIG to PNG format
+# We go the long route to ensure that the image is of the highest
+# possible quality.
+
+# We expect a single arg, the name of the input file.
+test $# -eq 1 || exit 1
+
+input=`basename $1`
+base=`basename ${input} .fig`
+test ${input} = ${base} && {
+ echo Expecting an XFIG file as input
+ exit 1
+}
+
+dir=`dirname $1`
+base=${dir}/${base}
+
+# Generate the fig2dev output
+eps=${base}.eps
+pstex_t=${base}.pstex_t
+
+echo Entered FIG2PNG.SH
+
+fig2dev -Lpstex ${input} ${eps}
+fig2dev -Lpstex_t -p${base} ${input} ${pstex_t}
+
+# Convert the EPS file (free of "special" text) to PNG format using gs
+# gs is extremely fussy about the EPS files it converts, so ensure it is
+# "clean" first.
+clean_eps=${eps}.$$
+eps2eps ${eps} ${clean_eps}
+
+# Extract the width and height of the image using gs' bbox device.
+# Ie, take output that includes a line "%%BoundingBox: 0 0 <width> <height>"
+# and rewrite it as "-g<width>x<height>"
+geometry=`gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=bbox ${clean_eps} 2>&1 | \
+ sed '/^%%BoundingBox/! d' | cut -d' ' -f4,5 | \
+ sed 's/^\([0-9]\{1,\}\) \([0-9]\{1,\}\)$/-g\1x\2/'`
+
+# Generate the bitmap using the -g option to ensure the size is the same
+# as the original.
+# If we're using a version of gs that does not have a bbox device, then
+# $GEOMETRY = "", so there are no unwanted side effects.
+png=${base}.png
+gs -q -dSAFER -dBATCH -dNOPAUSE ${geometry} -sDEVICE=png16m \
+ -sOutputFile=${png} ${clean_eps}
+rm -f ${clean_eps} ${eps}
pid = os.fork()
if pid == 0:
- os.execvp("fig2dev", ["fig2dev", "-Lpstex_t"] + parameters + [filename, basename + ".pstex_t"])
- print "convert did not work second time"
+ os.execvp("fig2dev", ["fig2dev", "-Lpstex_t", "-p" + basename] + parameters + [filename, basename + ".pstex_t"])
+ print "fig2dev did not work the second time"
os.exit(1)
os.wait()
+2003-05-23 Angus Leeming <leeming@lyx.org>
+
+ * insetexternal.C (write): check how many lines are output.
+ (latex): use the "PDFLaTeX" flavour if outputting to pfdlatex and
+ if the template has defined it.
+
2003-05-23 Angus Leeming <leeming@lyx.org>
* insetquotes (validate): use the new LaTeXFeatures::useBabel() method.
#include <config.h>
#include "insetexternal.h"
-#include "ExternalTemplate.h"
-#include "BufferView.h"
+
#include "buffer.h"
+#include "BufferView.h"
+#include "debug.h"
+#include "ExternalTemplate.h"
#include "funcrequest.h"
-#include "lyx_main.h"
-#include "LaTeXFeatures.h"
#include "gettext.h"
-#include "debug.h"
+#include "LaTeXFeatures.h"
+#include "latexrunparams.h"
+#include "lyx_main.h"
#include "lyxlex.h"
#include "Lsstream.h"
#include "support/filetools.h"
#include "support/lstrings.h"
+#include "support/lyxalgo.h"
#include "support/path.h"
#include "support/systemcall.h"
#include "support/FileInfo.h"
}
updateExternal(format, buf);
- os << doSubstitution(buf, cit->second.product);
- return 0; // CHECK (FIXME check what ? - jbl)
+ string const str = doSubstitution(buf, cit->second.product);
+ os << str;
+ return int(lyx::count(str.begin(), str.end(),'\n') + 1);
}
int InsetExternal::latex(Buffer const * buf, ostream & os,
- LatexRunParams const &) const
+ LatexRunParams const & runparams) const
{
+ // If the template has specified a PDFLaTeX output, then we try and
+ // use that.
+ if (runparams.flavor == LatexRunParams::PDFLATEX) {
+ ExternalTemplate const & et = params_.templ;
+ ExternalTemplate::Formats::const_iterator cit =
+ et.formats.find("PDFLaTeX");
+ if (cit != et.formats.end())
+ return write("PDFLaTeX", buf, os);
+ }
+
return write("LaTeX", buf, os);
}