\n",groupid); /* PolyLine */
fprintf(fp, " \n", kludgex, kludgey);
fprintf(fp, "> #end curve PL\n");
fprintf(fp, " >\n",groupid,pgroup); /*Driver exit */
members=0;
groupid++; /* start a new group if pen attributes were changed/called */
} else if(members != 0){
fprintf(fp, " >\n",groupid,pgroup); /*Driver exit */
members=0;
groupid++; /* start a new group if pen attributes were changed/called */
}
return (0);
}
/******************************************************************************/
/* MIF_exit do a flush and close the output file if necessary. */
static int MIF_exit(void) {
closeline(); /* close Polyline line if it open */
/*
Define the group for all the objects to make the chart easier to manipulate
after it is imported into FrameMaker
*/
groupem();
fprintf(fp, " >\n",pgroup); /*Page Clear*/
fprintf(fp, "> #end of Page\n");
fprintf(fp, "# End of MIFFile\n");
pgroup=groupid; /* page id */
groupid++; /* increment group id */
drawn = 0;
points = 0;
if (fp != stdout && fp != stderr ){
fflush(fp);
if(vdevice.writestoprocess == 2){
pclose(fp);
}else{
fclose(fp);
}
}
return (0);
}
/******************************************************************************/
/* MIF_draw draw to an x, y point. */
/* Note: (0, 0) is defined as the top left of the window in MIF (easy to forget). */
static int MIF_draw(int x, int y){
float realx, realy;
float realx0, realy0;
realx = (x)/MIFTORAS+borderx;
realy = (vdevice.sizeSy -y)/MIFTORAS+bordery;
realx0 = (vdevice.cpVx)/MIFTORAS+borderx;
realy0 = (vdevice.sizeSy - vdevice.cpVy)/MIFTORAS+bordery;
if (pslstx != vdevice.cpVx || pslsty != vdevice.cpVy || points >= MAXPOINTS ){
closeline(); /* close line if required */
openline(); /* start line */
fprintf(fp, " \n", realx0, realy0);
kludgex=realx0;
kludgey=realy0;
points = 1;
}
openline(); /* start line if required */
fprintf(fp, "
\n", realx, realy);
points++;
pslstx = x;
pslsty = y;
drawn = 1;
return (0);
}
/******************************************************************************/
/* MIF_clear flush the current page without resetting the graphics state */
static int MIF_clear(void) {
closeline(); /* close line if required */
if (drawn)
{
groupem();
fprintf(fp, " >\n",pgroup); /*Page Clear*/
fprintf(fp,"> #end of Page\n");
fprintf(fp,"\n",MIFXSIZE0,MIFYSIZE0);
pgroup=groupid; /* page id */
groupid++; /* increment group id */
}
drawn = 0;
points = 0;
return(0);
}
/******************************************************************************/
/* MIF_color change the color of the pen
* kludged so negative value sets raster line width
*/
static int MIF_color(int col) {
closeline(); /* close line if required */
if ( col < 0 )
{
curwid = abs(col);
} else {
curcol4= col % CMAPSIZE; /* MIF 4.0 allows user-defined colors */
col=col % MIN(256,CMAPSIZE); /* following assumes result is 0 thru 255 */
curcol = cmap[col % 8]; /* MIF 3.0 only has colors 0 thru 7 */
if(MIFVERSION == 4 ){
curpat = col/CMAPSIZE; /* MIF 4.0 does not need patterns; it has colors*/
}else{
curpat = col/16; /* MIF 3.0 has patterns 0 thru 15 */
}
}
groupem();
return(0);
}
/******************************************************************************/
static int MIF_setlw(int width){ /* Set line width */
closeline(); /* close line if required */
curwid = abs(width);
groupem();
return(0);
}
/******************************************************************************/
/* MIF_font load in small or large - could be improved. */
static int MIF_font(char *font) {
if (strcmp(font, "small") == 0) {
vdevice.hwidth = 12.0/72.0/.03937*MIFTORAS;
vdevice.hheight = vdevice.hwidth * 2.2;
} else if (strcmp(font, "large") == 0) {
vdevice.hheight = 55.0/72.0/.03937*MIFTORAS;
vdevice.hwidth = vdevice.hheight / 4.5;
} else
return(0);
return(1);
}
/******************************************************************************/
/* MIF_string output a string. */
static int MIF_string(char *s) {
float realy0, realx0;
char c;
int i;
realy0 = (vdevice.sizeSy - vdevice.cpVy)/MIFTORAS+bordery;
realx0 = (vdevice.cpVx)/MIFTORAS+bordery;
closeline(); /* close line if required */
fprintf(fp,"\n",groupid); /* TextLine */
members++;
fprintf(fp, " \n",curpat);
fprintf(fp, " \n",realx0, realy0);
kludgex=realx0;
kludgey=realy0;
fprintf(fp," \n");
fprintf(fp," \n",vdevice.hheight/MIFTORAS);
fprintf(fp," \n");
fprintf(fp," \n");
fprintf(fp," \n",curcol);
fprintf(fp," > # end Font \n");
fprintf(fp, "':
fprintf(fp, "\\>");
break;
case '\'':
fprintf(fp, "\\q");
break;
default:
fprintf(fp, "%c",c);
}
}
fprintf(fp,"'> \n");
fprintf(fp,"> # end TextLine [%s] \n",s);
drawn = 1;
pslstx = pslsty = -1;
return(0);
}
/******************************************************************************/
/* MIF_char output a character */
static int MIF_char(char c) {
char s[2];
s[0] = c; s[1]='\0';
MIF_string(s);
return(0);
}
/******************************************************************************/
/* fill a polygon */
static int MIF_fill(int n, int x[], int y[]) {
int i;
float realx, realy ;
closeline(); /* close line if required */
fprintf(fp, "\n");
fprintf(fp, " \n",groupid); /* Polygon */
members++;
fprintf(fp, " \n",vdevice.sizeX*curwid/10000.0/MIFTORAS);
fprintf(fp, " \n",curcol);
printcolor(curcol4);
fprintf(fp, " \n",curpat);
kludgex = (x[0])/MIFTORAS+borderx;
kludgey = (vdevice.sizeSy -y[0])/MIFTORAS+bordery;
for (i = 0; i < n; i++)
{
realx = (x[i])/MIFTORAS+borderx;
realy = (vdevice.sizeSy -y[i])/MIFTORAS+bordery;
fprintf(fp, " \n", realx, realy);
}
fprintf(fp, "> #end of Polygon \n");
vdevice.cpVx = x[n - 1];
vdevice.cpVy = y[n - 1];
pslstx = pslsty = -1; /* fill destroys current path */
drawn = 1;
return(0);
}
/******************************************************************************/
/* no operations - do nothing but return -1 */
static int noop(void) { return(-1); }
static int noop2(int *x, int *y) { return(-1); }
/******************************************************************************/
static DevEntry mifdev = {
"mif", /* name of device */
"large", /* name of large font */
"small", /* name of small font */
noop, /* Set drawing in back buffer */
MIF_char, /* Draw a hardware character */
noop, /* Check if a key was hit */
MIF_clear, /* Clear the screen to current color */
MIF_color, /* Set current color */
MIF_draw, /* Draw a line */
MIF_exit, /* Exit graphics */
MIF_fill, /* Fill a polygon */
MIF_font, /* Set hardware font */
noop, /* Set drawing in front buffer */
noop, /* Wait for and get the next key hit */
MIF_init, /* Initialize the device */
noop2, /* Get mouse/cross hair position */
MIF_mapcolor,/* Set color indices */
MIF_setlw, /* Set line width */
MIF_string, /* Draw a hardware string */
noop, /* Swap front and back buffers */
noop /* Syncronize the display */
};
/******************************************************************************/
/* _MIF_devcpy copy the mif device into vdevice.dev. */
int _MIF_devcpy(void) {
/* - if you don't have structure assignment ...
char *dev, *tdev, *edev;
dev = (char *)&mifdev;
tdev = (char *)&vdevice.dev;
edev = dev + sizeof(Device);
while (dev != edev)
*tdev++ = *dev++;
*/
vdevice.dev = mifdev;
MIFVERSION=3;
vdevice.depth = 3;
return(0);
}
/******************************************************************************/
/* _MIF4_devcpy copy the mif device into vdevice.dev. */
int _MIF4_devcpy(void) {
/* - if you don't have structure assignment ...
char *dev, *tdev, *edev;
dev = (char *)&mifdev;
tdev = (char *)&vdevice.dev;
edev = dev + sizeof(Device);
while (dev != edev)
*tdev++ = *dev++;
*/
vdevice.dev = mifdev;
MIFVERSION=4;
vdevice.depth = 8;
return(0);
}
/******************************************************************************/