Received: from sgi.sgi.com (192.48.153.1) by cerious.com
 with SMTP (Apple Internet Mail Server 1.1.1); Mon, 20 Jan 1997 20:24:39 -0500
Received: from cthulhu.engr.sgi.com (cthulhu.engr.sgi.com [192.26.80.2]) by sgi.sgi.com (950413.SGI.8.6.12/950213.SGI.AUTOCF) via ESMTP id RAA28493; Mon, 20 Jan 1997 17:17:25 -0800
Received: (from daemon@localhost) by cthulhu.engr.sgi.com (950413.SGI.8.6.12/960327.SGI.AUTOCF) id XAA08998 for tiff-list; Mon, 20 Jan 1997 23:58:44 GMT
Received: from sgi.sgi.com (sgi.engr.sgi.com [192.26.80.37]) by cthulhu.engr.sgi.com (950413.SGI.8.6.12/960327.SGI.AUTOCF) via ESMTP id PAA08993 for <tiff-relay@relay.engr.sgi.com>; Mon, 20 Jan 1997 15:58:43 -0800
Received: from feith1.FEITH.COM (feith1.FEITH.COM [192.251.93.1]) by sgi.sgi.com (950413.SGI.8.6.12/950213.SGI.AUTOCF) via ESMTP id PAA15769 for <tiff@sgi.com>; Mon, 20 Jan 1997 15:58:38 -0800
Received: from jwlab.FEITH.COM by feith1.FEITH.COM (SMI-8.6/SMI-SVR4/Feith May 2 1996)
	id SAA04975; Mon, 20 Jan 1997 18:58:36 -0500
Received: by jwlab.FEITH.COM (SMI-8.6/SMI-SVR4)
	id SAA01696; Mon, 20 Jan 1997 18:58:34 -0500
Date: Mon, 20 Jan 1997 18:58:34 -0500
From: john@jwlab.feith.com (John Wehle)
Message-Id: <199701202358.SAA01696@jwlab.FEITH.COM>
To: tiff@sgi.com
Subject: Tiff Version 3.4 Beta 035 Patch to add tiff2ps enhancments
Content-Type: text
Sender: owner-tiff@relay.engr.SGI.COM
Precedence: bulk

Changes:

  1) When printing tiff files it is frequently nice to print an each entire
     image on single page regardless of the image size.  The problem is
     currently tiff2ps allows the printer to truncate the page unless the
     -w and -h options are used in which case tiff2ps causes the printer
     to scale the image to eactly that size (even if the original image
     is smaller than that size or if this causes the image to be distorted).

     This patch adds a -m option which ensures that the aspect ratio is
     maintained and only scales the image if it doesn't fit within the
     -w and -h specifications.

  2) Many printers have a deadzone around the edge of the paper.

     This patch adds a -z option to avoid the deadzone when printing.  This
     is especially useful when printing faxes as the deadzone often times
     gobbles up the sender's fax id.  Note: this option currently requires
     that the printer support PostScript Level 2.

  3) There appears to be a minor code bug in Ascii85Put which causes p
     to be incremented by four twice.

     This patch fixes that.

Enjoy,

John Wehle
john@feith.com

PS: I'm not on the tiff mailing list so please copy any reponses to me
    via my email address.  Thanks.
--------------8<------------------8<-------------------8<--------------------
*** tools/tiff2ps.c.ORIGINAL	Mon Jun 10 18:25:28 1996
--- tools/tiff2ps.c	Thu Jan 16 19:55:16 1997
***************
*** 42,51 ****
--- 42,53 ----
  int     ascii85 = FALSE;		/* use ASCII85 encoding */
  int	interpolate = TRUE;		/* interpolate level2 image */
  int	level2 = FALSE;			/* generate PostScript level 2 */
+ int	maintainAspect = FALSE;		/* maintain aspect ratio and size */
  int	printAll = FALSE;		/* print all images in file */
  int	generateEPSF = TRUE;		/* generate Encapsulated PostScript */
  int 	PSduplex = FALSE;		/* enable duplex printing */
  int	PStumble = FALSE;		/* enable top edge binding */
+ int	PSavoiddeadzone = FALSE;	/* enable avoiding printer deadzone */
  char	*filename;			/* input filename */
  
  /*
***************
*** 83,89 ****
  	extern int optind;
  	FILE* output = stdout;
  
! 	while ((c = getopt(argc, argv, "h:w:d:o:O:aeps128DT")) != -1)
  		switch (c) {
  		case 'd':
  			dirnum = atoi(optarg);
--- 85,91 ----
  	extern int optind;
  	FILE* output = stdout;
  
! 	while ((c = getopt(argc, argv, "h:w:d:o:O:aemzps128DT")) != -1)
  		switch (c) {
  		case 'd':
  			dirnum = atoi(optarg);
***************
*** 124,132 ****
--- 126,141 ----
  		case 'w':
  			pageWidth = atof(optarg);
  			break;
+ 		case 'm':
+ 			maintainAspect = TRUE;
+ 			break;
+ 		case 'z':
+ 			PSavoiddeadzone = TRUE;
+ 			break;
  		case '1':
  			level2 = FALSE;
  			ascii85 = FALSE;
+ 			PSavoiddeadzone = FALSE;
  			break;
  		case '2':
  			level2 = TRUE;
***************
*** 314,319 ****
--- 323,329 ----
  {
  	uint32 w, h;
  	float ox, oy, prw, prh;
+ 	float scale;
  	uint32 subfiletype;
  	uint16* sampleinfo;
  	static int npages = 0;
***************
*** 362,369 ****
  			fprintf(fd, "gsave\n");
  			fprintf(fd, "100 dict begin\n");
  			if (pw != 0 && ph != 0)
! 				fprintf(fd, "%f %f scale\n",
! 				    pw*PS_UNIT_SIZE, ph*PS_UNIT_SIZE);
  			else
  				fprintf(fd, "%f %f scale\n", prw, prh);
  			PSpage(fd, tif, w, h);
--- 372,392 ----
  			fprintf(fd, "gsave\n");
  			fprintf(fd, "100 dict begin\n");
  			if (pw != 0 && ph != 0)
! 				if (maintainAspect) {
! 					scale = ((pw*PS_UNIT_SIZE/prw) <
! 					    (ph*PS_UNIT_SIZE/prh)) ?
! 					    (pw*PS_UNIT_SIZE/prw) :
! 					    (ph*PS_UNIT_SIZE/prh);
! 					if (scale > 1.0)
! 					    scale = 1.0;
! 					fprintf(fd, "0 %f translate\n",
! 					    ph*PS_UNIT_SIZE-prh*scale);
! 					fprintf(fd, "%f %f scale\n",
! 					    prw*scale, prh*scale);
! 				}
! 				else
! 					fprintf(fd, "%f %f scale\n",
! 					    pw*PS_UNIT_SIZE, ph*PS_UNIT_SIZE);
  			else
  				fprintf(fd, "%f %f scale\n", prw, prh);
  			PSpage(fd, tif, w, h);
***************
*** 403,408 ****
--- 426,441 ----
  %%EndFeature\n\
  ";
  
+ static char AvoidDeadZonePreamble[] = "\
+ gsave newpath clippath pathbbox grestore\n\
+   4 2 roll 2 copy translate\n\
+   exch 3 1 roll sub 3 1 roll sub exch\n\
+   currentpagedevice /PageSize get aload pop\n\
+   exch 3 1 roll div 3 1 roll div abs exch abs\n\
+   2 copy gt { exch } if pop\n\
+   dup 1 lt { dup scale } { pop } ifelse\n\
+ ";
+ 
  void
  PSHead(FILE *fd, TIFF *tif, uint32 w, uint32 h, float pw, float ph,
  	float ox, float oy)
***************
*** 428,433 ****
--- 461,468 ----
  	        fprintf(fd, "%s", DuplexPreamble);
  	if (PStumble)
  	        fprintf(fd, "%s", TumblePreamble);
+ 	if (PSavoiddeadzone)
+ 	        fprintf(fd, "%s", AvoidDeadZonePreamble);
  	fprintf(fd, "%%%%EndSetup\n");
  }
  
***************
*** 1312,1318 ****
  					ascii85breaklen = 2*MAXLINE;
  				}
  			}
- 			p += 4;
  		}
  		_TIFFmemcpy(ascii85buf, p, n);
  		ascii85count = n;
--- 1347,1352 ----
***************
*** 1344,1349 ****
--- 1378,1385 ----
  " -o #          convert directory at file offset #",
  " -O file       write PostScript to file instead of standard output",
  " -a            convert all directories in file (default is first)",
+ " -m            maintain aspect ratio and size if possible",
+ " -z            avoid printing in the deadzone (uses PostScript Level II)",
  " -p            generate regular PostScript",
  " -s            generate PostScript for a single image",
  " -T            print pages for top edge binding",
-------------------------------------------------------------------------
|   Feith Systems  |   Voice: 1-215-646-8000  |  Email: john@feith.com  |
|    John Wehle    |     Fax: 1-215-540-5495  |                         |
-------------------------------------------------------------------------

