1997.01.20 23:58 "Tiff Version 3.4 Beta 035 Patch to add tiff2ps enhancments", by John Wehle

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).
  2. 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.
  3. Many printers have a deadzone around the edge of the paper.
  4. 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.
  5. There appears to be a minor code bug in Ascii85Put which causes p to be incremented by four twice.
  6. 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  |                         |
-------------------------------------------------------------------------