#!/bin/sh
#
# This file acts as a preprocessor for the npd-lpr utility.  What it does
# is inserts all of the PostScript fonts into a print job.  This is 
# ultimately handy for non-NeXT PostScript printers.  
#
# How to install:  
#	1.  As root, rename /usr/lib/NextPrinter/npd-lpr to npd-lpr.original.
#		If you rename it to something other than that, you'll have to 
#		change the NPD_LPR_NAME variable in the new npd-lpr file.
#	2.	Put the new npd-lpr file (this file) in /usr/lib/NextPrinter.
#	3. 	Put the listfonts.perl file in /usr/local/bin.  If you put it 
#		somewhere else, you have to change the LISTFONTS variable in the
#		new npd-lpr file.
#	4.	Put the perl executable in /usr/local/bin (or somewhere in you
#		path). 
#

#	Name of the original NeXT supplied npd-lpr file
NPD_LPR_NAME=npd-lpr.original

#	Full path to the listfonts.perl command
LISTFONTS=/usr/local/bin/listfonts.perl

#	Create the first line of the PS file
echo "%!PS-Adobe-2.0" > /tmp/tmpfonts

#	listfonts.perl will return a list of PostScript font names seperated
#	by spaces.  fontloader uses this to generate a PostScript stream
#	of the fonts appropriate for feeding to the printer.  We chop off
#	the first 6 lines because we don't want the fonts to be loaded 
#	into global VM.  We only want them to be kept in memory as long 
#	as this document is being printed.  Dump the resulting PS stream to
#	a temp file.
fontloader `$LISTFONTS $7` | tail +7 >> /tmp/tmpfonts

#	Put the spooled file together with the fonts file and redirect to a file
cat /tmp/tmpfonts $7 > /tmp/final.ps

#	Now move it to where the orignal spool file was
mv /tmp/final.ps $7

#	Clean up the temp files
rm /tmp/final.ps /tmp/tmpfonts

#	Call the real print program so that the document gets printed.
#	$* passes all the original arguments that were passed to us in
#	the first place.
/usr/lib/NextPrinter/$NPD_LPR_NAME $*