1993.11.12 19:51 "fax2ps improvements (??)", by Achille Petrilli

Hi,

I've slightly modified fax2ps to make it more suited for Europe (no more fixed paper size, the printer decides what paper size is available) and I added a -F option to fit the image to the paper while retaining the x/y ratio of the image.

While I was at it, I also added a calculation to find out whether the shape of the image is more suited for portrait or landscape printing, and I generate the appropriate rotation as needed.

I would like to thank you for making available such a good software.

I successfully compiled the modified fax2ps.c on a Sun using the ANSI C compiler from Sun. I believe that should just compile everywhere.

Cheers,

Achille Petrilli

Here are the diffs between my version and the 3.2+patch fax2ps.c version as available on sgi.com:

----- cut here -----
37d36
< int   fitToPage = FALSE;      /* if true, fit raster to page dimensions */
401d399
<     int rotate;
478,481d475
<     /*
<      * AP: if width > length ==> rotate the whole page !!.
<      */
<     rotate = w > h;
485,523c479,482
<       float ypoint = 72.*h/yres;
<       float xpoint = 72.*w/xres;

<       printf("gsave\n");
<       printf("clippath pathbbox\n");
<       printf("grestore\n");
<       printf("3 2 roll %% llx urx ury lly\n");
<       printf("sub /pH exch def exch sub /pW exch def\n");
<       if (rotate) {
<           printf("90 rotate\n");
<           printf("/yS pW %f div def\n",ypoint);
<           printf("/xS pH %f div def\n",xpoint);
<       } else {
<           printf("/yS pH %f div def\n",ypoint);
<           printf("/xS pW %f div def\n",xpoint);
<           printf("0 yS %d mul translate\n", (int)((h/yres)*72.));
<       }
<       printf("xS %g mul yS %g mul scale\n", 72./xres, -72./yres);
<     } else if (fitToPage) {
<       float ypoint = 72.*h/yres;
<       float xpoint = 72.*w/xres;

<       printf("gsave\n");
<       printf("clippath pathbbox\n");
<       printf("grestore\n");
<       printf("3 2 roll %% llx urx ury lly\n");
<       printf("sub /pH exch def exch sub /pW exch def\n");
<       if (rotate) {
<           printf("90 rotate\n");
<           printf("/yS pW %f div def\n",ypoint);
<           printf("/xS pH %f div def\n",xpoint);
<           printf("xS yS lt {/yS xS def} {/xS yS def} ifelse\n");
<       } else {
<           printf("/yS pH %f div def\n",ypoint);
<           printf("/xS pW %f div def\n",xpoint);
<           printf("xS yS lt {/yS xS def} {/xS yS def} ifelse\n");
<           printf("0 yS %d mul translate\n", (int)((h/yres)*72.));
<       }
<       printf("xS %g mul yS %g mul scale\n", 72./xres, -72./yres);
---
>       float yscale = pageHeight / (h/yres);
>       float xscale = pageWidth / (w/xres);
>       printf("0 %d translate\n", (int)(yscale*(h/yres)*72.));
>       printf("%g %g scale\n", (72.*xscale)/xres, -(72.*yscale)/yres);
525,529c484
<       if (rotate) {
<           printf("90 rotate\n");
<       } else {
<           printf("0 %d translate\n", (int)(72.*h/yres));
<       }
---
>       printf("0 %d translate\n", (int)(72.*h/yres));
621c576
<     while ((c = getopt(argc, argv, "p:x:y:W:H:aswzSF")) != -1)
---
>     while ((c = getopt(argc, argv, "p:x:y:W:H:aswzS")) != -1)
626,628d580
<       case 'F':               /* scale to page */
<           fitToPage = TRUE;
<           break;
642,643c594,595
<           if (pageNumber < 0) {
<               fprintf(stderr, "%s: Invalid page number (must be >= 0).\n",
---
>           if (pageNumber < 1) {
>               fprintf(stderr, "%s: Invalid page number (must be > 0).\n",
670c622
< "usage: %s [-a] [-w] [-p pagenumber] [-x xres] [-y res] [-s] [-F] [-S] [-W
pagewidth] [-H pageheight] [files]\n",
---
> "usage: %s [-a] [-w] [-p pagenumber] [-x xres] [-y res] [-s] [-S] [-W
pagewidth] [-H pageheight] [files]\n",