#include #include #ifdef __STDC__ #define ARGS(alist) alist #else #define ARGS(alist) () #endif #define MAXWIDTH 4096 #define PageSideMargin 12 #define PageTopMargin 12 #define PageWidth 612 #define PageHeight 792 #define put_string nc=strlen(s); for(i=0;i MAXWIDTH || Height <= 0 || Height > MAXWIDTH) { fprintf(stderr, "\n%s: incorrect image size: %d x %d\n", ProgName, Width, Height); return 0; } if (Ncol <= 0 || Ncol > 256) { fprintf(stderr,"\n%s: wrong number of colors: %d\n", ProgName, Ncol); return 0; } /* F I N D R O T A T I O N A N G L E , S C A L E, T R A N S L A T I O N & B O U N D I N G B O X */ if (Width < Height) { Angle = 0.0; ScaleX = (float)(PageWidth - 2*PageSideMargin) / (float)(Width); ScaleY = (float)(PageHeight - 2*PageTopMargin) / (float)(Height); Scale = ScaleX < ScaleY ? ScaleX : ScaleY; ScaleX = Width*Scale; ScaleY = Height*Scale; DeltaX = PageWidth - (ScaleX + 2*PageSideMargin); if (DeltaX > 0.) DeltaX = 0.5*DeltaX + PageSideMargin; else DeltaX = PageSideMargin; DeltaY = PageHeight - (ScaleY + 2*PageTopMargin); if (DeltaY > 0.) DeltaY = 0.5*DeltaY + PageTopMargin; else DeltaY = PageTopMargin; Xmin = DeltaX; Ymin = DeltaY; Xmax = DeltaX + ScaleX; Ymax = DeltaY + ScaleY; }else{ Angle = 90.0; ScaleX = (float)(PageHeight - 2*PageTopMargin) / (float)(Width); ScaleY = (float)(PageWidth - 2*PageSideMargin) / (float)(Height); Scale = ScaleX < ScaleY ? ScaleX : ScaleY; ScaleX = Width*Scale; ScaleY = Height*Scale; DeltaX = PageHeight - (ScaleX + 2*PageTopMargin); if (DeltaX > 0.) DeltaX = 0.5*DeltaX + PageTopMargin; else DeltaX = PageTopMargin; DeltaY = PageWidth - (ScaleY + 2*PageSideMargin); if (DeltaY > 0.) DeltaY = 0.5*DeltaY + PageSideMargin; else DeltaY = PageSideMargin; Xmin = DeltaY; Ymin = DeltaX; Xmax = DeltaY + ScaleY; Ymax = DeltaX + ScaleX; DeltaY = -(DeltaY + ScaleY); } /* O U T P U T H E A D E R */ Nbyte = 0; sprintf(s,"%%!PS-Adobe-2.0 EPSF-2.0\n"); put_string; sprintf(s,"%%%%Title: %s\n",FileName); put_string; sprintf(s,"%%%%Creator: %s %s\n", ProgName, ProgVers); put_string; sprintf(s,"%%%%BoundingBox: %d %d %d %d\n", Xmin, Ymin, Xmax, Ymax); put_string; sprintf(s,"%%%%EndComments\n"); put_string; /* O U T P U T P O S T S C R I P T P R O G R A M M */ for (q=PostScript; *q; q++) { sprintf(s,"%s\n",*q); put_string; } /* O U T P U T I M A G E D A T A */ sprintf(s,"%.2f\n", Angle); put_string; sprintf(s,"%.2f %.2f\n", DeltaX, DeltaY); put_string; sprintf(s,"%.2f %.2f\n", ScaleX, ScaleY); put_string; sprintf(s,"%d %d\n", Width, Height); put_string; sprintf(s,"%d\n",Ncol); put_string; for (k=0; k