*** gdevtiff.c~	Sun Nov 20 09:38:19 1994
--- gdevtiff.c	Sun Nov 20 09:56:03 1994
***************
*** 23,32 ****
   * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
   * OF THIS SOFTWARE.
   */
- /*
-  * 5/19/93 modified by L. Peter Deutsch, Aladdin Enterprises,
-  *   for compatibility with Ghostscript 2.6.1.
-  */
  /* gdevtiff.c */
  
  #include "gdevprn.h"
--- 23,28 ----
***************
*** 109,117 ****
  #define	PAPER_SIZE_LETTER	0
      { 85,  110, 1728 },
  #define	PAPER_SIZE_A4		1
!     { 85,  117, 1728 },
  #define	PAPER_SIZE_B4		2
!     { 101, 143, 2048 }
  };
  #define	NPAGEINFO (sizeof (pageinfo) / sizeof (pageinfo[0]))
  
--- 105,113 ----
  #define	PAPER_SIZE_LETTER	0
      { 85,  110, 1728 },
  #define	PAPER_SIZE_A4		1
!     { 85,  116, 1728 },
  #define	PAPER_SIZE_B4		2
!     { 101,  143, 2048 }
  };
  #define	NPAGEINFO (sizeof (pageinfo) / sizeof (pageinfo[0]))
  
***************
*** 191,197 ****
      faxp->prevdir = 0L;
      faxp->bigendian = arch_is_big_endian;
      faxp->fax_byte = 0;
!     faxp->fax_weight = 0x80;
  }
  
  /* NB: this array is sorted by tag number (assumed below) */
--- 187,193 ----
      faxp->prevdir = 0L;
      faxp->bigendian = arch_is_big_endian;
      faxp->fax_byte = 0;
!     faxp->fax_weight = 0x01;
  }
  
  /* NB: this array is sorted by tag number (assumed below) */
***************
*** 231,237 ****
      { TIFFTAG_BITSPERSAMPLE,	TIFF_SHORT, 1, 1 },
      { TIFFTAG_COMPRESSION,	TIFF_SHORT, 1, COMPRESSION_CCITTFAX3 },
      { TIFFTAG_PHOTOMETRIC,	TIFF_SHORT, 1, PHOTOMETRIC_MINISWHITE },
!     { TIFFTAG_FILLORDER,	TIFF_SHORT, 1, FILLORDER_MSB2LSB },
  #ifdef notdef
      { TIFFTAG_DOCUMENTNAME,	TIFF_ASCII, 1 },
  #endif
--- 227,233 ----
      { TIFFTAG_BITSPERSAMPLE,	TIFF_SHORT, 1, 1 },
      { TIFFTAG_COMPRESSION,	TIFF_SHORT, 1, COMPRESSION_CCITTFAX3 },
      { TIFFTAG_PHOTOMETRIC,	TIFF_SHORT, 1, PHOTOMETRIC_MINISWHITE },
!     { TIFFTAG_FILLORDER,	TIFF_SHORT, 1, FILLORDER_LSB2MSB },
  #ifdef notdef
      { TIFFTAG_DOCUMENTNAME,	TIFF_ASCII, 1 },
  #endif
***************
*** 275,280 ****
--- 271,284 ----
      TIFFDirectory dir;
  
      /*
+      * If Ghostscript was invoked with -sOutputFile=file.%d, then
+      * it is expected to generate a new file for each page.  This
+      * makes no sense for TIFF, but in the interest of compatibility
+      * we do the right thing here.
+      */
+     if (gdev_prn_file_is_new(pdev))
+         faxp->diroff = 0;
+     /*
       * Writing the header is delayed to here because the
       * FILE* is not setup when faxout_open is called.
       */
***************
*** 750,769 ****
  {
      if(d) 
  	faxp->fax_byte = faxp->fax_byte|faxp->fax_weight;
!     faxp->fax_weight = faxp->fax_weight>>1;
      if((faxp->fax_weight&0xff) == 0) {
  	putc(faxp->fax_byte, faxp->fp);
  	faxp->fax_byte = 0;
! 	faxp->fax_weight = 0x80;
      }
  }
  
  private void
  flushbits(register TIFFOUT *faxp)
  {
!     if (faxp->fax_weight != 0x80) {
  	putc(faxp->fax_byte, faxp->fp);
  	faxp->fax_byte = 0;
! 	faxp->fax_weight = 0x80;
      }
  }
--- 754,773 ----
  {
      if(d) 
  	faxp->fax_byte = faxp->fax_byte|faxp->fax_weight;
!     faxp->fax_weight = faxp->fax_weight<<1;
      if((faxp->fax_weight&0xff) == 0) {
  	putc(faxp->fax_byte, faxp->fp);
  	faxp->fax_byte = 0;
! 	faxp->fax_weight = 0x01;
      }
  }
  
  private void
  flushbits(register TIFFOUT *faxp)
  {
!     if (faxp->fax_weight != 0x01) {
  	putc(faxp->fax_byte, faxp->fp);
  	faxp->fax_byte = 0;
! 	faxp->fax_weight = 0x01;
      }
  }
