Blob
- Date:
- Message:
- svgpic: new program to convert pic to svg This is an experiment. Like tpic it's a copy-and-paste fork of pic. Change-Id: Ia22772bd5881c7904a6d8f8e0b46fde8cea89cbd Reviewed-on: https://plan9port-review.googlesource.com/2920 Reviewed-by: Russ Cox <rsc@swtch.com>
- Actions:
- History | Blame | Raw File
1 #include <stdio.h>2 #include "pic.h"3 #include "y.tab.h"5 obj *textgen(void)6 {7 int i, sub, nstr, at, with, hset, invis;8 double xwith, ywith, h, w, x0, y0, x1, y1;9 obj *p, *ppos;10 Attr *ap;12 at = with = nstr = hset = invis = 0;13 h = getfval("textht");14 w = getfval("textwid");15 for (i = 0; i < nattr; i++) {16 ap = &attr[i];17 switch (ap->a_type) {18 case HEIGHT:19 h = ap->a_val.f;20 hset++;21 break;22 case WIDTH:23 w = ap->a_val.f;24 break;25 case WITH:26 with = ap->a_val.i;27 break;28 case INVIS:29 invis = INVIS;30 break;31 case AT:32 ppos = ap->a_val.o;33 curx = ppos->o_x;34 cury = ppos->o_y;35 at++;36 break;37 case TEXTATTR:38 sub = ap->a_sub;39 if (ap->a_val.p == NULL) /* an isolated modifier */40 text[ntext-1].t_type = sub;41 else {42 savetext(sub, ap->a_val.p);43 nstr++;44 }45 break;46 }47 }48 if (hset == 0) /* no explicit ht cmd */49 h *= nstr;50 if (with) {51 xwith = ywith = 0.0;52 switch (with) {53 case NORTH: ywith = -h / 2; break;54 case SOUTH: ywith = h / 2; break;55 case EAST: xwith = -w / 2; break;56 case WEST: xwith = w / 2; break;57 case NE: xwith = -w / 2; ywith = -h / 2; break;58 case SE: xwith = -w / 2; ywith = h / 2; break;59 case NW: xwith = w / 2; ywith = -h / 2; break;60 case SW: xwith = w / 2; ywith = h / 2; break;61 }62 curx += xwith;63 cury += ywith;64 }65 if (!at) {66 if (isright(hvmode))67 curx += w / 2;68 else if (isleft(hvmode))69 curx -= w / 2;70 else if (isup(hvmode))71 cury += h / 2;72 else73 cury -= h / 2;74 }75 x0 = curx - w / 2;76 y0 = cury - h / 2;77 x1 = curx + w / 2;78 y1 = cury + h / 2;79 extreme(x0, y0);80 extreme(x1, y1);81 dprintf("Text h %g w %g at %g,%g\n", h, w, curx, cury);82 p = makenode(TEXT, 2);83 p->o_attr = invis;84 p->o_val[0] = w;85 p->o_val[1] = h;86 if (isright(hvmode))87 curx = x1;88 else if (isleft(hvmode))89 curx = x0;90 else if (isup(hvmode))91 cury = y1;92 else93 cury = y0;94 return(p);95 }97 obj *troffgen(char *s) /* save away a string of troff commands */98 {99 savetext(CENTER, s); /* use the existing text mechanism */100 return makenode(TROFF, 0);101 }103 void savetext(int t, char *s) /* record text elements for current object */104 {105 if (ntext >= ntextlist)106 text = (Text *) grow((char *) text, "text", ntextlist += 200, sizeof(Text));107 text[ntext].t_type = t;108 text[ntext].t_val = s;109 dprintf("saving %d text %s at %d\n", t, s, ntext);110 ntext++;111 }