HylaFAX The world's most advanced open source fax server

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: offset/chopping problem with postscript faxes.



The problem is probably in the tiffg3-to-postscript conversion, which is
done by either tiff2ps or fax2ps (in the faxrcvd script).  These programs
will fit the fax to the page if you specify the page size with the -h and
-w options. 

In addition, I have attached a patch to tiff2ps which makes it behave
better for faxes which are longer or shorter than the page.  Here is what
I said the first time I posted this patch:

On Thu, 8 Oct 1998, John Williams wrote:
> Last week I asked about fixing tiff2ps so that short pages would be put at
> the top of the page instead of the bottom.  I didn't get any responses,
> but I have fixed it myself, so others who are sending their faxes to a
> printer may find the changes useful as well.
>
> Previously, tiff2ps had 2 modes.  If no page height and width were
> specified (via -h and -w), the tiff image is simply bottom-left justified
> at the resolution specified in the tiff file.  If a page size is given via
> -h and -w the tiff image is shrunk or expanded to exactly fill the page.
> This is nice for oversize pages, but results in terribly elongated
> stretching if the page is short.
>
> To fix this behavior, I have modified the behavior when -h and -w are used
> to specify the page size.  Short (or narrow) images are no longer
> stretched, instead they are simply positioned at the top-left on the page
> (previous behavior put it at the bottom-left).  Long (or wide) images are
> shrunk to fit the page.
>
> The new behavior only applies to Postscript level-1 output so far.  (But I
> think level-2 output was already broken anyway.)
>
> A patch for tiff2ps.c (against tiff-v3.4beta035) is attached.  Feedback is
> appreciated, positive or negative.  I would like to get this included in
> the tiff distribution, so if anyone is maintaining it, feel free to
> contact me.

On Fri, 20 Nov 1998, Michael Henry wrote:

> Hi, I'm running HylaFAX v4.0pl2alpha023 on a Solaris 2.5 box, using a Netcomm modem
> (an Australian made class 2 modem).  Imaging is done via GNU Ghostscript 4.03 (1998-5-1),
> and version 3.4 of the SGI tiff software. 
> 
> I have a problem with faxes sent from this modem being printed out on
> the receiving modem with the left edge of the picture being clipped.
> 
> This occurs with Postscript imaged via ghostscript to tiffg3.  The intermediate
> tiff image (captured before being sent via the modem), contains the left edge, so
> something happens to it after this.  I would have thought that the tiff image
> would be printed on the receiving machine with its origin at the beginning of
> the printable area.
> 
> I can hack around this by offsetting the Postscript, but then the same documents
> run off the right hand side of a laserwriter.
> 
> has anyone seen similar problems and (hopefully :-) found a solution ?
> 
> thanks,
> 
> michael.
> -- 
> Michael Henry                     |  email : Michael.Henry@utas.edu.au
> IT Services (Systems)             |  Phone : [+61 3 | (03)] 6226 7417
> University of Tasmania,           |  Fax   : [+61 3 | (03)] 6226 7488
> Australia.                        |  post  : GPO Box 252-69, Hobart 7001
> 
--- tiff2ps.c	1998/09/29 15:42:13	1.1
+++ tiff2ps.c	1998/10/08 16:56:50
@@ -56,9 +56,9 @@
 int	ascii85breaklen;
 
 int	TIFF2PS(FILE*, TIFF*, float, float);
-void	PSpage(FILE*, TIFF*, uint32, uint32);
-void	PSColorContigPreamble(FILE*, uint32, uint32, int);
-void	PSColorSeparatePreamble(FILE*, uint32, uint32, int);
+void	PSpage(FILE*, TIFF*, uint32, uint32, uint32);
+void	PSColorContigPreamble(FILE*, uint32, uint32, uint32, int);
+void	PSColorSeparatePreamble(FILE*, uint32, uint32, uint32, int);
 void	PSDataColorContig(FILE*, TIFF*, uint32, uint32, int);
 void	PSDataColorSeparate(FILE*, TIFF*, uint32, uint32, int);
 void	PSDataPalette(FILE*, TIFF*, uint32, uint32);
@@ -71,6 +71,8 @@
 void 	PSTail(FILE*, int);
 
 static	void usage(int);
+#define MIN(a,b)	((a)<(b)?(a):(b))
+#define MAX(a,b)	((a)>(b)?(a):(b))
 
 int
 main(int argc, char* argv[])
@@ -263,10 +265,10 @@
 }
 
 static void
-setupPageState(TIFF* tif, uint32* pw, uint32* ph, float* pprw, float* pprh)
+setupPageState(TIFF* tif, uint32* pw, uint32* ph, float* pprw, float* pprh, float *xres, float *yres)
 {
 	uint16 res_unit;
-	float xres, yres;
+	/*float xres, yres;*/
 
 	TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, pw);
 	TIFFGetField(tif, TIFFTAG_IMAGELENGTH, ph);
@@ -274,20 +276,20 @@
 	/*
 	 * Calculate printable area.
 	 */
-	if (!TIFFGetField(tif, TIFFTAG_XRESOLUTION, &xres))
-		xres = PS_UNIT_SIZE;
-	if (!TIFFGetField(tif, TIFFTAG_YRESOLUTION, &yres))
-		yres = PS_UNIT_SIZE;
+	if (!TIFFGetField(tif, TIFFTAG_XRESOLUTION, xres))
+		*xres = PS_UNIT_SIZE;
+	if (!TIFFGetField(tif, TIFFTAG_YRESOLUTION, yres))
+		*yres = PS_UNIT_SIZE;
 	switch (res_unit) {
 	case RESUNIT_CENTIMETER:
-		xres /= 2.54, yres /= 2.54;
+		*xres /= 2.54, *yres /= 2.54;
 		break;
 	case RESUNIT_NONE:
-		xres *= PS_UNIT_SIZE, yres *= PS_UNIT_SIZE;
+		*xres *= PS_UNIT_SIZE, *yres *= PS_UNIT_SIZE;
 		break;
 	}
-	*pprh = PSUNITS(*ph, yres);
-	*pprw = PSUNITS(*pw, xres);
+	*pprh = PSUNITS(*ph, *yres);
+	*pprw = PSUNITS(*pw, *xres);
 }
 
 static int
@@ -317,18 +319,19 @@
 	uint32 subfiletype;
 	uint16* sampleinfo;
 	static int npages = 0;
+	float xres,yres;
 
 	if (!TIFFGetField(tif, TIFFTAG_XPOSITION, &ox))
 		ox = 0;
 	if (!TIFFGetField(tif, TIFFTAG_YPOSITION, &oy))
 		oy = 0;
-	setupPageState(tif, &w, &h, &prw, &prh);
+	setupPageState(tif, &w, &h, &prw, &prh, &xres, &yres);
 
 	do {
 	        tf_numberstrips = TIFFNumberOfStrips(tif);
 		TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP,
 		    &tf_rowsperstrip);
-		setupPageState(tif, &w, &h, &prw, &prh);
+		setupPageState(tif, &w, &h, &prw, &prh, &xres, &yres);
 		if (!npages)
 		        PSHead(fd, tif, w, h, prw, prh, ox, oy);
 		tf_bytesperrow = TIFFScanlineSize(tif);
@@ -361,12 +364,22 @@
 			fprintf(fd, "%%%%Page: %d %d\n", npages, npages);
 			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
+			if (pw != 0 && ph != 0) {
+				if (ph*PS_UNIT_SIZE < prh) {
+					fprintf(fd, "%f %f scale\n",
+					    MIN(pw*PS_UNIT_SIZE,prw), 
+					    ph*PS_UNIT_SIZE );
+					PSpage(fd, tif, w, h, h);
+				} else {
+					fprintf(fd, "%f %f scale\n",
+					    MIN(pw*PS_UNIT_SIZE,prw),
+					    prh );
+					PSpage(fd, tif, w, h, (unsigned long)(ph*yres));
+				}
+			} else {
 				fprintf(fd, "%f %f scale\n", prw, prh);
-			PSpage(fd, tif, w, h);
+				PSpage(fd, tif, w, h, h);
+			}
 			fprintf(fd, "end\n");
 			fprintf(fd, "grestore\n");
 			fprintf(fd, "showpage\n");
@@ -901,7 +914,7 @@
 }
 
 void
-PSpage(FILE* fd, TIFF* tif, uint32 w, uint32 h)
+PSpage(FILE* fd, TIFF* tif, uint32 w, uint32 h, uint32 ph)
 {
 	if (level2 && PS_Lvl2page(fd, tif, w, h))
 		return;
@@ -910,20 +923,20 @@
 	case PHOTOMETRIC_RGB:
 		if (planarconfiguration == PLANARCONFIG_CONTIG) {
 			fprintf(fd, "%s", RGBcolorimage);
-			PSColorContigPreamble(fd, w, h, 3);
+			PSColorContigPreamble(fd, w, h, ph, 3);
 			PSDataColorContig(fd, tif, w, h, 3);
 		} else {
-			PSColorSeparatePreamble(fd, w, h, 3);
+			PSColorSeparatePreamble(fd, w, h, ph, 3);
 			PSDataColorSeparate(fd, tif, w, h, 3);
 		}
 		break;
 	case PHOTOMETRIC_SEPARATED:
 		/* XXX should emit CMYKcolorimage */
 		if (planarconfiguration == PLANARCONFIG_CONTIG) {
-			PSColorContigPreamble(fd, w, h, 4);
+			PSColorContigPreamble(fd, w, h, ph, 4);
 			PSDataColorContig(fd, tif, w, h, 4);
 		} else {
-			PSColorSeparatePreamble(fd, w, h, 4);
+			PSColorSeparatePreamble(fd, w, h, ph, 4);
 			PSDataColorSeparate(fd, tif, w, h, 4);
 		}
 		break;
@@ -935,7 +948,7 @@
 		fprintf(fd, "%lu %lu 8\n",
 		    (unsigned long) w, (unsigned long) h);
 		fprintf(fd, "[%lu 0 0 -%lu 0 %lu]\n",
-		    (unsigned long) w, (unsigned long) h, (unsigned long) h);
+		    (unsigned long) w, (unsigned long) h, (unsigned long) ph);
 		fprintf(fd, "{currentfile scanLine readhexstring pop} bind\n");
 		fprintf(fd, "false 3 colorimage\n");
 		PSDataPalette(fd, tif, w, h);
@@ -948,7 +961,7 @@
 		fprintf(fd, "%lu %lu %d\n",
 		    (unsigned long) w, (unsigned long) h, bitspersample);
 		fprintf(fd, "[%lu 0 0 -%lu 0 %lu]\n",
-		    (unsigned long) w, (unsigned long) h, (unsigned long) h);
+		    (unsigned long) w, (unsigned long) h, (unsigned long) ph);
 		fprintf(fd,
 		    "{currentfile scanLine readhexstring pop} bind\n");
 		fprintf(fd, "image\n");
@@ -959,7 +972,7 @@
 }
 
 void
-PSColorContigPreamble(FILE* fd, uint32 w, uint32 h, int nc)
+PSColorContigPreamble(FILE* fd, uint32 w, uint32 h, uint32 ph, int nc)
 {
 	ps_bytesperrow = nc * (tf_bytesperrow / samplesperpixel);
 	PhotoshopBanner(fd, w, h, 1, nc, "false %d colorimage");
@@ -967,13 +980,13 @@
 	fprintf(fd, "%lu %lu %d\n",
 	    (unsigned long) w, (unsigned long) h, bitspersample);
 	fprintf(fd, "[%lu 0 0 -%lu 0 %lu]\n",
-	    (unsigned long) w, (unsigned long) h, (unsigned long) h);
+	    (unsigned long) w, (unsigned long) h, (unsigned long) ph);
 	fprintf(fd, "{currentfile line readhexstring pop} bind\n");
 	fprintf(fd, "false %d colorimage\n", nc);
 }
 
 void
-PSColorSeparatePreamble(FILE* fd, uint32 w, uint32 h, int nc)
+PSColorSeparatePreamble(FILE* fd, uint32 w, uint32 h, uint32 ph, int nc)
 {
 	int i;
 
@@ -984,7 +997,7 @@
 	fprintf(fd, "%lu %lu %d\n",
 	    (unsigned long) w, (unsigned long) h, bitspersample);
 	fprintf(fd, "[%lu 0 0 -%lu 0 %lu] \n",
-	    (unsigned long) w, (unsigned long) h, (unsigned long) h);
+	    (unsigned long) w, (unsigned long) h, (unsigned long) ph);
 	for (i = 0; i < nc; i++)
 		fprintf(fd, "{currentfile line%d readhexstring pop}bind\n", i);
 	fprintf(fd, "true %d colorimage\n", nc);
Date: Fri, 20 Nov 1998 09:58:23 +1100
From: Damian A Ivereigh <damian@cisco.com>
Organization: Cisco Systems Inc
X-Mailer: Mozilla 4.05 [en] (X11; U; Linux 2.0.34 i586)
To: Eric Smith <list@eric.nafex.com>
CC: flexfax@sgi.com
Subject: Re: flexfax: AutoAnswer
Sender: owner-flexfax@celestial.com

You may want to uncomment the

#RingsBeforeAnswer:     1

line. I don't know what the default is but it may be zero (no answer).

Damian

Eric Smith wrote:
> 
> Apologies for the repeat but i forgot to include my config file:
> 
> I have a USR 33.6 Faxmodem.  I have had many problems with config and here is a
> file that sends faxes ok.  The question is what can I do to get the modem to
> autoanswer.  It has worked for me in the past but I cannot seem to get it
> working now. faxgetty is running.
> The AA light just comes on but does not go off hook.
> if I type faxanswer cua0, then it will answer.
> Thank you
> 
> Eric Smith
> 
> # $Id: usr-rts,v 1.6 1996/06/24 02:58:43 sam Rel $
> #
> # Configuration for using the Class 1 command interface with
> # a USR Courier or Sportster modem and RTS/CTS flow control.
> #
> # CONFIG:CLASS1:1444:.*:RTSCTS: Manufacturer=USRobotics Model=Courier/Sportster
> # CONFIG:CLASS1:1445:.*:RTSCTS: Manufacturer=USRobotics Model=Courier/Sportster
> # CONFIG:CLASS1:2886:.*:RTSCTS: Manufacturer=USRobotics Model=Courier/Sportster
> # CONFIG:CLASS1:3366:.*:RTSCTS: Manufacturer=USRobotics Model=Courier
> #
> # BEGIN-SERVER
> # END-SERVER
> #
> # Modem-related stuff: should reflect modem command interface
> # and hardware connection/cabling (e.g. flow control).
> #
> ModemType:              Class1          # use class 1 interface
> ModemRate:              38400           # max rate for DCE-DTE communication
> ModemFlowControl:       rtscts          # hardware flow control
> #
> ModemSetupDTRCmd:       ATS13=1&D2      # setup so DTR drop resets modem
> ModemSetupDCDCmd:       AT&C1           # setup so DCD reflects carrier (or not)
> ModemNoFlowCmd:         AT&H0&I0&R1     # setup modem for no flow control
> ModemHardFlowCmd:       AT&H1&I0&R2     # setup modem for hardware flow control
> ModemSoftFlowCmd:       AT&H2&I2&R1     # setup modem for software flow control
> ModemResultCodesCmd:    ATQ0X4          # enable result codes
> #
> ModemMfrQueryCmd:       !USR
> ModemModelQueryCmd:     ATI3
> ModemRevQueryCmd:       ATI7            # XXX, returns a multi-line result
> #
> # When AT+FCLASS=1 is issued the modem automatically switches
> # to software flow control; these parameters let the fax software
> # reset flow control as needed after entering Class 1.
> #
> Class1NFLOCmd:          AT&H0&I0&R1     # setup modem for no flow control
> Class1HFLOCmd:          AT&H1&I0&R2     # setup modem for hardware flow control
> Class1SFLOCmd:          ""              # modem does this automatically
> #
> # The remainder of this configuration is included so that the
> # modem "idles" in Class 0 while not sending or receiving facsimile.
> 
> #Eric fiddled here unsuccesfully to get AA to work
> #ModemSetupAACmd:       AT+FCLASS=0&H1&I0&R2    # leave modem in class 0
> #ModemAnswerFaxCmd:     ATA  # if null reads ModemAnswerCmd
> #ModemAnswerCmd:                AT+FCLASS=1&H1&I0&R2A   # force RTS/CTS after change
> #ModemAnswerCmd:                ATA
> #RingsBeforeAnswer:     1

-- 
 ______________________________________________________________________
* Damian Ivereigh     *      ||        ||      * Cisco Systems, Inc.   *
* MIS Printer Admin   *    .||||.    .||||.    * Sydney, Australia     *
* Linux Bigot         * ..:||||||:..:||||||:.. * +61 2 8448 7344       *
* damian@cisco.com    *   cisco Systems, Inc.  * Fax: +61 2 8448 7228  *
*______________________________________________________________________*




Project hosted by iFAX Solutions