		Transfig-2.1.8 EPS object パッチ

  このパッチは transfig-2.1.8 において、xfig で読み込んだ EPS ファイル
の BoundingBox の値がおかしい場合、あるいは PS ファイルであった場合でも
正常に出力できるようにする非公式パッチです。
  同様のパッチの当たった xfig と併用すると、xfig のキャンバスに一つのオ
ブジェクトとして PS ファイルを EPS ファイルと同様に読み込んで、PS ファ
イルに出力したり印刷したり出来るようになります。
  PS ファイルを読み込んだ時は EPS の BoundingBox ヘッダーがありませんの
で、PS 図形を A4 または Letter size と見倣して処理します。A4 か Letter
size かの選択は、fig2dev/fig2dev.h の #define ASSUME_A4(LETTER) を変更
してください。

						1994.10.23  杉本敏則
					   toshi@arcadia.genny.or.jp
					   pfd01107@niftyserve.or.jp

diff -cr transfig.2.1.8/patchlevel.h transfig.2.1.8-eps/patchlevel.h
*** transfig.2.1.8/patchlevel.h	Wed Aug 11 02:20:24 1993
--- transfig.2.1.8-eps/patchlevel.h	Sat Oct 22 19:19:52 1994
***************
*** 1,2 ****
  #define VERSION		"2.1.8"
! #define PATCHLEVEL	"0 (J)"
--- 1,2 ----
  #define VERSION		"2.1.8"
! #define PATCHLEVEL	"0 (J/EPS)"
diff -cr transfig.2.1.8/fig2dev/fig2dev.h transfig.2.1.8-eps/fig2dev/fig2dev.h
*** transfig.2.1.8/fig2dev/fig2dev.h	Wed Jul  7 00:45:30 1993
--- transfig.2.1.8-eps/fig2dev/fig2dev.h	Sat Oct 22 19:19:52 1994
***************
*** 36,41 ****
--- 36,55 ----
  
  #define round(x)	((int) ((x) + ((x >= 0)? 0.5: -0.5)))
  
+ #define ASSUME_A4        /* A4 or LETTER */
+                          /* Assume the letter size or ISO A4 size 
+ 			    when bad value of EPS bounding box */
+ #ifdef  ASSUME_LETTER
+ #define ASSUME_PAPER    "Letter"
+ #define ASSUME_X        612
+ #define ASSUME_Y        792
+ #endif
+ #ifdef  ASSUME_A4
+ #define ASSUME_PAPER    "A4"
+ #define ASSUME_X        595
+ #define ASSUME_Y        842
+ #endif
+ 
  /* 
   * Device driver interface structure
   */
diff -cr transfig.2.1.8/fig2dev/read.c transfig.2.1.8-eps/fig2dev/read.c
*** transfig.2.1.8/fig2dev/read.c	Tue May 11 00:49:12 1993
--- transfig.2.1.8-eps/fig2dev/read.c	Sat Oct 22 19:55:28 1994
***************
*** 36,41 ****
--- 36,42 ----
  #include <errno.h>
  #include "alloc.h"
  #include "object.h"
+ #include "fig2dev.h"
  
  #if defined(hpux) || defined(SYSV)
  #define bzero(s,n) memset((s),'\0',(n))
***************
*** 771,777 ****
      int             n;
      int             flag;
      char            buf[300];
!     int             llx, lly, urx, ury;
      FILE           *epsf;
      register unsigned char *last;
      double          fllx, flly, furx, fury;
--- 772,778 ----
      int             n;
      int             flag;
      char            buf[300];
!     int             llx, lly, urx, ury, i, bad_eps;
      FILE           *epsf;
      register unsigned char *last;
      double          fllx, flly, furx, fury;
***************
*** 781,803 ****
  	put_msg("Cannot open file: %s", eps->file);
  	return 0;
      }
!     while (fgets(buf, 300, epsf) != NULL) {
! 	lower(buf);
! 	if (!strncmp(buf, "%%boundingbox", 13)) {
! 	    if (sscanf(buf, "%%%%boundingbox: %lf %lf %lf %lf",
! 		       &fllx, &flly, &furx, &fury) < 4) {
! 		put_msg("Bad EPS bitmap file: %s", eps->file);
! 		fclose(epsf);
! 		return 0;
! 	    }
!           llx= floor(fllx);
!           lly= floor(flly);
!           urx= ceil(furx);
!           ury= ceil(fury);
! 	    break;
  	}
      }
! 
      eps->hw_ratio = (float) (ury - lly) / (float) (urx - llx);
  
      eps->bitmap = NULL;
--- 782,819 ----
  	put_msg("Cannot open file: %s", eps->file);
  	return 0;
      }
!     bad_eps = 1;
!     for ( i = 0; i < 100; i++ ) {
!       if (fgets(buf, 300, epsf) == NULL) {
! 	break;
!       }
!       lower(buf);
!       if (!strncmp(buf, "%%boundingbox", 13)) {
! 	if (sscanf(buf, "%%%%boundingbox: %lf %lf %lf %lf",
! 		   &fllx, &flly, &furx, &fury) == 4 ) {
! 	  bad_eps = 0;
  	}
+ 	llx= floor(fllx);
+ 	lly= floor(flly);
+ 	urx= ceil(furx);
+ 	ury= ceil(fury);
+ 	break;
+       }
      }
!     if (bad_eps) {
!       put_msg("Bad EPS bitmap file: %s ", eps->file);
!       /* fclose(epsf);
! 	 return 0; */
!     }
!     if ((ury - lly <= 0 || urx - llx <= 0) || bad_eps) {
!       put_msg("Bad values in EPS bitmap bounding box (%d %d %d %d)",
! 	      llx, lly, urx, ury );
!       llx = lly = 0;
!       urx = ASSUME_X;
!       ury = ASSUME_Y;
!       put_msg("Assumed to %s size (%d %d %d %d)",
! 	      ASSUME_PAPER, llx, lly, urx, ury);
!     }
      eps->hw_ratio = (float) (ury - lly) / (float) (urx - llx);
  
      eps->bitmap = NULL;
***************
*** 808,816 ****
      eps->pix_width = 0;
      eps->pix_height = 0;
  
-     if (ury - lly <= 0 || urx - llx <= 0) {
- 	put_msg("Bad values in EPS bitmap bounding box");
-     }
      bitmapz = 0;
  
      /* look for a preview bitmap */
--- 824,829 ----
diff -cr transfig.2.1.8/fig2dev/dev/genps.c transfig.2.1.8-eps/fig2dev/dev/genps.c
*** transfig.2.1.8/fig2dev/dev/genps.c	Sat Oct  2 03:13:11 1993
--- transfig.2.1.8-eps/fig2dev/dev/genps.c	Sat Oct 22 20:06:22 1994
***************
*** 515,520 ****
--- 515,521 ----
  	{
  		int             dx, dy, rotation;
  		int		llx, lly, urx, ury;
+ 		int             bad_eps, i;
  		double          fllx, flly, furx, fury;
  
  		dx = l->points->next->next->x - l->points->x;
***************
*** 535,559 ****
  			fprintf (stderr, "Unable to open eps file: %s, error: (%d)\n",
  				l->eps->file, sys_errlist[errno],errno);
  			return;
! 		}
! 		while (fgets(buf, 512, epsf) != NULL) {
  		  lower(buf);
  		  if (!strncmp(buf, "%%boundingbox", 13)) {
! 			if (sscanf(buf, "%%%%boundingbox: %lf %lf %lf %lf",
! 					   &fllx, &flly, &furx, &fury) < 4) {
! 			  fprintf(stderr,"Bad EPS bitmap file: %s", l->eps->file);
! 			  fclose(epsf);
! 			  return;
! 			}
! 			llx= floor(fllx);
! 			lly= floor(flly);
! 			urx= ceil(furx);
! 			ury= ceil(fury);
! 			break;
  		  }
  		}
  		fclose(epsf);
! 
  		fprintf(tfp, "n gs\n");
  		if (((rotation == 90 || rotation == 270) && !l->eps->flipped) ||
  		    (rotation != 90 && rotation != 270 && l->eps->flipped)) {
--- 536,573 ----
  			fprintf (stderr, "Unable to open eps file: %s, error: (%d)\n",
  				l->eps->file, sys_errlist[errno],errno);
  			return;
! 		 }
! 		bad_eps = 1;
! 		for ( i = 0; i < 100; i++ ) {
! 		  if (fgets(buf, 300, epsf) == NULL) {
! 		    break;
! 		  }
  		  lower(buf);
  		  if (!strncmp(buf, "%%boundingbox", 13)) {
! 		    if (sscanf(buf, "%%%%boundingbox: %lf %lf %lf %lf",
! 			       &fllx, &flly, &furx, &fury) == 4) {
! 		      bad_eps = 0 ;
! 		    }
! 		    llx= floor(fllx);
! 		    lly= floor(flly);
! 		    urx= ceil(furx);
! 		    ury= ceil(fury);
! 		    break;
  		  }
  		}
  		fclose(epsf);
! 		if (bad_eps) {
! 		  put_msg("Bad EPS bitmap file: %s ", l->eps->file);
! 		}
! 		if ((ury - lly <= 0 || urx - llx <= 0) || bad_eps){
! 		  put_msg("Bad values in EPS bitmap bounding box (%d %d %d %d)",
! 			  llx, lly, urx, ury );
! 		  llx = lly = 0;
! 		  urx = ASSUME_X;
! 		  ury = ASSUME_Y;
! 		  put_msg("Assumed to %s size (%d %d %d %d)",
! 			  ASSUME_PAPER, llx, lly, urx, ury);
! 		}
  		fprintf(tfp, "n gs\n");
  		if (((rotation == 90 || rotation == 270) && !l->eps->flipped) ||
  		    (rotation != 90 && rotation != 270 && l->eps->flipped)) {
