📄 zbufinout.c
字号:
} }}/* dumps a line of chars in the Aldus FreeHand ps format*/void dump_line_as_ps(fp, psline, x_position, y_position, font_size)char *psline;double x_position, y_position, font_size;FILE *fp;{ fprintf(fp, "%%%%IncludeFont: Times-Roman\n"); fprintf(fp, "/f1 /|______Times-Roman dup RF findfont def\n{\n"); fprintf(fp, "f1 [%g 0 0 %g 0 0] makesetfont\n", font_size, font_size); fprintf(fp, "%g %g moveto\n", x_position, y_position); fprintf(fp, "0 0 32 0 0 (%s) ts\n}\n", psline); fprintf(fp, "[0 0 0 1]\nsts\nvmrs\n");}/* dump nblocks blocks with shades between white and black, labeled with density*/void dump_shading_key(fp, nblocks, precision, font_size, use_density)int nblocks, precision, use_density;double font_size;FILE *fp;{ int i; double x_right, y_top, block_hgt, block_x, block_y, string_x, diddle_x; double grey_step, grey_lev, density, density_step, white_width; char linein[BUFSIZ], ctrl[BUFSIZ]; extern double black, white, linewd; x_right = OFFSETX + IMAGEX; y_top = OFFSETY + IMAGEY; block_hgt = KEYHGT/(double)nblocks; block_x = x_right - KEYWID; block_y = y_top; /*string_x = block_x - font_size*(6.0/2.0 + (double)precision);*/ string_x = block_x + font_size/2.0; /* writing raw ps so 1.0 = white, 0.0 = black */ grey_lev = 0.0; grey_step = 1.0/(double)(nblocks-1); density = black; density_step = (black-white)/(double)(nblocks-1); /*white_width = 3.0 + (double)precision;*/ white_width = KEYWID; /* write the key title */ if(use_density) { strcpy(linein, "DENSITY, statC/m^2"); diddle_x = font_size; } else { strcpy(linein, "CHARGE, statC"); diddle_x = font_size/2.0; } dump_line_as_ps(fp, linein, string_x-diddle_x, y_top + font_size/2.0, font_size); for(i = 0; i < nblocks; i++) { /* write a fill with border for the key block */ /* dump the fill */ fprintf(fp, "%g %g moveto\n", block_x, block_y); fprintf(fp, "%g %g lineto\n", block_x + KEYWID, block_y); fprintf(fp, "%g %g lineto\n", block_x + KEYWID, block_y - block_hgt); fprintf(fp, "%g %g lineto\n", block_x, block_y - block_hgt); fprintf(fp, "closepath\n"); fprintf(fp, " %g setgray fill\n", grey_lev); /* dump the white out for the label */ fprintf(fp, "%g %g moveto\n", block_x, block_y); fprintf(fp, "%g %g lineto\n", block_x + white_width, block_y); fprintf(fp, "%g %g lineto\n", block_x + white_width, block_y - font_size - font_size/10.0); fprintf(fp, "%g %g lineto\n", block_x, block_y - font_size - font_size/10.0); fprintf(fp, "closepath\n"); fprintf(fp, " 1.0 setgray fill\n"); /* dump the outline */ fprintf(fp, "%g %g moveto\n", block_x, block_y); fprintf(fp, "%g %g lineto\n", block_x + KEYWID, block_y); fprintf(fp, "%g %g lineto\n", block_x + KEYWID, block_y - block_hgt); fprintf(fp, "%g %g lineto\n", block_x, block_y - block_hgt); fprintf(fp, "closepath\n"); fprintf(fp, "%g setlinewidth %d setlinecap %d setlinejoin ", linewd, LINCAP, LINJIN); fprintf(fp, " 0 setgray stroke\n"); /* dump the label */ sprintf(ctrl, "%%.%dg", precision); sprintf(linein, ctrl, density); dump_line_as_ps(fp, linein, string_x, block_y - font_size, font_size); block_y -= block_hgt; density -= density_step; grey_lev += grey_step; }}/* numbers the lines for checking */void numberLines(lines, numlines, fp)line **lines;int numlines;FILE *fp;{ int i, mid[2]; /* put line number on midpoint of each line */ for(i = 0; i < numlines; i++) { /* figure midpoint, truncate (truncation not really necessary) */ mid[0] = ((lines[i]->from)[0] + (lines[i]->to)[0])/2; mid[1] = ((lines[i]->from)[1] + (lines[i]->to)[1])/2; /* dump a label with associated garbage */ fprintf(fp, "%%%%IncludeFont: Times-Roman\n"); fprintf(fp, "/f1 /|______Times-Roman dup RF findfont def\n{\n"); fprintf(fp, "f1 [%d 0 0 %d 0 0] makesetfont\n", FONT, FONT); fprintf(fp, "%d %d moveto\n", mid[0], mid[1]); fprintf(fp, "0 0 32 0 0 (%d) ts\n}\n", lines[i]->index); fprintf(fp, "[0 0 0 1]\nsts\nvmrs\n"); }}/* lobotomized version of dumpPs in orthoPs.c - dumps lines/arrows*/void dumpLines(fp, lines, numlines)line **lines;int numlines;FILE *fp;{ int i, j, w_; double temp[3], temp1[3], x, y; if(fp == NULL) { fprintf(stderr, "dumpLines: null ps file pointer\n"); exit(1); } w_ = 0; /* hardwire for no width override */ /* dump the lines */ for(i = 0; i < numlines; i++) { fprintf(fp, "%%%% begin line %d\n", lines[i]->index); fprintf(fp, "0 sf\nnewpath\n"); x = (lines[i]->from)[0]; y = (lines[i]->from)[1]; fprintf(fp, "%g %g moveto\n", x, y); x = (lines[i]->to)[0]; y = (lines[i]->to)[1]; fprintf(fp, "%g %g lineto\n", x, y); fprintf(fp, "gsave\n"); if(lines[i]->width == DASHED) { if(w_ == 0) fprintf(fp, "%d setlinewidth 1 setlinecap 0 setlinejoin 3.863693", DASWTH); else fprintf(fp, "%d setlinewidth 1 setlinecap 0 setlinejoin 3.863693", OVRWTH); fprintf(fp, " setmiterlimit [0 0 0 1]setcolor [2 4] 0 setdash {stroke}fp\n"); } else { if(w_ == 0) fprintf(fp, "%d setlinewidth 1 setlinecap 0 setlinejoin 3.863693", lines[i]->width); else fprintf(fp, "%d setlinewidth 1 setlinecap 0 setlinejoin 3.863693", OVRWTH); fprintf(fp, " setmiterlimit [0 0 0 1]setcolor {stroke}fp\n"); } fprintf(fp, "grestore\n"); if(lines[i]->arrow > 0.0) { /* put arrow head on to side if desired */ /* figure unit vector from `to' point to `from' point */ for(j = 0; j < 2; j++) temp[j] = lines[i]->from[j]-lines[i]->to[j]; temp1[0] = sqrt(temp[0]*temp[0]+temp[1]*temp[1]); for(j = 0; j < 2; j++) temp[j] /= temp1[0]; for(j = 0; j < 2; j++) /* figure unit perpendicular */ temp1[j] = 1.0/(temp[j]*sqrt(1.0/(temp[0]*temp[0])+1.0/(temp[1]*temp[1]))); temp1[0] = -temp1[0]; /* draw the arrow */ fprintf(fp, "%%%% Begin arrow head for line %d\n", i); fprintf(fp, "%g %g moveto\n", lines[i]->to[0], lines[i]->to[1]); fprintf(fp, "%g %g lineto\n", lines[i]->to[0]+lines[i]->arrow*ALEN*temp[0] +lines[i]->arrow*(AWID/2)*temp1[0], lines[i]->to[1]+lines[i]->arrow*ALEN*temp[1] +lines[i]->arrow*(AWID/2)*temp1[1]); fprintf(fp, "%g %g lineto\n", lines[i]->to[0]+lines[i]->arrow*ALEN*temp[0] -lines[i]->arrow*(AWID/2)*temp1[0], lines[i]->to[1]+lines[i]->arrow*ALEN*temp[1] -lines[i]->arrow*(AWID/2)*temp1[1]); fprintf(fp, "closepath\n"); fprintf(fp, " 0 setgray fill\n"); /* put dot on from end of line, if called for */ if(lines[i]->dot > 0.0) fprintf(fp, "%g %g %g 0 360 arc closepath fill\n", lines[i]->from[0], lines[i]->from[1], lines[i]->dot*DOTSIZ); } }} /* dump faces in ps Aldus FreeHand format - assumes header body in afhpsheader*/void dumpPs(faces, numfaces, lines, numlines, fp, argv, argc, use_density)face **faces;line **lines;char **argv;int numfaces, numlines, argc, use_density;FILE *fp; { int i, j, f, lowx, lowy; extern int s_, n_, g_, c_, x_, q_, rk_, f_, m_; /* command line flags */ extern double ***axes; extern double black, white; char linein[BUFSIZ]; double dot(), len, temp[2], xc, yc; double x, y; /* print the lines before the bounding box */ fprintf(fp, "%%!PS-Adobe-2.0 EPSF-1.2\n"); fprintf(fp, "%%%%Creator: FreeHand\n"); fprintf(fp, "%%%%Title: test.ps\n"); fprintf(fp, "%%%%CreationDate: 4/19/90 10:47 AM\n"); getBndingBox(faces, numfaces, lines, numlines, &lowx, &lowy, fp, axes); /* prnt bnding box */ copyBody(fp); /* copys the body of the header from "afhpsheader" */ /* dump the text header if needed */ if(n_ == TRUE || g_ == TRUE || c_ == TRUE || q_ == TRUE) { fprintf(fp, "/textopf false def\n/curtextmtx{}def\n/otw .25 def\n"); fprintf(fp, "/msf{dup/curtextmtx xdf makefont setfont}bdf\n"); fprintf(fp, "/makesetfont/msf load def\n"); fprintf(fp, "/curtextheight{.707104 .707104 curtextmtx dtransform\n"); fprintf(fp, "dup mul exch dup mul add sqrt}bdf\n"); fprintf(fp, "/ta{1 index\n{tempstr 0 2 index put tempstr 2 index\n"); fprintf(fp, "gsave exec grestore\ntempstr stringwidth rmoveto\n"); fprintf(fp, "5 index eq{6 index 6 index rmoveto}if\n"); fprintf(fp, "3 index 3 index rmoveto\n"); fprintf(fp, "}forall 7{pop}repeat}bdf\n"); fprintf(fp, "/sts{setcolor textopf setoverprint/ts{awidthshow}def exec}bdf\n"); fprintf(fp, "/stol{setlinewidth setcolor textopf setoverprint newpath\n"); fprintf(fp, "/ts{{false charpath stroke}ta}def exec}bdf\n"); } /* print rest of header (starting with after /currentpacking where...) */ fprintf(fp, "/currentpacking where{pop false setpacking}if\n"); fprintf(fp, "%%%%EndSetup\n"); fprintf(fp, "/spots[1 0 0 0 (Process Cyan) false newcmykcustomcolor\n"); fprintf(fp, "0 1 0 0 (Process Magenta) false newcmykcustomcolor\n"); fprintf(fp, "0 0 1 0 (Process Yellow) false newcmykcustomcolor\n"); fprintf(fp, "0 0 0 1 (Process Black) false newcmykcustomcolor\n]def\nvms\n"); /* dump command line as a comment */ fprintf(fp, "%%%% "); for(i = 0; i < argc; i++) fprintf(fp, " %s", argv[i]); fprintf(fp, "\n"); if(x_ == TRUE) dumpAxes(axes, fp); /* dump axes if called for */ /* for each face - dump fill, then outline - assumes depth ordering */ for(f = 0; f < numfaces; f++) { if(!f_) { /* dump the fill */ fprintf(fp, "%%%% Begin face %d\n", f); /* fprintf(fp, "0 sf\nnewpath\n"); */ /* fprintf(fp, "newpath\n");*/ fprintf(fp, "%g %g moveto\n", faces[f]->c[0][0], faces[f]->c[0][1]); for(i = 1; i < faces[f]->numsides; i++) { fprintf(fp, "%g %g lineto\n", faces[f]->c[i][0], faces[f]->c[i][1]); } fprintf(fp, "closepath\n"); /* fprintf(fp, "gsave\n");*/ /* fprintf(fp, "[0 0 0 %g]setcolor {fill}fp\ngrestore\n", GREYLEV); */ /* fprintf(fp, "[0 0 0 %g]setcolor fill\n", GREYLEV);*/ fprintf(fp, " %g setgray fill\n", 1.0-faces[f]->greylev); /* fprintf(fp, "grestore\n");*/ } /* dump the outline */ /* fprintf(fp, "0 sf\nnewpath\n"); */ /* fprintf(fp, "newpath\n");*/ fprintf(fp, "%g %g moveto\n", faces[f]->c[0][0], faces[f]->c[0][1]); for(i = 1; i < faces[f]->numsides; i++) { fprintf(fp, "%g %g lineto\n", faces[f]->c[i][0], faces[f]->c[i][1]); } fprintf(fp, "closepath\n"); /* fprintf(fp, "gsave\n");*/ if(faces[f]->width == DASHED) { fprintf(fp, "%d setlinewidth %d setlinecap %d setlinejoin 3.863693", DASWTH, LINCAP, LINJIN); /* fprintf(fp, " setmiterlimit [0 0 0 1]setcolor [2 4] 0 setdash {stroke}fp\n");*/ fprintf(fp, " setmiterlimit [0 0 0 1]setcolor [2 4] 0 setdash stroke\n"); } else { /* fprintf(fp, "%g setlinewidth %d setlinecap %d setlinejoin 3.863693", faces[f]->width, LINCAP, LINJIN); */ fprintf(fp, "%g setlinewidth %d setlinecap %d setlinejoin ", faces[f]->width, LINCAP, LINJIN); /* fprintf(fp, "[0 0 0 1]setcolor {stroke}fp\ngrestore\n"); */ /* fprintf(fp, "[0 0 0 1]setcolor stroke\n");*/ fprintf(fp, " 0 setgray stroke\n"); /* fprintf(fp, "grestore\n");*/ } if(n_ == TRUE) numberFace(faces[f], fp); } dumpLines(fp, lines, numlines); /* if this is just to check placement, number the faces */ if(n_ == TRUE) { /* numberFaces(faces, numfaces, fp); */ numberLines(lines, numlines, fp); /*fprintf(stderr, "Faces and lines numbered\n");*/ } /* if fills were not included, say so if(f_) fprintf(stderr, "Face fills not written to ps file\n"); */ /* print shading key if not disabled and charge density info was inputed */ if(q_ && !rk_ && !m_) dump_shading_key(fp, KEYBLKS, KEYPREC, KEYFONT, use_density); /* print footer */ if(c_ == TRUE) { /* print command line if asked for */ for(f = 0, linein[0] = '\0'; f < argc; f++) { strcat(linein, argv[f]); strcat(linein, " "); } dump_line_as_ps(fp, linein, OFFSETX+2*CMDFONT, IMAGEY-2*CMDFONT, CMDFONT); /*fprintf(stderr, "Command line printed\n");*/ } fprintf(fp, "vmr\nend %% FreeHandDict\n"); if(s_ == FALSE) { fprintf(fp, "showpage\n"); /*fprintf(stderr, "Showpage inserted\n");*/ } fprintf(fp, "%%%%EndDocument: _\n");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -