#!/bin/bash

PTT_MACRO="-m";
PTT_PRINT="";
PTT_DPI="";

if [ "$1" = "-c" ] ; then
	PTT_MACRO="-c";
	PTT_DPI="1200"
	shift
fi
if [ "$1" = "-l" ] ; then
	PTT_MACRO="-l";
	shift
fi
if [ "$1" = "-m" ] ; then
	PTT_MACRO="-m";
	PTT_DPI="600"
	shift
fi
if [ "$1" = "-h" ] ; then
	PTT_MACRO="-h";
	PTT_DPI="1200"
	shift
fi

if [ "$1" = "-p" ] ; then
	PTT_PRINT="-p";
	PTT_MACRO="-c";
	PTT_DPI="1200"
	shift
fi

PTT_PSFILE=`basename "$1" \.ps`
if [ "x$PTT_PSFILE" = "x" ] || [ "$PTT_PSFILE" = ".ps" ] || ! [ -f "$1" ]; then
	echo "No PostScript file given!!"
	echo "Usage: "
	echo "  `basename $0` [-c|-l|-m|-h] [-p] <postscript file>, (c)2005-2024 PaulTT"
	echo "    '-c' creates a color laserjet 1200dpi pcl"
	echo "    '-l' creates a laserjet low res pcl"
	echo "    '-m' creates a ljet4 600dpi pcl (for macro creation) (default)"
	echo "    '-h' creates an high res ljet4 1200dpi pcl"
	echo "    '-p' prints the generated file to the default printer (defaults to -c)"
	echo ""
	exit 0
fi


case "$PTT_MACRO" in
	"-c")
		/usr/bin/gs -q -dBATCH -dNOPAUSE \
			-sDEVICE=pxlcolor -sPAGESIZE=a4 \
			-r$PTT_DPI \
			-sOutputFile="$PTT_PSFILE".pcl "$1"
			#-sDEVICE=pxlcolor -dColorImageResolution=$PTT_DPI -sPAGESIZE=a4 \
		;;
	"-l")
		/usr/bin/gs -q -dBATCH -dNOPAUSE \
			-sDEVICE=laserjet \
			-sOutputFile="$PTT_PSFILE".pcl "$1"
		;;
	"-m"|*)
		/usr/bin/gs -q -dBATCH -dNOPAUSE \
			-sDEVICE=ljet4 -r$PTT_DPI -sPAGESIZE=a4 \
			-sOutputFile="$PTT_PSFILE".pcl "$1"
		;;
esac

if [ "$PTT_PRINT" = "-p" ] ; then
	lpr "$PTT_PSFILE".pcl
fi

