Super Plot (2 of 8)
Marc Majka
majka at ubc-vision.UUCP
Mon Apr 28 08:47:51 AEST 1986
- - - CUT - - - CUT - - - CUT - - - CUT - - - CUT - - - CUT - - - CUT - - -
#!/bin/sh
#
# shell archive - extract with /bin/sh
#
echo Plot archive part 2 of 8
echo
echo extracting file fplot.man
sed 's/^X//' > fplot.man <<'!FUNKY!STUFF!'
XFPLOT(3) UNIX Programmer's Manual FPLOT(3)
X
XNAME
X fplot: graphics interface.
X
XSYNOPSIS
X plotopen(fname)
X char *fname;
X
X plotappend(fname)
X char *fname;
X
X plotflush()
X
X plotclose()
X
X area(x1,y1)
X short x1,y1;
X
X arc(x1,y1,x2,y2,x3,y3)
X short x1,y1,x2,y2,x3,y3;
X
X blabel(w,h,str)
X short w,h;
X char *str;
X
X bppin(b)
X short b;
X
X bppout(b)
X short b;
X
X bspline(k,n,v)
X short k, n, *v;
X
X chain(n,v)
X short n, *v;
X
X circle(x1,y1,r)
X short x1,y1,r;
X
X clabel(str)
X char *str;
X
X colour(red,green,blue)
X short red,green,blue;
X
X comment(str)
X char *str;
X
X cont(x1,y1)
X short x1,y1;
X
X contrel(x1,y1)
X short x1,y1;
X
X endp()
X
X erase()
X
X fillpat(pn,x1,y1,str)
X short pn,x1,y1;
X char *str;
X
X font(str)
X char *str;
X
X frame(x1,y1,x2,y2,hv)
X short x1,y1,x2,y2,hv;
X
X fspec(ws,hs,theta)
X double ws,hs,theta;
X
X gray(g)
X short g;
X
X label(str)
X char *str;
X
X line(x1,y1,x2,y2)
X short x1,y1,x2,y2;
X
X linemod(str)
X char *str;
X
X llabel(w,h,str)
X short w,h;
X char *str;
X
X move(x1,y1)
X short x1,y1;
X
X moverel(x1,y1)
X short x1,y1;
X
X pensize(pn)
X short pn;
X
X point(x1,y1)
X short x1,y1;
X
X polygon(n,v)
X short n, *v;
X
X setpat(pn)
X short pn;
X
X space(x1,y1,x2,y2,hv)
X short x1,y1,x2,y2,hv;
X
X startp()
X
XDESCRIPTION
X These routines write plot commands to an output file named
X in the plotopen(fname) call, or to standard output if no
X name is given. plotappend(fname) opens the plot file in
X append mode. plotflush() flushes the output stream. Plot
X commands in the output file are identified by a single
X character, followed by their arguments. The plot file
X should be closed with a call to plotclose().
X
XPLOT FILE FORMAT
X a arc xc yc x1 y1 x2 y2: draw a circular arc centered at
X (xc yc), from (x1 y1) to (x2 y2). Arcs are drawn clock-
X wise. (x2 y2) becomes the current point.
X
X b bppout b: scale output gray and colour values to a b
X bit per pixel range. Specifies the output device's gray-
X scale range.
X
X c circle x y r: draw a circle of radius r with centre
X (x y). The centre becomes the current point.
X
X d pensize n: set the diameter of the pen.
X
X e erase: clear the image to the current gray or current
X colour value.
X
X f linemod str: change the line mask used by the vector
X generator. Str is be a string of 0s an 1s. The line gen-
X erator will set pixels marked by a 1 in the string. For
X example, to produce a dotted line, a string like 11000
X might be used. The line generator cycles through the
X mask. The mask pointer is not reset on n (cont) instruc-
X tions, so the pattern will continue to the next segment,
X if desired. The initial line mask is 1, which generates
X solid lines.
X
X g gray g: set the current gray level to g from the user's
X gray scale range. This value will be scaled to the output
X gray scale range.
X
X k bspline k n x1 y1 x2 y2 ... xn yn: draw an order k
X B-spline. The n points are control points. The spline
X does not interpolate between the points. The algorithm
X is taken from "Principles of Interactive Computer Graph-
X ics" by Newmann and Sproull, page 323.
X
X l line x1 y1 x2 y2: draw a line from (x1 y1) to (x2 y2).
X (x2 y2) becomes the current point.
X
X m move x y: (x y) becomes the current point.
X
X n cont x y: draw a line from the current point to (x y).
X (x y) becomes the current point.
X
X o polygon n x1 y1 x2 y2 ... xn yn: draw a filled polygon.
X The polygon has n vertices, x1 y1 ... xn yn. The polygon
X subroutine expects the value of n, and a pointer to an
X array of 2*n values, which are used as x y pairs.
X
X p point x y: set the point (x y). It becomes the
X current point.
X
X s space x1 y1 x2 y2 hv: define the user's co-
X ordinates. (x1 y1) and (x2 y2) define the ends of a diag-
X onal through the space. If hv is one, then the first
X coordinate (x) will be regarded as horizontal, and the
X second as vertical. Otherwise, the first coordinate will
X be regarded as vertical and the second as horizontal.
X
X t label str: write the text string, up to a newline,
X starting at the current point. The text is written using
X the current font, with the current width scale, height
X scale and rotation angle.
X
X A area x y: fill an area starting at the seed point (x y).
X All 4-connected points having the same gray level as the
X seed point will be set to the current gray level. The
X boundary thus consists of pixels with a gray level dif-
X ferent from the seed point gray level, or the edge of the
X defined space.
X
X B bppin b: input gray and colour values will be drawn
X from a b bit per pixel range.
X
X C colour red green blue: set the current red green
X and blue values from the user's input range.
X
X F frame r1 c1 r2 r2 hv: define the device coordi-
X nate system. The point (x1 y1) from the user's coordinate
X system (from the space command) will be mapped to
X (r1 c1), and (x2 y2) will be mapped to (r2 c2). If hv is
X one, the device's first coordinate is horizontal.
X
X L chain n x1 y1 x2 y2 ... xn yn: draw a polyline (or
X chain). The line has n vertices, x1 y1 ... xn yn. The
X chain subroutine expects the value of n, and a pointer to
X an array of 2*n values, which are used as x y pairs.
X
X M moverel dx dy: displace the current point by dx and
X dy.
X
X N contrel dx dy: draw a line from the current point to
X a new current point displaced by dx and dy.
X
X P fillpat n r c str: the string str is used as an r
X row by c column pattern, which may be used for area,
X fill, and erase commands. Pixels under a 1 in the pattern
X are set to the current gray level. The pattern is labeled
X n. This label is used to refer to the pattern.
X
X S fspec ws hs theta: change the width scale (ws),
X height scale(hs), and rotation angle (theta) for labels
X in the current font. The angle theta is in radians, meas-
X ured anticlockwise from 0.0.
X
X T setpat n: set the current fill pattern to n.
X
X U blabel w h str: draws the string as a label, but scales
X the characters to fit in a box w units wide by h units
X high, with the current point at the upper left corner.
X
X V llabel w h str: like blabel, except that the height scale
X is based on the maximum height of caracters in the entire
X current font.
X
X X font str: change the current font to that named by str.
X See the section on fonts below.
X
X [ startp: start a filled polygon. Any closed figure
X drawn with the current gray level, will be filled using
X the current gray level and fill pattern. The end of the
X polygon must be marked by a ] (endp) plot command.
X
X ] endp: end a filled polygon. This command must be pre-
X ceeded by a [ (startp) plot command. The polygon is
X filled when this command is encountered.
X
X ; comment str: all characters up to a newline are taken
X as a comment. No action is taken.
X
X % clabel str: draws the string so that it is horizontally
X and vertically centered at the current point.
X
XFONTS
X Labels are plotted using the current font, using the current
X width and height scales, and rotation angle. The initial
X font is Simplex Roman, the width and height scales are 1.0,
X and the rotation angle is 0.0. Label characters not in the
X font are ignored.
X
X Caveat Scriptor
X Characters are plotted relative to the current point.
X This point is usually near the upper left corner of the
X character. However, characters may extend above and to
X the left of the current point. Some experimentation may
X be necessary for correct label placement.
X
X The following fonts are available:
X
X sr Simplex Roman
X dr Duplex Roman
X cr Complex Roman
X tr Triplex Roman
X ci Complex Italic
X ti Triplex Italic
X ss Simplex Script
X cs Complex Script
X ge Gothic English
X gg Gothic German
X gi Gothic Italian
X
X If the font name begins with the character /, the name is
X taken to be a file name containing an alternate font.
X
XAUTHOR
X Marc Majka
!FUNKY!STUFF!
echo extracting file hcat.c
sed 's/^X//' > hcat.c <<'!FUNKY!STUFF!'
X#include<stdio.h>
X#define TB "vfont/hf.table"
X#define CL "vfont/hf.clist"
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X short glyph;
X int g, x, y, i, xc, yc, rc, index, f;
X char c, cx, cy, gn[8], fn[32];
X FILE *tb, *cl, *fopen();
X
X tb = fopen(TB,"r");
X cl = fopen(CL,"r");
X
X if (tb == NULL) {
X fprintf(stderr,"Can't open %s!\n",TB);
X exit(0);
X }
X if (cl == NULL) {
X fprintf(stderr,"Can't open %s!\n",CL);
X exit(0);
X }
X
X f = 0;
X sprintf(fn,"hfcat.%d\0",f++);
X
X fprintf(stderr,"[%d",f-1);
X fflush(stderr);
X
X plotopen(fn);
X space(0,0,680,680,1);
X font("sr");
X fspec(0.5,-0.5,0.0);
X
X xc = 40; yc = 40;
X move(xc,yc);
X
X rc = fread(&glyph,2,1,tb);
X
X while (rc > 0) {
X rc = fread(&index,4,1,tb);
X rc = fseek(cl,index,0);
X if (rc < 0) fprintf(stderr,"cl fseek failed! offset = %d\n",index);
X c = getc(cl);
X while (c != '\0') {
X cx = getc(cl);
X cy = getc(cl);
X x = cx; y = -1 * cy;
X if (c == 'M') moverel(x,y);
X else if (c == 'N') contrel(x,y);
X c = getc(cl);
X }
X move(xc,yc+30);
X sprintf(gn,"%d\0",glyph);
X label(gn);
X xc += 80;
X if (xc > 640) {
X xc = 40;
X yc += 80;
X if (yc > 640) {
X plotclose();
X yc = 40;
X sprintf(fn,"hfcat.%d\0",f++);
X fprintf(stderr,"] [%d",f-1);
X fflush(stderr);
X plotopen(fn);
X space(0,0,680,680,1);
X font("sr");
X fspec(0.5,-0.5,0.0);
X }
X }
X move(xc,yc);
X
X rc = fread(&glyph,2,1,tb);
X }
X plotclose();
X fprintf(stderr,"]\n");
X}
!FUNKY!STUFF!
echo extracting file hcat.man
sed 's/^X//' > hcat.man <<'!FUNKY!STUFF!'
XHCAT(1) UNIX Programmer's Manual HCAT(1)
X
XNAME
X hcat - make Hershey font catalogue
X
XSYNOPSIS
X hcat
X
XDESCRIPTION
X hcat creates a set of plot files which form a catalogue for
X the Hershey fonts. The program hform must be run before this
X routine in order to create the necessary files. hcat creates
X the files hfcat.0 - hfcat.24. Each is a single page contain-
X ing 64 numbered glyphs from the Hershey fonts.
X
XAUTHOR
X Marc Majka
X
!FUNKY!STUFF!
echo extracting file hfont.c
sed 's/^X//' > hfont.c <<'!FUNKY!STUFF!'
X#include<stdio.h>
X#define TB "vfont/hf.table"
X#define CL "vfont/hf.clist"
X#define MAXF 32768
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X short glyph;
X int g, x, y, i, dx, dy;
X int rc, index, gx[256], cn, cpt, spt, cstart[256];
X char c, cx, cy, fstr[MAXF];
X FILE *tb, *cl, *fopen();
X
X tb = fopen(TB,"r");
X cl = fopen(CL,"r");
X
X if (tb == NULL) {
X fprintf(stderr,"Can't open %s!\n",TB);
X exit(1);
X }
X if (cl == NULL) {
X fprintf(stderr,"Can't open %s!\n",CL);
X exit(1);
X }
X
X for (i = 0; i < 256; i++) gx[i] = -1;
X
X scanf("%d %d%*[^\n]%*c",&dx,&dy);
X
X c = getchar();
X while (c != EOF) {
X scanf("%d%*[^\n]%*c",&g);
X cn = (unsigned)c;
X
X fseek(tb,0,0);
X rc = fread(&glyph,2,1,tb);
X
X while ((rc > 0) && (g != glyph)) {
X rc = fread(&index,4,1,tb);
X rc = fread(&glyph,2,1,tb);
X }
X
X if (rc == 0) {
X fprintf(stderr,"Glyph %d not found (char \'%c\')!\n",g,c);
X fclose(tb);
X tb = fopen(TB,"r");
X
X if (tb == NULL) {
X fprintf(stderr,"Can't open %s!\n",TB);
X exit(1);
X }
X }
X
X else {
X rc = fread(&index,4,1,tb);
X gx[cn] = index;
X }
X c = getchar();
X }
X
X spt = 0;
X
X for (i = 0; i < 256; i++) {
X if (gx[i] >= 0) {
X rc = fseek(cl,gx[i],0);
X if (rc < 0) {
X fprintf(stderr,"cl fseek failed! offset = %d\n",gx[i]);
X exit(1);
X }
X
X cstart[i] = spt;
X
X c = getc(cl);
X cx = getc(cl);
X cy = getc(cl);
X fstr[spt++] = c;
X fstr[spt++] = cx + dx;
X fstr[spt++] = cy + dy;
X c = getc(cl);
X
X while (c != '\0') {
X cx = getc(cl);
X cy = getc(cl);
X fstr[spt++] = c;
X fstr[spt++] = cx;
X fstr[spt++] = cy;
X c = getc(cl);
X }
X
X fstr[spt-2] -= dx;
X fstr[spt-1] -= dy;
X
X fstr[spt++] = '\0';
X }
X }
X
X for (i = 0; i < 256; i++) {
X if (gx[i] >= 0) {
X c = i;
X fwrite(&c,1,1,stdout);
X fwrite(&cstart[i],4,1,stdout);
X }
X }
X
X c = '\0';
X fwrite(&c,1,1,stdout);
X for (i = 0; i < spt; i++) fwrite(&fstr[i],1,1,stdout);
X
X exit(0);
X}
!FUNKY!STUFF!
echo extracting file hfont.man
sed 's/^X//' > hfont.man <<'!FUNKY!STUFF!'
XHFONT(1) UNIX Programmer's Manual HFONT(1)
X
XNAME
X hfont - make a plot-file font from the Hershey fonts
X
XSYNOPSIS
X hfont
X
XDESCRIPTION
X hfont creates a font file compatibe with the new plot rou-
X tines. Glyphs are selected from the Hershey font catalogue,
X and associated with single characters in the new font. hfont
X reads a list of character - glyph number pairs from standard
X input, and writes the new vector font file on standard out-
X put. The first line of the input file must contain 2
X integer values. These are x and y offsets for the character
X coordinate systems. A positive value will cause each char-
X acter to be shifted to the left and up for x and y respec-
X tively. Each successive line in the input must contain a
X single character, a blank, and an integer value, followed by
X a newline. The integer must be a Hershey glyph number,
X which will be associated with the character in the font.
X For example, if the input file contained the lines:
X
X S 741
X H 742
X D 743
X C 744
X
X Then the font would contain the glyphs for the playing-card
X symbols for Spades, Hearts, Diamonds, and Clubs attached to
X the characters S, H, D, and C.
X
X Copies of the Hershey font catalogue may be created with hcat.
X
XAUTHOR
X Marc Majka
X
!FUNKY!STUFF!
echo extracting file hform.c
sed 's/^X//' > hform.c <<'!FUNKY!STUFF!'
X#include <stdio.h>
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X short glyph;
X int np, x[256], y[256], i, mflag, xl, xr;
X short xc, yc, x0, y0;
X int index, d;
X char cg[6],cnp[4], c, dx, dy;
X FILE *ff, *tb, *cl, *fopen();
X
X ff = stdin;
X tb = fopen("vfont/hf.table","w");
X cl = fopen("vfont/hf.clist","w");
X
X index = 0;
X
X xc = 0; yc = 0;
X
X cg[0] = getc(ff);
X if (cg[0] == '\n') cg[0] = getc(ff);
X while (cg[0] != EOF) {
X /* first 5 chars: glyph number */
X
X for (i = 1; i < 5; i++) cg[i] = getc(ff);
X cg[i] = '\0';
X glyph = atoi(cg);
X if (glyph == 0) fprintf(stderr,"%d! \"%s\"\n",glyph,cg);
X
X /* next 3 chars: number of pairs */
X for (i = 0; i < 3; i++) cnp[i] = getc(ff);
X cnp[i] = '\0';
X np = atoi(cnp);
X
X /* left and right (X) boundaries */
X xl = getc(ff) - 'R';
X xr = getc(ff) - 'R';
X np--;
X
X /* points + skip commands */
X for (i = 0; i < np; i++) {
X if ((i == 31) || (i == 67) || (i == 103) || (i == 139))
X c = getc(ff);
X x[i] = getc(ff) - 'R';
X y[i] = getc(ff) - 'R';
X }
X
X /* extra char(s) at end */
X while ('\n' != (c = getc(ff)));
X
X xc = 0;
X yc = 0;
X
X /* write the table entry */
X if (glyph == d) {
X fprintf(stderr,"glyph %d index %d\n",glyph,index);
X fprintf(stderr,"xl %d xr %d\n",xl,xr);
X }
X
X fwrite(&glyph,2,1,tb);
X fwrite(&index,4,1,tb);
X
X /* write the plot list */
X /* first point is a skip */
X dx = xc - x[0] + xl;
X dy = yc - y[0];
X xc = x[0];
X yc = y[0];
X dx *= -1;
X
X fwrite("M",1,1,cl);
X fwrite(&dx,1,1,cl);
X fwrite(&dy,1,1,cl);
X
X index += 3;
X mflag = 0;
X
X for (i = 1; i < np; i++) {
X if (x[i] == -50) mflag = 1;
X else if (mflag) {
X dx = xc - x[i];
X dy = yc - y[i];
X xc = x[i];
X yc = y[i];
X dx *= -1;
X fwrite("M",1,1,cl);
X fwrite(&dx,1,1,cl);
X fwrite(&dy,1,1,cl);
X index += 3;
X mflag = 0;
X }
X else {
X dx = xc - x[i];
X dy = yc - y[i];
X xc = x[i];
X yc = y[i];
X dx *= -1;
X fwrite("N",1,1,cl);
X fwrite(&dx,1,1,cl);
X fwrite(&dy,1,1,cl);
X index += 3;
X }
X }
X dx = xc - xr;
X dy = yc - 0;
X dx *= -1;
X fwrite("M",1,1,cl);
X fwrite(&dx,1,1,cl);
X fwrite(&dy,1,1,cl);
X index += 3;
X xc = xr;
X yc = 0;
X fwrite(&yc,1,1,cl);
X index += 1;
X
X cg[0] = getc(ff);
X if (cg[0] == '\n') cg[0] = getc(ff);
X }
X fclose(ff);
X fclose(tb);
X fclose(cl);
X exit(0);
X}
!FUNKY!STUFF!
echo
echo finished part 2 of 8
More information about the Comp.sources.unix
mailing list