aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/svgpic/circgen.c
diff options
context:
space:
mode:
authorPetter Rodhelind <petter.rodhelind@gmail.com>2017-07-03 20:55:47 +0200
committerPetter Rodhelind <petter.rodhelind@gmail.com>2017-07-03 20:55:47 +0200
commit7d0663b7c023cd7dd2764cb232798f8bc1309c20 (patch)
treee5b8eca2f1b0e825f115fb1b73c3ccb0103b9f39 /src/cmd/svgpic/circgen.c
parent5e176c5794de5124b67d3ac4ea7afe2f210b6d84 (diff)
parent711336c348ac9b98cd22464496e6b7e9a109c3a9 (diff)
downloadplan9port-7d0663b7c023cd7dd2764cb232798f8bc1309c20.tar.gz
plan9port-7d0663b7c023cd7dd2764cb232798f8bc1309c20.tar.bz2
plan9port-7d0663b7c023cd7dd2764cb232798f8bc1309c20.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'src/cmd/svgpic/circgen.c')
-rw-r--r--src/cmd/svgpic/circgen.c128
1 files changed, 128 insertions, 0 deletions
diff --git a/src/cmd/svgpic/circgen.c b/src/cmd/svgpic/circgen.c
new file mode 100644
index 00000000..6b1f1548
--- /dev/null
+++ b/src/cmd/svgpic/circgen.c
@@ -0,0 +1,128 @@
+#include <stdio.h>
+#include "pic.h"
+#include "y.tab.h"
+
+obj *circgen(int type)
+{
+ static double rad[2] = { HT2, WID2 };
+ static double rad2[2] = { HT2, HT2 };
+ int i, at, t, with, battr;
+ double xwith, ywith;
+ double r, r2, ddval, fillval;
+ obj *p, *ppos;
+ Attr *ap;
+
+ r = r2 = 0.0; /* Botch? (gcc) */
+
+ battr = at = 0;
+ with = xwith = ywith = fillval = ddval = 0;
+ t = (type == CIRCLE) ? 0 : 1;
+ if (type == CIRCLE)
+ r = r2 = getfval("circlerad");
+ else if (type == ELLIPSE) {
+ r = getfval("ellipsewid") / 2;
+ r2 = getfval("ellipseht") / 2;
+ }
+ 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 RADIUS:
+ r = ap->a_val.f;
+ break;
+ case DIAMETER:
+ case WIDTH:
+ r = ap->a_val.f / 2;
+ break;
+ case HEIGHT:
+ r2 = ap->a_val.f / 2;
+ break;
+ case SAME:
+ r = rad[t];
+ r2 = rad2[t];
+ break;
+ case WITH:
+ with = ap->a_val.i;
+ 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;
+ }
+ }
+ if (type == CIRCLE)
+ r2 = r; /* probably superfluous */
+ if (with) {
+ switch (with) {
+ case NORTH: ywith = -r2; break;
+ case SOUTH: ywith = r2; break;
+ case EAST: xwith = -r; break;
+ case WEST: xwith = r; break;
+ case NE: xwith = -r * 0.707; ywith = -r2 * 0.707; break;
+ case SE: xwith = -r * 0.707; ywith = r2 * 0.707; break;
+ case NW: xwith = r * 0.707; ywith = -r2 * 0.707; break;
+ case SW: xwith = r * 0.707; ywith = r2 * 0.707; break;
+ }
+ curx += xwith;
+ cury += ywith;
+ }
+ if (!at) {
+ if (isright(hvmode))
+ curx += r;
+ else if (isleft(hvmode))
+ curx -= r;
+ else if (isup(hvmode))
+ cury += r2;
+ else
+ cury -= r2;
+ }
+ p = makenode(type, 2);
+ p->o_val[0] = rad[t] = r;
+ p->o_val[1] = rad2[t] = r2;
+ if (r <= 0 || r2 <= 0) {
+ ERROR "%s has invalid radius %g\n", (type==CIRCLE) ? "circle" : "ellipse", r<r2 ? r : r2 WARNING;
+ }
+ p->o_attr = battr;
+ p->o_ddval = ddval;
+ p->o_fillval = fillval;
+ extreme(curx+r, cury+r2);
+ extreme(curx-r, cury-r2);
+ if (type == CIRCLE)
+ dprintf("C %g %g %g\n", curx, cury, r);
+ if (type == ELLIPSE)
+ dprintf("E %g %g %g %g\n", curx, cury, r, r2);
+ if (isright(hvmode))
+ curx += r;
+ else if (isleft(hvmode))
+ curx -= r;
+ else if (isup(hvmode))
+ cury += r2;
+ else
+ cury -= r2;
+ return(p);
+}