[comp.sources.bugs] added backspace support to tpscript, patch included

danjudd@thor.stolaf.edu (Dan Judd) (05/26/89)

In volume 15 of comp.sources.unix there is a ditroff to postscript package,
that also includes an ascii to postscript converter called lpscript. 
lpscript as is does not support backspaces, instead it just prints a question
mark. This causes programs that do their own underlining via the backspace
underscore method to look pretty ugly.

I modified lpscript.c to handle backspaces. Only Courier, the default font,
is handled absolutely correct because it is the only fixed-width font. The
other fonts will have some variation of effect due to the changes in width
from character to character.  

All the changes are #ifdef'd on STO

Dan Judd, St. Olaf College 5/25/1989
danjudd@thor.acc.stolaf.edu

-----------cut here for patch, your numbers may vary --------------------------
*** lpscript.org.c	Mon May 22 14:27:13 1989
--- lpscript.c	Thu May 25 16:21:42 1989
***************
*** 14,19 ****
--- 14,20 ----
  #include	<stdio.h>
  #include	"pscript.h"
  
+ #define STO
  #define	PAGEOFFSET	(1.0*PU_CM)
  #define	FONTSIZE	12.0		/* default font size (in points) */
  #define	TABSIZE		8
***************
*** 188,194 ****
--- 189,199 ----
  			putc('(', postr);
  			prefix = 1;
  		}
+ #ifdef STO
+ 		if(ch < ' ' && ch != '\b' && ch != '\t' && ch != '\n' && ch != '\r' && ch != '\f')
+ #else
  		if(ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r' && ch != '\f')
+ #endif
  			ch = '?';
  		switch(ch)
  		{	
***************
*** 215,220 ****
--- 220,232 ----
  			fprintf(postr, ")n dpage\n");
  			prefix = 0;
  			break;
+ #ifdef STO
+ 		case '\b':
+ 			x = 0;
+ 			fprintf(postr, ")bs\n");
+ 			prefix = 0;
+ 			break;
+ #endif
  		default:
  			pch(ch);
  			x++;
***************
*** 281,286 ****
--- 293,304 ----
  	fprintf(postr, "/pgbot currentfont /FontBBox get 1 get neg 1000 div %.1f mul def\n", fontsize * aspect);
  	/* apply horizontal offset, if any */
  	fprintf(postr, "%.1f 0 translate\n", pageoffset);
+ #ifdef STO
+ 	/* figure out how big a _ is so the backspace will work right */
+ 	fprintf(postr, "/offset (_) stringwidth pop neg def\n");
+ 	/* define bs so so only 4 extra chars have to be sent for backspace*/
+ 	fprintf(postr, "/bs\n{ show\noffset 0 rmoveto\n} def");
+ #endif
  
  	/* save state */
  	endinit();