]> git.lyx.org Git - features.git/commitdiff
Enable the external inset to output different flavours of latex.
authorAngus Leeming <leeming@lyx.org>
Fri, 23 May 2003 14:36:26 +0000 (14:36 +0000)
committerAngus Leeming <leeming@lyx.org>
Fri, 23 May 2003 14:36:26 +0000 (14:36 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7031 a592a061-630c-0410-9148-cb99ea01b6c8

lib/ChangeLog
lib/external_templates
lib/scripts/fig2png.py [new file with mode: 0644]
lib/scripts/fig2png.sh [new file with mode: 0755]
lib/scripts/fig2pstex.py
src/insets/ChangeLog
src/insets/insetexternal.C

index bdc4ddeebf09ebc32be680e290007af198f6b6f6..c9d37577da359981ff7cc3d3100d6d414869135a 100644 (file)
@@ -1,3 +1,9 @@
+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:
index 5de7fce4fb03d7d204ab5ef7c290e84da6bd7334..5d758797f7c4fb03808ca6c4305fd163810f2bc9 100644 (file)
@@ -67,9 +67,15 @@ Template XFig
        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
diff --git a/lib/scripts/fig2png.py b/lib/scripts/fig2png.py
new file mode 100644 (file)
index 0000000..3bce897
--- /dev/null
@@ -0,0 +1,16 @@
+#! /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()
diff --git a/lib/scripts/fig2png.sh b/lib/scripts/fig2png.sh
new file mode 100755 (executable)
index 0000000..ec51fdd
--- /dev/null
@@ -0,0 +1,48 @@
+#! /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}
index e6432900364837c98c48c18d28399367961dcbe7..741665736f3f97cfb785bf64027df7bcd7ea6605 100644 (file)
@@ -17,7 +17,7 @@ os.wait()
 
 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()
index f51c6c5b7b03293a89abcefb9df3d0aab9e3c4a2..3c761ca39cf8d26d633b058123950563b0cc6925 100644 (file)
@@ -1,3 +1,9 @@
+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.
index 0ffdcc7973750debbb5b0b1ce56e481d43ce52f3..872bc63a87ac3a21b6d47df3b745222cc04470d2 100644 (file)
 #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"
 
@@ -27,6 +29,7 @@
 
 #include "support/filetools.h"
 #include "support/lstrings.h"
+#include "support/lyxalgo.h"
 #include "support/path.h"
 #include "support/systemcall.h"
 #include "support/FileInfo.h"
@@ -161,14 +164,25 @@ int InsetExternal::write(string const & format,
        }
 
        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);
 }