Additional freeing of device-dependent information for bug #419 and related bugs.

This commit is contained in:
Jim Monte 2019-12-15 01:17:04 -05:00
parent 5e29293a0d
commit b7d40636e5
6 changed files with 495 additions and 462 deletions

View File

@ -89,7 +89,8 @@ int GL_Init(void)
{ {
if (!cp_getvar("hcopyscale", CP_STRING, psscale, sizeof(psscale))) { if (!cp_getvar("hcopyscale", CP_STRING, psscale, sizeof(psscale))) {
scale = 1.0; scale = 1.0;
} else { }
else {
sscanf(psscale, "%lf", &scale); sscanf(psscale, "%lf", &scale);
if ((scale <= 0) || (scale > 10)) if ((scale <= 0) || (scale > 10))
scale = 1.0; scale = 1.0;
@ -106,20 +107,21 @@ int GL_Init(void)
dispdev->minx = (int)(XOFF * 1.0); dispdev->minx = (int)(XOFF * 1.0);
dispdev->miny = (int)(YOFF * 1.0); dispdev->miny = (int)(YOFF * 1.0);
return (0); return 0;
} }
/* devdep initially contains name of output file */ /* devdep initially contains name of output file */
int int GL_NewViewport(GRAPH *graph)
GL_NewViewport(GRAPH *graph)
{ {
hcopygraphid = graph->graphid; hcopygraphid = graph->graphid;
if ((plotfile = fopen((char*) graph->devdep, "w")) == NULL) { if ((plotfile = fopen((char*) graph->devdep, "w")) == NULL) {
perror((char*) graph->devdep); perror((char *) graph->devdep);
free(graph->devdep);
graph->devdep = NULL; graph->devdep = NULL;
return (1); graph->n_byte_devdep = 0;
return 1;
} }
if (graph->absolute.width) { if (graph->absolute.width) {
@ -146,13 +148,18 @@ GL_NewViewport(GRAPH *graph)
/* start file off with a % */ /* start file off with a % */
fprintf(plotfile, "IN;DF;PA;"); fprintf(plotfile, "IN;DF;PA;");
fprintf(plotfile, "SI %f,%f;", tocm*jgmult*fontwidth*scale, tocm*jgmult*fontheight*scale); fprintf(plotfile, "SI %f,%f;",
tocm * jgmult * fontwidth * scale,
tocm * jgmult * fontheight * scale);
#ifdef notdef #ifdef notdef
if (!screenflag) if (!screenflag)
#endif #endif
{
graph->devdep = TMALLOC(GLdevdep, 1); graph->devdep = TMALLOC(GLdevdep, 1);
graph->n_byte_devdep = sizeof(GLdevdep);
}
DEVDEP(graph).lastlinestyle = -1; DEVDEP(graph).lastlinestyle = -1;
DEVDEP(graph).lastx = -1; DEVDEP(graph).lastx = -1;
DEVDEP(graph).lasty = -1; DEVDEP(graph).lasty = -1;
@ -163,8 +170,7 @@ GL_NewViewport(GRAPH *graph)
} }
int int GL_Close(void)
GL_Close(void)
{ {
/* in case GL_Close is called as part of an abort, /* in case GL_Close is called as part of an abort,
w/o having reached GL_NewViewport */ w/o having reached GL_NewViewport */
@ -187,8 +193,7 @@ GL_Close(void)
} }
int int GL_Clear(void)
GL_Clear(void)
{ {
/* do nothing */ /* do nothing */
@ -196,21 +201,21 @@ GL_Clear(void)
} }
int int GL_DrawLine(int x1, int y1, int x2, int y2)
GL_DrawLine(int x1, int y1, int x2, int y2)
{ {
/* note: this is not extendible to more than one graph /* note: this is not extendible to more than one graph
=> will have to give NewViewport a writeable graph XXX */ => will have to give NewViewport a writeable graph XXX */
if (DEVDEP(currentgraph).linecount == 0 if (DEVDEP(currentgraph).linecount == 0
|| x1 != DEVDEP(currentgraph).lastx || x1 != DEVDEP(currentgraph).lastx
|| y1 != DEVDEP(currentgraph).lasty) || y1 != DEVDEP(currentgraph).lasty) {
{ fprintf(plotfile, "PU;PA %d , %d ;",
fprintf(plotfile, "PU;PA %d , %d ;", jgmult*(x1 + xoff), jgmult*(y1 + yoff)); jgmult * (x1 + xoff), jgmult * (y1 + yoff));
} }
if (x1 != x2 || y1 != y2) { if (x1 != x2 || y1 != y2) {
fprintf(plotfile, "PD;PA %d , %d ;", jgmult*(x2 + xoff), jgmult*(y2 + yoff)); fprintf(plotfile, "PD;PA %d , %d ;",
jgmult * (x2 + xoff), jgmult * (y2 + yoff));
DEVDEP(currentgraph).linecount += 1; DEVDEP(currentgraph).linecount += 1;
} }
@ -223,8 +228,7 @@ GL_DrawLine(int x1, int y1, int x2, int y2)
/* ARGSUSED */ /* ARGSUSED */
int int GL_Arc(int x0, int y0, int r, double theta, double delta_theta)
GL_Arc(int x0, int y0, int r, double theta, double delta_theta)
{ {
int x1, y1, angle; int x1, y1, angle;
@ -233,8 +237,10 @@ GL_Arc(int x0, int y0, int r, double theta, double delta_theta)
angle = (int)(RAD_TO_DEG * delta_theta); angle = (int)(RAD_TO_DEG * delta_theta);
fprintf(plotfile, "PU;PA %d , %d;", jgmult*(x1+xoff+XTADJ), jgmult*(y1+yoff+YTADJ)); fprintf(plotfile, "PU;PA %d , %d;",
fprintf(plotfile, "PD;AA %d , %d, %d;", jgmult*(x0+xoff+XTADJ), jgmult*(y0+yoff+YTADJ), angle); jgmult * (x1 + xoff + XTADJ), jgmult * (y1 + yoff + YTADJ));
fprintf(plotfile, "PD;AA %d , %d, %d;",
jgmult * (x0 + xoff + XTADJ), jgmult*(y0 + yoff + YTADJ), angle);
DEVDEP(currentgraph).linecount = 0; DEVDEP(currentgraph).linecount = 0;
@ -242,13 +248,13 @@ GL_Arc(int x0, int y0, int r, double theta, double delta_theta)
} }
int int GL_Text(char *text, int x, int y, int angle)
GL_Text(char *text, int x, int y, int angle)
{ {
/* move to (x, y) */ /* move to (x, y) */
NG_IGNORE(angle); NG_IGNORE(angle);
fprintf(plotfile, "PU;PA %d , %d;", jgmult*(x+xoff+XTADJ), jgmult*(y+yoff+YTADJ)); fprintf(plotfile, "PU;PA %d , %d;",
jgmult * (x + xoff + XTADJ), jgmult * (y + yoff + YTADJ));
fprintf(plotfile, "LB %s \x03", text); fprintf(plotfile, "LB %s \x03", text);
DEVDEP(currentgraph).lastx = -1; DEVDEP(currentgraph).lastx = -1;
@ -258,8 +264,7 @@ GL_Text(char *text, int x, int y, int angle)
} }
int int GL_SetLinestyle(int linestyleid)
GL_SetLinestyle(int linestyleid)
{ {
/* special case /* special case
get it when GL_Text restores a -1 linestyle */ get it when GL_Text restores a -1 linestyle */
@ -283,8 +288,7 @@ GL_SetLinestyle(int linestyleid)
/* ARGSUSED */ /* ARGSUSED */
int int GL_SetColor(int colorid)
GL_SetColor(int colorid)
{ {
fprintf(plotfile, "SP %d;", colorid); fprintf(plotfile, "SP %d;", colorid);
@ -292,8 +296,7 @@ GL_SetColor(int colorid)
} }
int int GL_Update(void)
GL_Update(void)
{ {
fflush(plotfile); fflush(plotfile);

View File

@ -28,8 +28,7 @@ static char *linestyle[] = {
static int currentlinestyle = SOLID; static int currentlinestyle = SOLID;
int int Plt5_Init(void)
Plt5_Init(void)
{ {
dispdev->numlinestyles = 4; dispdev->numlinestyles = 4;
dispdev->numcolors = 2; dispdev->numcolors = 2;
@ -38,17 +37,18 @@ Plt5_Init(void)
dispdev->width = 1000; dispdev->width = 1000;
dispdev->height = 1000; dispdev->height = 1000;
return (0); return 0;
} }
int int Plt5_NewViewport(GRAPH *graph)
Plt5_NewViewport(GRAPH *graph)
{ {
if ((plotfile = fopen((char*) graph->devdep, "w")) == NULL) { if ((plotfile = fopen((char*) graph->devdep, "w")) == NULL) {
perror((char *) graph->devdep);
free(graph->devdep);
graph->devdep = NULL; graph->devdep = NULL;
perror((char*) graph->devdep); graph->n_byte_devdep = 0;
return (1); return 1;
} }
if (graph->absolute.width) { if (graph->absolute.width) {
@ -64,7 +64,8 @@ Plt5_NewViewport(GRAPH *graph)
/* re-scale linestyles */ /* re-scale linestyles */
gr_relinestyle(graph); gr_relinestyle(graph);
} else { }
else {
/* scale space */ /* scale space */
putc('s', plotfile); putc('s', plotfile);
putsi(0); putsi(0);
@ -83,13 +84,13 @@ Plt5_NewViewport(GRAPH *graph)
/* set to NULL so graphdb doesn't incorrectly de-allocate it */ /* set to NULL so graphdb doesn't incorrectly de-allocate it */
graph->devdep = NULL; graph->devdep = NULL;
graph->n_byte_devdep = 0;
return (0); return 0;
} }
int int Plt5_Close(void)
Plt5_Close(void)
{ {
/* in case Plt5_Close is called as part of an abort, /* in case Plt5_Close is called as part of an abort,
w/o having reached Plt5_NewViewport */ w/o having reached Plt5_NewViewport */
@ -100,16 +101,14 @@ Plt5_Close(void)
} }
int int Plt5_Clear(void)
Plt5_Clear(void)
{ {
/* do nothing */ /* do nothing */
return 0; return 0;
} }
int int Plt5_DrawLine(int x1, int y1, int x2, int y2)
Plt5_DrawLine(int x1, int y1, int x2, int y2)
{ {
putc('l', plotfile); putc('l', plotfile);
putsi(x1); putsi(x1);
@ -121,8 +120,7 @@ Plt5_DrawLine(int x1, int y1, int x2, int y2)
} }
int int Plt5_Arc(int xc, int yc, int radius, double theta, double delta_theta)
Plt5_Arc(int xc, int yc, int radius, double theta, double delta_theta)
{ {
int x0, y0, x1, y1; int x0, y0, x1, y1;
@ -169,8 +167,7 @@ Plt5_Arc(int xc, int yc, int radius, double theta, double delta_theta)
} }
int int Plt5_Text(char *text, int x, int y, int angle)
Plt5_Text(char *text, int x, int y, int angle)
{ {
int savedlstyle; int savedlstyle;
NG_IGNORE(angle); NG_IGNORE(angle);
@ -195,8 +192,7 @@ Plt5_Text(char *text, int x, int y, int angle)
} }
int int Plt5_SetLinestyle(int linestyleid)
Plt5_SetLinestyle(int linestyleid)
{ {
if (linestyleid < 0 || linestyleid > dispdev->numlinestyles) { if (linestyleid < 0 || linestyleid > dispdev->numlinestyles) {
internalerror("bad linestyleid"); internalerror("bad linestyleid");
@ -211,8 +207,7 @@ Plt5_SetLinestyle(int linestyleid)
/* ARGSUSED */ /* ARGSUSED */
int int Plt5_SetColor(int colorid)
Plt5_SetColor(int colorid)
{ {
NG_IGNORE(colorid); NG_IGNORE(colorid);
@ -221,8 +216,7 @@ Plt5_SetColor(int colorid)
} }
int int Plt5_Update(void)
Plt5_Update(void)
{ {
fflush(plotfile); fflush(plotfile);
return 0; return 0;

View File

@ -383,6 +383,7 @@ X11_NewViewport(GRAPH *graph)
int trys; int trys;
graph->devdep = TMALLOC(X11devdep, 1); graph->devdep = TMALLOC(X11devdep, 1);
graph->n_byte_devdep = sizeof(X11devdep);
/* set up new shell */ /* set up new shell */
DEVDEP(graph).shell = XtCreateApplicationShell DEVDEP(graph).shell = XtCreateApplicationShell
@ -855,7 +856,7 @@ hardcopy(Widget w, XtPointer client_data, XtPointer call_data)
NG_IGNORE(call_data); NG_IGNORE(call_data);
NG_IGNORE(w); NG_IGNORE(w);
/* com_hardcopy() -> gr_resize() -> setcolor() dirung postscript /* com_hardcopy() -> gr_resize() -> setcolor() during postscript
printing will act on currentgraph with a DEVDEP inherited from PSdevdep. printing will act on currentgraph with a DEVDEP inherited from PSdevdep.
But currentgraph had not changed its devdep, which was derived from But currentgraph had not changed its devdep, which was derived from
incompatible X11devdep, thus overwriting some variables. Here you find a incompatible X11devdep, thus overwriting some variables. Here you find a
@ -893,16 +894,16 @@ killwin(Widget w, XtPointer client_data, XtPointer call_data)
} }
/* called from postcoms.c /* called from postcoms.c
In the command 'destroy ac2' Will remove window associated with In the command 'destroy ac2' Will remove window associated with
the plot (e.g. ac2) just before data of the plot are deleted.*/ the plot (e.g. ac2) just before data of the plot are deleted.*/
void void RemoveWindow(GRAPH *graph)
RemoveWindow(GRAPH *graph)
{ {
if (graph->devdep) { if (graph->devdep) {
/* Iplots are done asynchronously */ /* Iplots are done asynchronously */
DEVDEP(graph).isopen = 0; DEVDEP(graph).isopen = 0;
/* MW. Not sure but DestroyGraph might free() to much - try Xt...() first */ /* MW. Not sure but DestroyGraph might free() too much - try Xt...() first */
XtUnmapWidget(DEVDEP(graph).shell); XtUnmapWidget(DEVDEP(graph).shell);
XtDestroyWidget(DEVDEP(graph).shell); XtDestroyWidget(DEVDEP(graph).shell);
XFreeFont(display, DEVDEP(graph).font); XFreeFont(display, DEVDEP(graph).font);
@ -913,7 +914,8 @@ RemoveWindow(GRAPH *graph)
currentgraph = NULL; currentgraph = NULL;
DestroyGraph(graph->graphid); DestroyGraph(graph->graphid);
} } /* end of function RemoveWindow */
/* call higher gr_redraw routine */ /* call higher gr_redraw routine */

View File

@ -79,8 +79,7 @@ void PS_Stroke(void);
/* Set scale, color and size of the plot */ /* Set scale, color and size of the plot */
int int PS_Init(void)
PS_Init(void)
{ {
char pswidth[30], psheight[30]; char pswidth[30], psheight[30];
@ -108,7 +107,8 @@ PS_Init(void)
/* plot size */ /* plot size */
if (!cp_getvar("hcopywidth", CP_STRING, pswidth, sizeof( pswidth))) { if (!cp_getvar("hcopywidth", CP_STRING, pswidth, sizeof( pswidth))) {
dispdev->width = (int)(7.75 * 72.0 * scale); /* (8 1/2 - 3/4) * 72 */ dispdev->width = (int)(7.75 * 72.0 * scale); /* (8 1/2 - 3/4) * 72 */
} else { }
else {
sscanf(pswidth, "%d", &(dispdev->width)); sscanf(pswidth, "%d", &(dispdev->width));
if (dispdev->width <= 100) if (dispdev->width <= 100)
dispdev->width = 100; dispdev->width = 100;
@ -117,7 +117,8 @@ PS_Init(void)
} }
if (!cp_getvar("hcopyheight", CP_STRING, psheight, sizeof(psheight))) { if (!cp_getvar("hcopyheight", CP_STRING, psheight, sizeof(psheight))) {
dispdev->height = dispdev->width; dispdev->height = dispdev->width;
} else { }
else {
sscanf(psheight, "%d", &(dispdev->height)); sscanf(psheight, "%d", &(dispdev->height));
if (dispdev->height <= 100) if (dispdev->height <= 100)
dispdev->height = 100; dispdev->height = 100;
@ -135,15 +136,17 @@ PS_Init(void)
* viewport.height = absolute.height - 2 * viewportyoff * viewport.height = absolute.height - 2 * viewportyoff
*/ */
if (!cp_getvar("hcopyfont", CP_STRING, psfont, sizeof(psfont))) if (!cp_getvar("hcopyfont", CP_STRING, psfont, sizeof(psfont))) {
strcpy(psfont, "Helvetica"); strcpy(psfont, "Helvetica");
}
if (!cp_getvar("hcopyfontsize", CP_STRING, psfontsize, sizeof(psfontsize))) { if (!cp_getvar("hcopyfontsize", CP_STRING, psfontsize, sizeof(psfontsize))) {
fontsize = 10; fontsize = 10;
fontwidth = 6; fontwidth = 6;
fontheight = 14; fontheight = 14;
xtadj = (int)(XTADJ * scale); xtadj = (int)(XTADJ * scale);
ytadj = (int)(YTADJ * scale); ytadj = (int)(YTADJ * scale);
} else { }
else {
sscanf(psfontsize, "%d", &fontsize); sscanf(psfontsize, "%d", &fontsize);
if ((fontsize < 10) || (fontsize > 14)) if ((fontsize < 10) || (fontsize > 14))
fontsize = 10; fontsize = 10;
@ -157,21 +160,23 @@ PS_Init(void)
dispdev->minx = (int)(XOFF / scale); dispdev->minx = (int)(XOFF / scale);
dispdev->miny = (int)(YOFF / scale); dispdev->miny = (int)(YOFF / scale);
return (0); return 0;
} } /* end of function PS_Init */
/* Plot and fill bounding box */ /* Plot and fill bounding box */
int int PS_NewViewport(GRAPH *graph)
PS_NewViewport(GRAPH *graph)
{ {
int x1, x2, y1, y2; int x1, x2, y1, y2;
hcopygraphid = graph->graphid; hcopygraphid = graph->graphid;
/* devdep initially contains name of output file */ /* devdep initially contains name of output file */
if ((plotfile = fopen((char*)graph->devdep, "w")) == NULL) { if ((plotfile = fopen((char*)graph->devdep, "w")) == NULL) {
perror((char*)graph->devdep); perror((char *) graph->devdep);
free(graph->devdep);
graph->devdep = NULL; graph->devdep = NULL;
return (1); graph->n_byte_devdep = 0;
return 1;
} }
if (graph->absolute.width) { if (graph->absolute.width) {
@ -233,6 +238,7 @@ PS_NewViewport(GRAPH *graph)
psfont, (int) (fontsize * scale)); psfont, (int) (fontsize * scale));
graph->devdep = TMALLOC(PSdevdep, 1); graph->devdep = TMALLOC(PSdevdep, 1);
graph->n_byte_devdep = sizeof(PSdevdep);
DEVDEP(graph).lastlinestyle = -1; DEVDEP(graph).lastlinestyle = -1;
DEVDEP(graph).lastcolor = -1; DEVDEP(graph).lastcolor = -1;
DEVDEP(graph).lastx = -1; DEVDEP(graph).lastx = -1;
@ -245,8 +251,7 @@ PS_NewViewport(GRAPH *graph)
} }
int int PS_Close(void)
PS_Close(void)
{ {
/* in case PS_Close is called as part of an abort, /* in case PS_Close is called as part of an abort,
w/o having reached PS_NewViewport */ w/o having reached PS_NewViewport */
@ -267,16 +272,14 @@ PS_Close(void)
} }
int int PS_Clear(void)
PS_Clear(void)
{ {
/* do nothing */ /* do nothing */
return 0; return 0;
} }
int int PS_DrawLine(int x1, int y1, int x2, int y2)
PS_DrawLine(int x1, int y1, int x2, int y2)
{ {
/* note: this is not extendible to more than one graph /* note: this is not extendible to more than one graph
=> will have to give NewViewport a writeable graph XXX */ => will have to give NewViewport a writeable graph XXX */
@ -303,8 +306,7 @@ PS_DrawLine(int x1, int y1, int x2, int y2)
} }
int int PS_Arc(int x0, int y0, int r, double theta, double delta_theta)
PS_Arc(int x0, int y0, int r, double theta, double delta_theta)
{ {
double x1, y1; double x1, y1;
double angle1, angle2; double angle1, angle2;
@ -325,8 +327,7 @@ PS_Arc(int x0, int y0, int r, double theta, double delta_theta)
} }
int int PS_Text(char *text, int x, int y, int angle)
PS_Text(char *text, int x, int y, int angle)
{ {
int savedlstyle, savedcolor; int savedlstyle, savedcolor;
@ -368,8 +369,7 @@ PS_Text(char *text, int x, int y, int angle)
/* PS_DefineColor */ /* PS_DefineColor */
/* PS_DefineLinestyle */ /* PS_DefineLinestyle */
int int PS_SetLinestyle(int linestyleid)
PS_SetLinestyle(int linestyleid)
{ {
/* special case /* special case
get it when PS_Text restores a -1 linestyle */ get it when PS_Text restores a -1 linestyle */
@ -387,16 +387,14 @@ PS_SetLinestyle(int linestyleid)
} }
int int PS_SetColor(int colorid)
PS_SetColor(int colorid)
{ {
PS_LinestyleColor(currentgraph->linestyle, colorid); PS_LinestyleColor(currentgraph->linestyle, colorid);
return 0; return 0;
} }
int int PS_Update(void)
PS_Update(void)
{ {
fflush(plotfile); fflush(plotfile);
return 0; return 0;
@ -405,8 +403,7 @@ PS_Update(void)
/**************** PRIVAT FUNCTIONS OF PS FRONTEND *****************************/ /**************** PRIVAT FUNCTIONS OF PS FRONTEND *****************************/
void void PS_SelectColor(int colorid) /* should be replaced by PS_DefineColor */
PS_SelectColor(int colorid) /* should be replaced by PS_DefineColor */
{ {
char colorN[30] = "", colorstring[30] = ""; char colorN[30] = "", colorstring[30] = "";
char rgb[30], s_red[30] = "0x", s_green[30] = "0x", s_blue[30] = "0x"; char rgb[30], s_red[30] = "0x", s_green[30] = "0x", s_blue[30] = "0x";
@ -468,8 +465,7 @@ PS_SelectColor(int colorid) /* should be replaced by PS_DefineColor */
} }
void void PS_LinestyleColor(int linestyleid, int colorid)
PS_LinestyleColor(int linestyleid, int colorid)
{ {
/* we have some different linestyles and colors: /* we have some different linestyles and colors:
- color and linestyle we got via function call - color and linestyle we got via function call
@ -519,8 +515,7 @@ PS_LinestyleColor(int linestyleid, int colorid)
} }
void void PS_Stroke(void)
PS_Stroke(void)
{ {
/* strokes an open path */ /* strokes an open path */
if (DEVDEP(currentgraph).linecount > 0) { if (DEVDEP(currentgraph).linecount > 0) {

View File

@ -107,9 +107,7 @@ WIN_Init() returns 0, if no error ocurred.
WIN_Init() does not yet open a window, this happens only in WIN_NewViewport() WIN_Init() does not yet open a window, this happens only in WIN_NewViewport()
******************************************************************************/ ******************************************************************************/
int WIN_Init(void)
int
WIN_Init(void)
{ {
char colorstring[BSIZE_SP]; char colorstring[BSIZE_SP];
@ -126,10 +124,12 @@ WIN_Init(void)
isblack = !cieq(colorstring, "white"); isblack = !cieq(colorstring, "white");
/* get linewidth information from spinit */ /* get linewidth information from spinit */
if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth, 0)) if (!cp_getvar("xbrushwidth", CP_NUM, &linewidth, 0)) {
linewidth = 0; linewidth = 0;
if (linewidth < 0) }
if (linewidth < 0) {
linewidth = 0; linewidth = 0;
}
/* only for the first time: */ /* only for the first time: */
if (!IsRegistered) { if (!IsRegistered) {
@ -165,10 +165,12 @@ WIN_Init(void)
ColorTable[11] = RGB(255, 128, 128); /* pink */ ColorTable[11] = RGB(255, 128, 128); /* pink */
/* 2. color bank (with different line style */ /* 2. color bank (with different line style */
if (isblack) if (isblack) {
ColorTable[12] = RGB(255, 255, 255); /* white */ ColorTable[12] = RGB(255, 255, 255); /* white */
else }
else {
ColorTable[12] = RGB( 0, 0, 0); /* black */ ColorTable[12] = RGB( 0, 0, 0); /* black */
}
ColorTable[13] = RGB( 0, 255, 0); /* green */ ColorTable[13] = RGB( 0, 255, 0); /* green */
ColorTable[14] = RGB(255, 0, 0); /* red */ ColorTable[14] = RGB(255, 0, 0); /* red */
@ -192,17 +194,20 @@ WIN_Init(void)
TheWndClass.lpszMenuName = NULL; TheWndClass.lpszMenuName = NULL;
TheWndClass.hCursor = LoadCursor(NULL, IDC_ARROW); TheWndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
if (isblack) if (isblack) {
TheWndClass.hbrBackground = GetStockObject(BLACK_BRUSH); TheWndClass.hbrBackground = GetStockObject(BLACK_BRUSH);
else }
else {
TheWndClass.hbrBackground = GetStockObject(WHITE_BRUSH); TheWndClass.hbrBackground = GetStockObject(WHITE_BRUSH);
}
TheWndClass.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(2)); TheWndClass.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(2));
TheWndClass.cbClsExtra = 0; TheWndClass.cbClsExtra = 0;
TheWndClass.cbWndExtra = sizeof(GRAPH *); TheWndClass.cbWndExtra = sizeof(GRAPH *);
if (!RegisterClass(&TheWndClass)) if (!RegisterClass(&TheWndClass)) {
return 1; return 1;
}
} }
/* not first time */ /* not first time */
else if (isblackold != isblack) { else if (isblackold != isblack) {
@ -214,10 +219,12 @@ WIN_Init(void)
ColorTable[0] = RGB(255, 255, 255); /* white = background */ ColorTable[0] = RGB(255, 255, 255); /* white = background */
ColorTable[1] = RGB( 0, 0, 0); /* black = text and grid */ ColorTable[1] = RGB( 0, 0, 0); /* black = text and grid */
} }
if (isblack) if (isblack) {
ColorTable[12] = RGB(255, 255, 255); /* white */ ColorTable[12] = RGB(255, 255, 255); /* white */
else }
else {
ColorTable[12] = RGB( 0, 0, 0); /* black */ ColorTable[12] = RGB( 0, 0, 0); /* black */
}
isblackold = isblack; isblackold = isblack;
} }
@ -230,28 +237,27 @@ WIN_Init(void)
/* get pointer to graph */ /* get pointer to graph */
/* (attach to window) */ /* (attach to window) */
static GRAPH * static GRAPH *pGraph(HWND hwnd)
pGraph(HWND hwnd)
{ {
return (GRAPH *) GetWindowLongPtr(hwnd, 0); return (GRAPH *) GetWindowLongPtr(hwnd, 0);
} }
/* return line style for plotting */ /* return line style for plotting */
static int static int LType(int ColorIndex)
LType(int ColorIndex)
{ {
if (ColorIndex >= 12) if (ColorIndex >= 12) {
return PS_DOT; return PS_DOT;
else }
else {
return PS_SOLID; return PS_SOLID;
}
} }
/* postscript hardcopy from a plot window */ /* postscript hardcopy from a plot window */
/* called by SystemMenue / Postscript hardcopy */ /* called by SystemMenue / Postscript hardcopy */
static LRESULT static LRESULT HcpyPlot(HWND hwnd)
HcpyPlot(HWND hwnd)
{ {
int colorval = isblack? 0 : 1; int colorval = isblack? 0 : 1;
NG_IGNORE(hwnd); NG_IGNORE(hwnd);
@ -261,13 +267,13 @@ HcpyPlot(HWND hwnd)
} }
static LRESULT static LRESULT HcpyPlotBW(HWND hwnd)
HcpyPlotBW(HWND hwnd)
{ {
int bgcolor; int bgcolor;
NG_IGNORE(hwnd); NG_IGNORE(hwnd);
if (cp_getvar("hcopypscolor", CP_NUM, &bgcolor, 0)) if (cp_getvar("hcopypscolor", CP_NUM, &bgcolor, 0)) {
cp_remvar("hcopypscolor"); cp_remvar("hcopypscolor");
}
com_hardcopy(NULL); com_hardcopy(NULL);
return 0; return 0;
} }
@ -275,8 +281,7 @@ HcpyPlotBW(HWND hwnd)
/* print a plot window */ /* print a plot window */
/* called by SystemMenue / Print */ /* called by SystemMenue / Print */
static LRESULT static LRESULT PrintPlot(HWND hwnd)
PrintPlot(HWND hwnd)
{ {
GRAPH *graph; GRAPH *graph;
GRAPH *temp; GRAPH *temp;
@ -288,20 +293,23 @@ PrintPlot(HWND hwnd)
/* switch to printer */ /* switch to printer */
/* (results in WPRINT_Init()) */ /* (results in WPRINT_Init()) */
if (DevSwitch("WinPrint")) if (DevSwitch("WinPrint")) {
return 0; return 0;
}
/* Cursor = wait */ /* Cursor = wait */
SetCursor(LoadCursor(NULL, IDC_WAIT)); SetCursor(LoadCursor(NULL, IDC_WAIT));
/* copy graph */ /* copy graph */
temp = CopyGraph(graph); temp = CopyGraph(graph);
if (!temp) if (!temp) {
goto PrintEND; goto PrintEND;
}
/* add to the copy the new printer data */ /* add to the copy the new printer data */
if (NewViewport(temp)) if (NewViewport(temp)) {
goto PrintEND2; goto PrintEND2;
}
/* make correction to placement of grid (copy from gr_init) */ /* make correction to placement of grid (copy from gr_init) */
temp->viewportxoff = temp->fontwidth * 8; temp->viewportxoff = temp->fontwidth * 8;
@ -326,8 +334,7 @@ PrintPlot(HWND hwnd)
/* initialze printer */ /* initialze printer */
static LRESULT static LRESULT PrintInit(HWND hwnd)
PrintInit(HWND hwnd)
{ {
/* hand over to printer module */ /* hand over to printer module */
WPRINT_PrintInit(hwnd); WPRINT_PrintInit(hwnd);
@ -336,8 +343,8 @@ PrintInit(HWND hwnd)
/* window procedure */ /* window procedure */
LRESULT CALLBACK LRESULT CALLBACK PlotWindowProc(HWND hwnd, UINT uMsg,
PlotWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) WPARAM wParam, LPARAM lParam)
{ {
static int x0, y0, xep, yep; static int x0, y0, xep, yep;
int xe, ye, prevmix; int xe, ye, prevmix;
@ -380,10 +387,12 @@ PlotWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
/* left mouse button: connect coordinate pair by dashed pair of x, y lines */ /* left mouse button: connect coordinate pair by dashed pair of x, y lines */
if (wParam & MK_LBUTTON) { if (wParam & MK_LBUTTON) {
hdc = GetDC(hwnd); hdc = GetDC(hwnd);
if (isblack) if (isblack) {
prevmix = SetROP2(hdc, R2_XORPEN); prevmix = SetROP2(hdc, R2_XORPEN);
else }
else {
prevmix = SetROP2(hdc, R2_NOTXORPEN); prevmix = SetROP2(hdc, R2_NOTXORPEN);
}
/* Create white dashed pen */ /* Create white dashed pen */
NewPen = CreatePen(LType(12), 0, ColorTable[1]); NewPen = CreatePen(LType(12), 0, ColorTable[1]);
OldPen = SelectObject(hdc, NewPen); OldPen = SelectObject(hdc, NewPen);
@ -466,7 +475,8 @@ PlotWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
hypot(fx0, fy0), hypot(fx0, fy0),
(angle > 0) ? angle : 360.0 + angle); (angle > 0) ? angle : 360.0 + angle);
} }
} else { }
else {
/* need to print info about two points */ /* need to print info about two points */
fprintf(stdout, "\nx0 = %g, y0 = %g x1 = %g, y1 = %g\n", fprintf(stdout, "\nx0 = %g, y0 = %g x1 = %g, y1 = %g\n",
fx0, fy0, fxe, fye); fx0, fy0, fxe, fye);
@ -601,8 +611,7 @@ PlotWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
******************************************************************************/ ******************************************************************************/
int int WIN_NewViewport(GRAPH *graph)
WIN_NewViewport(GRAPH *graph)
{ {
int i; int i;
HWND window; HWND window;
@ -612,8 +621,9 @@ WIN_NewViewport(GRAPH *graph)
HMENU sysmenu; HMENU sysmenu;
/* test the parameters */ /* test the parameters */
if (!graph) if (!graph) {
return 1; return 1;
}
/* initialize if not yet done */ /* initialize if not yet done */
if (WIN_Init() != 0) { if (WIN_Init() != 0) {
@ -623,24 +633,30 @@ WIN_NewViewport(GRAPH *graph)
/* allocate device dependency info */ /* allocate device dependency info */
wd = calloc(1, sizeof(tWindowData)); wd = calloc(1, sizeof(tWindowData));
if (!wd) if (!wd) {
return 1; return 1;
}
graph->devdep = wd; graph->devdep = wd;
graph->n_byte_devdep = sizeof(tWindowData);
/* Create the window */ /* Create the window */
i = GetSystemMetrics(SM_CYSCREEN) / 3; i = GetSystemMetrics(SM_CYSCREEN) / 3;
window = CreateWindow(WindowName, graph->plotname, WS_OVERLAPPEDWINDOW, window = CreateWindow(WindowName, graph->plotname, WS_OVERLAPPEDWINDOW,
0, 0, WinLineWidth, i * 2 - 22, NULL, NULL, hInst, NULL); 0, 0, WinLineWidth, i * 2 - 22, NULL, NULL, hInst, NULL);
if (!window) if (!window) {
return 1; return 1;
}
/* change the background color of all windows (both new and already plotted) /* change the background color of all windows (both new and already plotted)
by assessing the registered window class */ by assessing the registered window class */
if (isblack) if (isblack) {
SetClassLongPtr(window, GCLP_HBRBACKGROUND, (LONG_PTR)GetStockObject(BLACK_BRUSH)); SetClassLongPtr(window, GCLP_HBRBACKGROUND, (LONG_PTR)GetStockObject(BLACK_BRUSH));
else }
else {
SetClassLongPtr(window, GCLP_HBRBACKGROUND, (LONG_PTR)GetStockObject(WHITE_BRUSH)); SetClassLongPtr(window, GCLP_HBRBACKGROUND, (LONG_PTR)GetStockObject(WHITE_BRUSH));
}
wd->wnd = window; wd->wnd = window;
@ -709,8 +725,7 @@ to the printer. Therefore WIN_Close is not allowed to do anything, cancelling
of the structures occurs at program termination. of the structures occurs at program termination.
******************************************************************************/ ******************************************************************************/
int int WIN_Close(void)
WIN_Close(void)
{ {
return 0; return 0;
} }
@ -733,8 +748,7 @@ RealClose(void)
#endif #endif
int int WIN_Clear(void)
WIN_Clear(void)
{ {
tpWindowData wd; tpWindowData wd;
@ -753,8 +767,7 @@ WIN_Clear(void)
} }
int int WIN_DrawLine(int x1, int y1, int x2, int y2)
WIN_DrawLine(int x1, int y1, int x2, int y2)
{ {
tpWindowData wd; tpWindowData wd;
HPEN OldPen; HPEN OldPen;
@ -778,8 +791,7 @@ WIN_DrawLine(int x1, int y1, int x2, int y2)
} }
int int WIN_Arc(int x0, int y0, int radius, double theta, double delta_theta)
WIN_Arc(int x0, int y0, int radius, double theta, double delta_theta)
/* /*
* Notes: * Notes:
* Draws an arc of <radius> and center at (x0,y0) beginning at * Draws an arc of <radius> and center at (x0,y0) beginning at
@ -859,8 +871,7 @@ WIN_Text_old(char *text, int x, int y, int degrees)
#endif #endif
int int WIN_Text(char *text, int x, int y, int angle)
WIN_Text(char *text, int x, int y, int angle)
{ {
tpWindowData wd; tpWindowData wd;
HFONT hfont; HFONT hfont;
@ -906,8 +917,7 @@ WIN_Text(char *text, int x, int y, int angle)
} }
int int WIN_DefineColor(int colorid, double red, double green, double blue)
WIN_DefineColor(int colorid, double red, double green, double blue)
{ {
NG_IGNORE(colorid); NG_IGNORE(colorid);
NG_IGNORE(red); NG_IGNORE(red);
@ -917,8 +927,7 @@ WIN_DefineColor(int colorid, double red, double green, double blue)
} }
int int WIN_DefineLinestyle(int num, int mask)
WIN_DefineLinestyle(int num, int mask)
{ {
NG_IGNORE(num); NG_IGNORE(num);
NG_IGNORE(mask); NG_IGNORE(mask);
@ -926,16 +935,14 @@ WIN_DefineLinestyle(int num, int mask)
} }
int int WIN_SetLinestyle(int style)
WIN_SetLinestyle(int style)
{ {
NG_IGNORE(style); NG_IGNORE(style);
return 0; return 0;
} }
int int WIN_SetColor(int color)
WIN_SetColor(int color)
{ {
tpWindowData wd; tpWindowData wd;
@ -952,8 +959,7 @@ WIN_SetColor(int color)
} }
int int WIN_Update(void)
WIN_Update(void)
{ {
tpWindowData wd; tpWindowData wd;
@ -973,16 +979,14 @@ WIN_Update(void)
#if 0 #if 0
int int WIN_DiagramReady(void)
WIN_DiagramReady(void)
{ {
return 0; return 0;
} }
#endif #endif
void void RemoveWindow(GRAPH *dgraph)
RemoveWindow(GRAPH *dgraph)
{ {
tpWindowData wd; tpWindowData wd;
@ -998,15 +1002,15 @@ static void WIN_ScreentoData(GRAPH *graph, int x, int y, double *fx, double *fy)
double lmin, lmax; double lmin, lmax;
if (graph->grid.gridtype == GRID_XLOG || if (graph->grid.gridtype == GRID_XLOG ||
graph->grid.gridtype == GRID_LOGLOG) graph->grid.gridtype == GRID_LOGLOG) {
{
lmin = log10(graph->datawindow.xmin); lmin = log10(graph->datawindow.xmin);
lmax = log10(graph->datawindow.xmax); lmax = log10(graph->datawindow.xmax);
*fx = exp(((x - graph->viewportxoff) * *fx = exp(((x - graph->viewportxoff) *
(lmax - lmin) / graph->viewport.width + lmin) * M_LN10); (lmax - lmin) / graph->viewport.width + lmin) * M_LN10);
} else { }
else {
*fx = (x - graph->viewportxoff) * graph->aspectratiox + *fx = (x - graph->viewportxoff) * graph->aspectratiox +
graph->datawindow.xmin; graph->datawindow.xmin;
} }
if (graph->grid.gridtype == GRID_YLOG || if (graph->grid.gridtype == GRID_YLOG ||
@ -1015,10 +1019,10 @@ static void WIN_ScreentoData(GRAPH *graph, int x, int y, double *fx, double *fy)
lmin = log10(graph->datawindow.ymin); lmin = log10(graph->datawindow.ymin);
lmax = log10(graph->datawindow.ymax); lmax = log10(graph->datawindow.ymax);
*fy = exp(((graph->absolute.height - y - graph->viewportyoff) * *fy = exp(((graph->absolute.height - y - graph->viewportyoff) *
(lmax - lmin) / graph->viewport.height + lmin) * M_LN10); (lmax - lmin) / graph->viewport.height + lmin) * M_LN10);
} else { } else {
*fy = ((graph->absolute.height - y) - graph->viewportyoff) * *fy = ((graph->absolute.height - y) - graph->viewportyoff) *
graph->aspectratioy + graph->datawindow.ymin; graph->aspectratioy + graph->datawindow.ymin;
} }
} }

View File

@ -34,26 +34,26 @@
#include "winprint.h" /* function prototypes */ #include "winprint.h" /* function prototypes */
/* Typen */ /* Typen */
typedef struct { /* Extra Printdaten */ typedef struct { /* Extra Printdaten */
int ColorIndex; /* Index auf die akt. Farbe */ int ColorIndex; /* Index auf die akt. Farbe */
int LineIndex; /* Index auf den akt. Linientyp */ int LineIndex; /* Index auf den akt. Linientyp */
} tPrintData; } tPrintData;
typedef tPrintData * tpPrintData; /* Zeiger darauf */ typedef tPrintData *tpPrintData; /* Zeiger darauf */
#define pPrintData(g) ((tpPrintData)(g->devdep)) #define pPrintData(g) ((tpPrintData)(g->devdep))
/* externals */ /* externals */
void WaitForIdle(void); /* Warte, bis keine Events da */ void WaitForIdle(void); /* Warte, bis keine Events da */
/* lokale Variablen */ /* lokale Variablen */
static HFONT PlotFont = NULL; /* Font-Merker */ static HFONT PlotFont = NULL; /* Font-Merker */
static HFONT OldFont = NULL; static HFONT OldFont = NULL;
#define NumLines 7 /* Anzahl der LineStyles */ #define NumLines 7 /* Anzahl der LineStyles */
static int LineTable[NumLines]; /* Speicher fuer die LineStyles */ static int LineTable[NumLines]; /* Speicher fuer die LineStyles */
static HDC PrinterDC = NULL; /* Device Context */ static HDC PrinterDC = NULL; /* Device Context */
#define NumPrintColors 2 /* vordef. Farben */ #define NumPrintColors 2 /* vordef. Farben */
static COLORREF ColorTable[NumPrintColors];/* Speicher fuer die Farben */ static COLORREF ColorTable[NumPrintColors];/* Speicher fuer die Farben */
static int PrinterWidth = 1000; /* Breite des Papiers */ static int PrinterWidth = 1000; /* Breite des Papiers */
static int PrinterHeight = 1000; /* Hoehe des Papiers */ static int PrinterHeight = 1000; /* Hoehe des Papiers */
/****************************************************************************** /******************************************************************************
Drucker-Initialisierung Drucker-Initialisierung
@ -61,59 +61,63 @@ static int PrinterHeight = 1000; /* Hoehe des Papiers */
void WPRINT_PrintInit(HWND hwnd) void WPRINT_PrintInit(HWND hwnd)
{ {
/* Parameter-Block */ /* Parameter-Block */
PRINTDLG pd; PRINTDLG pd;
/* Initialisieren */ /* Initialisieren */
pd.lStructSize = sizeof(PRINTDLG); pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = hwnd; pd.hwndOwner = hwnd;
pd.hDevMode = NULL; pd.hDevMode = NULL;
pd.hDevNames = NULL; pd.hDevNames = NULL;
pd.hDC = NULL; pd.hDC = NULL;
pd.Flags = PD_PRINTSETUP; pd.Flags = PD_PRINTSETUP;
pd.nFromPage = 1; pd.nFromPage = 1;
pd.nToPage = 1; pd.nToPage = 1;
pd.nMinPage = 0; pd.nMinPage = 0;
pd.nMaxPage = 0; pd.nMaxPage = 0;
pd.nCopies = 1; pd.nCopies = 1;
pd.hInstance = NULL; pd.hInstance = NULL;
pd.lCustData = 0; pd.lCustData = 0;
pd.lpfnPrintHook = NULL; pd.lpfnPrintHook = NULL;
pd.lpfnSetupHook = NULL; pd.lpfnSetupHook = NULL;
pd.lpPrintTemplateName = NULL; pd.lpPrintTemplateName = NULL;
pd.lpSetupTemplateName = NULL; pd.lpSetupTemplateName = NULL;
pd.hPrintTemplate = NULL; pd.hPrintTemplate = NULL;
pd.hSetupTemplate = NULL; pd.hSetupTemplate = NULL;
/* Default-Drucker initialisieren */ /* Default-Drucker initialisieren */
(void) PrintDlg( &pd); (void) PrintDlg(&pd);
/* Speicher freigeben */ /* Speicher freigeben */
if( pd.hDevMode) GlobalFree( pd.hDevMode); if (pd.hDevMode) {
if( pd.hDevNames) GlobalFree( pd.hDevNames); GlobalFree(pd.hDevMode);
}
if (pd.hDevNames) {
GlobalFree(pd.hDevNames);
}
} }
/* Abort-Procedur zum Drucken */ /* Abort-Procedur zum Drucken */
BOOL CALLBACK WPRINT_Abort( HDC hdc, int iError) BOOL CALLBACK WPRINT_Abort(HDC hdc, int iError)
{ {
NG_IGNORE(hdc); NG_IGNORE(hdc);
NG_IGNORE(iError); NG_IGNORE(iError);
/* Multitasking */ /* Multitasking */
WaitForIdle(); WaitForIdle();
/* Warten */ /* Warten */
return TRUE; return TRUE;
} }
/****************************************************************************** /******************************************************************************
WPRINT_Init() stellt die Verbindung zur Grafik her. Dazu gehoert die Feststellung WPRINT_Init() stellt die Verbindung zur Grafik her. Dazu gehoert die Feststellung
von von
dispdev->numlinestyles dispdev->numlinestyles
dispdev->numcolors dispdev->numcolors
dispdev->width dispdev->width
dispdev->height dispdev->height
WPRINT_Init() gibt 0 zurueck, falls kein Fehler auftrat. WPRINT_Init() gibt 0 zurueck, falls kein Fehler auftrat.
@ -121,102 +125,108 @@ WPRINT_Init() gibt 0 zurueck, falls kein Fehler auftrat.
int WPRINT_Init(void) int WPRINT_Init(void)
{ {
int pWidth; int pWidth;
int pHeight; int pHeight;
/* Printer-DC holen */ /* Printer-DC holen */
if (!PrinterDC) { if (!PrinterDC) {
/* Parameter-Block */ /* Parameter-Block */
PRINTDLG pd; PRINTDLG pd;
/* Initialisieren */ /* Initialisieren */
pd.lStructSize = sizeof(PRINTDLG); pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = NULL; pd.hwndOwner = NULL;
pd.hDevMode = NULL; pd.hDevMode = NULL;
pd.hDevNames = NULL; pd.hDevNames = NULL;
pd.hDC = NULL; pd.hDC = NULL;
pd.Flags = PD_NOPAGENUMS | PD_NOSELECTION | PD_RETURNDC; pd.Flags = PD_NOPAGENUMS | PD_NOSELECTION | PD_RETURNDC;
pd.nFromPage = 1; pd.nFromPage = 1;
pd.nToPage = 1; pd.nToPage = 1;
pd.nMinPage = 0; pd.nMinPage = 0;
pd.nMaxPage = 0; pd.nMaxPage = 0;
pd.nCopies = 1; pd.nCopies = 1;
pd.hInstance = NULL; pd.hInstance = NULL;
pd.lCustData = 0; pd.lCustData = 0;
pd.lpfnPrintHook = NULL; pd.lpfnPrintHook = NULL;
pd.lpfnSetupHook = NULL; pd.lpfnSetupHook = NULL;
pd.lpPrintTemplateName = NULL; pd.lpPrintTemplateName = NULL;
pd.lpSetupTemplateName = NULL; pd.lpSetupTemplateName = NULL;
pd.hPrintTemplate = NULL; pd.hPrintTemplate = NULL;
pd.hSetupTemplate = NULL; pd.hSetupTemplate = NULL;
/* Default-Drucker initialisieren */ /* Default-Drucker initialisieren */
(void) PrintDlg( &pd); (void) PrintDlg(&pd);
/* Speicher freigeben */ /* Speicher freigeben */
if( pd.hDevMode) GlobalFree( pd.hDevMode); if (pd.hDevMode) {
if( pd.hDevNames) GlobalFree( pd.hDevNames); GlobalFree(pd.hDevMode);
}
if (pd.hDevNames) {
GlobalFree(pd.hDevNames);
}
/* DC holen */ /* DC holen */
PrinterDC = pd.hDC; PrinterDC = pd.hDC;
if (!PrinterDC) return 1; if (!PrinterDC) return 1;
/* Abmasze bestimmen */ /* Abmasze bestimmen */
PrinterWidth = GetDeviceCaps( PrinterDC, HORZRES); PrinterWidth = GetDeviceCaps(PrinterDC, HORZRES);
PrinterHeight = GetDeviceCaps( PrinterDC, VERTRES); PrinterHeight = GetDeviceCaps(PrinterDC, VERTRES);
pWidth = GetDeviceCaps( PrinterDC, HORZSIZE); pWidth = GetDeviceCaps(PrinterDC, HORZSIZE);
pHeight = GetDeviceCaps( PrinterDC, VERTSIZE); pHeight = GetDeviceCaps(PrinterDC, VERTSIZE);
/* Mapping Mode setzen (fuer Kreise) */ /* Mapping Mode setzen (fuer Kreise) */
if ( pWidth > pHeight) if (pWidth > pHeight) {
/* Querformat */ /* Querformat */
PrinterWidth = (PrinterHeight * pWidth) / pHeight; PrinterWidth = (PrinterHeight * pWidth) / pHeight;
else }
/* Hochformat */ else {
PrinterHeight = (PrinterWidth * pHeight) / pWidth; /* Hochformat */
PrinterHeight = (PrinterWidth * pHeight) / pWidth;
}
SetMapMode( PrinterDC, MM_ISOTROPIC); SetMapMode(PrinterDC, MM_ISOTROPIC);
SetWindowExtEx( PrinterDC, PrinterWidth, PrinterHeight, NULL); SetWindowExtEx(PrinterDC, PrinterWidth, PrinterHeight, NULL);
SetViewportExtEx( PrinterDC, PrinterWidth, PrinterHeight, NULL); SetViewportExtEx(PrinterDC, PrinterWidth, PrinterHeight, NULL);
/* nicht hoeher als breit zeichnen */ /* nicht hoeher als breit zeichnen */
if (pWidth < pHeight) { if (pWidth < pHeight) {
/* Papier im Hochformat */ /* Papier im Hochformat */
PrinterHeight = PrinterWidth; PrinterHeight = PrinterWidth;
} }
/* Initialisierungen des Display-Descriptors */ /* Initialisierungen des Display-Descriptors */
dispdev->width = PrinterWidth; dispdev->width = PrinterWidth;
dispdev->height = PrinterHeight; dispdev->height = PrinterHeight;
dispdev->numlinestyles = NumLines; dispdev->numlinestyles = NumLines;
dispdev->numcolors = NumPrintColors; dispdev->numcolors = NumPrintColors;
/* Farben initialisieren */ /* Farben initialisieren */
ColorTable[0] = RGB(255,255,255); /* Weisz */ ColorTable[0] = RGB(255,255,255); /* Weisz */
ColorTable[1] = RGB( 0, 0, 0); /* Schwarz */ ColorTable[1] = RGB(0, 0, 0); /* Schwarz */
/* LineStyles initialisieren */ /* LineStyles initialisieren */
LineTable[0] = PS_SOLID; LineTable[0] = PS_SOLID;
LineTable[1] = PS_DOT; /* Gitter */ LineTable[1] = PS_DOT; /* Gitter */
LineTable[2] = PS_SOLID; /* Erste Linie */ LineTable[2] = PS_SOLID; /* Erste Linie */
LineTable[3] = PS_DOT; /* Zweite Linie */ LineTable[3] = PS_DOT; /* Zweite Linie */
LineTable[4] = PS_DASH; /* usw */ LineTable[4] = PS_DASH; /* usw */
LineTable[5] = PS_DASHDOT; LineTable[5] = PS_DASHDOT;
LineTable[6] = PS_DASHDOTDOT; LineTable[6] = PS_DASHDOTDOT;
/* Font */ /* Font */
if (!PlotFont) { if (!PlotFont) {
PlotFont = CreateFont( 0,0,0,0, FW_DONTCARE, FALSE, FALSE, FALSE, PlotFont = CreateFont(0,0,0,0, FW_DONTCARE, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
PROOF_QUALITY, FIXED_PITCH, NULL); PROOF_QUALITY, FIXED_PITCH, NULL);
} }
/* Abort-Prozedur setzen */ /* Abort-Prozedur setzen */
SetAbortProc( PrinterDC, WPRINT_Abort); SetAbortProc(PrinterDC, WPRINT_Abort);
} }
/* fertig */ /* fertig */
return (0); return 0;
} }
@ -227,250 +237,275 @@ int WPRINT_Init(void)
******************************************************************************/ ******************************************************************************/
int WPRINT_NewViewport( GRAPH * graph) int WPRINT_NewViewport(GRAPH * graph)
{ {
TEXTMETRIC tm; TEXTMETRIC tm;
tpPrintData pd; tpPrintData pd;
DOCINFO di; DOCINFO di;
/* Parameter testen */ /* Parameter testen */
if (!graph) return 1; if (!graph) {
return 1;
}
/* Initialisiere, falls noch nicht geschehen */ /* Initialisiere, falls noch nicht geschehen */
if (WPRINT_Init() != 0) { if (WPRINT_Init() != 0) {
externalerror("Can't initialize Printer."); externalerror("Can't initialize Printer.");
return(1); return(1);
} }
/* Device dep. Info allocieren */ /* Device dep. Info allocieren */
pd = calloc(1, sizeof(tPrintData)); pd = calloc(1, sizeof(tPrintData));
if (!pd) return 1; if (!pd) return 1;
graph->devdep = pd; graph->devdep = pd;
graph->n_byte_devdep = sizeof(tPrintData);
/* Setze den Color-Index */ /* Setze den Color-Index */
pd->ColorIndex = 0; pd->ColorIndex = 0;
/* Font setzen */ /* Font setzen */
OldFont = SelectObject( PrinterDC, PlotFont); OldFont = SelectObject(PrinterDC, PlotFont);
/* Font-Parameter abfragen */ /* Font-Parameter abfragen */
if (GetTextMetrics( PrinterDC, &tm)) { if (GetTextMetrics(PrinterDC, &tm)) {
graph->fontheight = tm.tmHeight; graph->fontheight = tm.tmHeight;
graph->fontwidth = tm.tmAveCharWidth; graph->fontwidth = tm.tmAveCharWidth;
} }
/* Setze den Linien-Index */ /* Setze den Linien-Index */
pd->LineIndex = 0; pd->LineIndex = 0;
/* Viewport-Parameter setzen */ /* Viewport-Parameter setzen */
graph->viewport.height = PrinterHeight; graph->viewport.height = PrinterHeight;
graph->viewport.width = PrinterWidth; graph->viewport.width = PrinterWidth;
/* Absolut-Parameter setzen */ /* Absolut-Parameter setzen */
graph->absolute.xpos = 0; graph->absolute.xpos = 0;
graph->absolute.ypos = 0; graph->absolute.ypos = 0;
graph->absolute.width = PrinterWidth; graph->absolute.width = PrinterWidth;
graph->absolute.height = PrinterHeight; graph->absolute.height = PrinterHeight;
/* Druckauftrag anmelden */ /* Druckauftrag anmelden */
di.cbSize = sizeof( DOCINFO); di.cbSize = sizeof(DOCINFO);
di.lpszDocName = graph->plotname; di.lpszDocName = graph->plotname;
di.lpszOutput = NULL; di.lpszOutput = NULL;
if (StartDoc( PrinterDC, &di) <= 0) return 1; if (StartDoc(PrinterDC, &di) <= 0) {
if (StartPage( PrinterDC) <= 0) return 1; return 1;
}
if (StartPage(PrinterDC) <= 0) {
return 1;
}
/* titel drucken */ /* titel drucken */
if (graph->plotname) { if (graph->plotname) {
UINT align; UINT align;
align = GetTextAlign( PrinterDC); align = GetTextAlign(PrinterDC);
SetTextAlign( PrinterDC, TA_RIGHT | TA_TOP | TA_NOUPDATECP); SetTextAlign(PrinterDC, TA_RIGHT | TA_TOP | TA_NOUPDATECP);
TextOut( PrinterDC, PrinterWidth-graph->fontwidth, 1, graph->plotname, TextOut(PrinterDC, PrinterWidth-graph->fontwidth, 1, graph->plotname,
(int)strlen(graph->plotname)); (int) strlen(graph->plotname));
SetTextAlign( PrinterDC, align); SetTextAlign(PrinterDC, align);
} }
/* fertig */ /* fertig */
return(0); return 0;
} }
int WPRINT_Close(void) int WPRINT_Close(void)
{ {
if (PrinterDC) { if (PrinterDC) {
EndPage( PrinterDC); EndPage(PrinterDC);
EndDoc( PrinterDC); EndDoc(PrinterDC);
if (OldFont) { if (OldFont) {
SelectObject( PrinterDC, OldFont); SelectObject(PrinterDC, OldFont);
OldFont = NULL; OldFont = NULL;
} }
DeleteObject( PlotFont); DeleteObject(PlotFont);
DeleteDC( PrinterDC); DeleteDC(PrinterDC);
PrinterDC = NULL; PrinterDC = NULL;
} }
return (0); return 0;
} }
int WPRINT_Clear(void) int WPRINT_Clear(void)
{ {
return 0; return 0;
} }
int WPRINT_DrawLine(int x1, int y1, int x2, int y2) int WPRINT_DrawLine(int x1, int y1, int x2, int y2)
{ {
tpPrintData pd; tpPrintData pd;
HPEN OldPen; HPEN OldPen;
HPEN NewPen; HPEN NewPen;
int ColIndex; int ColIndex;
if (!currentgraph) return 0; if (!currentgraph) return 0;
pd = pPrintData(currentgraph); pd = pPrintData(currentgraph);
if (!pd) return 0; if (!pd) return 0;
/* Farben/Dicke */ /* Farben/Dicke */
ColIndex = pd->ColorIndex; ColIndex = pd->ColorIndex;
if (ColIndex > 1) if (ColIndex > 1)
ColIndex = 1; ColIndex = 1;
MoveToEx(PrinterDC, x1, PrinterHeight - y1, NULL); MoveToEx(PrinterDC, x1, PrinterHeight - y1, NULL);
NewPen = CreatePen( LineTable[pd->LineIndex], 0, ColorTable[ColIndex] ); NewPen = CreatePen(LineTable[pd->LineIndex], 0, ColorTable[ColIndex] );
OldPen = SelectObject(PrinterDC, NewPen); OldPen = SelectObject(PrinterDC, NewPen);
LineTo(PrinterDC, x2, PrinterHeight - y2); LineTo(PrinterDC, x2, PrinterHeight - y2);
OldPen = SelectObject(PrinterDC, OldPen); OldPen = SelectObject(PrinterDC, OldPen);
DeleteObject( NewPen); DeleteObject(NewPen);
return (0); return 0;
} }
int WPRINT_Arc(int x0, int y0, int radius, double theta, double delta_theta) int WPRINT_Arc(int x0, int y0, int radius, double theta, double delta_theta)
/* /*
* Notes: * Notes:
* Draws an arc of <radius> and center at (x0,y0) beginning at * Draws an arc of <radius> and center at (x0,y0) beginning at
* angle theta (in rad) and ending at theta + delta_theta * angle theta (in rad) and ending at theta + delta_theta
*/ */
{ {
tpPrintData pd; tpPrintData pd;
HPEN OldPen; HPEN OldPen;
HPEN NewPen; HPEN NewPen;
int left, right, top, bottom; int left, right, top, bottom;
int xs, ys, xe, ye; int xs, ys, xe, ye;
int yb; int yb;
int direction; int direction;
int ColIndex; int ColIndex;
double r; double r;
double dx0; double dx0;
double dy0; double dy0;
if (!currentgraph) return 0; if (!currentgraph) {
pd = pPrintData(currentgraph); return 0;
if (!pd) return 0; }
pd = pPrintData(currentgraph);
if (!pd) {
return 0;
}
ColIndex = pd->ColorIndex; ColIndex = pd->ColorIndex;
if (ColIndex > 1) if (ColIndex > 1) {
ColIndex = 1; ColIndex = 1;
}
direction = AD_COUNTERCLOCKWISE; direction = AD_COUNTERCLOCKWISE;
if (delta_theta < 0) { if (delta_theta < 0) {
theta = theta + delta_theta; theta = theta + delta_theta;
delta_theta = - delta_theta; delta_theta = - delta_theta;
direction = AD_CLOCKWISE; direction = AD_CLOCKWISE;
} }
SetArcDirection( PrinterDC, direction); SetArcDirection(PrinterDC, direction);
/* Geometrische Vorueberlegungen */ /* Geometrische Vorueberlegungen */
yb = PrinterHeight; yb = PrinterHeight;
left = x0 - radius; left = x0 - radius;
right = x0 + radius; right = x0 + radius;
top = y0 + radius; top = y0 + radius;
bottom = y0 - radius; bottom = y0 - radius;
r = radius; r = radius;
dx0 = x0; dx0 = x0;
dy0 = y0; dy0 = y0;
xs = (int)(dx0 + (r * cos(theta))); xs = (int) (dx0 + (r * cos(theta)));
ys = (int)(dy0 + (r * sin(theta))); ys = (int) (dy0 + (r * sin(theta)));
xe = (int)(dx0 + (r * cos(theta + delta_theta))); xe = (int) (dx0 + (r * cos(theta + delta_theta)));
ye = (int)(dy0 + (r * sin(theta + delta_theta))); ye = (int) (dy0 + (r * sin(theta + delta_theta)));
/* Zeichnen */ /* Zeichnen */
NewPen = CreatePen( LineTable[pd->LineIndex], 0, ColorTable[ColIndex] ); NewPen = CreatePen(LineTable[pd->LineIndex], 0, ColorTable[ColIndex] );
OldPen = SelectObject(PrinterDC, NewPen); OldPen = SelectObject(PrinterDC, NewPen);
Arc( PrinterDC, left, yb-top, right, yb-bottom, xs, yb-ys, xe, yb-ye); Arc(PrinterDC, left, yb-top, right, yb-bottom, xs, yb-ys, xe, yb-ye);
OldPen = SelectObject(PrinterDC, OldPen); OldPen = SelectObject(PrinterDC, OldPen);
DeleteObject( NewPen); DeleteObject(NewPen);
return 0; return 0;
} }
int WPRINT_Text( char * text, int x, int y, int degrees) int WPRINT_Text(char * text, int x, int y, int degrees)
{ {
tpPrintData pd; tpPrintData pd;
int ColIndex; int ColIndex;
NG_IGNORE(degrees); NG_IGNORE(degrees);
if (!currentgraph) return 0; if (!currentgraph) {
pd = pPrintData(currentgraph); return 0;
if (!pd) return 0; }
pd = pPrintData(currentgraph);
if (!pd) {
return 0;
}
ColIndex = pd->ColorIndex; ColIndex = pd->ColorIndex;
if (ColIndex > 1) { if (ColIndex > 1) {
ColIndex = 1; ColIndex = 1;
} }
SetTextColor( PrinterDC, ColorTable[ColIndex]); SetTextColor(PrinterDC, ColorTable[ColIndex]);
TextOut( PrinterDC, x, PrinterHeight - y - currentgraph->fontheight, text, (int) strlen(text)); TextOut(PrinterDC, x, PrinterHeight - y - currentgraph->fontheight,
return (0); text, (int) strlen(text));
return 0;
} }
int WPRINT_DefineColor(int colorid, double red, double green, double blue) int WPRINT_DefineColor(int colorid, double red, double green, double blue)
{ {
/* nix */ /* nix */
NG_IGNORE(colorid); NG_IGNORE(colorid);
NG_IGNORE(red); NG_IGNORE(red);
NG_IGNORE(green); NG_IGNORE(green);
NG_IGNORE(blue); NG_IGNORE(blue);
return (0); return 0;
} }
int WPRINT_DefineLinestyle(int num, int mask) int WPRINT_DefineLinestyle(int num, int mask)
{ {
/* nix */ /* nix */
NG_IGNORE(num); NG_IGNORE(num);
NG_IGNORE(mask); NG_IGNORE(mask);
return (0); return 0;
} }
int WPRINT_SetLinestyle(int style) int WPRINT_SetLinestyle(int style)
{ {
tpPrintData pd; tpPrintData pd;
if (!currentgraph) return 0; if (!currentgraph) {
pd = pPrintData(currentgraph); return 0;
if (!pd) return 0; }
pd = pPrintData(currentgraph);
if (!pd) {
return 0;
}
pd->LineIndex = style % NumLines; pd->LineIndex = style % NumLines;
return (0); return 0;
} }
int WPRINT_SetColor( int color) int WPRINT_SetColor(int color)
{ {
tpPrintData pd; tpPrintData pd;
if (!currentgraph) return 0; if (!currentgraph) {
pd = pPrintData(currentgraph); return 0;
if (!pd) return 0; }
pd = pPrintData(currentgraph);
if (!pd) {
return 0;
}
pd->ColorIndex = color; pd->ColorIndex = color;
return (0); return 0;
} }
int WPRINT_Update(void) int WPRINT_Update(void)
{ {
return (0); return 0;
} }
int WPRINT_DiagramReady(void) int WPRINT_DiagramReady(void)
{ {
return 0; return 0;
} }
#endif /* HAS_WINGUI */ #endif /* HAS_WINGUI */