📄 grdevsub.c
字号:
/*************************************************************************History*************************************************************************//*26 March 1996 Add color routines for color postscript*//*************************************************************************Include files*************************************************************************/#include <stdio.h>#include <string.h>#include <math.h>#include <stdarg.h>#include "grdevsub.h"#include "cdhouse.h"/*************************************************************************Type definitions*************************************************************************/typedef struct { float x,y; } polytype;/*************************************************************************Defines*************************************************************************//* DEFINES */#define MAXPOLY 12#define CANONYOFF 10.625#define CANONXOFF 0.00#define CANONSC 300#define NTEMPSTR 4#define BOOLEAN int#define TRUE 1#define FALSE 0/*************************************************************************Module-Wide Variables*************************************************************************/float curx, cury, textsize;int fillflag, settextflag;FILE *__f;polytype temppoly[MAXPOLY];char __tempstr[NTEMPSTR][256];int __itempstr = 0;int PSflag = 0;/*************************************************************************Local Functions*************************************************************************//* CONVERT float TO ROUNDED integer */int round (float x) { int i = x + 0.5; return(i);}/* CONVERT float TO SHORT FORMATED STRING (TRUNCATED TRAILING 0 AND .) */char *fmt (float x, int n) { char *t, *u; t = &__tempstr[__itempstr++][1]; /* ROTATE BETWEEN STRING BUFFERS */ __itempstr %= NTEMPSTR; sprintf (t, "%12.*f", n, 72*x); /* Remove Leading Blanks */ while (*t==' ' && *t!=0) t++; /* if DECIMAL POINT REMOVE TRAILING ZEROS */ if (n>0) { /* Point to end of string */ u = t + strlen(t) - 1; while (*u=='0' && u!=t) u--; *(u+1) = 0; /* Remove trailing decimal point */ if (*u=='.') *u = 0; } /* REMOVE JUST TRAILING DECIMAL */ else if (n==0) { /* Point to end of string */ u = t + strlen(t) - 1; /* Remove trailing decimal point */ if (*u=='.') *u = 0; } /* Pad with one leading blank */ *(--t) = ' '; return(t);}/* CONVERT INTEGER TO SPECIAL CANON PRINTER FORMAT */void sendvals (int NumToPrinter){ static char TempStr[4]; unsigned char Sign; unsigned int OutByte, LoByte, HiByte; int n = 0; if (NumToPrinter>=0) Sign = 1; else { Sign = 0; NumToPrinter = -NumToPrinter; } LoByte = NumToPrinter & 0x00FF; HiByte = (NumToPrinter & 0xFF00) >> 8; /* FIRST BYTE */ OutByte = HiByte >> 2; if (OutByte>0) TempStr[n++] = OutByte + 64; /* Second Byte */ OutByte = ((HiByte & 0x0003) << 4) + ((LoByte & 0x00f0) >> 4); if (OutByte>0 || n) TempStr[n++] = OutByte + 64; /* Set Second Bit*/ /* Third Byte */ OutByte = LoByte & 0x000f; if (Sign) TempStr[n++] = OutByte + 48; else TempStr[n++] = OutByte + 32; TempStr[n] = 0; fprintf (__f, "%s", TempStr);} /* CANON DEVICE DEPENDENT ROUTINES */void Canon_InitFile (void){ fprintf (__f, "%s%s", "\033","<"); /* SOFT RESET */ fprintf (__f, "%s%s", "\033",";"); /* ISO */ fprintf (__f, "%s%s", "\033","[2&z"); /* FULL PAINT */ fprintf (__f, "%s%s", "\033",";"); /* ISO */ fprintf (__f, "%s%s", "\033","[&}"); /* VDM */ fprintf (__f, "%s%s", "#","\036"); /* BEGIN PICTURE */ fprintf (__f, "%s", "!0"); /* SET SCALE (units 0.01 inch, scale 1 inch) */ sendvals ( -3); sendvals ( 3); fprintf (__f, "%s", "\036"); fprintf (__f, "%s%s","$","\036"); /* BEGIN BODY */ fprintf (__f, "%s%s","E10","\036"); /* LINE TYPE */ fprintf (__f, "%s","F1"); /* LINE WIDTH (3 dots) */ sendvals ( -2); fprintf (__f, "%s", "\036"); fprintf (__f, "%s%s","}G0","\036"); /* LINE STYLE */}void Canon_DrawTo (float x, float y){ /* DEVICE SPECIFIC DRAWING COMMANDS */ fprintf (__f, "%s", "1"); sendvals (round( CANONSC*(CANONXOFF+curx))); sendvals (round( CANONSC*(CANONYOFF-cury))); sendvals (round( CANONSC*(x-curx))); sendvals (round(-CANONSC*(y-cury))); fprintf (__f, "%s", "\036"); /* RESET CURRENT POSITION */ curx = x; cury = y;}void Canon_DrawRel (float dx, float dy){ /* DEVICE SPECIFIC DRAWING COMMANDS */ fprintf (__f, "%s", "1"); sendvals (round(CANONSC*(CANONXOFF+curx))); sendvals (round(CANONSC*(CANONYOFF-cury))); sendvals (round( CANONSC*dx)); sendvals (round(-CANONSC*dy)); fprintf (__f, "%s", "\036"); /* RESET CURRENT POSITION */ curx = curx + dx; cury = cury + dy;}void Canon_Drawpoly (int npoly, polytype *poly){ int i; /* SET FILL STATE */ fprintf (__f, "%s", "I"); if (fillflag) sendvals ( 1); else sendvals ( 0); fprintf (__f, "%s", "\036"); /* DRAW POLYGON */ fprintf (__f, "%s", "*/2"); sendvals (round(CANONSC*(CANONXOFF+curx+poly[0].x))); sendvals (round(CANONSC*(CANONYOFF-cury-poly[0].y))); for (i=1;i<npoly;i++) { sendvals (round( CANONSC*poly[i].x)); sendvals (round(-CANONSC*poly[i].y)); } fprintf (__f, "%s", "\036");}void Canon_WriteText (char *instr){ fprintf (__f, "%s%s", "}p", "\036"); /* EXIT VDM MODE */ fprintf (__f, "%s%s", "\033","[11h"); /* SIZE UNIT MODE */ fprintf (__f, "%s%s%s%s%s", "\033[7 I", /* SELECT SIZE UNIT (1/300") */ "\033[?8l", /* ENABLE PROPORTIONAL SPACING */ "\033[?32h ", /* ENABLE SCALABLE FONT SEL. */ "\033PzSwiss.ISO_USA", /* SELECT FONT */ "\033\\"); fprintf (__f, "%s%s%i%s", "\033", "[",round(300*textsize), " C"); /* CHARCTER SIZE */ fprintf (__f, "%s%s%i%s", "\033", "[",round(300*curx),"`"); /* HOR POS */ fprintf (__f, "%s%s%i%s", "\033", /* VER POS */ "[",round(300*(CANONYOFF-cury-2*textsize)),"d"); fprintf (__f, "%s", instr); /* RETURN TO VDM MODE */ fprintf (__f, "%s%s", "\033","[0&}"); /* VDM */ fprintf (__f, "%s%s", "#","\036"); /* BEGIN PICTURE */ fprintf (__f, "%s", "!0"); /* SET SCALE (units 0.01 inch, scale 1 inch) */ sendvals ( -3); sendvals ( 3); fprintf (__f, "%s", "\036"); fprintf (__f, "%s%s","$","\036"); /* BEGIN BODY */}void Canon_Circle (float radius){ /* SET FILL STATE */ fprintf (__f, "%s", "I"); if (fillflag) sendvals ( 1); else sendvals ( 0); fprintf (__f, "%s", "\036"); /* WRITE CIRCLE */ fprintf (__f, "%s", "5"); sendvals ( round(CANONSC*(CANONXOFF+curx))); sendvals ( round(CANONSC*(CANONYOFF-cury))); sendvals ( round(CANONSC*radius)); fprintf (__f, "%s", "\036");}void Canon_WritePage (void){ /* DEVICE SPECIFIC COMMANDS */ fprintf (__f, "%s", "\014");} /* PostScript DEVICE DEPENDENT ROUTINES */void PS_InitFile (void) { char **HeaderPtr; char *HeaderComments[] = { "%!PS-Adobe-2.0", "%%Creator: XMD", "%%EndComments", "%%Page: ?", NULL }; /* Write header comments */ HeaderPtr = HeaderComments; while (*HeaderPtr!=NULL) { fprintf (__f, "%s\n", *HeaderPtr); HeaderPtr++; } /* SET LINE WIDTH AND CAPS */ fprintf (__f, "%s\n", "0.48 setlinewidth 1 setlinecap "); /* SET FILL LEVEL */ fprintf (__f, "%s\n", "0 setgray"); /* STORE SETTINGS */ fprintf (__f, "%s\n", "gsave "); }void PS_DrawTo (float x, float y){ /* DEVICE SPECIFIC DRAWING COMMANDS */ fprintf (__f, "%s%s%s ", fmt(curx,3), fmt(cury,3), " moveto" ); fprintf (__f, "%s%s%s\n", fmt(x, 3), fmt(y, 3), " lineto stroke"); /* RESET CURRENT POSITION */ curx = x; cury = y;}void PS_DrawRel (float dx, float dy){ /* DEVICE SPECIFIC DRAWING COMMANDS */ fprintf (__f, "%s%s%s", fmt(curx,3), fmt(cury,3), " moveto" ); fprintf (__f, "%s%s%s\n", fmt(dx, 3), fmt(dy, 3), " rlineto stroke"); /* RESET CURRENT POSITION */ curx = curx + dx; cury = cury + dy;}void PS_Drawpoly (int npoly, polytype *poly){ int i; fprintf (__f, "%s%s%s\n", fmt(curx,3), fmt(cury,3), " moveto"); if (npoly>=1) fprintf (__f, "%s%s%s\n", fmt(poly[0].x,3), fmt(poly[0].y,3), " rmoveto"); if (npoly> 1) for (i=1;i<npoly;i++) fprintf (__f, "%s%s%s\n", fmt(poly[i].x,3), fmt(poly[i].y,3), " rlineto"); if (npoly>=1) if (fillflag) fprintf (__f, "%s\n", "closepath fill"); else fprintf (__f, "%s\n", "closepath stroke");}void PS_WriteText (char *instr){ /* DEVICE SPECIFIC TEXT COMMANDS */ if (settextflag) { fprintf (__f, "%s%s%s\n", "/Courier findfont", fmt(textsize,0), " scalefont setfont "); settextflag = 0; } fprintf (__f, "%s%s%s\n", fmt(curx,2), fmt(cury,2), " moveto"); fprintf (__f, "%s%s%s\n", "(", instr, ") show newpath" );}void PS_Circle (float radius){ /* DEVICE SPECIFIC CIRCLE COMMANDS */ fprintf (__f, "%s%s%s%s", fmt(curx,3), fmt(cury,3), fmt(radius,3), " 0 360 arc "); if (fillflag) fprintf (__f, "%s\n", "fill"); else fprintf (__f, "%s\n", "stroke");}void PS_WritePage (void){ /* DEVICE SPECIFIC COMMANDS */ fprintf (__f, "%s\n", "newpath showpage grestore");}/* Set color according to Cyan-Magenta-Yellow-Black model */void PS_setcmybcolor (float Cyan, float Magenta, float Yellow, float Black) { fprintf (__f, "%5.3f %5.3f %5.3f %5.3f setcmybcolor\n", Cyan, Magenta, Yellow, Black); }/* Set color according to Hue-Saturation-Brightness model */void PS_sethsbcolor (float Hue, float Saturation, float Brightness) { fprintf (__f, "%5.3f %5.3f %5.3f sethsbcolor\n", Hue, Saturation, Brightness); }/* Set color according to Red-Green-Blue model */void PS_setrgbcolor (float Red, float Green, float Blue) { fprintf (__f, "%5.3f %5.3f %5.3f setrgbcolor\n", Red, Green, Blue); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -