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/movegen.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/cmd/svgpic/movegen.c (limited to 'src/cmd/svgpic/movegen.c') diff --git a/src/cmd/svgpic/movegen.c b/src/cmd/svgpic/movegen.c new file mode 100644 index 00000000..5ff44d46 --- /dev/null +++ b/src/cmd/svgpic/movegen.c @@ -0,0 +1,86 @@ +#include +#include "pic.h" +#include "y.tab.h" + +obj *movegen(void) +{ + static double prevdx, prevdy; + int i, some; + double defx, defy, dx, dy; + obj *p; + obj *ppos; + static int xtab[] = { 1, 0, -1, 0 }; /* R=0, U=1, L=2, D=3 */ + static int ytab[] = { 0, 1, 0, -1 }; + Attr *ap; + + defx = getfval("movewid"); + defy = getfval("moveht"); + dx = dy = some = 0; + for (i = 0; i < nattr; i++) { + ap = &attr[i]; + switch (ap->a_type) { + case TEXTATTR: + savetext(ap->a_sub, ap->a_val.p); + break; + case SAME: + dx = prevdx; + dy = prevdy; + some++; + break; + case LEFT: + dx -= (ap->a_sub==DEFAULT) ? defx : ap->a_val.f; + some++; + hvmode = L_DIR; + break; + case RIGHT: + dx += (ap->a_sub==DEFAULT) ? defx : ap->a_val.f; + some++; + hvmode = R_DIR; + break; + case UP: + dy += (ap->a_sub==DEFAULT) ? defy : ap->a_val.f; + some++; + hvmode = U_DIR; + break; + case DOWN: + dy -= (ap->a_sub==DEFAULT) ? defy : ap->a_val.f; + some++; + hvmode = D_DIR; + break; + case TO: + ppos = ap->a_val.o; + dx = ppos->o_x - curx; + dy = ppos->o_y - cury; + some++; + break; + case BY: + ppos = ap->a_val.o; + dx = ppos->o_x; + dy = ppos->o_y; + some++; + break; + case FROM: + case AT: + ppos = ap->a_val.o; + curx = ppos->o_x; + cury = ppos->o_y; + break; + } + } + if (some) { + defx = dx; + defy = dy; + } else { + defx *= xtab[hvmode]; + defy *= ytab[hvmode]; + } + prevdx = defx; + prevdy = defy; + extreme(curx, cury); + curx += defx; + cury += defy; + extreme(curx, cury); + p = makenode(MOVE, 0); + dprintf("M %g %g\n", curx, cury); + return(p); +} -- cgit v1.2.3