Skip to content

Commit

Permalink
Add support for colored PS output for 2D image
Browse files Browse the repository at this point in the history
  • Loading branch information
oldk1331 committed Apr 22, 2024
1 parent d3e6b51 commit 9049e04
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 39 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2024-04-23 Qian Yun <oldk1331@gmail.com>

* src/graph/view2D/viewport2D.c:
Add support for colored PS output for 2D image
* src/graph/Gdraws/ps_files/drawline.ps,
src/graph/Gdraws/ps_files/fillarc.ps, src/graph/Gdraws/Gfun.c:
Add new function 'GColorLine', 'GColorFillArc'

2024-04-22 Qian Yun <oldk1331@gmail.com>

* src/graph/view2D/write2d.c, src/graph/view2D/write3d.c:
Expand Down
87 changes: 87 additions & 0 deletions src/graph/Gdraws/Gfun.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,47 @@ GDrawLine(
return (s);
}

/*
* GColorLine draws a colored line, see GDrawLine
*/

int
GColorLine(
GC gc, /* graphics context */
Window wid, /* window id */
int x0, int y0, int x1, int y1, int color, int dFlag)
{
int s = 0;

switch (dFlag) {
case Xoption:
XSetForeground(dsply, gc, (unsigned long) color);
XDrawLine(dsply, wid, gc, x0, y0, x1, y1);
break;
case PSoption:
{
PSsetrgbcolor(color);
FILE *fp;

if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) {
fprintf(stderr, "GColorLine cannot open %s\n",
psData[scriptps].filename);
return (psError);
}

psData[drawlineps].flag = yes; /* sets procedure flag */
fprintf(fp, "\t%d\t%d\t%d\t%d\tpsColorLine\n",
x1, y1, x0, y0);
s = fclose(fp);
}
break;
default:
fprintf(stderr, "GColorLine request (%d) not implemented yet.\n",
dFlag);
return (psError);
}
return (s);
}



Expand Down Expand Up @@ -683,6 +724,52 @@ GFillArc(
return (s);
}

/*
* Draws and fills an arc with color; see GFillArc
*/

int
GColorFillArc(
GC gc, /* graphics context */
Window wid, /* window id */
int x, int y,
unsigned int wdth, unsigned int hght,
int ang1, int ang2, int color, int dFlag)
{
int s = 0;

switch (dFlag) {
case Xoption: /* angle: times 64 already */
XSetForeground(dsply, gc, (unsigned long) color);
XFillArc(dsply, wid, gc, x, y, wdth, hght, ang1, ang2);
break;
case PSoption:
{
PSsetrgbcolor(color);

FILE *fp;

if ((fp = fopen(psData[scriptps].filename, "a")) == NULL) {
fprintf(stderr, "GColorFillArc cannot open %s\n",
psData[scriptps].filename);
return (psError);
}

psData[fillarcps].flag = yes; /* sets procedure flag */
fprintf(fp, "\t%d %d\t%d %d\t%d %d\t%d %d\tpsColorFillArc\n",
x, y, hght, wdth, ang1 / 64, ang2 / 64,
x + wdth / 2, y + hght / 2);
s = fclose(fp);
}
break;
default:
fprintf(stderr, "GColorFillArc request (%d) not implemented yet\n",
dFlag);
return (psError);
}
return (s);
}

/*
* Initializes the path and files to be used.
*/
Expand Down
Binary file modified src/graph/Gdraws/ps_files/drawline.ps
Binary file not shown.
Binary file modified src/graph/Gdraws/ps_files/fillarc.ps
Binary file not shown.
59 changes: 20 additions & 39 deletions src/graph/view2D/viewport2D.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ drawTheViewport(int dFlag) /* display flag: X, PS,... */
int xAxis,yAxis,dummyInt, ascent, descent;
int unitWidth,boxX,boxY,boxW,boxH;
XCharStruct overall;
int color;

drawMore = yes;
vw = viewport->viewWindow;
Expand Down Expand Up @@ -344,22 +345,15 @@ drawTheViewport(int dFlag) /* display flag: X, PS,... */
clipped = ptX > vwInfo.x && ptX < vwInfo.width &&
ptY > 0 && ptY < vwInfo.height;
if (graphStateArray[i].pointsOn) {
if (dFlag==Xoption) {
if (mono) {
GSetForeground(globalGC1,
(float)monoColor((int)(aPoint->hue)),
dFlag);
} else {
GSetForeground(globalGC1,
(float)XSolidColor((int)(aPoint->hue),
(int)(aPoint->shade)),
dFlag);
}
if (mono) {
color = monoColor((int)(aPoint->hue));
} else {
color = XSolidColor((int)(aPoint->hue), (int)(aPoint->shade));
}
if (clipped && !eqNANQ(ptX) && !eqNANQ(ptY))
GFillArc(globalGC1,vw,ptX-halfSize,
ptY-halfSize,aList->pointSize,aList->pointSize,
0,360*64, dFlag);
GColorFillArc(globalGC1, vw, ptX-halfSize, ptY-halfSize,
aList->pointSize, aList->pointSize,
0, 360*64, color, dFlag);

} /* if points on */
for (ii=0, aPoint=aList->listOfPoints;
Expand All @@ -370,41 +364,28 @@ drawTheViewport(int dFlag) /* display flag: X, PS,... */
clipped1 = ptX1 > vwInfo.x && ptX1 < vwInfo.width &&
ptY1 > 0 && ptY1 < vwInfo.height;
if (graphStateArray[i].connectOn) {
if (dFlag==Xoption) {
if (mono) {
GSetForeground(globalGC1,
(float)monoColor((int)(aList->lineColor-1)/5),
dFlag);
if (mono) {
color = monoColor((int)(aList->lineColor-1)/5);
} else {
GSetForeground(globalGC1,
(float)XSolidColor((int)(aList->lineColor-1)/5,
(int)((aList->lineColor-1)%5)/2),
dFlag);
color = XSolidColor((int)(aList->lineColor-1)/5,
(int)((aList->lineColor-1)%5)/2);
}
} /* if X */
if ((clipped || clipped1) && !eqNANQ(ptX) && !eqNANQ(ptY) &&
!eqNANQ(ptX1) && !eqNANQ(ptY1))
GDrawLine(globalGC1,vw,
ptX,ptY,ptX1,ptY1,
dFlag);
GColorLine(globalGC1, vw, ptX, ptY, ptX1, ptY1,
color, dFlag);
} /* if lines on */
if (graphStateArray[i].pointsOn) {
if (dFlag==Xoption) {
if (mono) {
GSetForeground(globalGC1,
(float)monoColor((int)(aPoint->hue)),
dFlag);
color = monoColor((int)(aPoint->hue));
} else {
GSetForeground(globalGC1,
(float)XSolidColor((int)(aPoint->hue),
(int)(aPoint->shade)),
dFlag);
color = XSolidColor((int)(aPoint->hue),
(int)(aPoint->shade));
}
}
if (clipped1 && !eqNANQ(ptX1) && !eqNANQ(ptY1))
GFillArc(globalGC1,vw,ptX1-halfSize,
ptY1-halfSize,aList->pointSize,aList->pointSize,
0,360*64, dFlag);
GColorFillArc(globalGC1, vw, ptX1-halfSize, ptY1-halfSize,
aList->pointSize, aList->pointSize,
0, 360*64, color, dFlag);
} /* if points on */
ptX = ptX1; ptY = ptY1; clipped = clipped1;
} /* for all points */
Expand Down

0 comments on commit 9049e04

Please sign in to comment.