From 3ebbd193dce0724e106ec9af627a3782676ae510 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 3 Apr 2017 23:12:14 -0400 Subject: 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 --- src/cmd/svgpic/boxgen.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/cmd/svgpic/boxgen.c (limited to 'src/cmd/svgpic/boxgen.c') diff --git a/src/cmd/svgpic/boxgen.c b/src/cmd/svgpic/boxgen.c new file mode 100644 index 00000000..b575cd2f --- /dev/null +++ b/src/cmd/svgpic/boxgen.c @@ -0,0 +1,115 @@ +#include +#include "pic.h" +#include "y.tab.h" + +obj *boxgen(void) +{ + static double prevh = HT; + static double prevw = WID; /* golden mean, sort of */ + int i, at, battr, with; + double ddval, fillval, xwith, ywith; + double h, w, x0, y0, x1, y1; + obj *p, *ppos; + Attr *ap; + + h = getfval("boxht"); + w = getfval("boxwid"); + at = battr = with = 0; + ddval = fillval = xwith = ywith = 0; + for (i = 0; i < nattr; i++) { + ap = &attr[i]; + switch (ap->a_type) { + case HEIGHT: + h = ap->a_val.f; + break; + case WIDTH: + w = ap->a_val.f; + break; + case SAME: + h = prevh; + w = prevw; + break; + case WITH: + with = ap->a_val.i; /* corner */ + break; + case AT: + ppos = ap->a_val.o; + curx = ppos->o_x; + cury = ppos->o_y; + at++; + break; + case INVIS: + battr |= INVIS; + break; + case NOEDGE: + battr |= NOEDGEBIT; + break; + case DOT: + case DASH: + battr |= ap->a_type==DOT ? DOTBIT : DASHBIT; + if (ap->a_sub == DEFAULT) + ddval = getfval("dashwid"); + else + ddval = ap->a_val.f; + break; + case FILL: + battr |= FILLBIT; + if (ap->a_sub == DEFAULT) + fillval = getfval("fillval"); + else + fillval = ap->a_val.f; + break; + case TEXTATTR: + savetext(ap->a_sub, ap->a_val.p); + break; + } + } + if (with) { + switch (with) { + case NORTH: ywith = -h / 2; break; + case SOUTH: ywith = h / 2; break; + case EAST: xwith = -w / 2; break; + case WEST: xwith = w / 2; break; + case NE: xwith = -w / 2; ywith = -h / 2; break; + case SE: xwith = -w / 2; ywith = h / 2; break; + case NW: xwith = w / 2; ywith = -h / 2; break; + case SW: xwith = w / 2; ywith = h / 2; break; + } + curx += xwith; + cury += ywith; + } + if (!at) { + if (isright(hvmode)) + curx += w / 2; + else if (isleft(hvmode)) + curx -= w / 2; + else if (isup(hvmode)) + cury += h / 2; + else + cury -= h / 2; + } + x0 = curx - w / 2; + y0 = cury - h / 2; + x1 = curx + w / 2; + y1 = cury + h / 2; + extreme(x0, y0); + extreme(x1, y1); + p = makenode(BOX, 2); + p->o_val[0] = w; + p->o_val[1] = h; + p->o_attr = battr; + p->o_ddval = ddval; + p->o_fillval = fillval; + dprintf("B %g %g %g %g at %g %g, h=%g, w=%g\n", x0, y0, x1, y1, curx, cury, h, w); + if (isright(hvmode)) + curx = x1; + else if (isleft(hvmode)) + curx = x0; + else if (isup(hvmode)) + cury = y1; + else + cury = y0; + prevh = h; + prevw = w; + return(p); +} -- cgit v1.2.3