#!/bin/sh
#
#	This script is part of rtfdtohtml.
#	Copyright (c) 1996  Elmar Ludwig - Universitaet Osnabrueck
#
#	Convert eps to gif or png (needs ghostscript, ppm).

GSLIBDIR="@@GSLIBDIR@@"

tmp=$$_rtf
trap 'rm -f $tmp.ps $tmp.ppm; exit 2' 1 2 3 15

cat ${1+"$1"} >/tmp/$tmp.ps
cd /tmp

echo "($tmp) ppm8run" | gs -q -sDEVICE=ppmraw "$GSLIBDIR/pstoppm.ps" - >&2
res1=$?

set `grep '^%%BoundingBox:' $tmp.ps`
res2=$?
shift

if [ $IMG_TYPE = gif ]; then
    pnmcut $1 -$4 `expr $3 - $1` `expr $4 - $2` $tmp.ppm |
    ppmtogif -interlace -sort
    res3=$?
else
    pnmcut $1 -$4 `expr $3 - $1` `expr $4 - $2` $tmp.ppm | pnmtotiff -none |
    tiffto$IMG_TYPE.sh
    res3=$?
fi

rm -f $tmp.ps $tmp.ppm
exit `expr $res1 + $res2 + $res3`
