From 3f19fdd0bca2937a6713cb0844dcb1d1f79da1db Mon Sep 17 00:00:00 2001 From: erg Date: Sat, 26 Feb 2005 23:04:16 +0000 Subject: [PATCH] Fixed show box feature to put output into generated postscript rather than onto stderr. --- lib/common/globals.h | 2 +- lib/common/postproc.c | 11 +-- lib/common/psgen.c | 18 ++++- lib/common/routespl.c | 152 +++++++++++++++++++++++++++++++++--------- 4 files changed, 142 insertions(+), 41 deletions(-) diff --git a/lib/common/globals.h b/lib/common/globals.h index 3c1bc282e..305a505dd 100644 --- a/lib/common/globals.h +++ b/lib/common/globals.h @@ -79,7 +79,7 @@ extern "C" { EXTERN int Nop; EXTERN double PSinputscale; EXTERN int Syntax_errors; - EXTERN int Show_boxes; /* emit code for correct box coordinates */ + EXTERN char** Show_boxes; /* emit code for correct box coordinates */ EXTERN int CL_type; /* NONE, LOCAL, GLOBAL */ EXTERN boolean Concentrate; /* if parallel edges should be merged */ EXTERN double Epsilon; /* defined in input_graph */ diff --git a/lib/common/postproc.c b/lib/common/postproc.c index 7e01c1651..ff68ea795 100644 --- a/lib/common/postproc.c +++ b/lib/common/postproc.c @@ -25,9 +25,9 @@ static point Offset; static void place_flip_graph_label(graph_t * g); #define M1 \ - "/pathbox { /Y exch %d sub def /X exch %d sub def /y exch %d sub def /x exch %d sub def newpath x y moveto X y lineto X Y lineto x Y lineto closepath stroke } def\n" + "/pathbox { /Y exch %d sub def /X exch %d sub def /y exch %d sub def /x exch %d sub def newpath x y moveto X y lineto X Y lineto x Y lineto closepath stroke } def\n/dbgstart { gsave %d %d translate } def\n/arrowlength 10 def\n/arrowwidth arrowlength 2 div def\n/arrowhead {\n gsave\n rotate\n currentpoint\n newpath\n moveto\n arrowlength arrowwidth 2 div rlineto\n 0 arrowwidth neg rlineto\n closepath fill\n grestore\n } bind def\n /makearrow {\n currentpoint exch pop sub exch currentpoint pop sub atan\n arrowhead\n } bind def\n /makevec {\n /Y exch def\n /X exch def\n /y exch def\n /x exch def\n newpath x y moveto\n X Y lineto stroke\n X Y moveto\n x y makearrow\n } def" #define M2 \ - "/pathbox { /X exch neg %d sub def /Y exch %d sub def /x exch neg %d sub def /y exch %d sub def newpath x y moveto X y lineto X Y lineto x Y lineto closepath stroke } def\n" + "/pathbox { /X exch neg %d sub def /Y exch %d sub def /x exch neg %d sub def /y exch %d sub def newpath x y moveto X y lineto X Y lineto x Y lineto closepath stroke } def" point map_point(point p) { @@ -204,10 +204,13 @@ void dotneato_postprocess(Agraph_t * g, nodesizefn_t ns) place_root_label(g, d); if (Show_boxes) { + char buf[BUFSIZ]; if (Flip) - fprintf(stderr, M2, Offset.x, Offset.y, Offset.x, Offset.y); + sprintf(buf, M2, Offset.x, Offset.y, Offset.x, Offset.y); else - fprintf(stderr, M1, Offset.y, Offset.x, Offset.y, Offset.x); + sprintf(buf, M1, Offset.y, Offset.x, Offset.y, Offset.x, + -Offset.x, -Offset.y); + Show_boxes[0] = strdup(buf); } } diff --git a/lib/common/psgen.c b/lib/common/psgen.c index 09360adc8..018ed2160 100644 --- a/lib/common/psgen.c +++ b/lib/common/psgen.c @@ -107,12 +107,19 @@ static void ps_begin_graph(GVC_t * gvc, graph_t * g, box bb, point pb) PB = bb; sz = add_points(PB.LL, PB.UR); if (onetime) { - fprintf(Output_file, "%%%%BoundingBox: %d %d %d %d\n", + if (Show_boxes == NULL) + fprintf(Output_file, "%%%%BoundingBox: %d %d %d %d\n", 0, 0, sz.x, sz.y); ps_comment(g, agfindattr(g, "comment")); fprintf(Output_file, "%%%%EndComments\nsave\n"); cat_libfile(Output_file, U_lib, ps_txt); epsf_define(Output_file); + if (Show_boxes) { + char* args[2]; + args[0] = Show_boxes[0]; + args[1] = NULL; + cat_libfile(Output_file, NULL, args); + } /* Set base URL for relative links (for Distiller >= 3.0) */ if (((s = agget(g, "href")) && s[0]) @@ -147,11 +154,13 @@ fprintf(stderr,"offset = %d,%d\n", offset.x, offset.y); sz = add_points(PB.LL, PB.UR); Cur_page++; fprintf(Output_file, "%%%%Page: %d %d\n", Cur_page, Cur_page); - fprintf(Output_file, "%%%%PageBoundingBox: %d %d %d %d\n", + if (Show_boxes == NULL) + fprintf(Output_file, "%%%%PageBoundingBox: %d %d %d %d\n", PB.LL.x, PB.LL.y, PB.UR.x, PB.UR.y); fprintf(Output_file, "%%%%PageOrientation: %s\n", (rot ? "Landscape" : "Portrait")); - fprintf(Output_file, "gsave\n%d %d %d %d boxprim clip newpath\n", + if (Show_boxes == NULL) + fprintf(Output_file, "gsave\n%d %d %d %d boxprim clip newpath\n", 0, 0, sz.x, sz.y); fprintf(Output_file, "%d %d translate\n", PB.LL.x, PB.LL.y); if (rot) @@ -181,6 +190,9 @@ fprintf(stderr,"offset = %d,%d\n", offset.x, offset.y); static void ps_end_page(void) { + if (Show_boxes) + cat_libfile(Output_file, NULL, Show_boxes+1); + /* the showpage is really a no-op, but at least one PS processor * out there needs to see this literal token. endpage does the real work. */ diff --git a/lib/common/routespl.c b/lib/common/routespl.c index 1dcb34ccf..3d19fffd3 100644 --- a/lib/common/routespl.c +++ b/lib/common/routespl.c @@ -29,6 +29,7 @@ static int maxbn = 0; static point *ps = NULL; static int pn; static int maxpn = 0; +static int psstrcnt = 0; #define PINC 300 static box *boxes; @@ -51,12 +52,14 @@ static Pedge_t *edges; static int edgen; static void checkpath(void); -static void printboxes(void); static void mkspacep(int size); static void printpath(path * pp); +static void printboxes(void); +static void psprintinit (int); static void psprintboxes(box * b, int bn); static void psprintspline(Ppolyline_t); static void psprintline(Ppolyline_t); +static void psprintpoly(Ppoly_t p); static int debugleveln(int i) { return (GD_showboxes(realedge->head->graph) == i || @@ -96,7 +99,14 @@ void routesplinesinit(void) maxpn = PINC; minbbox.LL.x = minbbox.LL.y = INT_MAX; minbbox.UR.x = minbbox.UR.y = INT_MIN; - Show_boxes = FALSE; + if (Show_boxes) { + int i; + for (i = 0; Show_boxes[i]; i++) + free (Show_boxes[i]); + free (Show_boxes); + Show_boxes = NULL; + psstrcnt = 0; + } if (Verbose) start_timer(); } @@ -145,8 +155,10 @@ point *routesplines(path * pp, int *npoints) if (debugleveln(1)) printboxes(); - if (debugleveln(3)) - psprintboxes(boxes, boxn); + if (debugleveln(3)) { + psprintinit(1); + /* psprintboxes(boxes, boxn); */ + } if (boxn * 8 > polypointn) { polypoints = ALLOC(boxn * 8, polypoints, Ppoint_t); @@ -254,8 +266,10 @@ point *routesplines(path * pp, int *npoints) eps[1].x = pp->end.p.x, eps[1].y = pp->end.p.y; if (Pshortestpath(&poly, eps, &pl) == -1) abort(); - if (debugleveln(3)) + if (debugleveln(3)) { + psprintpoly(poly); psprintline(pl); + } if (poly.pn > edgen) { edges = ALLOC(poly.pn, edges, Pedge_t); edgen = poly.pn; @@ -277,8 +291,10 @@ point *routesplines(path * pp, int *npoints) if (Proutespline(edges, poly.pn, pl, evs, &spl) == -1) abort(); - if (debugleveln(3)) + if (debugleveln(3)) { psprintspline(spl); + psprintinit(0); + } mkspacep(spl.pn); for (bi = 0; bi <= boxn; bi++) boxes[bi].LL.x = minbbox.LL.x, boxes[bi].UR.x = minbbox.UR.x; @@ -693,12 +709,17 @@ static void printboxes(void) { point ll, ur; int bi; + char buf[BUFSIZ]; + int newcnt = psstrcnt + boxn; - Show_boxes = TRUE; + Show_boxes = ALLOC(newcnt+2,Show_boxes,char*); for (bi = 0; bi < boxn; bi++) { ll = boxes[bi].LL, ur = boxes[bi].UR; - fprintf(stderr, "%d %d %d %d pathbox\n", ll.x, ll.y, ur.x, ur.y); + sprintf(buf, "%d %d %d %d pathbox", ll.x, ll.y, ur.x, ur.y); + Show_boxes[bi+1+psstrcnt] = strdup (buf); } + psstrcnt = newcnt; + Show_boxes[psstrcnt+1] = NULL; } #ifdef DEBUG @@ -729,44 +750,109 @@ static void psprintpoint(point p) static void psprintspline(Ppolyline_t spl) { - int i; - fprintf(stderr, "%%!\n"); - fprintf(stderr, "%% spline\n"); - fprintf(stderr, "gsave 1 0 0 setrgbcolor newpath\n"); + char buf[BUFSIZ]; + int newcnt = psstrcnt + spl.pn + 4; + int li, i; + + Show_boxes = ALLOC(newcnt+2,Show_boxes,char*); + li = psstrcnt+1; + Show_boxes[li++] = strdup ("%%!"); + Show_boxes[li++] = strdup ("%% spline"); + Show_boxes[li++] = strdup ("gsave 1 0 0 setrgbcolor newpath"); for (i = 0; i < spl.pn; i++) { - fprintf(stderr, "%f %f\n", spl.ps[i].x, spl.ps[i].y); - if (i == 0) - fprintf(stderr, "moveto\n"); - else if (i % 3 == 0) - fprintf(stderr, "curveto\n"); + sprintf(buf, "%f %f %s", spl.ps[i].x, spl.ps[i].y, + (i == 0) ? "moveto" : ((i % 3 == 0) ? "curveto" : "")); + Show_boxes[li++] = strdup (buf); } - fprintf(stderr, "stroke grestore\n"); + Show_boxes[li++] = strdup ("stroke grestore"); + psstrcnt = newcnt; + Show_boxes[psstrcnt+1] = NULL; } static void psprintline(Ppolyline_t pl) { - int i; - fprintf(stderr, "%%!\n"); - fprintf(stderr, "%% line\n"); - fprintf(stderr, "gsave 0 0 1 setrgbcolor newpath\n"); + char buf[BUFSIZ]; + int newcnt = psstrcnt + pl.pn + 4; + int i, li; + + Show_boxes = ALLOC(newcnt+2,Show_boxes,char*); + li = psstrcnt+1; + Show_boxes[li++] = strdup ("%%!"); + Show_boxes[li++] = strdup ("%% line"); + Show_boxes[li++] = strdup ("gsave 0 0 1 setrgbcolor newpath"); for (i = 0; i < pl.pn; i++) { - fprintf(stderr, "%f %f %s\n", pl.ps[i].x, pl.ps[i].y, + sprintf(buf, "%f %f %s", pl.ps[i].x, pl.ps[i].y, (i == 0 ? "moveto" : "lineto")); + Show_boxes[li++] = strdup (buf); } - fprintf(stderr, "stroke grestore\n"); + Show_boxes[li++] = strdup ("stroke grestore"); + psstrcnt = newcnt; + Show_boxes[psstrcnt+1] = NULL; +} +static void psprintpoly(Ppoly_t p) +{ + char buf[BUFSIZ]; + int newcnt = psstrcnt + p.pn + 3; + point tl, hd; + int bi, li; + char* pfx; + + Show_boxes = ALLOC(newcnt+2,Show_boxes,char*); + li = psstrcnt+1; + Show_boxes[li++] = strdup ("%% poly list"); + Show_boxes[li++] = strdup ("gsave 0 1 0 setrgbcolor"); + for (bi = 0; bi < p.pn; bi++) { + tl.x = (int)p.ps[bi].x; + tl.y = (int)p.ps[bi].y; + hd.x = (int)p.ps[(bi+1) % p.pn].x; + hd.y = (int)p.ps[(bi+1) % p.pn].y; + if ((tl.x == hd.x) && (tl.y == hd.y)) pfx = "%%"; + else pfx =""; + sprintf(buf, "%s%d %d %d %d makevec", pfx, tl.x, tl.y, hd.x, hd.y); + Show_boxes[li++] = strdup (buf); + } + Show_boxes[li++] = strdup ("grestore"); + + psstrcnt = newcnt; + Show_boxes[psstrcnt+1] = NULL; } static void psprintboxes(box * b, int bn) { + char buf[BUFSIZ]; + int newcnt = psstrcnt + 5*bn + 3; point ll, ur; - int bi; - fprintf(stderr, "%% box list\n"); - fprintf(stderr, "gsave 0 1 0 setrgbcolor\n"); + int bi, li; + + Show_boxes = ALLOC(newcnt+2,Show_boxes,char*); + li = psstrcnt+1; + Show_boxes[li++] = strdup ("%% box list"); + Show_boxes[li++] = strdup ("gsave 0 1 0 setrgbcolor"); for (bi = 0; bi < boxn; bi++) { ll = boxes[bi].LL, ur = boxes[bi].UR; - fprintf(stderr, "newpath\n%d %d moveto\n", ll.x, ll.y); - fprintf(stderr, "%d %d lineto\n", ll.x, ur.y); - fprintf(stderr, "%d %d lineto\n", ur.x, ur.y); - fprintf(stderr, "%d %d lineto\n", ur.x, ll.y); - fprintf(stderr, "closepath stroke\n"); + sprintf(buf, "newpath\n%d %d moveto", ll.x, ll.y); + Show_boxes[li++] = strdup (buf); + sprintf(buf, "%d %d lineto", ll.x, ur.y); + Show_boxes[li++] = strdup (buf); + sprintf(buf, "%d %d lineto", ur.x, ur.y); + Show_boxes[li++] = strdup (buf); + sprintf(buf, "%d %d lineto", ur.x, ll.y); + Show_boxes[li++] = strdup (buf); + Show_boxes[li++] = strdup ("closepath stroke"); } - fprintf(stderr, "grestore\n"); + Show_boxes[li++] = strdup ("grestore"); + + psstrcnt = newcnt; + Show_boxes[psstrcnt+1] = NULL; } +static void psprintinit (int begin) +{ + int newcnt = psstrcnt + 1; + + Show_boxes = ALLOC(newcnt+2,Show_boxes,char*); + if (begin) + Show_boxes[1+psstrcnt] = strdup ("dbgstart"); + else + Show_boxes[1+psstrcnt] = strdup ("grestore"); + psstrcnt = newcnt; + Show_boxes[psstrcnt+1] = NULL; +} + -- 2.40.0