w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

epstool.c
Go to the documentation of this file.
1 /* Copyright (C) 1993-2000, Ghostgum Software Pty Ltd. All rights reserved.
2 
3  This file is part of GSview.
4 
5  This program is distributed with NO WARRANTY OF ANY KIND. No author
6  or distributor accepts any responsibility for the consequences of using it,
7  or for whether it serves any particular purpose or works at all, unless he
8  or she says so in writing. Refer to the GSview Free Public Licence
9  (the "Licence") for full details.
10 
11  Every copy of GSview must include a copy of the Licence, normally in a
12  plain ASCII text file named LICENCE. The Licence grants you the right
13  to copy, modify and redistribute GSview, but only under certain conditions
14  described in the Licence. Among other things, the Licence requires that
15  the copyright notice and this notice be preserved on all copies.
16 */
17 
18 /* epstool.c */
19 #include "epstool.h"
20 
21 char szVersion[] = "1.08 2000-02-15";
22 
23 char iname[MAXSTR];
24 char oname[MAXSTR];
25 char upname[MAXSTR];
26 char gsname[MAXSTR] = GSCOMMAND;
29 char szScratch[] = "ep";
30 char szAppName[] = "epstool";
31 int resolution = 72;
32 int page = 1; /* default is page 1 */
38 int ptwidth = 612; /* letter width */
39 int ptheight = 842; /* A4 height */
40 int op = 0;
41 #define EXTRACTPS 1
42 #define EXTRACTPRE 2
43 #define INTERCHANGE 3
44 #define TIFF4 4
45 #define TIFF6U 5
46 #define TIFF6P 6
47 #define TIFFGS 7
48 #define USER 8
49 #define WMF 9
50 #define COPY 10
51 
52 /* KLUDGE variables */
56 char GVFAR *bitmap_base;
58 
59 /* function prototypes */
60 BOOL load_bitmap(void);
61 int scan_args(int argc, char *argv[]);
62 void do_help(void);
63 int extract_section(void);
64 int add_preview(void);
66 void psfile_extract_page(FILE *f, int page);
67 int make_eps_copy(void);
68 
69 /* KLUDGE functions */
71 {
72  return bitmap_pbmi;
73 }
74 void release_bitmap(void)
75 {
76 }
77 void play_sound(int i)
78 {
79 }
80 
81 char *
83 {
84  /* don't support gzipped files in epstool */
85  /* so return original file name */
86  return psf->name;
87 }
88 
89 int
90 main(int argc, char *argv[])
91 {
92 #ifdef UNIX
93  strcpy(devname, "pbmraw");
94 #else
95  strcpy(devname, "bmpmono");
96 #endif
97 #ifdef __WIN32__
98  strcpy(argv[0], "epstool");
99 #endif
100  if (scan_args(argc, argv))
101  return 1;
102 #if defined(__EMX__) || defined(MSDOS) || defined(__WIN32__)
104 #endif
105 
107  if ((psfile.file = fopen(psfile.name, READBIN)) == (FILE *)NULL) {
108  fprintf(stderr, "Can't open %s\n", psfile.name);
109  return 1;
110  }
111  doc = psscan(psfile.file);
112  psfile.doc = doc;
113  if (doc == (PSDOC *)NULL) {
114  fprintf(stderr, "File %s does not contain DSC comments\n", psfile.name);
115  fclose(psfile.file);
116  return 1;
117  }
118 
119  if (op==INTERCHANGE || op==TIFF4 || op==TIFF6U || op==TIFF6P || op==TIFFGS
120  || op==WMF || op==COPY)
121  return add_preview();
122  if (op==USER)
123  return make_eps_user();
124  if (op==EXTRACTPS || op==EXTRACTPRE)
125  return extract_section();
126 
127  psfree(doc);
128  return 0;
129 }
130 
131 int
133 {
134  if (op == EXTRACTPS)
136  else if (op == EXTRACTPRE)
138  else
139  fprintf(stderr, "Unknown operation %d\n", op);
140  return 0;
141 }
142 
143 int
145 {
146 char ename[MAXSTR];
147 char tempname[MAXSTR];
148 FILE *tempfile;
149 FILE *bmpfile;
150 char gscommand[MAXSTR+MAXSTR];
151 char rspname[MAXSTR];
152 FILE *rspfile;
153 int width, height;
154 int code = 0;
155  if (!calc_bbox &&
156  ((doc->boundingbox[URX] < doc->boundingbox[LLX]) ||
157  (doc->boundingbox[URY] < doc->boundingbox[LLY])) ) {
158  fprintf(stderr, "Bounding Box is inconsistent");
159  return 1;
160  }
161  if ((op == TIFFGS) && calc_bbox) {
162  calc_bbox = FALSE;
163  fprintf(stderr, "Can't calculate Bounding Box when using GS TIFF driver\n");
164  fprintf(stderr, "Using %%BoundingBox from EPS file\n");
165  }
166  if ( !calc_bbox &&
167  ((doc->boundingbox[URX] == doc->boundingbox[LLX]) ||
168  (doc->boundingbox[URY] == doc->boundingbox[LLY])) ) {
169  fprintf(stderr, "Bounding Box is empty");
170  return 1;
171  /* if calc_bbox, this shouldn't be an error */
172  }
173  if (doc->numpages > 1) {
174  /* create temporary file to hold extracted page */
176  if (tempfile == (FILE *)NULL) {
177  fprintf(stderr, "Couldn't open temporary file %s\n", ename);
178  return 1;
179  }
180  /* copy page to new file */
183  fclose(tempfile);
184  psfree(doc); /* forget original file */
185  /* scan new file */
186  strcpy(psfile.name, ename);
187  if ((psfile.file = fopen(psfile.name, READBIN)) == (FILE *)NULL) {
188  fprintf(stderr, "Can't open %s\n", psfile.name);
189  return 1;
190  }
191  doc = psscan(psfile.file);
192  psfile.doc = doc;
193  if (doc == (PSDOC *)NULL) {
194  fprintf(stderr, "File %s does not contain DSC comments\n", psfile.name);
195  fclose(psfile.file);
196  return 1;
197  }
198  page = 1; /* we want the one and only remaining page */
199  }
201  if (tempfile == (FILE *)NULL) {
202  fprintf(stderr, "Couldn't open temporary file %s\n", tempname);
203  return 1;
204  }
205  rspfile = gp_open_scratch_file(szScratch, rspname, WRITEBIN);
206  if (rspfile == (FILE *)NULL) {
207  fprintf(stderr, "Couldn't open temporary response file %s\n", rspname);
208  if (!debug)
209  unlink(tempname);
210  return 1;
211  }
213  if (bmpfile == (FILE *)NULL) {
214  fprintf(stderr, "Couldn't open temporary bitmap file %s\n", bmpname);
215  if (!debug) {
216  unlink(tempname);
217  unlink(rspname);
218  }
219  return 1;
220  }
221  fclose(bmpfile);
222  if (!debug)
223  unlink(bmpname);
224  /* offset to bottom left corner of bounding box */
225  if (!calc_bbox)
226  fprintf(tempfile, "%d %d translate\r\n", -doc->boundingbox[LLX], -doc->boundingbox[LLY]);
227  /* calculate page size */
228  if (calc_bbox) {
229  if (doc->default_page_media && !ptsize) {
230  width = (int)(doc->default_page_media->width*(long)resolution/72L);
232  }
233  else {
234  width = (int)(((long)ptwidth)*resolution/72L);
235  height = (int)(((long)ptheight)*resolution/72L);
236  }
237  }
238  else {
239  width = (int)((doc->boundingbox[URX] - doc->boundingbox[LLX])*(long)resolution/72L);
240  height = (int)((doc->boundingbox[URY] - doc->boundingbox[LLY])*(long)resolution/72L);
241  }
242  /* cope with EPS files with and without showpage */
243  fprintf(tempfile, " /EPSTOOL_save save def\r\n /showpage {} def\r\n");
244  fprintf(tempfile, " count /EPSTOOL_count exch def\r\n");
245  fprintf(tempfile, " /EPSTOOL_countdictstack countdictstack def\r\n");
246 
247  /* copy page to temporary file */
248  if (doc->numpages != 0) {
251  if (doc->numpages > 1)
252  fprintf(stderr,"Can't handle multiple page PostScript files\n");
253  }
254  else {
257  }
258  /* cope with EPS files with and without showpage */
259  fprintf(tempfile, "\n count EPSTOOL_count sub {pop} repeat\r\n");
260  fprintf(tempfile, " countdictstack EPSTOOL_countdictstack sub {end} repeat\r\n");
261  fprintf(tempfile, " EPSTOOL_save restore\r\n showpage\r\n");
262  fprintf(tempfile, "\nquit\n");
263  fclose(tempfile);
264 #ifdef UNIX
265  sprintf(gscommand, "%s -dNOPAUSE -dQUIET -sDEVICE=%s -sOutputFile=\042%s\042 -r%d -g%dx%d %s",
266  gsname, devname, bmpname, resolution, width, height, tempname);
267 #else
268  sprintf(gscommand, "-dNOPAUSE\n-dQUIET\n-sDEVICE=%s\n-sOutputFile=\042%s\042\n-r%d\n-g%dx%d\n\042%s\042",
269  devname, bmpname, resolution, width, height, tempname);
270  if (!quiet) {
271  fputs(gscommand, stderr);
272  fputs("\n", stderr);
273  }
274  fputs(gscommand, rspfile);
275  fclose(rspfile);
276  sprintf(gscommand, "%s @%s", gsname, rspname);
277 #endif
278  if (!quiet)
279  fprintf(stderr,"%s\n", gscommand);
280  system(gscommand);
281 
282  if (!debug) {
283  unlink(rspname);
284  unlink(tempname);
285  }
286 
287  if (op == TIFFGS) {
289  code = make_eps_user(); /* create user TIFF preview */
290  if (!debug)
291  unlink(bmpname);
292  }
293  else {
294  if (!load_bitmap()) {
295  if (!debug)
296  unlink(bmpname);
297  fprintf(stderr, "no bitmap\n");
298  return 1;
299  }
300  if (!debug)
301  unlink(bmpname);
302  /* now create new file with preview */
303  if (op == INTERCHANGE)
305  else if (op == TIFF4)
307  else if (op == TIFF6U)
309  else if (op == TIFF6P)
311  else if (op == WMF)
313  else if (op == COPY)
314  code = make_eps_copy();
315  else
316  fprintf(stderr, "Unknown operation %d\n", op);
317  }
318 
319  if (*ename) {
320  fclose(psfile.file);
321  if (!debug)
322  unlink(ename); /* remove temporary file */
323  }
324 
325  if (!quiet)
326  fprintf(stderr, "Operation %s\n",
327  code ? "failed" : "was successful");
328 
329  return code;
330 }
331 
332 int
333 scan_args(int argc, char *argv[])
334 {
335 char *argp;
336 int count;
337  if (argc == 1) {
338  do_help();
339  return 1;
340  }
341  for (count=1, argp = argv[1]; count < argc; count++, argp=argv[count]) {
342  if (*argp == '-') {
343  switch(argp[1]) {
344  case 'h':
345  do_help();
346  return 1;
347  case 'o':
348  if (argp[2])
349  strcpy(oname, argp+2);
350  else {
351  fprintf(stderr,"Missing output filename for -o\n");
352  return 1;
353  }
354  break;
355  case 'n':
356  if (argp[2])
357  page = atoi(argp+2);
358  else {
359  fprintf(stderr,"Missing page number for -n\n");
360  page = atoi(argp);
361  }
362  break;
363  case 'r':
364  if (argp[2])
365  resolution = atoi(argp+2);
366  else {
367  fprintf(stderr,"Missing resolution for -r\n");
368  return 1;
369  }
370  break;
371  case 's':
372  if (argp[2]) {
373  if (sscanf(argp+2, "%dx%d", &ptwidth, &ptheight)
374  == 2)
375  ptsize = TRUE;
376  else {
377  fprintf(stderr,"Incorrect size specified with -s\n");
378  return 1;
379  }
380  }
381  break;
382  case 'b':
383  calc_bbox = !calc_bbox;
384  break;
385  case 'd':
386  debug = !debug;
387  break;
388  case 'q':
389  quiet = !quiet;
390  break;
391  case 'g':
392  if (argp[2])
393  strcpy(gsname, argp+2);
394  else {
395  fprintf(stderr,"Missing Ghostscript command for -g\n");
396  return 1;
397  }
398  break;
399  case 't':
400  if (got_op) {
401  fprintf(stderr,"Can't select two operations");
402  return 1;
403  }
404  if (argp[2] && argp[2]=='4') {
405  op = TIFF4;
406  got_op = TRUE;
407  }
408  else if (argp[2] && argp[2]=='6' && argp[3] && toupper(argp[3])=='U') {
409  op = TIFF6U;
410  got_op = TRUE;
411  }
412  else if (argp[2] && argp[2]=='6' && argp[3] && toupper(argp[3])=='P') {
413  op = TIFF6P;
414  got_op = TRUE;
415  }
416  else if (argp[2] && toupper(argp[2])=='G') {
417  op = TIFFGS;
418  got_op = TRUE;
419  }
420  else {
421  fprintf(stderr,"Missing TIFF type or device name for -t\n");
422  return 1;
423  }
424  break;
425  case 'i':
426  if (got_op) {
427  fprintf(stderr,"Can't select two operations");
428  return 1;
429  }
430  op = INTERCHANGE;
431  got_op = TRUE;
432  break;
433  case 'z':
434  if (argp[2])
435  strcpy(devname, argp+2);
436  break;
437  case 'c':
438  if (got_op) {
439  fprintf(stderr,"Can't select two operations");
440  return 1;
441  }
442  op = COPY;
443  got_op = TRUE;
444  break;
445  case 'w':
446  if (got_op) {
447  fprintf(stderr,"Can't select two operations");
448  return 1;
449  }
450  op = WMF;
451  got_op = TRUE;
452  break;
453  case 'u':
454  if (got_op) {
455  fprintf(stderr,"Can't select two operations");
456  return 1;
457  }
458  op = USER;
459  got_op = TRUE;
460  if (argp[2])
461  strcpy(upname, argp+2);
462  else {
463  fprintf(stderr,"Missing input filename for -u\n");
464  return 1;
465  }
466  break;
467  case 'p':
468  if (got_op) {
469  fprintf(stderr,"Can't select two operations");
470  return 1;
471  }
472  op = EXTRACTPS;
473  got_op = TRUE;
474  break;
475  case 'v':
476  if (got_op) {
477  fprintf(stderr,"Can't select two operations");
478  return 1;
479  }
480  op = EXTRACTPRE;
481  got_op = TRUE;
482  break;
483  default:
484  fprintf(stderr,"Unknown option %s\n", argp);
485  return 1;
486  }
487  }
488  else {
489  /* input filename */
490  if (*iname) {
491  fprintf(stderr,"Only one input file permitted\n");
492  return 1;
493  }
494  strcpy(iname, argp);
495  }
496  }
497  option.xdpi = option.ydpi = resolution;
498  if (*iname == '\0') {
499  fprintf(stderr, "No input file specified");
500  return 1;
501  }
502  if (!got_op) {
503  fprintf(stderr, "No operation specified");
504  return 1;
505  }
506  return 0;
507 }
508 
509 void
510 do_help(void)
511 {
512  fprintf(stderr,"Usage: epstool [option] operation filename\n");
513  fprintf(stderr," Copyright (C) 1995-2000, Ghostgum Software Pty Ltd. All rights reserved.\n");
514  fprintf(stderr," Version: %s\n", szVersion);
515  fprintf(stderr," Options:\n");
516  fprintf(stderr," -b Calculate BoundingBox from image\n");
517  fprintf(stderr," -gcommand Ghostscript command\n");
518  fprintf(stderr," -nnumber Page number to extract\n");
519  fprintf(stderr," -ofilename Output filename\n");
520  fprintf(stderr," -q Quiet (no messages)\n");
521  fprintf(stderr," -rnumber Preview resolution in dpi\n");
522  fprintf(stderr," -sWIDTHxHEIGHT Size of page used with -b\n");
523  fprintf(stderr," -zdevice Ghostscript device name\n");
524  fprintf(stderr," Operations: (one only)\n");
525  fprintf(stderr," -i Add Interchange preview (EPSI)\n");
526  fprintf(stderr," -t4 Add TIFF4 preview (DOS EPS)\n");
527  fprintf(stderr," -t6u Add TIFF6 uncompressed (DOS EPS)\n");
528  fprintf(stderr," -t6p Add TIFF6 packbits (DOS EPS)\n");
529  fprintf(stderr," -tg Add GS TIFF preview (DOS EPS)\n");
530  fprintf(stderr," -w Add WMF preview (DOS EPS)\n");
531  fprintf(stderr," -ufilename Add user supplied preview (DOS EPS)\n");
532  fprintf(stderr," -p Extract PostScript (DOS EPS)\n");
533  fprintf(stderr," -v Extract Preview (DOS EPS)\n");
534  fprintf(stderr," -c Copy without preview (use with -b)\n");
535 }
536 
537 char *err_msgs[] = {"", "No preview in input file", "Preview file is not TIFF or Windows Metafile", ""};
538 
539 void
540 gserror(UINT id, char *str, UINT icon, int sound)
541 {
542  fprintf(stderr, "%s %s\n", err_msgs[id], str ? str : "");
543 }
544 
545 /* Create and open a scratch file with a given name prefix. */
546 /* Write the actual file name at fname. */
547 FILE *
548 gp_open_scratch_file(const char *prefix, char *fname, const char *mode)
549 { char *temp;
550  if ( (temp = getenv("TEMP")) == NULL )
551 #if defined(UNIX) || defined(__UNIX) || defined(__unix)
552  strcpy(fname, "/tmp");
553 #else
555 #endif
556  else
557  strcpy(fname, temp);
558 
559  /* Prevent X's in path from being converted by mktemp. */
560  for ( temp = fname; *temp; temp++ ) {
561  *temp = (char)tolower(*temp);
562  if (*temp == '/')
563  *temp = DIRSEP;
564  }
565  if ( strlen(fname) && (fname[strlen(fname)-1] != DIRSEP ) ) {
566  fname[strlen(fname)+1] = '\0';
567  fname[strlen(fname)] = DIRSEP;
568  }
569 
570  strcat(fname, prefix);
571  strcat(fname, "XXXXXX");
572  mktemp(fname);
573  return fopen(fname, mode);
574 }
575 
576 char *
577 gs_getcwd(char *dirname, int size)
578 {
579 #ifdef __EMX__
580  return _getcwd2(dirname, size);
581 #else
582  return getcwd(dirname, size);
583 #endif
584 }
585 
586 
587 void pserror(char *str)
588 {
589  fputs(str, stderr);
590 }
591 
592 
593 
594 /* general purpose read file into memory */
595 /* should work for files > 64k under MSDOS */
596 /* malloc's memory to hold file contents and returns pointer to this memory */
597 char GVFAR *
599 {
600  FILE *f;
601  LONG length, nread, count;
602  char GVFAR *base;
603  char GVHUGE *bp;
604 
605  if ( (f = fopen(fname, READBIN)) == (FILE *)NULL ) {
606  fprintf(stderr, "Can't open %s\n", fname);
607  return NULL;
608  }
609  fseek(f, 0, SEEK_END);
610  length = ftell(f);
611  fseek(f, 0, SEEK_SET);
612  if (length == 0) {
613  fprintf(stderr, "File %s is empty\n", fname);
614  }
615 #ifdef MSDOS /* I hate segmented architectures */
616  if ( (base = (char GVFAR *)farmalloc(length)) == (char *)NULL )
617 #else
618  if ( (base = (char GVFAR *)malloc(length)) == (char *)NULL )
619 #endif
620  {
621  fprintf(stderr, "Can't malloc memory to hold file %s\n", fname);
622  fclose(f);
623  return NULL;
624  }
625  bp = base;
626  while (length > 0) {
627 #ifdef MSDOS
628  /* get smaller of 16k, length, remaining bytes in segment */
629  count = min( min(16384, length), (DWORD)(65536UL-((WORD)(bp))) );
630 #else
631  count = length;
632 #endif
633  nread = fread(bp, 1, (int)count, f);
634  if (nread == 0) {
635  fprintf(stderr, "Can't read file %s\n", fname);
636  fclose(f);
637  free(base);
638  return NULL;
639  }
640  length -= nread;
641  bp += nread;
642  }
643  fclose(f);
644  return base;
645 }
646 
647 BOOL
649 {
650  LPBITMAPFILE pbmf;
651 
652  /* extract some info about bitmap */
653  pbmf = (LPBITMAPFILE)read_file(bmpname);
654  if (pbmf == NULL)
655  return FALSE;
656  switch (*(char *)(pbmf)) {
657  case 'B': /* BMP format */
658  bitmap_pbmi = (LPBITMAP2)( (char *)pbmf + sizeof(BITMAPFILE) );
659  break;
660  case 'P': /* PBMPLUS format */
661  bitmap_pbmi = (LPBITMAP2)(pbmf); /* a KLUDGE */
662  break;
663  default:
664  fprintf(stderr,"Unknown bitmap format\n");
665  return FALSE;
666  }
667  return TRUE;
668 }
669 
670 
671 /* Copy the header to file f */
672 /* change first line to EPSF if needed */
673 void
675 {
676  char text[PSLINELENGTH];
677  char *comment;
678  BOOL pages_written = FALSE;
679  long position;
680 
683  if (doc->epsf)
684  fputs(text,f);
685  else {
686  switch(text[11]) {
687  case '1':
688  fputs("%!PS-Adobe-1.0 EPSF-1.0\r\n",f);
689  break;
690  case '2':
691  fputs("%!PS-Adobe-2.0 EPSF-2.0\r\n",f);
692  break;
693  default:
694  fputs("%!PS-Adobe-3.0 EPSF-3.0\r\n",f);
695  }
696  }
698  while ( (comment = pscopyuntil(psfile.file, f, position,
699  doc->endheader, "%%Pages:")) != (char *)NULL ) {
701  if (pages_written) {
702  free(comment);
703  continue;
704  }
705  fprintf(f, "%%%%Pages: 1\r\n");
706  pages_written = TRUE;
707  free(comment);
708  }
709 }
710 
711 /* Copy the selected page and trailer to file f */
712 void
714 {
715  char *comment;
716  int i;
717  long position;
718 
719  /* don't copy preview because we might be adding our own */
723 
724  /* map page number to zero based index */
725  if (doc->pageorder == DESCEND)
726  i = doc->numpages - page;
727  else
728  i = page - 1;
730  doc->pages[i].end, "%%Page:");
731  fprintf(f, "%%%%Page: %s %d\r\n",
732  doc->pages[i].label, page++);
733  free(comment);
734  pscopyuntil(psfile.file, f, -1, doc->pages[i].end, NULL);
735 
737  while ( (comment = pscopyuntil(psfile.file, f, position,
738  doc->endtrailer, "%%Pages:")) != (char *)NULL ) {
740  free(comment);
741  }
742 }
743 
744 /* Copy the header to file f */
745 /* change bbox line if present, or add bbox line */
746 void
748 {
749  char text[PSLINELENGTH];
750  char *comment;
751  BOOL bbox_written = FALSE;
752  long position;
753  PSDOC *doc = psfile.doc;
754 
756  /* make sure first line is EPS */
758  if (doc->epsf)
759  fputs(text,f);
760  else {
761  switch(text[11]) {
762  case '1':
763  fputs("%!PS-Adobe-1.0 EPSF-1.0\r\n",f);
764  break;
765  case '2':
766  fputs("%!PS-Adobe-2.0 EPSF-2.0\r\n",f);
767  break;
768  default:
769  fputs("%!PS-Adobe-3.0 EPSF-3.0\r\n",f);
770  }
771  }
773  if (!( (doc->boundingbox[LLX]==0) && (doc->boundingbox[LLY]==0)
774  && (doc->boundingbox[URX]==0) && (doc->boundingbox[URY]==0) )) {
775  /* BoundingBox was in original file, replace it */
777  while ( (comment = pscopyuntil(psfile.file, f, position,
778  doc->endheader, "%%BoundingBox:")) != (char *)NULL ) {
780  if (bbox_written) {
781  free(comment);
782  continue;
783  }
784  fprintf(f, "%%%%BoundingBox: %d %d %d %d\r\n",
785  bbox.llx, bbox.lly, bbox.urx, bbox.ury);
786  bbox_written = TRUE;
787  free(comment);
788  }
789  }
790  else {
791  /* BoundingBox was not in original file, add it */
793  fputs(text,f);
794  fprintf(f, "%%%%BoundingBox: %d %d %d %d\r\n",
795  bbox.llx, bbox.lly, bbox.urx, bbox.ury);
798  free(comment);
799  }
800 }
801 
802 /* copy psfile, updating %%BoundingBox */
803 int
805 {
806 char epsname[MAXSTR];
807 FILE *epsfile;
808 PREBMAP prebmap;
809 PSBBOX devbbox; /* in pixel units */
810 LPBITMAP2 pbm;
811 int code;
812  if ( (pbm = get_bitmap()) == (LPBITMAP2)NULL) {
813  return 1;
814  }
815  if (*(char *)pbm == 'P')
816  code = scan_pbmplus(&prebmap, pbm);
817  else
818  code = scan_dib(&prebmap, pbm);
819  if (code) {
820  release_bitmap();
821  return code;
822  }
823 
824  strcpy(epsname, oname);
825  if (*epsname!='\0')
826  epsfile = fopen(epsname,"wb");
827  else
828  epsfile = stdout;
829  if (epsfile == (FILE *)NULL) {
830  release_bitmap();
831  return 1;
832  }
833  if (calc_bbox) {
834  scan_bbox(&prebmap, &devbbox);
835  if (devbbox.valid) {
836  /* copy to global bbox as if obtained by PS to EPS */
837  bbox.llx = (int)(devbbox.llx * 72.0 / option.xdpi - 0.5);
838  bbox.lly = (int)(devbbox.lly * 72.0 / option.ydpi - 0.5);
839  bbox.urx = (int)(devbbox.urx * 72.0 / option.xdpi + 1.5);
840  bbox.ury = (int)(devbbox.ury * 72.0 / option.ydpi + 1.5);
841  bbox.valid = TRUE;
842  }
843 
844 
845 
846  copy_eps_bbox_header(epsfile); /* adjust %%BoundingBox: comment */
847 
849  }
850  else {
852  }
853  if (*epsname!='\0')
854  fclose(epsfile);
855  release_bitmap();
856  return 0;
857 }
bp
Definition: action.c:1035
int code
Definition: aftopl.c:52
static char * dirname(mrb_state *mrb, const char *path)
Definition: apilist.c:64
#define width(a)
Definition: aptex-macros.h:198
#define count(a)
Definition: aptex-macros.h:781
#define height(a)
Definition: aptex-macros.h:200
#define mode
Definition: aptex-macros.h:510
#define MAXSTR
Definition: cmscgats.c:34
BOOL
Definition: dd.h:100
@ FALSE
Definition: dd.h:101
@ TRUE
Definition: dd.h:102
#define free(a)
Definition: decNumber.cpp:310
#define fopen
Definition: xxstdio.h:21
#define fread
Definition: xxstdio.h:25
#define fseek
Definition: xxstdio.h:30
#define fgets
Definition: xxstdio.h:29
#define ftell
Definition: xxstdio.h:31
#define WRITEBIN
Definition: dvips.h:95
#define mktemp
Definition: dvi2xx.c:3706
@ URX
Definition: dvi2xx.c:3545
@ URY
Definition: dvi2xx.c:3546
@ LLX
Definition: dvi2xx.c:3543
@ LLY
Definition: dvi2xx.c:3544
int sscanf()
char * strcpy()
char * temp
Definition: dvidvi.c:137
#define READBIN
Definition: dvidvi.c:103
char gsname[MAXSTR]
Definition: epstool.c:26
void do_help(void)
Definition: epstool.c:510
int ptheight
Definition: epstool.c:39
int main(int argc, char *argv[])
Definition: epstool.c:90
void play_sound(int i)
Definition: epstool.c:77
char * psfile_name(PSFILE *psf)
Definition: epstool.c:82
#define TIFF4
Definition: epstool.c:44
#define WMF
Definition: epstool.c:49
char GVFAR * read_file(char *fname)
Definition: epstool.c:598
#define TIFF6P
Definition: epstool.c:46
BOOL quiet
Definition: epstool.c:36
int resolution
Definition: epstool.c:31
void gserror(UINT id, char *str, UINT icon, int sound)
Definition: epstool.c:540
BOOL ptsize
Definition: epstool.c:37
PSDOC * doc
Definition: epstool.c:53
BOOL load_bitmap(void)
Definition: epstool.c:648
LPBITMAP2 get_bitmap(void)
Definition: epstool.c:70
void pserror(char *str)
Definition: epstool.c:587
void copy_eps_bbox_header(FILE *f)
Definition: epstool.c:747
#define TIFF6U
Definition: epstool.c:45
char szVersion[]
Definition: epstool.c:21
int ptwidth
Definition: epstool.c:38
void psfile_extract_header(FILE *f)
Definition: epstool.c:674
BOOL debug
Definition: epstool.c:35
char * err_msgs[]
Definition: epstool.c:537
char * gs_getcwd(char *dirname, int size)
Definition: epstool.c:577
#define USER
Definition: epstool.c:48
char bmpname[MAXSTR]
Definition: epstool.c:27
int make_eps_copy(void)
Definition: epstool.c:804
char upname[MAXSTR]
Definition: epstool.c:25
#define TIFFGS
Definition: epstool.c:47
void psfile_extract_page(FILE *f, int page)
Definition: epstool.c:713
#define COPY
Definition: epstool.c:50
#define EXTRACTPS
Definition: epstool.c:41
int scan_args(int argc, char *argv[])
Definition: epstool.c:333
#define EXTRACTPRE
Definition: epstool.c:42
char devname[MAXSTR]
Definition: epstool.c:28
LPBITMAP2 bitmap_pbmi
Definition: epstool.c:57
char szScratch[]
Definition: epstool.c:29
BOOL got_op
Definition: epstool.c:34
char GVFAR * bitmap_base
Definition: epstool.c:56
char iname[MAXSTR]
Definition: epstool.c:23
int extract_section(void)
Definition: epstool.c:132
OPTION option
Definition: epstool.c:55
char oname[MAXSTR]
Definition: epstool.c:24
char szAppName[]
Definition: epstool.c:30
int page
Definition: epstool.c:32
BOOL calc_bbox
Definition: epstool.c:33
int add_preview(void)
Definition: epstool.c:144
#define INTERCHANGE
Definition: epstool.c:43
FILE * gp_open_scratch_file(const char *prefix, char *fname, const char *mode)
Definition: epstool.c:548
PSFILE psfile
Definition: epstool.c:54
void release_bitmap(void)
Definition: epstool.c:74
#define IDM_EXTRACTPS
Definition: epstool.h:178
#define IDM_MAKEEPST6U
Definition: epstool.h:181
#define IDM_EXTRACTPRE
Definition: epstool.h:179
#define IDM_MAKEEPST4
Definition: epstool.h:180
#define IDM_MAKEEPST6P
Definition: epstool.h:182
mpz_t * f
Definition: gen-fib.c:34
int base
Definition: gsftopk.c:1502
int make_eps_metafile(BOOL calc_bbox)
Definition: gvceps.c:2374
int make_eps_tiff(int type, BOOL calc_bbox)
Definition: gvceps.c:1401
int make_eps_user(void)
Definition: gvceps.c:1896
void extract_doseps(int command)
Definition: gvceps.c:248
int scan_dib(PREBMAP *ppbmap, LPBITMAP2 pbm)
Definition: gvceps.c:478
int scan_pbmplus(PREBMAP *ppbmap, LPBITMAP2 pbm)
Definition: gvceps.c:411
int make_eps_interchange(BOOL calc_bbox)
Definition: gvceps.c:1675
void scan_bbox(PREBMAP *pprebmap, PSBBOX *psbbox)
Definition: gvceps.c:1723
struct tagBITMAPFILE BITMAPFILE
BITMAP2 GVFAR * LPBITMAP2
Definition: gvceps.h:73
BITMAPFILE GVFAR * LPBITMAPFILE
Definition: gvceps.h:83
char comment[255+1]
Definition: hbf2gf.c:350
#define SEEK_SET
Definition: jmemansi.c:26
#define NULL
Definition: ftobjs.h:61
small capitals from c petite p scientific i
Definition: afcover.h:80
#define SEEK_END
Definition: ftzconf.h:251
char * getenv()
int atoi(const char *)
#define O_BINARY
Definition: config.h:393
#define unlink(file)
Definition: config.h:413
#define DIRSEP
Definition: paths.h:75
#define fclose
Definition: debug.h:100
#define fileno
Definition: win32lib.h:72
#define getcwd
Definition: win32lib.h:77
#define system(p)
Definition: win32lib.h:269
#define fputs
Definition: mendex.h:67
#define fprintf
Definition: mendex.h:64
#define length(c)
Definition: ctangleboot.c:65
#define malloc
Definition: alloca.c:91
char * argp
Definition: fixwrites.c:8
char tempfile[100]
Definition: splitup.c:51
int setmode()
unsigned short WORD
Definition: common.h:143
long LONG
Definition: common.h:146
unsigned int UINT
Definition: common.h:145
#define sprintf
Definition: snprintf.c:44
unsigned int DWORD
Definition: mktexlib.h:49
#define min(a, b)
Definition: pbmplus.h:223
char * fname
Definition: plain2.c:121
static int size
Definition: ppmlabel.c:24
type_C toupper(type_C)
#define tolower(ch)
Definition: utype.h:137
#define str(s)
Definition: sh6.c:399
Definition: nsfix.c:44
t2b llx
Definition: nsfix.c:45
t2b lly
Definition: nsfix.c:46
t2b urx
Definition: nsfix.c:47
t2b ury
Definition: nsfix.c:48
Definition: inftrees.h:24
Definition: ps.h:63
long beginsetup
Definition: ps.h:76
long beginheader
Definition: ps.h:68
long beginprolog
Definition: ps.h:74
struct page * pages
Definition: ps.h:89
long endsetup
Definition: ps.h:76
long endtrailer
Definition: ps.h:78
int pageorder
Definition: ps.h:67
long endpreview
Definition: ps.h:70
long endheader
Definition: ps.h:68
int boundingbox[4]
Definition: ps.h:80
long begindefaults
Definition: ps.h:72
long enddefaults
Definition: ps.h:72
int epsf
Definition: ps.h:64
unsigned int numpages
Definition: ps.h:88
long begintrailer
Definition: ps.h:78
long beginpreview
Definition: ps.h:70
long endprolog
Definition: ps.h:74
struct documentmedia * default_page_media
Definition: ps.h:86
int height
Definition: ps.h:104
int width
Definition: ps.h:104
Definition: sh.h:1226
Definition: getopt.h:95
Definition: mendex.h:14
long begin
Definition: ps.h:98
char * label
Definition: ps.h:94
long end
Definition: ps.h:98
int llx
Definition: gvceps.h:115
int urx
Definition: gvceps.h:117
int valid
Definition: gvceps.h:119
int ury
Definition: gvceps.h:118
int lly
Definition: gvceps.h:116
char name[MAXSTR]
Definition: epstool.h:153
FILE * file
Definition: epstool.h:154
PSDOC * doc
Definition: epstool.h:151
#define FILE
Definition: t1stdio.h:34
*job_name strlen((char *) job_name) - 4)
return() int(((double) *(font_tbl[cur_fnt].wtbl+(int)(*(font_tbl[cur_fnt].char_wi+(int)(ch - font_tbl[cur_fnt].char_f)% 256)))/(double)(1L<< 20)) *(double) font_tbl[cur_fnt].scale)
char * pscopyuntil(FILE *from, FILE *to, long begin, long end, char *comment)
Definition: ps.c:1550
struct document * psscan(FILE *file)
Definition: ps.c:267
void psfree(struct document *doc)
Definition: ps.c:1164
#define PSLINELENGTH
Definition: ps.h:47
@ DESCEND
Definition: ps.h:45
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269
#define position
Definition: xmlparse.c:605