]> git.lyx.org Git - features.git/commitdiff
Rename lyxpreview2ppm.sh as lyxpreview2bitmap.sh because the script now
authorAngus Leeming <leeming@lyx.org>
Wed, 4 Sep 2002 11:56:45 +0000 (11:56 +0000)
committerAngus Leeming <leeming@lyx.org>
Wed, 4 Sep 2002 11:56:45 +0000 (11:56 +0000)
takes an extra argument specifying the desired output format, ppm or png.
Qt users may want to change their preferences file to suit ;-)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5205 a592a061-630c-0410-9148-cb99ea01b6c8

lib/ChangeLog
lib/configure.m4
lib/scripts/lyxpreview2bitmap.sh [new file with mode: 0644]
lib/scripts/lyxpreview2ppm.sh [deleted file]
src/graphics/ChangeLog
src/graphics/PreviewLoader.C

index f101cf1ea0ce0b5a32d64d73d61bda41a1cf99a5..acd3fef58719152df6ed0aaff66dd63af62d2c59 100644 (file)
@@ -1,3 +1,11 @@
+2002-09-04  Angus Leeming  <leeming@lyx.org>
+
+       * scripts/lyxpreview2bitmap.sh: rename lyxpreview2ppm.sh as this.
+       The new script takes an extra argument specifying the desired
+       output format, ppm or png.
+
+       * configure.m4: associated changes.
+
 2002-09-04  Angus Leeming  <leeming@lyx.org>
 
        * scripts/lyxpreview2ppm.sh: output gs filenames as %d, not %Nd where N
index 178ed8d594c8fdb8511b4871894b81089358a437..252689f31195b7ed3e08f305a95c358a1aa3c253 100644 (file)
@@ -271,7 +271,7 @@ SEARCH_PROG([for a DVI to PDF converter],dvi_to_pdf_command,dvipdfm)
 test $dvi_to_pdf_command = "dvipdfm" && dvi_to_pdf_command="dvipdfm \$\$i"
 
 # We have a script to convert previewlyx to ppm
-lyxpreview_to_ppm_command="lyxpreview2ppm.sh"
+lyxpreview_to_bitmap_command="lyxpreview2bitmap.sh"
 
 # Search a *roff program (used to translate tables in ASCII export)
 LYXRC_PROG([for a *roff formatter], \ascii_roff_command, dnl
@@ -475,7 +475,7 @@ cat >$outfile <<EOF
 \\converter linuxdoc html "$linuxdoc_to_html_command" ""
 \\converter docbook dvi "$docbook_to_dvi_command" ""
 \\converter docbook html "$docbook_to_html_command" ""
-\\converter lyxpreview ppm "$lyxpreview_to_ppm_command" ""
+\\converter lyxpreview ppm "$lyxpreview_to_bitmap_command" ""
 
 \\converter latex lyx "$tex_to_lyx_command" ""
 \\converter literate lyx "$literate_to_lyx_command" ""
diff --git a/lib/scripts/lyxpreview2bitmap.sh b/lib/scripts/lyxpreview2bitmap.sh
new file mode 100644 (file)
index 0000000..4012f73
--- /dev/null
@@ -0,0 +1,168 @@
+#! /bin/sh
+
+# \file tex2preview.sh
+# Copyright 2002 the LyX Team
+# Read the file COPYING
+# \author Angus Leeming, leeming@lyx.org
+# with much advice from David Kastrup, david.kastrup@t-online.de.
+
+# This script takes a LaTeX file and generates bitmap image files,
+# one per page.
+
+# The idea is to use it with preview.sty from the preview-latex project
+# (http://preview-latex.sourceforge.net/) to create small bitmap previews of
+# things like math equations.
+
+# preview.sty can be obtained from CTAN/macros/latex/contrib/supported/preview.
+
+# This script takes three arguments:
+# TEXFILE:       the name of the .tex file to be converted.
+# SCALEFACTOR:   a scale factor, used to ascertain the resolution of the
+#                generated image which is then passed to gs.
+# OUTPUTFORMAT:  the format of the output bitmap image files. Two formats
+#                are recognised: PPM and PNG
+
+# If successful, this script will leave in dir ${DIR}:
+# ${BASE}\([0-9]*\).ppm/png:  a (possibly large) number of image files.
+# ${BASE}.metrics:            a file containing info needed by LyX to
+#                             position the images correctly on the screen.
+# All other files ${BASE}* will be deleted.
+
+# Three helper functions.
+FIND_IT () {
+       which ${EXECUTABLE} > /dev/null
+       if [ $? -ne 0 ]; then
+               echo "Unable to find \"${EXECUTABLE}\". Please install."
+               exit 1
+       fi
+}
+
+BAIL_OUT () {
+       # Remove everything except the original .tex file.
+       FILES=`ls ${BASE}* | sed -e "/${BASE}.tex/d"`
+       rm -f ${FILES} texput.log
+       exit 1
+}
+
+REQUIRED_VERSION () {
+       echo "We require preview.sty version 0.73 or newer. You're using"
+       grep 'Package: preview' ${LOGFILE}
+}
+
+# Preliminary check.
+if [ $# -ne 3 ]; then
+       exit 1
+fi
+
+# Extract the params from the argument list.
+DIR=`dirname $1`
+BASE=`basename $1 .tex`
+
+SCALEFACTOR=$2
+
+if [ "$3" = "ppm" ]; then
+       GSDEVICE=pnmraw
+       GSSUFFIX=ppm
+elif [ "$3" = "png" ]; then
+       GSDEVICE=png16m
+       GSSUFFIX=png
+else
+       echo "Unrecognised output format ${OUTPUTFORMAT}."
+       echo "Expected either \"ppm\" or \"png\"."
+       BAIL_OUT
+fi
+
+# We use latex, dvips and gs, so check that they're all there.
+EXECUTABLE=latex; FIND_IT
+EXECUTABLE=dvips; FIND_IT
+EXECUTABLE=gs;    FIND_IT
+
+# Initialise some variables.
+TEXFILE=${BASE}.tex
+LOGFILE=${BASE}.log
+DVIFILE=${BASE}.dvi
+PSFILE=${BASE}.ps
+METRICSFILE=${BASE}.metrics
+
+# LaTeX -> DVI.
+cd ${DIR}
+latex ${TEXFILE}
+if [ $? -ne 0 ]; then
+       echo "Failed: latex ${TEXFILE}"
+       BAIL_OUT
+fi
+
+# Parse ${LOGFILE} to obtain bounding box info to output to ${METRICSFILE}.
+# This extracts lines starting "Preview: Tightpage" and "Preview: Snippet".
+grep -E 'Preview: [ST]' ${LOGFILE} > ${METRICSFILE}
+if [ $? -ne 0 ]; then
+       echo "Failed: grep -E 'Preview: [ST]' ${LOGFILE}"
+       REQUIRED_VERSION
+       BAIL_OUT
+fi
+
+# Parse ${LOGFILE} to obtain ${RESOLUTION} for the gs process to follow.
+# 1. Extract font size from a line like "Preview: Fontsize 20.74pt"
+# Use grep for speed and because it gives an error if the line is not found.
+LINE=`grep 'Preview: Fontsize' ${LOGFILE}`
+if [ $? -ne 0 ]; then
+       echo "Failed: grep 'Preview: Fontsize' ${LOGFILE}"
+       REQUIRED_VERSION
+       BAIL_OUT
+fi
+# Use "" quotes in the echo to preserve newlines (technically IFS separators).
+# The sed script strips out everything that won't form a decimal number from the
+# line. It bails out after the first match has been made in case there are
+# multiple lines "Preview: Fontsize". (There shouldn't be.)
+LATEXFONT=`echo "${LINE}" | sed 's/[^0-9\.]//g; 1q'`
+
+# 2. Extract magnification from a line like "Preview: Magnification 2074"
+# If no such line found, default to MAGNIFICATION=1000.
+LINE=`grep 'Preview: Magnification' ${LOGFILE}`
+if [ $? -ne 0 ]; then
+       MAGNIFICATION=1000
+else
+       # The sed script strips out everything that won't form an /integer/.
+       MAGNIFICATION=`echo "${LINE}" | sed 's/[^0-9]//g; 1q'`
+fi
+
+# 3. Compute resolution.
+# "bc" allows floating-point arithmetic, unlike "expr" or "dc".
+RESOLUTION=`echo "scale=2; \
+               ${SCALEFACTOR} * (10/${LATEXFONT}) * (1000/${MAGNIFICATION})" \
+               | bc`
+
+# DVI -> PostScript
+dvips -o ${PSFILE} ${DVIFILE}
+if [ $? -ne 0 ]; then
+       echo "Failed: dvips -o ${PSFILE} ${DVIFILE}"
+       BAIL_OUT
+fi
+
+# PostScript -> Bitmap files
+# Older versions of gs have problems with a large degree of anti-aliasing
+# at high resolutions
+
+# test expects integer arguments. ${RESOLUTION} may be a float. Truncate it.
+INT_RESOLUTION=`echo "${RESOLUTION} / 1" | bc`
+
+ALPHA=4
+if [ ${INT_RESOLUTION} -gt 150 ]; then
+       ALPHA=2
+fi
+
+gs -q -dNOPAUSE -dBATCH -dSAFER \
+    -sDEVICE=${GSDEVICE} -sOutputFile=${BASE}%d.${GSSUFFIX} \
+    -dGraphicsAlphaBit=${ALPHA} -dTextAlphaBits=${ALPHA} -r${RESOLUTION} \
+    ${PSFILE}
+
+if [ $? -ne 0 ]; then
+       echo "Failed: gs ${PSFILE}"
+       BAIL_OUT
+fi
+
+# All has been successful, so remove everything except the bitmap files
+# and the metrics file.
+FILES=`ls ${BASE}* | \
+       sed -e "/${BASE}.metrics/d" -e "/${BASE}\([0-9]*\).${GSSUFFIX}/d"`
+rm -f ${FILES} texput.log
diff --git a/lib/scripts/lyxpreview2ppm.sh b/lib/scripts/lyxpreview2ppm.sh
deleted file mode 100644 (file)
index a6d12eb..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-#! /bin/sh
-#
-# \file lyxpreview2ppm.sh
-# Copyright 2002 the LyX Team
-# Read the file COPYING
-#
-# \author Angus Leeming, leeming@lyx.org
-# with much advice from David Kastrup, david.kastrup@t-online.de.
-#
-# This script takes a LaTeX file and generates PPM files, one per page.
-# The idea is to use it with preview.sty from the preview-latex project
-# (http://preview-latex.sourceforge.net/) to create small bitmap previews of
-# things like math equations.
-
-# preview.sty can be obtained from CTAN/macros/latex/contrib/supported/preview.
-
-# This script takes two arguments:
-# TEXFILE:     the name of the .tex file to be converted.
-# SCALEFACTOR: a scale factor, used to ascertain the resolution of the
-#              generated image which is then passed to gs.
-
-# If successful, this script will leave in dir ${DIR}:
-# ${BASE}\([0-9]*\).ppm:  a (possibly large) number of image files.
-# ${BASE}.metrics:        a file containing info needed by LyX to position the
-#                         images correctly on the screen.
-# All other files ${BASE}* will be deleted.
-
-# Three helper functions.
-FIND_IT () {
-       which ${EXECUTABLE} > /dev/null
-       if [ $? -ne 0 ]; then
-               echo "Unable to find \"${EXECUTABLE}\". Please install."
-               exit 1
-       fi
-}
-
-BAIL_OUT () {
-       # Remove everything except the original .tex file.
-       FILES=`ls ${BASE}* | sed -e "/${BASE}.tex/d"`
-       rm -f ${FILES} texput.log
-       exit 1
-}
-
-REQUIRED_VERSION () {
-       echo "We require preview.sty version 0.73 or newer. You're using"
-       grep 'Package: preview' ${LOGFILE}
-}
-
-# Preliminary check.
-if [ $# -ne 2 ]; then
-       exit 1
-fi
-
-# We use latex, dvips and gs, so check that they're all there.
-EXECUTABLE=latex; FIND_IT
-EXECUTABLE=dvips; FIND_IT
-EXECUTABLE=gs;    FIND_IT
-
-# Initialise some variables.
-DIR=`dirname $1`
-BASE=`basename $1 .tex`
-
-SCALEFACTOR=$2
-
-TEXFILE=${BASE}.tex
-LOGFILE=${BASE}.log
-DVIFILE=${BASE}.dvi
-PSFILE=${BASE}.ps
-METRICSFILE=${BASE}.metrics
-
-# LaTeX -> DVI.
-cd ${DIR}
-latex ${TEXFILE}
-if [ $? -ne 0 ]; then
-       echo "Failed: latex ${TEXFILE}"
-       BAIL_OUT
-fi
-
-# Parse ${LOGFILE} to obtain bounding box info to output to ${METRICSFILE}.
-# This extracts lines starting "Preview: Tightpage" and "Preview: Snippet".
-grep -E 'Preview: [ST]' ${LOGFILE} > ${METRICSFILE}
-if [ $? -ne 0 ]; then
-       echo "Failed: grep -E 'Preview: [ST]' ${LOGFILE}"
-       REQUIRED_VERSION
-       BAIL_OUT
-fi
-
-# Parse ${LOGFILE} to obtain ${RESOLUTION} for the gs process to follow.
-# 1. Extract font size from a line like "Preview: Fontsize 20.74pt"
-# Use grep for speed and because it gives an error if the line is not found.
-LINE=`grep 'Preview: Fontsize' ${LOGFILE}`
-if [ $? -ne 0 ]; then
-       echo "Failed: grep 'Preview: Fontsize' ${LOGFILE}"
-       REQUIRED_VERSION
-       BAIL_OUT
-fi
-# Use "" quotes in the echo to preserve newlines (technically IFS separators).
-# The sed script strips out everything that won't form a decimal number from the
-# line. It bails out after the first match has been made in case there are
-# multiple lines "Preview: Fontsize". (There shouldn't be.)
-LATEXFONT=`echo "${LINE}" | sed 's/[^0-9\.]//g; 1q'`
-
-# 2. Extract magnification from a line like "Preview: Magnification 2074"
-# If no such line found, default to MAGNIFICATION=1000.
-LINE=`grep 'Preview: Magnification' ${LOGFILE}`
-if [ $? -ne 0 ]; then
-       MAGNIFICATION=1000
-else
-       # The sed script strips out everything that won't form an /integer/.
-       MAGNIFICATION=`echo "${LINE}" | sed 's/[^0-9]//g; 1q'`
-fi
-
-# 3. Compute resolution.
-# "bc" allows floating-point arithmetic, unlike "expr" or "dc".
-RESOLUTION=`echo "scale=2; \
-               ${SCALEFACTOR} * (10/${LATEXFONT}) * (1000/${MAGNIFICATION})" \
-               | bc`
-
-# DVI -> PostScript
-dvips -o ${PSFILE} ${DVIFILE}
-if [ $? -ne 0 ]; then
-       echo "Failed: dvips -o ${PSFILE} ${DVIFILE}"
-       BAIL_OUT
-fi
-
-# PostScript -> Bitmap files
-# Older versions of gs have problems with a large degree of anti-aliasing
-# at high resolutions
-
-# test expects integer arguments. ${RESOLUTION} may be a float. Truncate it.
-INT_RESOLUTION=`echo "${RESOLUTION} / 1" | bc`
-
-ALPHA=4
-if [ ${INT_RESOLUTION} -gt 150 ]; then
-       ALPHA=2
-fi
-
-gs -q -dNOPAUSE -dBATCH -dSAFER \
-    -sDEVICE=pnmraw -sOutputFile=${BASE}%d.ppm \
-    -dGraphicsAlphaBit=${ALPHA} -dTextAlphaBits=${ALPHA} -r${RESOLUTION} \
-    ${PSFILE}
-
-if [ $? -ne 0 ]; then
-       echo "Failed: gs ${PSFILE}"
-       BAIL_OUT
-fi
-
-# All has been successful, so remove everything except the bitmap files
-# and the metrics file.
-FILES=`ls ${BASE}* | \
-       sed -e "/${BASE}.metrics/d" -e "/${BASE}\([0-9]*\).ppm/d"`
-rm -f ${FILES} texput.log
index d9fa602899dbe0465c2d55500f70dba06a4890b1..9aa02950c52a16af94ff770785ebd2d5fb03e571 100644 (file)
@@ -1,3 +1,8 @@
+2002-09-04  Angus Leeming  <leeming@lyx.org>
+
+       * PreviewLoader.C (startLoading): pass the desired output format to the
+       conversion script.
+
 2002-09-04  Angus Leeming  <leeming@lyx.org>
 
        * PreviewLoader.C: remove this ndigits stuff as an unnecessary extra.
index 8eb1e1597eeff02146082cada75fd00c6b4ac596..d6bd52a54503bdfcfa7542429de0ef3a3fc4666a 100644 (file)
@@ -472,9 +472,9 @@ void PreviewLoader::Impl::startLoading()
        // The conversion command.
        ostringstream cs;
        cs << pconverter_->command << " " << latexfile << " "
-          << int(font_scaling_factor_);
+          << int(font_scaling_factor_) << " " << pconverter_->to;
 
-       string const command = LibScriptSearch(cs.str().c_str());
+       string const command = "sh " + LibScriptSearch(cs.str().c_str());
 
        // Initiate the conversion from LaTeX to bitmap images files.
        Forkedcall::SignalTypePtr convert_ptr;