Exemplo n.º 1
0
void
printTIF(TIFF* tif, uint16 pageNumber)
{
    uint32 w, h;
    uint16 unit, compression;
    float xres, yres, scale = 1.0;
    tstrip_t s, ns;
    time_t creation_time;

    TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
    TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
    if (!TIFFGetField(tif, TIFFTAG_COMPRESSION, &compression)
	|| compression < COMPRESSION_CCITTRLE
	|| compression > COMPRESSION_CCITT_T6)
	return;
    if (!TIFFGetField(tif, TIFFTAG_XRESOLUTION, &xres) || !xres) {
	TIFFWarning(TIFFFileName(tif),
	    "No x-resolution, assuming %g dpi", defxres);
	xres = defxres;
    }
    if (!TIFFGetField(tif, TIFFTAG_YRESOLUTION, &yres) || !yres) {
	TIFFWarning(TIFFFileName(tif),
	    "No y-resolution, assuming %g lpi", defyres);
	yres = defyres;					/* XXX */
    }
    if (TIFFGetField(tif, TIFFTAG_RESOLUTIONUNIT, &unit) &&
      unit == RESUNIT_CENTIMETER) {
	xres *= 2.54F;
	yres *= 2.54F;
    }
    if (pageWidth == 0)
	pageWidth = w / xres;
    if (pageHeight == 0)
	pageHeight = h / yres;

    printf("%%!PS-Adobe-3.0\n");
    printf("%%%%Creator: fax2ps\n");
#ifdef notdef
    printf("%%%%Title: %s\n", file);
#endif
    creation_time = time(0);
    printf("%%%%CreationDate: %s", ctime(&creation_time));
    printf("%%%%Origin: 0 0\n");
    printf("%%%%BoundingBox: 0 0 %u %u\n",
	(int)(pageWidth * points), (int)(pageHeight * points));	/* XXX */
    printf("%%%%Pages: (atend)\n");
    printf("%%%%EndComments\n");
    printf("%%%%BeginProlog\n");
    emitFont(stdout);
    printf("/d{bind def}def\n"); /* bind and def proc */
    printf("/m{0 exch moveto}d\n");
    printf("/s{show}d\n");
    printf("/p{showpage}d \n");	/* end page */
    printf("%%%%EndProlog\n");
    printf("%%%%Page: \"%u\" %u\n", pageNumber, pageNumber);
    printf("/$pageTop save def gsave\n");
    if (scaleToPage)
        scale = pageHeight / (h/yres) < pageWidth / (w/xres) ?
            pageHeight / (h/yres) : pageWidth / (w/xres);
    printf("%g %g translate\n",
           points * (pageWidth - scale*w/xres) * half,
           points * (scale*h/yres + (pageHeight - scale*h/yres) * half));
    printf("%g %g scale\n", points/xres*scale, -points/yres*scale);
    printf("0 setgray\n");
    TIFFSetField(tif, TIFFTAG_FAXFILLFUNC, printruns);
    ns = TIFFNumberOfStrips(tif);
    row = 0;
    for (s = 0; s < ns; s++)
	(void) TIFFReadEncodedStrip(tif, s, (tdata_t) NULL, (tsize_t) -1);
    printf("p\n");
    printf("grestore $pageTop restore\n");
    totalPages++;
}
Exemplo n.º 2
0
int
main(int argc, char** argv)
{
    extern int optind;
    extern char* optarg;
    int c, pageNumber;
    int* pages = 0, npages = 0;
    int dowarnings = 0;		/* if 1, enable library warnings */
    time_t t;
    TIFF* tif;

    while ((c = getopt(argc, argv, "l:p:x:y:W:H:wS")) != -1)
	switch (c) {
	case 'H':		/* page height */
	    pageHeight = atof(optarg);
	    break;
	case 'S':		/* scale to page */
	    scaleToPage = 1;
	    break;
	case 'W':		/* page width */
	    pageWidth = atof(optarg);
	    break;
	case 'p':		/* print specific page */
	    pageNumber = atoi(optarg);
	    if (pageNumber < 1) {
		fprintf(stderr, "%s: Invalid page number (must be > 0).\n",
		    optarg);
		usage(-1);
	    }
	    if (pages)
		pages = (int*) realloc((char*) pages, (npages+1)*sizeof (int));
	    else
		pages = (int*) malloc(sizeof (int));
	    pages[npages++] = pageNumber;
	    break;
	case 'w':
	    dowarnings = 1;
	    break;
	case 'x':
	    defxres = atof(optarg);
	    break;
	case 'y':
	    defyres = atof(optarg);
	    break;
	case 'l':
	    maxline = atoi(optarg);
	    break;
	case '?':
	    usage(-1);
	}
    if (npages > 0)
	qsort(pages, npages, sizeof (int), pcompar);
    if (!dowarnings)
	TIFFSetWarningHandler(0);
    printf("%%!PS-Adobe-3.0\n");
    printf("%%%%Creator: fax2ps\n");
#ifdef notdef
    printf("%%%%Title: %s\n", file);
#endif
    t = time(0);
    printf("%%%%CreationDate: %s", ctime(&t));
    printf("%%%%Origin: 0 0\n");
    printf("%%%%BoundingBox: 0 0 %u %u\n",
	(int)(pageWidth*72), (int)(pageHeight*72));	/* XXX */
    printf("%%%%Pages: (atend)\n");
    printf("%%%%EndComments\n");
    printf("%%%%BeginProlog\n");
    emitFont(stdout);
    printf("/d{bind def}def\n"); /* bind and def proc */
    printf("/m{0 exch moveto}d\n");
    printf("/s{show}d\n");
    printf("/p{showpage}d \n");	/* end page */
    printf("%%%%EndProlog\n");
    if (optind < argc) {
	do {
	    tif = TIFFOpen(argv[optind], "r");
	    if (tif) {
		fax2ps(tif, npages, pages, argv[optind]);
		TIFFClose(tif);
	    } else
		fprintf(stderr, "%s: Can not open, or not a TIFF file.\n",
		    argv[optind]);
	} while (++optind < argc);
    } else {
	int n;
	FILE* fd;
	char temp[1024], buf[16*1024];

	strcpy(temp, "/tmp/fax2psXXXXXX");
	(void) mktemp(temp);
	fd = fopen(temp, "w");
	if (fd == NULL) {
	    fprintf(stderr, "Could not create temp file \"%s\"\n", temp);
	    exit(-2);
	}
	while ((n = read(fileno(stdin), buf, sizeof (buf))) > 0)
	    write(fileno(fd), buf, n);
	tif = TIFFOpen(temp, "r");
#ifndef VMS
	unlink(temp);
#else
	remove(temp);
#endif
	if (tif) {
	    fax2ps(tif, npages, pages, "<stdin>");
	    TIFFClose(tif);
	} else
	    fprintf(stderr, "%s: Can not open, or not a TIFF file.\n", temp);
	fclose(fd);
    }
    printf("%%%%Trailer\n");
    printf("%%%%Pages: %u\n", totalPages);
    printf("%%%%EOF\n");

    return (0);
}
Exemplo n.º 3
0
int
fax2psmain(char* faxtiff_file,  FILE* psoutput,float width, float height, int scale)
{

    int c, pageNumber;
    int* pages = 0, npages = 0;
    int dowarnings = 0;		/* if 1, enable library warnings */
    time_t t;
    TIFF* tif;

    mypsoutputfile = psoutput;
    pageHeight = height;
    pageWidth = width;
    scaleToPage = scale;

/*printf("Width %f Height %f\n",width,height);*/

    /*	    pageHeight = atof(optarg);*/
    /*	    scaleToPage = 1;*/
    /*	    pageWidth = atof(optarg);*/

    /*	    pageNumber = atoi(optarg);
	    if (pageNumber < 1) {
		fprintf(stderr, "%s: Invalid page number (must be > 0).\n",
		    optarg);
		usage(-1);
	    }
	    if (pages)
		pages = (int*) realloc((char*) pages, (npages+1)*sizeof (int));
	    else
		pages = (int*) malloc(sizeof (int));
	    pages[npages++] = pageNumber;
	    */

    /*Let's not do any warnings for now*/
    /*Bernd*/


    /*	    defxres = atof(optarg);*/
    /*    defyres = atof(optarg);*/
    /*	    maxline = atoi(optarg);*/

    if (npages > 0)
	qsort(pages, npages, sizeof (int), pcompar);
    if (!dowarnings)
	TIFFSetWarningHandler(0);


    fprintf(psoutput,"%%!PS-Adobe-3.0\n");
    fprintf(psoutput,"%%%%Creator: kfax Copyright 1997 Bernd Johannes Wuebben\n");
#ifdef notdef
    fprintf(psoutput,"%%%%Title: %s\n", file);
#endif
    t = time(0);
    fprintf(psoutput,"%%%%CreationDate: %s", ctime(&t));
    fprintf(psoutput,"%%%%Origin: 0 0\n");
    fprintf(psoutput,"%%%%BoundingBox: 0 0 %u %u\n",
	(int)(pageHeight*72), (int)(pageWidth*72));	/* XXX */
    fprintf(psoutput,"%%%%Pages: (atend)\n");
    fprintf(psoutput,"%%%%EndComments\n");
    fprintf(psoutput,"%%%%BeginProlog\n");
    emitFont(psoutput);
    fprintf(psoutput,"/d{bind def}def\n"); /* bind and def proc */
    fprintf(psoutput,"/m{0 exch moveto}d\n");
    fprintf(psoutput,"/s{show}d\n");
    fprintf(psoutput,"/p{showpage}d \n");	/* end page */
    fprintf(psoutput,"%%%%EndProlog\n");


    tif = TIFFOpen(faxtiff_file, "r");
    if (tif) {
      fax2ps(tif, npages, pages, faxtiff_file);
      TIFFClose(tif);
    } else
      fprintf(stderr, "%s: Can not open, or not a TIFF file.\n",
	      faxtiff_file);

    fprintf(psoutput,"%%%%Trailer\n");
    fprintf(psoutput,"%%%%Pages: %u\n", totalPages);
    fprintf(psoutput,"%%%%EOF\n");

    return (0);
}