15 Point xyoffset = { 0,0 };
17 Rectangle view[MAXVIEW];
18 Rectangle bound[MAXVIEW]; /* extreme points */
21 int lastp; /* last page number we were on */
27 } pagenums[NPAGENUMS];
32 char *getcmdstr(void);
34 static void initpage(void);
35 static void view_setup(int);
36 static Point scale(Point);
37 static void clearview(Rectangle);
38 static int addpage(int);
39 static void spline(Image *, int, Point *);
40 static int skipto(int, int);
41 static void wiggly(int);
42 static void devcntrl(void);
43 static void eatline(void);
44 static int getn(void);
45 static int botpage(int);
46 static void getstr(char *);
48 #define Do screen->r.min
49 #define Dc screen->r.max
51 /* declarations and definitions of font stuff are in font.c and main.c */
59 for (i = 0; i < nview-1; i++)
60 draw(screen, view[i], screen, nil, view[i+1].min);
61 clearview(view[nview-1]);
62 offset = view[nview-1].min;
69 int i, j, v, dx, dy, r, c;
72 case 1: r = 1; c = 1; break;
73 case 2: r = 1; c = 2; break;
74 case 3: r = 1; c = 3; break;
75 case 4: r = 2; c = 2; break;
76 case 5: case 6: r = 2; c = 3; break;
77 case 7: case 8: case 9: r = 3; c = 3; break;
78 default: r = (n+2)/3; c = 3; break; /* finking out */
80 dx = (Dc.x - Do.x) / c;
81 dy = (Dc.y - Do.y) / r;
83 for (i = 0; i < r && v < n; i++)
84 for (j = 0; j < c && v < n; j++) {
86 view[v].min.x = Do.x + j * dx;
87 view[v].max.x = Do.x + (j+1) * dx;
88 view[v].min.y = Do.y + i * dy;
89 view[v].max.y = Do.y + (i+1) * dy;
95 clearview(Rectangle r)
97 draw(screen, r, display->white, nil, r.min);
101 void eresized(int new)
103 /* this is called if we are resized */
104 if(new && getwindow(display, Refnone) < 0)
105 drawerror(display, "can't reattach to window");
115 return addpt(xyoffset, addpt(offset,p));
123 for (i = 0; i < npagenums; i++)
124 if (n == pagenums[i].num)
126 if (npagenums < NPAGENUMS-1) {
127 pagenums[npagenums].num = n;
128 pagenums[npagenums].adr = offsetc();
137 int c, i, a, alpha, phi;
138 static int first = 0;
143 offset = screen->clipr.min;
144 esetcursor(&deadmouse);
152 if (botpage(lastp+1)) {
157 case 'p': /* new page */
163 esetcursor(&deadmouse);
167 case '\n': /* when input is text */
169 case 0: /* occasional noise creeps in */
171 case '0': case '1': case '2': case '3': case '4':
172 case '5': case '6': case '7': case '8': case '9':
173 /* two motion digits plus a character */
174 hpos += (c-'0')*10 + getc()-'0';
177 case 'c': /* single ascii character */
200 case 'D': /* draw function */
203 case 'l': /* draw a line */
207 q = addpt(p, Pt(n,m));
210 line(screen, scale(p), scale(q), 0, 0, 0, display->black, ZP);
212 case 'c': /* circle */
217 ellipse(screen, scale(p), m/DIV, m/DIV, 0, display->black, ZP);
218 /* p=currentpt; p.x+=dmap(m/2);circle bp,p,a,ONES,Mode*/
220 case 'e': /* ellipse */
226 ellipse(screen, scale(p), m/DIV, n/DIV, 0, display->black, ZP);
229 p = scale(Pt(hpos,vpos));
234 q = scale(Pt(hpos,vpos));
239 qq = scale(Pt(hpos,vpos));
241 * tricky: convert from 3-point clockwise to
242 * center, angle1, delta-angle counterclockwise.
244 a = hypot(qq.x-q.x, qq.y-q.y);
245 phi = atan2(q.y-p.y, p.x-q.x)*180./PI;
246 alpha = atan2(q.y-qq.y, qq.x-q.x)*180./PI - phi;
249 arc(screen, q, a, a, 0, display->black, ZP, phi, alpha);
251 case '~': /* wiggly line */
260 n = getn(); /* ignore fractional sizes */
264 if (cursize >= NFONT)
270 case 'H': /* absolute horizontal motion */
273 case 'h': /* relative horizontal motion */
276 case 'w': /* word space */
284 case '#': /* comment */
285 case 'n': /* end of line */
288 case 'x': /* device control */
292 fprint(2, "unknown input character %o %c at offset %lud\n", c, c, offsetc());
300 spline(Image *b, int n, Point *pp)
302 long w, t1, t2, t3, fac=1000;
306 for (i = n; i > 0; i--)
311 for(i = 0; i < n-2; i++)
313 for(j = 0; j < steps; j++)
316 t1 = w * w / (2 * fac);
318 t2 = 3*fac/4 - w * w / fac;
320 t3 = w * w / (2*fac);
321 q.x = (t1*pp[i+2].x + t2*pp[i+1].x +
322 t3*pp[i].x + fac/2) / fac;
323 q.y = (t1*pp[i+2].y + t2*pp[i+1].y +
324 t3*pp[i].y + fac/2) / fac;
325 line(b, p, q, 0, 0, 0, display->black, ZP);
331 /* Have to parse skipped pages, to find out what fonts are loaded. */
333 skipto(int gotop, int curp)
340 for (i = 0; i < npagenums; i++)
341 if (pagenums[i].num == gotop) {
342 if (seekc(pagenums[i].adr) == Beof) {
343 fprint(2, "can't rewind input\n");
350 if (seekc(0) == Beof) {
351 fprint(2, "can't rewind input\n");
363 } else if (*p == 'p') {
364 lastp = curp = atoi(p+1);
365 addpage(lastp); /* maybe 1 too high */
377 for (n = 1; (c = getc()) != '\n' && c>=0; n++) {
382 p[0] = Pt(hpos, vpos);
383 for (i = 1; i < n; i++)
384 p[i] = addpt(p[i],p[i-1]);
387 for (i = 0; i < n; i++)
394 devcntrl(void) /* interpret device control functions */
400 switch (str[0]) { /* crude for now */
401 case 'i': /* initialize */
403 case 'T': /* device name */
406 case 't': /* trailer */
408 case 'p': /* pause -- can restart */
412 case 'r': /* resolution assumed when prepared */
414 DIV = floor(.5 + res/(100.0*mag));
417 mag = res/(100.0*DIV); /* adjust mag according to DIV coarseness */
419 case 'f': /* font used */
422 loadfontname(n, str);
424 /* these don't belong here... */
425 case 'H': /* char height */
427 case 'S': /* slant */
438 return c==' ' || c=='\t' || c=='\n';
444 uchar *s = (uchar *) is;
446 for (*s = getc(); isspace(*s); *s = getc())
448 for (; !isspace(*s); *++s = getc())
459 while ((c=getc()) != '\n' && c >= 0)
476 for (n = 0; '0'<=c && c<='9'; c = getc())
485 botpage(int np) /* called at bottom of page np-1 == top of page np */
490 while (p = getcmdstr()) {
495 if (*p == 'c') /* nop */
499 if (mag <= .1 || mag >= 10)
501 allfree(); /* zap fonts */
502 DIV = floor(.5 + res/(100.0*mag));
505 mag = res/(100.0*DIV);
506 return skipto(np-1, np); /* reprint the page */
509 xyoffset.x += atoi(p+1)*100;
514 xyoffset.y += atoi(p+1)*100;
518 if (*p == '/') { /* divide into n pieces */
522 else if (nview > MAXVIEW)
524 return skipto(np-1, np);
527 if (p[1] == '\0'){ /* bare 'p' */
534 if ('0'<=*p && *p<='9') {
540 if (*p == '-' || *p == '+') {
543 n = *p == '-' ? -1 : 1;
544 if(skipto(np - 1 + n, np))
553 fprint(2, "illegal; try q, 17, +2, -1, p, m.7, /2, x1, y-.5 or return\n");