📄 xpsgraph.c
字号:
{ fprintf (PSFile, "stroke\n"); fprintf (PSFile, "%d %d M\n", X, Y); PathLength = 0; }}voidDraw (X1, Y1, X2, Y2)double X1, Y1, X2, Y2;{ int WinX1, WinY1, WinX2, WinY2; if (InitOK == FALSE || FramOK == FALSE) error ("Sorry, you must call Initplot and Framing before anything else"); if ((X1<UserLLX || Y1<UserLLY || X1>UserLLX+UserWidth || Y1>UserLLY+UserHeight) && (X2<UserLLX || Y2<UserLLY || X2>UserLLX+UserWidth || Y2>UserLLY+UserHeight)) { if (Output == XOnly || Output == XAndPS) { User2Win (X1, Y1, &WinX1, &WinY1); User2Win (X2, Y2, &WinX2, &WinY2); LastWinX = WinX2; LastWinY = WinY2; } return; } if (Output == PSOnly || Output == XAndPS) { UserPSWin (X1, Y1, &WinX1, &WinY1); UserPSWin (X2, Y2, &WinX2, &WinY2); fprintf (PSFile, "%d %d M\n%d %d L\n", WinX1, WinY1, WinX2, WinY2); CheckPathLength(2, WinX2, WinY2); } if (Output == XOnly || Output == XAndPS) { CheckEvent(); User2Win (X1, Y1, &WinX1, &WinY1); User2Win (X2, Y2, &WinX2, &WinY2); XDrawLine (display, GraphWin, GraphContext, WinX1, WinY1, WinX2, WinY2); XDrawLine (display, Backup, BackContext, WinX1, WinY1, WinX2, WinY2); LastWinX = WinX2; LastWinY = WinY2; }}void SetPoint (X, Y)double X, Y;{ int WinX, WinY; if (X<UserLLX || Y<UserLLY || X>UserLLX+UserWidth || Y>UserLLY+UserHeight) { if (Output == XOnly || Output == XAndPS) { User2Win (X, Y, &WinX, &WinY); LastWinX = WinX; LastWinY = WinY; } return; } if (Output == PSOnly || Output == XAndPS) { UserPSWin (X, Y, &WinX, &WinY); fprintf (PSFile, "%d %d M %d %d L\n", WinX, WinY, WinX, WinY); CheckPathLength(1, WinX, WinY); } if (Output == XOnly || Output == XAndPS) { CheckEvent(); User2Win (X, Y, &WinX, &WinY); XDrawPoint (display, GraphWin, GraphContext, WinX, WinY); XDrawPoint (display, Backup, BackContext, WinX, WinY); LastWinX = WinX; LastWinY = WinY; }}void SetDPoint (X, Y)int X, Y;{ if (Output == PSOnly || Output == XAndPS) { fprintf (PSFile, "%d %d M %d %d L\n", X, Y, X, Y); CheckPathLength(1, X, Y); } if (Output == XOnly || Output == XAndPS) { CheckEvent(); XDrawPoint (display, GraphWin, GraphContext, X, Y); XDrawPoint (display, Backup, BackContext, X, Y); LastWinX = X; LastWinY = Y; }}void DrawTo (X, Y)double X, Y;{ int WinX, WinY; if (Output == PSOnly || Output == XAndPS) { UserPSWin (X, Y, &WinX, &WinY); fprintf (PSFile, "%d %d L\n", WinX, WinY); CheckPathLength(1, WinX, WinY); } if (Output == XOnly || Output == XAndPS) { CheckEvent(); User2Win (X, Y, &WinX, &WinY); XDrawLine (display, GraphWin, GraphContext, LastWinX, LastWinY, WinX, WinY); XDrawLine (display, Backup, BackContext, LastWinX, LastWinY, WinX, WinY); LastWinX = WinX; LastWinY = WinY; }}voidDrawRectangle(X1, Y1, X2, Y2)double X1, Y1, X2, Y2;{ int WinX1, WinY1, WinX2, WinY2; unsigned int RectWidth, RectHeight; if (InitOK == FALSE || FramOK == FALSE) error ("Sorry, you must call Initplot and Framing before anything else"); if (Output == XOnly || Output == XAndPS) { CheckEvent(); User2Win (X1, Y1, &WinX1, &WinY1); User2Win (X2, Y2, &WinX2, &WinY2); LastWinX = WinX1; LastWinY = WinY1; if (WinX1<WinX2) RectWidth = WinX2-WinX1; else { RectWidth = WinX1 - WinX2; WinX1 = WinX2; } if (WinY1<WinY2) RectHeight = WinY2-WinY1; else { RectHeight = WinY1 - WinY2; WinY1 = WinY2; } XDrawRectangle (display, GraphWin, GraphContext, WinX1, WinY1, RectWidth, RectHeight); XDrawRectangle (display, Backup, BackContext, WinX1, WinY1, RectWidth, RectHeight); } if (Output == PSOnly || Output == XAndPS) { UserPSWin (X1, Y1, &WinX1, &WinY1); UserPSWin (X2, Y2, &WinX2, &WinY2); fprintf (PSFile, "%d %d M\n%d %d L\n%d %d L\n%d %d L\n%d %d L\n", WinX1, WinY1, WinX2, WinY1, WinX2, WinY2, WinX1, WinY2, WinX1, WinY1); CheckPathLength(5, WinX1, WinY1); }}voidFillDirect(X, Y)int X, Y;{ CheckEvent(); XFillRectangle (display, GraphWin, GraphContext, X, Y, 5, 5); XFillRectangle (display, Backup, BackContext, X, Y, 5, 5);} voidFillRectangle (X1, Y1, X2, Y2)double X1, Y1, X2, Y2;{ int WinX1, WinY1, WinX2, WinY2; unsigned int RectWidth, RectHeight; if (InitOK == FALSE || FramOK == FALSE) error ("Sorry, you must call Initplot and Framing before anything else"); if (Output == XOnly || Output == XAndPS) { CheckEvent(); User2Win (X1, Y1, &WinX1, &WinY1); User2Win (X2, Y2, &WinX2, &WinY2); LastWinX = WinX1; LastWinY = WinY1; if (WinX1<WinX2) RectWidth = WinX2-WinX1; else { RectWidth = WinX1 - WinX2; WinX1 = WinX2; } if (WinY1<WinY2) RectHeight = WinY2-WinY1; else { RectHeight = WinY1 - WinY2; WinY1 = WinY2; } XFillRectangle (display, GraphWin, GraphContext, WinX1, WinY1, RectWidth, RectHeight); XFillRectangle (display, Backup, BackContext, WinX1, WinY1, RectWidth, RectHeight); } if (Output == PSOnly || Output == XAndPS) { UserPSWin (X1, Y1, &WinX1, &WinY1); UserPSWin (X2, Y2, &WinX2, &WinY2); fprintf (PSFile, "stroke newpath\n %d %d M\n%d %d L\n%d %d L\n%d %d L\n%d %d L\n", WinX1, WinY1, WinX2, WinY1, WinX2, WinY2, WinX1, WinY2, WinX1, WinY1); fprintf (PSFile, "CLP gsave 0.00 setgray fill grestore\n"); }}void FillPolygon (points, npoints)double points[]; int npoints;{ XPoint *WinPoints; double UserX, UserY; int xx, yy; int i; if (InitOK == FALSE || FramOK == FALSE) error ("Sorry, you must call Initplot and Framing before anything else"); if (Output == XOnly || Output == XAndPS) { CheckEvent(); WinPoints = (XPoint *) calloc (npoints, sizeof(XPoint)); } if (Output == PSOnly || Output == XAndPS) fprintf (PSFile, "stroke newpath\n"); for (i=0; i<npoints; i++) { UserX = points[2*i]; UserY = points[2*i+1]; if (Output == XOnly || Output == XAndPS) { User2Win (UserX, UserY, &xx, &yy); WinPoints[i].x = xx; WinPoints[i].y = yy; } if (Output == PSOnly || Output == XAndPS) { UserPSWin (UserX, UserY, &xx, &yy); if (i==0) fprintf (PSFile, "%d %d M\n", xx, yy); else fprintf (PSFile, "%d %d L\n", xx, yy); } } if (Output == PSOnly || Output == XAndPS) { fprintf (PSFile, "CLP gsave 0.00 setgray fill grestore\n"); CheckPathLength(npoints, xx, yy); } if (Output == XOnly || Output == XAndPS) { XFillPolygon (display, GraphWin, GraphContext, WinPoints, npoints, Complex, CoordModeOrigin); XFillPolygon (display, Backup, BackContext, WinPoints, npoints, Complex, CoordModeOrigin); } cfree (WinPoints);}voidDrawCircle(X, Y, Radius)double X, Y, Radius;{ double Xr, Yr, Xmax, DeltaX, YRad, CircPoints[10][2], UserZero; int PointNum =9, i, WinX, WinY, WinRad, Width, Height; if (InitOK == FALSE || FramOK == FALSE) error ("Sorry, you must call Initplot and Framing before anything else"); if (Output == XOnly || Output == XAndPS) { CheckEvent(); User2Win (X, Y, &WinX, &WinY); LastWinX = WinX; LastWinY = WinY; Xr = X+Radius; User2Win (Xr, Y, &WinRad, &WinY); WinRad = WinRad-WinX; WinX = WinX-WinRad; WinY = WinY-WinRad; Width = 2*WinRad; Height = 2*WinRad; XDrawArc(display, GraphWin, GraphContext, WinX, WinY, Width, Height, 0, 360*64-1); XDrawArc(display, Backup, BackContext, WinX, WinY, Width, Height, 0, 360*64-1); } if (Output == PSOnly || Output == XAndPS) { UserPSWin (X, Y, &WinX, &WinY); Xr = X+Radius; UserPSWin (Xr, Y, &WinRad, &WinY); WinRad = WinRad - WinX; fprintf (PSFile, "stroke newpath %d %d %d% d %d arc\n", WinX, WinY, WinRad, 0, 360); CheckPathLength(1, WinX, WinY); }} void MoveTo (X, Y)double X, Y;{ int WinX, WinY; if (InitOK == FALSE || FramOK == FALSE) error ("Sorry, you must call Initplot and Framing before anything else"); if (Output == XOnly || Output == XAndPS) { User2Win (X, Y, &WinX, &WinY); LastWinX = WinX; LastWinY = WinY; } if (Output == PSOnly || Output == XAndPS) { UserPSWin (X, Y, &WinX, &WinY); fprintf (PSFile, "%d %d M\n", WinX, WinY); CheckPathLength(1, WinX, WinY); }}void MoveRel (DX, DY)double DX, DY;{ double X, Y; Win2User (LastWinX, LastWinY, &X, &Y); MoveTo (X+DX, Y+DY);} void WriteText(Text)char *Text;{ int Xwin, Ywin, TextWidth; unsigned long returnval, CharHeight; Atom atom; if (InitOK == FALSE || FramOK == FALSE) error ("Sorry, you must call Initplot and Framing before anything else"); if (Output == XOnly || Output == XAndPS) { CheckEvent(); XGetFontProperty (CurrentFontStruct, XA_CAP_HEIGHT, &returnval); CharHeight = returnval; Ywin = LastWinY + CharHeight/2; Xwin = LastWinX; XDrawString (display, GraphWin, GraphContext, Xwin, Ywin, Text, strlen(Text)); XDrawString (display, Backup, GraphContext, Xwin, Ywin, Text, strlen(Text)); TextWidth = XTextWidth (CurrentFontStruct, Text, strlen(Text)); LastWinX = LastWinX+TextWidth; } if (Output == PSOnly || Output == XAndPS) fprintf (PSFile, "(%s) Lshow\n", Text);}voidSetDashLength (Length)int Length;{ CurrentDashLength = Length;}voidSetLineStyle(Style)int Style;{ char DashList[4]; int PSDashLength, WinX, WinY; double X, Y; if (InitOK == FALSE || FramOK == FALSE) error ("Sorry, you must call Initplot and Framing before anything else"); if (Output == XOnly || Output == XAndPS) { if (Style == 0) { XSetLineAttributes(display, GraphContext, CurrentLineWidth, LineSolid, CapButt, JoinMiter); XSetLineAttributes(display, BackContext, CurrentLineWidth, LineSolid, CapButt, JoinMiter); CurrentLineStyle = LineSolid; if (Output == XAndPS) fprintf (PSFile, "stroke [] 0 setdash\n"); } else if (Style == 1) { DashList[0] = 2*CurrentDashLength; DashList[1] = CurrentDashLength; XSetDashes(display, GraphContext, 0, DashList, 2); XSetDashes(display, BackContext, 0, DashList, 2); PSDashLength = CurrentDashLength*PSWidth/WinWidth; if (Output == XAndPS) fprintf (PSFile, "stroke \n[%d %d] 0 setdash\n", 2*PSDashLength, PSDashLength); } else if (Style == 2) { DashList[0] = CurrentLineWidth; DashList[1] = CurrentDashLength; XSetDashes(display, GraphContext, 0, DashList, 2); XSetDashes(display, BackContext, 0, DashList, 2); PSDashLength = CurrentDashLength*PSWidth/WinWidth; if (Output == XAndPS) fprintf (PSFile, "stroke \n[%d %d] 0 setdash\n", CurrentLineWidth, PSDashLength); } else if (Style == 3) { DashList[0] = 2*CurrentDashLength; DashList[1] = CurrentDashLength; DashList[2] = CurrentLineWidth; DashList[3] = CurrentDashLength; XSetDashes(display, GraphContext, 0, DashList, 4); XSetDashes(display, BackContext, 0, DashList, 4); PSDashLength = CurrentDashLength*PSWidth/WinWidth; if (Output == XAndPS) fprintf (PSFile, "stroke \n[%d %d %d %d] 0 setdash\n", 2*PSDashLength, PSDashLength, CurrentLineWidth, PSDashLength); } if (Style != 0) { XSetLineAttributes(display, GraphContext, CurrentLineWidth, LineOnOffDash, CapButt, JoinMiter); XSetLineAttributes(display, BackContext, CurrentLineWidth, LineOnOffDash, CapButt, JoinMiter); CurrentLineStyle = LineOnOffDash; } } if (Output == PSOnly) { if (Style == 0) { CurrentLineStyle = LineSolid; fprintf (PSFile, "stroke [] 0 setdash\n"); } else if (Style == 1) { DashList[0] = 2*CurrentDashLength; DashList[1] = CurrentDashLength; PSDashLength = CurrentDashLength*PSWidth/WinWidth; fprintf (PSFile, "stroke \n[%d %d] 0 setdash\n", 2*PSDashLength, PSDashLength); } else if (Style == 2) { DashList[0] = CurrentLineWidth; DashList[1] = CurrentDashLength; PSDashLength = CurrentDashLength*PSWidth/WinWidth; fprintf (PSFile, "stroke \n[%d %d] 0 setdash\n", CurrentLineWidth, PSDashLength); } else if (Style == 3) { DashList[0] = 2*CurrentDashLength; DashList[1] = CurrentDashLength; DashList[2] = CurrentLineWidth; DashList[3] = CurrentDashLength; PSDashLength = CurrentDashLength*PSWidth/WinWidth; fprintf (PSFile, "stroke \n[%d %d %d %d] 0 setdash\n", 2*PSDashLength, PSDashLength, CurrentLineWidth, PSDashLength); } if (Style != 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -