Graphviz 16.1.3~dev.20261121.1645
Loading...
Searching...
No Matches
emit.c
Go to the documentation of this file.
1
7/*************************************************************************
8 * Copyright (c) 2011 AT&T Intellectual Property
9 * All rights reserved. This program and the accompanying materials
10 * are made available under the terms of the Eclipse Public License v2.0
11 * which accompanies this distribution, and is available at
12 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
13 *
14 * Contributors: Details at https://graphviz.org
15 *************************************************************************/
16
17#include "config.h"
18#include <assert.h>
19#include <cdt/cdt.h>
20#include <common/geomprocs.h>
21#include <common/htmltable.h>
22#include <common/render.h>
23#include <float.h>
24#include <gvc/gvc.h>
25#include <limits.h>
26#include <locale.h>
27#include <math.h>
28#include <pathplan/pathgeom.h>
29#include <stdatomic.h>
30#include <stdbool.h>
31#include <stddef.h>
32#include <stdint.h>
33#include <stdlib.h>
34#include <string.h>
35#include <util/agxbuf.h>
36#include <util/alloc.h>
37#include <util/debug.h>
38#include <util/gv_ctype.h>
39#include <util/gv_math.h>
40#include <util/list.h>
41#include <util/lockfile.h>
42#include <util/streq.h>
43#include <util/strview.h>
44#include <util/tokenize.h>
45#include <util/unreachable.h>
46#include <util/unused.h>
47#include <xdot/xdot.h>
48
49#ifdef _WIN32
50#define strtok_r strtok_s
51#endif
52
53#define P2RECT(p, pr, sx, sy) \
54 (pr[0].x = p.x - sx, pr[0].y = p.y - sy, pr[1].x = p.x + sx, \
55 pr[1].y = p.y + sy)
56#define FUZZ 3
57#define EPSILON .0001
58
59#ifdef DEBUG
60enum { debug = 1 };
61#else
62enum { debug = 0 };
63#endif
64
65typedef struct {
69} exdot_op;
70
72 char *p;
73 xdot *xd = NULL;
74
75 if (!((p = agget(g, "_background")) && p[0])) {
76 if (!((p = agget(g, "_draw_")) && p[0])) {
77 return NULL;
78 }
79 }
80 if (debug && Verbose) {
82 }
83 xd = parseXDotF(p, NULL, sizeof(exdot_op));
84
85 if (!xd) {
86 agwarningf("Could not parse \"_background\" attribute in graph %s\n",
87 agnameof(g));
88 agerr(AGPREV, " \"%s\"\n", p);
89 }
90 if (debug && Verbose) {
91 xdot_stats stats;
92 double et = elapsed_sec();
93 statXDot(xd, &stats);
94 fprintf(stderr, "%" PRISIZE_T " ops %.2f sec\n", stats.cnt, et);
95 fprintf(stderr, "%" PRISIZE_T " polygons %" PRISIZE_T " points\n",
96 stats.n_polygon, stats.n_polygon_pts);
97 fprintf(stderr, "%" PRISIZE_T " polylines %" PRISIZE_T " points\n",
98 stats.n_polyline, stats.n_polyline_pts);
99 fprintf(stderr, "%" PRISIZE_T " beziers %" PRISIZE_T " points\n",
100 stats.n_bezier, stats.n_bezier_pts);
101 fprintf(stderr, "%" PRISIZE_T " ellipses\n", stats.n_ellipse);
102 fprintf(stderr, "%" PRISIZE_T " texts\n", stats.n_text);
103 }
104 return xd;
105}
106
107static char *defaultlinestyle[3] = {"solid\0", "setlinewidth\0001\0", 0};
108
109/* push empty graphic state for current object */
111 obj_state_t *obj = gv_alloc(sizeof(obj_state_t));
112
113 obj_state_t *parent = obj->parent = job->obj;
114 job->obj = obj;
115 if (parent) {
116 obj->pencolor = parent->pencolor; /* default styles to parent's style */
117 obj->fillcolor = parent->fillcolor;
118 obj->pen = parent->pen;
119 obj->fill = parent->fill;
120 obj->penwidth = parent->penwidth;
121 obj->gradient_angle = parent->gradient_angle;
122 obj->stopcolor = parent->stopcolor;
123 } else {
124 obj->pen = PEN_SOLID;
125 obj->fill = FILL_NONE;
127 }
128 return obj;
129}
130
131/* pop graphic state of current object */
133 obj_state_t *obj = job->obj;
134
135 assert(obj);
136
137 free(obj->id);
138 free(obj->url);
139 free(obj->labelurl);
140 free(obj->tailurl);
141 free(obj->headurl);
142 free(obj->tooltip);
143 free(obj->labeltooltip);
144 free(obj->tailtooltip);
145 free(obj->headtooltip);
146 free(obj->target);
147 free(obj->labeltarget);
148 free(obj->tailtarget);
149 free(obj->headtarget);
150 free(obj->url_map_p);
153
154 job->obj = obj->parent;
155 free(obj);
156}
157
158/* Store image map data into job, substituting for node, edge, etc.
159 * names.
160 * @return True if an assignment was made for ID, URL, tooltip, or target
161 */
162bool initMapData(GVJ_t *job, char *lbl, char *url, char *tooltip, char *target,
163 char *id, void *gobj) {
164 obj_state_t *obj = job->obj;
165 int flags = job->flags;
166 bool assigned = false;
167
168 if ((flags & GVRENDER_DOES_LABELS) && lbl)
169 obj->label = lbl;
171 obj->id = strdup_and_subst_obj(id, gobj);
172 if (url && url[0]) {
173 obj->url = strdup_and_subst_obj(url, gobj);
174 }
175 assigned = true;
176 }
178 if (tooltip && tooltip[0]) {
179 obj->tooltip = strdup_and_subst_obj(tooltip, gobj);
180 obj->explicit_tooltip = true;
181 assigned = true;
182 } else if (obj->label) {
183 obj->tooltip = gv_strdup(obj->label);
184 assigned = true;
185 }
186 }
187 if ((flags & GVRENDER_DOES_TARGETS) && target && target[0]) {
188 obj->target = strdup_and_subst_obj(target, gobj);
189 assigned = true;
190 }
191 return assigned;
192}
193
194static void layerPagePrefix(GVJ_t *job, agxbuf *xb) {
195 if (job->layerNum > 1) {
196 agxbprint(xb, "%s_", job->gvc->layerIDs[job->layerNum]);
197 }
198 if (job->pagesArrayElem.x > 0 || job->pagesArrayElem.y > 0) {
199 agxbprint(xb, "page%d,%d_", job->pagesArrayElem.x, job->pagesArrayElem.y);
200 }
201}
202
204char *getObjId(GVJ_t *job, void *obj, agxbuf *xb) {
205 char *id;
206 graph_t *root = job->gvc->g;
207 char *gid = GD_drawing(root)->id;
208 long idnum = 0;
209 char *pfx = NULL;
210
211 layerPagePrefix(job, xb);
212
213 id = agget(obj, "id");
214 if (id && *id != '\0') {
215 agxbput(xb, id);
216 return agxbuse(xb);
217 }
218
219 if (obj != root && gid) {
220 agxbprint(xb, "%s_", gid);
221 }
222
223 switch (agobjkind(obj)) {
224 case AGRAPH:
225 idnum = AGSEQ(obj);
226 if (root == obj)
227 pfx = "graph";
228 else
229 pfx = "clust";
230 break;
231 case AGNODE:
232 idnum = AGSEQ((Agnode_t *)obj);
233 pfx = "node";
234 break;
235 case AGEDGE:
236 idnum = AGSEQ((Agedge_t *)obj);
237 pfx = "edge";
238 break;
239 }
240
241 agxbprint(xb, "%s%ld", pfx, idnum);
242
243 return agxbuse(xb);
244}
245
246/* Map "\n" to ^J, "\r" to ^M and "\l" to ^J.
247 * Map "\\" to backslash.
248 * Map "\x" to x.
249 * Mapping is done in place.
250 * Return input string.
251 */
252static char *interpretCRNL(char *ins) {
253 char *rets = ins;
254 char *outs = ins;
255 char c;
256 bool backslash_seen = false;
257
258 while ((c = *ins++)) {
259 if (backslash_seen) {
260 switch (c) {
261 case 'n':
262 case 'l':
263 *outs++ = '\n';
264 break;
265 case 'r':
266 *outs++ = '\r';
267 break;
268 default:
269 *outs++ = c;
270 break;
271 }
272 backslash_seen = false;
273 } else {
274 if (c == '\\')
275 backslash_seen = true;
276 else
277 *outs++ = c;
278 }
279 }
280 *outs = '\0';
281 return rets;
282}
283
284/* Tooltips are a weak form of escString, so we expect object substitution
285 * and newlines to be handled. The former occurs in initMapData. Here we
286 * map "\r", "\l" and "\n" to newlines. (We don't try to handle alignment
287 * as in real labels.) To make things uniform when the
288 * tooltip is emitted latter as visible text, we also convert HTML escape
289 * sequences into UTF8. This is already occurring when tooltips are input
290 * via HTML-like tables.
291 */
292static char *preprocessTooltip(char *s, void *gobj) {
293 Agraph_t *g = agroot(gobj);
294 int charset = GD_charset(g);
295 char *news;
296 switch (charset) {
297 case CHAR_LATIN1:
298 news = latin1ToUTF8(s);
299 break;
300 default: /* UTF8 */
301 news = htmlEntityUTF8(s, g);
302 break;
303 }
304
305 return interpretCRNL(news);
306}
307
308static void initObjMapData(GVJ_t *job, textlabel_t *lab, void *gobj) {
309 char *lbl;
310 char *url = agget(gobj, "href");
311 char *tooltip = agget(gobj, "tooltip");
312 char *target = agget(gobj, "target");
313 char *id;
314 agxbuf xb = {0};
315
316 if (lab)
317 lbl = lab->text;
318 else
319 lbl = NULL;
320 if (!url || !*url) /* try URL as an alias for href */
321 url = agget(gobj, "URL");
322 id = getObjId(job, gobj, &xb);
323 if (tooltip)
324 tooltip = preprocessTooltip(tooltip, gobj);
325 initMapData(job, lbl, url, tooltip, target, id, gobj);
326
327 free(tooltip);
328 agxbfree(&xb);
329}
330
331static void map_point(GVJ_t *job, pointf pf) {
332 obj_state_t *obj = job->obj;
333 int flags = job->flags;
334 pointf *p;
335
339 obj->url_map_n = 2;
340 } else {
342 obj->url_map_n = 4;
343 }
344 free(obj->url_map_p);
345 obj->url_map_p = p = gv_calloc(obj->url_map_n, sizeof(pointf));
346 P2RECT(pf, p, FUZZ, FUZZ);
348 gvrender_ptf_A(job, p, p, 2);
350 rect2poly(p);
351 }
352}
353
355 char *style;
356 char **pstyle = NULL;
357 graphviz_polygon_style_t istyle = {0};
358
359 if ((style = agget(sg, "style")) != 0 && style[0]) {
360 char **pp;
361 char **qp;
362 char *p;
363 pp = pstyle = parse_style(style);
364 while ((p = *pp)) {
365 if (strcmp(p, "filled") == 0) {
366 istyle.filled = true;
367 pp++;
368 } else if (strcmp(p, "radial") == 0) {
369 istyle.filled = true;
370 istyle.radial = true;
371 qp = pp; /* remove rounded from list passed to renderer */
372 do {
373 qp++;
374 *(qp - 1) = *qp;
375 } while (*qp);
376 } else if (strcmp(p, "striped") == 0) {
377 istyle.striped = true;
378 qp = pp; /* remove rounded from list passed to renderer */
379 do {
380 qp++;
381 *(qp - 1) = *qp;
382 } while (*qp);
383 } else if (strcmp(p, "rounded") == 0) {
384 istyle.rounded = true;
385 qp = pp; /* remove rounded from list passed to renderer */
386 do {
387 qp++;
388 *(qp - 1) = *qp;
389 } while (*qp);
390 } else
391 pp++;
392 }
393 }
394
395 *flagp = istyle;
396 return pstyle;
397}
398
399typedef struct {
400 char *color; /* segment color */
401 double t;
402 bool hasFraction; /* true if color explicitly specifies its fraction */
403} colorseg_t;
404
405static void freeSeg(colorseg_t seg) { free(seg.color); }
406
407/* Sum of segment sizes should add to 1 */
408typedef LIST(colorseg_t) colorsegs_t;
409
410/* Find semicolon in s, replace with '\0'.
411 * Convert remainder to float v.
412 * Return 0 if no float given
413 * Return -1 on failure
414 */
415static double getSegLen(strview_t *s) {
416 char *p = memchr(s->data, ';', s->size);
417 char *endp;
418 double v;
419
420 if (!p) {
421 return 0;
422 }
423 s->size = (size_t)(p - s->data);
424 ++p;
425 // Calling `strtod` on something that originated from a `strview_t` here
426 // looks dangerous. But we know `s` points to something obtained from `tok`
427 // with ':'. So `strtod` will run into either a ':' or a '\0' to safely stop
428 // it.
429 v = strtod(p, &endp);
430 if (endp != p) { /* scanned something */
431 if (v >= 0)
432 return v;
433 }
434 return -1;
435}
436
437#define EPS 1E-5
438#define AEQ0(x) (((x) < EPS) && ((x) > -EPS))
439
440/* Parse string of form color;float:color;float:...:color;float:color
441 * where the semicolon-floats are optional, nonnegative, sum to <= 1.
442 * Store the values in an array of colorseg_t's and return the array in psegs.
443 * If nseg == 0, count the number of colors.
444 * If the sum of the floats does not equal 1, the remainder is equally
445 * distributed to all colors without an explicit float. If no such colors exist,
446 * the remainder is added to the last color. 0 => okay 1 => error without
447 * message 2 => error with message 3 => warning message
448 *
449 * Note that psegs is only assigned to if the return value is 0 or 3.
450 * Otherwise, psegs is left unchanged and the allocated memory is
451 * freed before returning.
452 */
453static int parseSegs(const char *clrs, colorsegs_t *psegs) {
454 colorsegs_t segs = {.dtor = freeSeg};
455 double v, left = 1;
456 static atomic_flag warned;
457 int rval = 0;
458
459 for (tok_t t = tok(clrs, ":"); !tok_end(&t); tok_next(&t)) {
460 strview_t color = tok_get(&t);
461 if ((v = getSegLen(&color)) >= 0) {
462 double del = v - left;
463 if (del > 0) {
464 if (!AEQ0(del) && !atomic_flag_test_and_set(&warned)) {
465 agwarningf("Total size > 1 in \"%s\" color spec ", clrs);
466 rval = 3;
467 }
468 v = left;
469 }
470 left -= v;
471 colorseg_t s = {.t = v};
472 if (v > 0)
473 s.hasFraction = true;
474 if (color.size > 0)
475 s.color = strview_str(color);
476 LIST_APPEND(&segs, s);
477 } else {
478 if (!atomic_flag_test_and_set(&warned)) {
479 agerrorf("Illegal value in \"%s\" color attribute; float expected "
480 "after ';'\n",
481 clrs);
482 rval = 2;
483 } else
484 rval = 1;
485 LIST_FREE(&segs);
486 return rval;
487 }
488 if (AEQ0(left)) {
489 left = 0;
490 break;
491 }
492 }
493
494 /* distribute remaining into slot with t == 0; if none, add to last */
495 if (left > 0) {
496 /* count zero segments */
497 size_t nseg = 0;
498 for (size_t i = 0; i < LIST_SIZE(&segs); ++i) {
499 if (LIST_GET(&segs, i).t <= 0)
500 nseg++;
501 }
502 if (nseg > 0) {
503 double delta = left / (double)nseg;
504 for (size_t i = 0; i < LIST_SIZE(&segs); ++i) {
505 colorseg_t *s = LIST_AT(&segs, i);
506 if (s->t <= 0)
507 s->t = delta;
508 }
509 } else {
510 LIST_BACK(&segs)->t += left;
511 }
512 }
513
514 // terminate at the last positive segment
515 while (!LIST_IS_EMPTY(&segs)) {
516 if (LIST_BACK(&segs)->t > 0)
517 break;
518 LIST_DROP_BACK(&segs);
519 }
520
521 *psegs = segs;
522 return rval;
523}
524
525#define THIN_LINE 0.5
526
527/* Fill an ellipse whose bounding box is given by 2 points in pf
528 * with multiple wedges determined by the color spec in clrs.
529 * clrs is a list of colon separated colors, with possible quantities.
530 * Thin boundaries are drawn.
531 * 0 => okay
532 * 1 => error without message
533 * 2 => error with message
534 * 3 => warning message
535 */
536int wedgedEllipse(GVJ_t *job, pointf *pf, const char *clrs) {
537 colorsegs_t segs;
538 int rv;
539 double save_penwidth = job->obj->penwidth;
540 Ppolyline_t *pp;
541 double angle0, angle1;
542
543 rv = parseSegs(clrs, &segs);
544 if (rv == 1 || rv == 2)
545 return rv;
546 const pointf ctr = mid_pointf(pf[0], pf[1]);
547 const pointf semi = sub_pointf(pf[1], ctr);
548 if (save_penwidth > THIN_LINE)
550
551 angle0 = 0;
552 for (size_t i = 0; i < LIST_SIZE(&segs); ++i) {
553 const colorseg_t s = LIST_GET(&segs, i);
554 if (s.color == NULL)
555 break;
556 if (s.t <= 0)
557 continue;
558 gvrender_set_fillcolor(job, s.color);
559
560 if (i + 1 == LIST_SIZE(&segs))
561 angle1 = 2 * M_PI;
562 else
563 angle1 = angle0 + 2 * M_PI * s.t;
564 pp = ellipticWedge(ctr, semi.x, semi.y, angle0, angle1);
565 gvrender_beziercurve(job, pp->ps, pp->pn, 1);
566 angle0 = angle1;
567 freePath(pp);
568 }
569
570 if (save_penwidth > THIN_LINE)
571 gvrender_set_penwidth(job, save_penwidth);
572 LIST_FREE(&segs);
573 return rv;
574}
575
576/* Fill a rectangular box with vertical stripes of colors.
577 * AF gives 4 corner points, with AF[0] the LL corner and the points ordered
578 * CCW. clrs is a list of colon separated colors, with possible quantities. Thin
579 * boundaries are drawn. 0 => okay 1 => error without message 2 => error with
580 * message 3 => warning message
581 */
582int stripedBox(GVJ_t *job, pointf *AF, const char *clrs, int rotate) {
583 colorsegs_t segs;
584 int rv;
585 double xdelta;
586 pointf pts[4];
587 double lastx;
588 double save_penwidth = job->obj->penwidth;
589
590 rv = parseSegs(clrs, &segs);
591 if (rv == 1 || rv == 2)
592 return rv;
593 if (rotate) {
594 pts[0] = AF[2];
595 pts[1] = AF[3];
596 pts[2] = AF[0];
597 pts[3] = AF[1];
598 } else {
599 pts[0] = AF[0];
600 pts[1] = AF[1];
601 pts[2] = AF[2];
602 pts[3] = AF[3];
603 }
604 lastx = pts[1].x;
605 xdelta = (pts[1].x - pts[0].x);
606 pts[1].x = pts[2].x = pts[0].x;
607
608 if (save_penwidth > THIN_LINE)
610 for (size_t i = 0; i < LIST_SIZE(&segs); ++i) {
611 const colorseg_t s = LIST_GET(&segs, i);
612 if (s.color == NULL)
613 break;
614 if (s.t <= 0)
615 continue;
616 gvrender_set_fillcolor(job, s.color);
617 if (i + 1 == LIST_SIZE(&segs))
618 pts[1].x = pts[2].x = lastx;
619 else
620 pts[1].x = pts[2].x = pts[0].x + xdelta * (s.t);
621 gvrender_polygon(job, pts, 4, FILL);
622 pts[0].x = pts[3].x = pts[1].x;
623 }
624 if (save_penwidth > THIN_LINE)
625 gvrender_set_penwidth(job, save_penwidth);
626 LIST_FREE(&segs);
627 return rv;
628}
629
630void emit_map_rect(GVJ_t *job, boxf b) {
631 obj_state_t *obj = job->obj;
632 int flags = job->flags;
633 pointf *p;
634
638 obj->url_map_n = 2;
639 } else {
641 obj->url_map_n = 4;
642 }
643 free(obj->url_map_p);
644 obj->url_map_p = p = gv_calloc(obj->url_map_n, sizeof(pointf));
645 p[0] = b.LL;
646 p[1] = b.UR;
648 gvrender_ptf_A(job, p, p, 2);
650 rect2poly(p);
651 }
652}
653
654static void map_label(GVJ_t *job, textlabel_t *lab) {
655 obj_state_t *obj = job->obj;
656 int flags = job->flags;
657 pointf *p;
658
662 obj->url_map_n = 2;
663 } else {
665 obj->url_map_n = 4;
666 }
667 free(obj->url_map_p);
668 obj->url_map_p = p = gv_calloc(obj->url_map_n, sizeof(pointf));
669 P2RECT(lab->pos, p, lab->dimen.x / 2., lab->dimen.y / 2.);
671 gvrender_ptf_A(job, p, p, 2);
673 rect2poly(p);
674 }
675}
676
677/* isRect function returns true when polygon has
678 * regular rectangular shape. Rectangle is regular when
679 * it is not skewed and distorted and orientation is almost zero
680 */
681static bool isRect(polygon_t *p) {
682 return p->sides == 4 && fabs(fmod(p->orientation, 90)) < 0.5 &&
684}
685
686/*
687 * isFilled function returns true if filled style has been set for node 'n'
688 * otherwise returns false. it accepts pointer to node_t as an argument
689 */
690static bool isFilled(node_t *n) {
691 char *style, *p, **pp;
692 bool r = false;
693 style = late_nnstring(n, N_style, "");
694 if (style[0]) {
695 pp = parse_style(style);
696 while ((p = *pp)) {
697 if (strcmp(p, "filled") == 0)
698 r = true;
699 pp++;
700 }
701 }
702 return r;
703}
704
705/* pEllipse function returns 'np' points from the circumference
706 * of ellipse described by radii 'a' and 'b'.
707 * Assumes 'np' is greater than zero.
708 * 'np' should be at least 4 to sample polygon from ellipse
709 */
710static pointf *pEllipse(double a, double b, size_t np) {
711 double theta = 0.0;
712 double deltheta = 2 * M_PI / (double)np;
713
714 pointf *ps = gv_calloc(np, sizeof(pointf));
715 for (size_t i = 0; i < np; i++) {
716 ps[i].x = a * cos(theta);
717 ps[i].y = b * sin(theta);
718 theta += deltheta;
719 }
720 return ps;
721}
722
723#define HW 2.0 /* maximum distance away from line, in points */
724
725/* check_control_points function checks the size of quadrilateral
726 * formed by four control points
727 * returns true if four points are in line (or close to line)
728 */
729static bool check_control_points(const pointf *cp) {
730 double dis1 = ptToLine2(cp[0], cp[3], cp[1]);
731 double dis2 = ptToLine2(cp[0], cp[3], cp[2]);
732 return dis1 < HW * HW && dis2 < HW * HW;
733}
734
735static void update_bb_bz_core(boxf *bb, const pointf *cp, size_t recurse) {
736
737 /* if any control point of the segment is outside the bounding box */
738 if (cp[0].x > bb->UR.x || cp[0].x < bb->LL.x || cp[0].y > bb->UR.y ||
739 cp[0].y < bb->LL.y || cp[1].x > bb->UR.x || cp[1].x < bb->LL.x ||
740 cp[1].y > bb->UR.y || cp[1].y < bb->LL.y || cp[2].x > bb->UR.x ||
741 cp[2].x < bb->LL.x || cp[2].y > bb->UR.y || cp[2].y < bb->LL.y ||
742 cp[3].x > bb->UR.x || cp[3].x < bb->LL.x || cp[3].y > bb->UR.y ||
743 cp[3].y < bb->LL.y) {
744
745 /* if the segment is sufficiently refined */
746 if (check_control_points(cp)) {
747 /* expand the bounding box */
748 for (int i = 0; i < 4; i++) {
749 if (cp[i].x > bb->UR.x)
750 bb->UR.x = cp[i].x;
751 else if (cp[i].x < bb->LL.x)
752 bb->LL.x = cp[i].x;
753 if (cp[i].y > bb->UR.y)
754 bb->UR.y = cp[i].y;
755 else if (cp[i].y < bb->LL.y)
756 bb->LL.y = cp[i].y;
757 }
758 } else { /* else refine the segment */
759 if (!recurse) {
760 return;
761 }
762 pointf left[4], right[4];
763 Bezier(cp, 0.5, left, right);
766 }
767 }
768}
769
770void update_bb_bz(boxf *bb, const pointf *cp) {
771
772 // how many times to attempt refinement of control points
773 const size_t ATTEMPTS = 10;
774
775 update_bb_bz_core(bb, cp, ATTEMPTS);
776}
777
778typedef LIST(pointf) points_t;
779
780static UNUSED void psmapOutput(const points_t *ps, size_t start, size_t n) {
781 const pointf first = LIST_GET(ps, start);
782 fprintf(stdout, "newpath %f %f moveto\n", first.x, first.y);
783 for (size_t i = start + 1; i < start + n; ++i) {
784 const pointf pt = LIST_GET(ps, i);
785 fprintf(stdout, "%f %f lineto\n", pt.x, pt.y);
786 }
787 fprintf(stdout, "closepath stroke\n");
788}
789
790typedef LIST(size_t) pbs_size_t;
791
792/* Output the polygon determined by the n points in p1, followed
793 * by the n points in p2 in reverse order. Assumes n <= 50.
794 */
795static void map_bspline_poly(points_t *pbs_p, pbs_size_t *pbs_n, size_t n,
796 pointf *p1, pointf *p2) {
797 LIST_APPEND(pbs_n, 2 * n);
798
799 const UNUSED size_t nump = LIST_SIZE(pbs_p);
800 for (size_t i = 0; i < n; i++) {
801 LIST_APPEND(pbs_p, p1[i]);
802 }
803 for (size_t i = 0; i < n; i++) {
804 LIST_APPEND(pbs_p, p2[n - i - 1]);
805 }
806#if defined(DEBUG) && DEBUG == 2
807 psmapOutput(pbs_p, nump, 2 * n);
808#endif
809}
810
811/* Approximate Bézier by line segments. If the four points are
812 * almost colinear, as determined by check_control_points, we store
813 * the segment cp[0]-cp[3]. Otherwise we split the Bézier into 2 and recurse.
814 * Since 2 contiguous segments share an endpoint, we actually store
815 * the segments as a list of points.
816 * New points are appended to the list given by lp. The tail of the
817 * list is returned.
818 */
819static void approx_bezier(pointf *cp, points_t *lp) {
820 pointf left[4], right[4];
821
822 if (check_control_points(cp)) {
823 if (LIST_IS_EMPTY(lp))
824 LIST_APPEND(lp, cp[0]);
825 LIST_APPEND(lp, cp[3]);
826 } else {
827 Bezier(cp, 0.5, left, right);
828 approx_bezier(left, lp);
829 approx_bezier(right, lp);
830 }
831}
832
833/* Return the angle of the bisector between the two rays
834 * pp-cp and cp-np. The bisector returned is always to the
835 * left of pp-cp-np.
836 */
837static double bisect(pointf pp, pointf cp, pointf np) {
838 double ang, theta, phi;
839 theta = atan2(np.y - cp.y, np.x - cp.x);
840 phi = atan2(pp.y - cp.y, pp.x - cp.x);
841 ang = theta - phi;
842 if (ang > 0)
843 ang -= 2 * M_PI;
844
845 return phi + ang / 2.0;
846}
847
848/* Determine polygon points related to 2 segments prv-cur and cur-nxt.
849 * The points lie on the bisector of the 2 segments, passing through cur,
850 * and distance w2 from cur. The points are stored in p1 and p2.
851 * If p1 is NULL, we use the normal to cur-nxt.
852 * If p2 is NULL, we use the normal to prv-cur.
853 * Assume at least one of prv or nxt is non-NULL.
854 */
855static void mkSegPts(const pointf *prv, pointf cur, const pointf *nxt,
856 pointf *p1, pointf *p2, double w2) {
857 pointf pp, np;
858
859 const pointf cp = cur;
860 /* if prv or nxt are NULL, use the one given to create a collinear
861 * prv or nxt. This could be more efficiently done with special case code,
862 * but this way is more uniform.
863 */
864 if (prv) {
865 pp = *prv;
866 if (nxt)
867 np = *nxt;
868 else {
869 np = scale(2, sub_pointf(cp, pp));
870 }
871 } else {
872 np = *nxt;
873 pp = scale(2, sub_pointf(cp, np));
874 }
875 const double theta = bisect(pp, cp, np);
876 const pointf del = {.x = w2 * cos(theta), .y = w2 * sin(theta)};
877 *p1 = add_pointf(cp, del);
878 *p2 = sub_pointf(cp, del);
879}
880
881/* Construct and output a closed polygon approximating the input
882 * B-spline bp. We do this by first approximating bp by a sequence
883 * of line segments. We then use the sequence of segments to determine
884 * the polygon.
885 * In cmapx, polygons are limited to 100 points, so we output polygons
886 * in chunks of 100.
887 */
888static void map_output_bspline(points_t *pbs, pbs_size_t *pbs_n, bezier *bp,
889 double w2) {
890 points_t segments = {0};
891 pointf pts[4], pt1[50], pt2[50];
892
893 const size_t nc = (bp->size - 1) / 3; // nc is number of Bézier curves
894 for (size_t j = 0; j < nc; j++) {
895 for (size_t k = 0; k < 4; k++) {
896 pts[k] = bp->list[3 * j + k];
897 }
898 approx_bezier(pts, &segments);
899 }
900
901 for (size_t i = 0, cnt = 0; i < LIST_SIZE(&segments); ++i) {
902 const pointf *prev = i == 0 ? NULL : LIST_AT(&segments, i - 1);
903 const pointf *next =
904 i + 1 < LIST_SIZE(&segments) ? LIST_AT(&segments, i + 1) : NULL;
905 mkSegPts(prev, LIST_GET(&segments, i), next, pt1 + cnt, pt2 + cnt, w2);
906 cnt++;
907 if (i + 1 == LIST_SIZE(&segments) || cnt == 50) {
908 map_bspline_poly(pbs, pbs_n, cnt, pt1, pt2);
909 pt1[0] = pt1[cnt - 1];
910 pt2[0] = pt2[cnt - 1];
911 cnt = 1;
912 }
913 }
914
915 LIST_FREE(&segments);
916}
917
918static bool is_natural_number(const char *sstr) {
919 const char *str = sstr;
920
921 while (*str)
922 if (!gv_isdigit(*str++))
923 return false;
924 return true;
925}
926
927static int layer_index(GVC_t *gvc, char *str, int all) {
928 int i;
929
930 if (streq(str, "all"))
931 return all;
933 return atoi(str);
934 if (gvc->layerIDs)
935 for (i = 1; i <= gvc->numLayers; i++)
936 if (streq(str, gvc->layerIDs[i]))
937 return i;
938 return -1;
939}
940
941static bool selectedLayer(GVC_t *gvc, int layerNum, int numLayers,
942 const char *spec) {
943 int n0, n1;
944 char *w0, *w1;
945 char *buf_part_p = NULL, *buf_p = NULL, *cur, *part_in_p;
946 bool rval = false;
947
948 // copy `spec` so we can `strtok_r` it
949 char *spec_copy = gv_strdup(spec);
950 part_in_p = spec_copy;
951
952 while (!rval &&
953 (cur = strtok_r(part_in_p, gvc->layerListDelims, &buf_part_p))) {
954 w1 = w0 = strtok_r(cur, gvc->layerDelims, &buf_p);
955 if (w0)
956 w1 = strtok_r(NULL, gvc->layerDelims, &buf_p);
957 if (w1 != NULL) {
958 assert(w0 != NULL);
959 n0 = layer_index(gvc, w0, 0);
960 n1 = layer_index(gvc, w1, numLayers);
961 if (n0 >= 0 || n1 >= 0) {
962 if (n0 > n1) {
963 SWAP(&n0, &n1);
964 }
965 rval = BETWEEN(n0, layerNum, n1);
966 }
967 } else if (w0 != NULL) {
968 n0 = layer_index(gvc, w0, layerNum);
969 rval = (n0 == layerNum);
970 } else {
971 rval = false;
972 }
973 part_in_p = NULL;
974 }
975 free(spec_copy);
976 return rval;
977}
978
979static bool selectedlayer(GVJ_t *job, const char *spec) {
980 return selectedLayer(job->gvc, job->layerNum, job->numLayers, spec);
981}
982
983/* Parse the graph's layerselect attribute, which determines
984 * which layers are emitted. The specification is the same used
985 * by the layer attribute.
986 *
987 * If we find n layers, we return an array arr of n+2 ints. arr[0]=n.
988 * arr[n+1]=numLayers+1, acting as a sentinel. The other entries give
989 * the desired layer indices.
990 *
991 * If no layers are detected, NULL is returned.
992 *
993 * This implementation does a linear walk through each layer index and
994 * uses selectedLayer to match it against p. There is probably a more
995 * efficient way to do this, but this is simple and until we find people
996 * using huge numbers of layers, it should be adequate.
997 */
998static int *parse_layerselect(GVC_t *gvc, const char *p) {
999 int *laylist = gv_calloc(gvc->numLayers + 2, sizeof(int));
1000 int i, cnt = 0;
1001 for (i = 1; i <= gvc->numLayers; i++) {
1002 if (selectedLayer(gvc, i, gvc->numLayers, p)) {
1003 laylist[++cnt] = i;
1004 }
1005 }
1006 if (cnt) {
1007 laylist[0] = cnt;
1008 laylist[cnt + 1] = gvc->numLayers + 1;
1009 } else {
1010 agwarningf("The layerselect attribute \"%s\" does not match any layer "
1011 "specifed by the layers attribute - ignored.\n",
1012 p);
1013 free(laylist);
1014 laylist = NULL;
1015 }
1016 return laylist;
1017}
1018
1019/* Split input string into tokens, with separators specified by
1020 * the layersep attribute. Store the values in the gvc->layerIDs array,
1021 * starting at index 1, and return the count.
1022 * Note that there is no mechanism
1023 * to free the memory before exit.
1024 */
1025static int parse_layers(GVC_t *gvc, graph_t *g, char *p) {
1026 char *tok;
1027
1028 gvc->layerDelims = agget(g, "layersep");
1029 if (!gvc->layerDelims)
1031 gvc->layerListDelims = agget(g, "layerlistsep");
1032 if (!gvc->layerListDelims)
1034 if ((tok =
1035 strpbrk(gvc->layerDelims,
1036 gvc->layerListDelims))) { /* conflict in delimiter strings */
1037 agwarningf("The character \'%c\' appears in both the layersep and "
1038 "layerlistsep attributes - layerlistsep ignored.\n",
1039 *tok);
1040 gvc->layerListDelims = "";
1041 }
1042
1043 gvc->layers = gv_strdup(p);
1044 LIST(char *) layerIDs = {0};
1045
1046 // inferred entry for the first (unnamed) layer
1047 LIST_APPEND(&layerIDs, NULL);
1048
1049 for (tok = strtok(gvc->layers, gvc->layerDelims); tok;
1050 tok = strtok(NULL, gvc->layerDelims)) {
1051 LIST_APPEND(&layerIDs, tok);
1052 }
1053
1054 assert(LIST_SIZE(&layerIDs) - 1 <= INT_MAX);
1055 int ntok = (int)(LIST_SIZE(&layerIDs) - 1);
1056
1057 // if we found layers, save them for later reference
1058 if (LIST_SIZE(&layerIDs) > 1) {
1059 LIST_APPEND(&layerIDs, NULL); // add a terminating entry
1060 LIST_DETACH(&layerIDs, &gvc->layerIDs, NULL);
1061 }
1062 LIST_FREE(&layerIDs);
1063
1064 return ntok;
1065}
1066
1067/* Determine order of output.
1068 * Output usually in breadth first graph walk order
1069 */
1070static int chkOrder(graph_t *g) {
1071 char *p = agget(g, "outputorder");
1072 if (p) {
1073 if (!strcmp(p, "nodesfirst"))
1074 return EMIT_SORTED;
1075 if (!strcmp(p, "edgesfirst"))
1076 return EMIT_EDGE_SORTED;
1077 }
1078 return 0;
1079}
1080
1081static void init_layering(GVC_t *gvc, graph_t *g) {
1082 char *str;
1083
1084 /* free layer strings and pointers from previous graph */
1085 free(gvc->layers);
1086 gvc->layers = NULL;
1087 free(gvc->layerIDs);
1088 gvc->layerIDs = NULL;
1089 free(gvc->layerlist);
1090 gvc->layerlist = NULL;
1091 if ((str = agget(g, "layers")) != 0) {
1093 if ((str = agget(g, "layerselect")) != 0 && *str) {
1095 }
1096 } else {
1097 gvc->numLayers = 1;
1098 }
1099}
1100
1102static int numPhysicalLayers(GVJ_t *job) {
1103 if (job->gvc->layerlist) {
1104 return job->gvc->layerlist[0];
1105 } else
1106 return job->numLayers;
1107}
1108
1109static void firstlayer(GVJ_t *job, int **listp) {
1110 job->numLayers = job->gvc->numLayers;
1111 if (job->gvc->layerlist) {
1112 int *list = job->gvc->layerlist;
1113 int cnt = *list++;
1114 if (cnt > 1 && !(job->flags & GVDEVICE_DOES_LAYERS)) {
1115 agwarningf("layers not supported in %s output\n", job->output_langname);
1116 list[1] = job->numLayers + 1; /* only one layer printed */
1117 }
1118 job->layerNum = *list++;
1119 *listp = list;
1120 } else {
1121 if (job->numLayers > 1 && !(job->flags & GVDEVICE_DOES_LAYERS)) {
1122 agwarningf("layers not supported in %s output\n", job->output_langname);
1123 job->numLayers = 1;
1124 }
1125 job->layerNum = 1;
1126 *listp = NULL;
1127 }
1128}
1129
1130static bool validlayer(GVJ_t *job) { return job->layerNum <= job->numLayers; }
1131
1132static void nextlayer(GVJ_t *job, int **listp) {
1133 int *list = *listp;
1134 if (list) {
1135 job->layerNum = *list++;
1136 *listp = list;
1137 } else
1138 job->layerNum++;
1139}
1140
1141static point pagecode(GVJ_t *job, char c) {
1142 point rv = {0};
1143 switch (c) {
1144 case 'T':
1145 job->pagesArrayFirst.y = job->pagesArraySize.y - 1;
1146 rv.y = -1;
1147 break;
1148 case 'B':
1149 rv.y = 1;
1150 break;
1151 case 'L':
1152 rv.x = 1;
1153 break;
1154 case 'R':
1155 job->pagesArrayFirst.x = job->pagesArraySize.x - 1;
1156 rv.x = -1;
1157 break;
1158 default:
1159 // ignore; will trigger a warning later in our caller
1160 break;
1161 }
1162 return rv;
1163}
1164
1165static void init_job_pagination(GVJ_t *job, graph_t *g) {
1166 GVC_t *gvc = job->gvc;
1167 pointf pageSize; /* page size for the graph - points*/
1168 pointf centering = {0}; // centering offset - points
1169
1170 /* unpaginated image size - in points - in graph orientation */
1171 pointf imageSize = job->view; // image size on one page of the graph - points
1172
1173 /* rotate imageSize to page orientation */
1174 if (job->rotation)
1175 imageSize = exch_xyf(imageSize);
1176
1177 /* margin - in points - in page orientation */
1178 pointf margin = job->margin; // margin for a page of the graph - points
1179
1180 /* determine pagination */
1182 /* page was set by user */
1183
1184 /* determine size of page for image */
1185 pageSize = sub_pointf(gvc->pageSize, scale(2, margin));
1186
1187 if (pageSize.x < EPSILON)
1188 job->pagesArraySize.x = 1;
1189 else {
1190 job->pagesArraySize.x = (int)(imageSize.x / pageSize.x);
1191 if (imageSize.x - job->pagesArraySize.x * pageSize.x > EPSILON)
1192 job->pagesArraySize.x++;
1193 }
1194 if (pageSize.y < EPSILON)
1195 job->pagesArraySize.y = 1;
1196 else {
1197 job->pagesArraySize.y = (int)(imageSize.y / pageSize.y);
1198 if (imageSize.y - job->pagesArraySize.y * pageSize.y > EPSILON)
1199 job->pagesArraySize.y++;
1200 }
1201 job->numPages = job->pagesArraySize.x * job->pagesArraySize.y;
1202
1203 /* find the drawable size in points */
1204 imageSize.x = fmin(imageSize.x, pageSize.x);
1205 imageSize.y = fmin(imageSize.y, pageSize.y);
1206 } else {
1207 /* page not set by user, use default from renderer */
1208 if (job->render.features) {
1209 pageSize =
1210 sub_pointf(job->device.features->default_pagesize, scale(2, margin));
1211 pageSize.x = fmax(pageSize.x, 0);
1212 pageSize.y = fmax(pageSize.y, 0);
1213 } else
1214 pageSize.x = pageSize.y = 0.;
1215 job->pagesArraySize.x = job->pagesArraySize.y = job->numPages = 1;
1216
1217 pageSize.x = fmax(pageSize.x, imageSize.x);
1218 pageSize.y = fmax(pageSize.y, imageSize.y);
1219 }
1220
1221 /* initial window size */
1222 job->width =
1223 d2u(round((pageSize.x + 2 * margin.x) * job->dpi.x / POINTS_PER_INCH));
1224 job->height =
1225 d2u(round((pageSize.y + 2 * margin.y) * job->dpi.y / POINTS_PER_INCH));
1226
1227 /* set up pagedir */
1228 job->pagesArrayMajor = (point){0};
1229 job->pagesArrayMinor = (point){0};
1230 job->pagesArrayFirst = (point){0};
1231 job->pagesArrayMajor = pagecode(job, gvc->pagedir[0]);
1232 job->pagesArrayMinor = pagecode(job, gvc->pagedir[1]);
1233 job->pagesArrayElem = (point){0};
1234 if (abs(job->pagesArrayMajor.x + job->pagesArrayMinor.x) != 1 ||
1235 abs(job->pagesArrayMajor.y + job->pagesArrayMinor.y) != 1) {
1236 job->pagesArrayMajor = pagecode(job, 'B');
1237 job->pagesArrayMinor = pagecode(job, 'L');
1238 agwarningf("pagedir=%s ignored\n", gvc->pagedir);
1239 }
1240
1241 /* determine page box including centering */
1242 if (GD_drawing(g)->centered) {
1243 if (pageSize.x > imageSize.x)
1244 centering.x = (pageSize.x - imageSize.x) / 2;
1245 if (pageSize.y > imageSize.y)
1246 centering.y = (pageSize.y - imageSize.y) / 2;
1247 }
1248
1249 /* rotate back into graph orientation */
1250 if (job->rotation) {
1251 imageSize = exch_xyf(imageSize);
1252 margin = exch_xyf(margin);
1253 centering = exch_xyf(centering);
1254 }
1255
1256 /* canvas area, centered if necessary */
1257 job->canvasBox.LL = add_pointf(margin, centering);
1258 job->canvasBox.UR = add_pointf(add_pointf(margin, centering), imageSize);
1259
1260 /* size of one page in graph units */
1261 job->pageSize.x = imageSize.x / job->zoom;
1262 job->pageSize.y = imageSize.y / job->zoom;
1263
1264 /* pageBoundingBox in device units and page orientation */
1265 job->pageBoundingBox.LL.x =
1266 d2i(round(job->canvasBox.LL.x * job->dpi.x / POINTS_PER_INCH));
1267 job->pageBoundingBox.LL.y =
1268 d2i(round(job->canvasBox.LL.y * job->dpi.y / POINTS_PER_INCH));
1269 job->pageBoundingBox.UR.x =
1270 d2i(round(job->canvasBox.UR.x * job->dpi.x / POINTS_PER_INCH));
1271 job->pageBoundingBox.UR.y =
1272 d2i(round(job->canvasBox.UR.y * job->dpi.y / POINTS_PER_INCH));
1273 if (job->rotation) {
1276 job->canvasBox.LL = exch_xyf(job->canvasBox.LL);
1277 job->canvasBox.UR = exch_xyf(job->canvasBox.UR);
1278 }
1279}
1280
1281static void firstpage(GVJ_t *job) {
1282 job->pagesArrayElem = job->pagesArrayFirst;
1283}
1284
1285static bool validpage(GVJ_t *job) {
1286 return job->pagesArrayElem.x >= 0 &&
1287 job->pagesArrayElem.x < job->pagesArraySize.x &&
1288 job->pagesArrayElem.y >= 0 &&
1289 job->pagesArrayElem.y < job->pagesArraySize.y;
1290}
1291
1292static void nextpage(GVJ_t *job) {
1294 if (!validpage(job)) {
1295 if (job->pagesArrayMajor.y)
1296 job->pagesArrayElem.x = job->pagesArrayFirst.x;
1297 else
1298 job->pagesArrayElem.y = job->pagesArrayFirst.y;
1300 }
1301}
1302
1303static bool write_edge_test(Agraph_t *g, Agedge_t *e) {
1304 Agraph_t *sg;
1305 int c;
1306
1307 for (c = 1; c <= GD_n_cluster(g); c++) {
1308 sg = GD_clust(g)[c];
1309 if (agcontains(sg, e))
1310 return false;
1311 }
1312 return true;
1313}
1314
1315static bool write_node_test(Agraph_t *g, Agnode_t *n) {
1316 Agraph_t *sg;
1317 int c;
1318
1319 for (c = 1; c <= GD_n_cluster(g); c++) {
1320 sg = GD_clust(g)[c];
1321 if (agcontains(sg, n))
1322 return false;
1323 }
1324 return true;
1325}
1326
1327static pointf *copyPts(xdot_point *inpts, size_t numpts) {
1328 pointf *pts = gv_calloc(numpts, sizeof(pointf));
1329 for (size_t i = 0; i < numpts; i++) {
1330 pts[i].x = inpts[i].x;
1331 pts[i].y = inpts[i].y;
1332 }
1333 return pts;
1334}
1335
1336static void emit_xdot(GVJ_t *job, xdot *xd) {
1337 int image_warn = 1;
1338 int angle;
1339 char **styles = NULL;
1340 int filled = FILL;
1341
1342 exdot_op *op = (exdot_op *)xd->ops;
1343 for (size_t i = 0; i < xd->cnt; i++) {
1344 switch (op->op.kind) {
1345 case xd_filled_ellipse:
1347 if (boxf_overlap(op->bb, job->clip)) {
1348 pointf pts[] = {{.x = op->op.u.ellipse.x - op->op.u.ellipse.w,
1349 .y = op->op.u.ellipse.y - op->op.u.ellipse.h},
1350 {.x = op->op.u.ellipse.x + op->op.u.ellipse.w,
1351 .y = op->op.u.ellipse.y + op->op.u.ellipse.h}};
1352 gvrender_ellipse(job, pts,
1353 op->op.kind == xd_filled_ellipse ? filled : 0);
1354 }
1355 break;
1356 case xd_filled_polygon:
1358 if (boxf_overlap(op->bb, job->clip)) {
1359 pointf *pts = copyPts(op->op.u.polygon.pts, op->op.u.polygon.cnt);
1360 assert(op->op.u.polygon.cnt <= INT_MAX &&
1361 "polygon count exceeds gvrender_polygon support");
1362 gvrender_polygon(job, pts, op->op.u.polygon.cnt,
1363 op->op.kind == xd_filled_polygon ? filled : 0);
1364 free(pts);
1365 }
1366 break;
1367 case xd_filled_bezier:
1368 case xd_unfilled_bezier:
1369 if (boxf_overlap(op->bb, job->clip)) {
1370 pointf *pts = copyPts(op->op.u.bezier.pts, op->op.u.bezier.cnt);
1371 gvrender_beziercurve(job, pts, op->op.u.bezier.cnt,
1372 op->op.kind == xd_filled_bezier ? filled : 0);
1373 free(pts);
1374 }
1375 break;
1376 case xd_polyline:
1377 if (boxf_overlap(op->bb, job->clip)) {
1378 pointf *pts = copyPts(op->op.u.polyline.pts, op->op.u.polyline.cnt);
1379 gvrender_polyline(job, pts, op->op.u.polyline.cnt);
1380 free(pts);
1381 }
1382 break;
1383 case xd_text:
1384 if (boxf_overlap(op->bb, job->clip)) {
1385 pointf pt = {.x = op->op.u.text.x, .y = op->op.u.text.y};
1386 gvrender_textspan(job, pt, op->span);
1387 }
1388 break;
1389 case xd_fill_color:
1390 gvrender_set_fillcolor(job, op->op.u.color);
1391 filled = FILL;
1392 break;
1393 case xd_pen_color:
1394 gvrender_set_pencolor(job, op->op.u.color);
1395 filled = FILL;
1396 break;
1397 case xd_grad_fill_color:
1398 if (op->op.u.grad_color.type == xd_radial) {
1400 char *const clr0 = p->stops[0].color;
1401 char *const clr1 = p->stops[1].color;
1402 const double frac = p->stops[1].frac;
1403 if (p->x1 == p->x0 && p->y1 == p->y0) {
1404 angle = 0;
1405 } else {
1406 angle = (int)(180 * acos((p->x0 - p->x1) / p->r0) / M_PI);
1407 }
1408 gvrender_set_fillcolor(job, clr0);
1409 gvrender_set_gradient_vals(job, clr1, angle, frac);
1410 filled = RGRADIENT;
1411 } else {
1413 char *const clr0 = p->stops[0].color;
1414 char *const clr1 = p->stops[1].color;
1415 const double frac = p->stops[1].frac;
1416 angle = (int)(180 * atan2(p->y1 - p->y0, p->x1 - p->x0) / M_PI);
1417 gvrender_set_fillcolor(job, clr0);
1418 gvrender_set_gradient_vals(job, clr1, angle, frac);
1419 filled = GRADIENT;
1420 }
1421 break;
1422 case xd_grad_pen_color:
1423 agwarningf("gradient pen colors not yet supported.\n");
1424 break;
1425 case xd_font:
1426 /* fontsize and fontname already encoded via xdotBB */
1427 break;
1428 case xd_style:
1429 styles = parse_style(op->op.u.style);
1430 gvrender_set_style(job, styles);
1431 break;
1432 case xd_fontchar:
1433 /* font characteristics already encoded via xdotBB */
1434 break;
1435 case xd_image:
1436 if (image_warn) {
1437 agwarningf("Images unsupported in \"background\" attribute\n");
1438 image_warn = 0;
1439 }
1440 break;
1441 default:
1442 UNREACHABLE();
1443 }
1444 op++;
1445 }
1446 if (styles)
1448}
1449
1450static void emit_background(GVJ_t *job, graph_t *g) {
1451 xdot *xd;
1452 char *str;
1453 int dfltColor;
1454
1455 /* if no bgcolor specified - first assume default of "white" */
1456 if (!((str = agget(g, "bgcolor")) && str[0])) {
1457 str = "white";
1458 dfltColor = 1;
1459 } else
1460 dfltColor = 0;
1461
1462 /* if device has no truecolor support, change "transparent" to "white" */
1463 if (!(job->flags & GVDEVICE_DOES_TRUECOLOR) && (streq(str, "transparent"))) {
1464 str = "white";
1465 dfltColor = 1;
1466 }
1467
1468 /* except for "transparent" on truecolor, or default "white" on (assumed)
1469 * white paper, paint background */
1470 if (!(((job->flags & GVDEVICE_DOES_TRUECOLOR) && streq(str, "transparent")) ||
1471 ((job->flags & GVRENDER_NO_WHITE_BG) && dfltColor))) {
1472 char *clrs[2] = {0};
1473 double frac;
1474
1475 if ((findStopColor(str, clrs, &frac))) {
1476 int filled;
1477 graphviz_polygon_style_t istyle = {0};
1478 gvrender_set_fillcolor(job, clrs[0]);
1479 gvrender_set_pencolor(job, "transparent");
1480 checkClusterStyle(g, &istyle);
1481 if (clrs[1])
1482 gvrender_set_gradient_vals(job, clrs[1],
1483 late_int(g, G_gradientangle, 0, 0), frac);
1484 else
1486 late_int(g, G_gradientangle, 0, 0), frac);
1487 if (istyle.radial)
1488 filled = RGRADIENT;
1489 else
1490 filled = GRADIENT;
1491 gvrender_box(job, job->clip, filled);
1492 free(clrs[0]);
1493 free(clrs[1]);
1494 } else {
1496 gvrender_set_pencolor(job, "transparent");
1497 gvrender_box(job, job->clip, FILL); /* filled */
1498 }
1499 }
1500
1501 if ((xd = GD_drawing(g)->xdots))
1502 emit_xdot(job, xd);
1503}
1504
1505static void setup_page(GVJ_t *job) {
1506 point pagesArrayElem = job->pagesArrayElem,
1507 pagesArraySize = job->pagesArraySize;
1508
1509 if (job->rotation) {
1510 pagesArrayElem = exch_xy(pagesArrayElem);
1511 pagesArraySize = exch_xy(pagesArraySize);
1512 }
1513
1514 /* establish current box in graph units */
1515 job->pageBox.LL.x = pagesArrayElem.x * job->pageSize.x - job->pad.x;
1516 job->pageBox.LL.y = pagesArrayElem.y * job->pageSize.y - job->pad.y;
1517 job->pageBox.UR.x = job->pageBox.LL.x + job->pageSize.x;
1518 job->pageBox.UR.y = job->pageBox.LL.y + job->pageSize.y;
1519
1520 /* maximum boundingBox in device units and page orientation */
1521 if (job->common->viewNum == 0)
1522 job->boundingBox = job->pageBoundingBox;
1523 else
1525
1526 if (job->flags & GVDEVICE_EVENTS) {
1527 job->clip.LL.x = job->focus.x - job->view.x / 2.;
1528 job->clip.LL.y = job->focus.y - job->view.y / 2.;
1529 job->clip.UR.x = job->focus.x + job->view.x / 2.;
1530 job->clip.UR.y = job->focus.y + job->view.y / 2.;
1531 } else {
1532 job->clip.LL.x = job->focus.x + job->pageSize.x * (pagesArrayElem.x -
1533 pagesArraySize.x / 2.);
1534 job->clip.LL.y = job->focus.y + job->pageSize.y * (pagesArrayElem.y -
1535 pagesArraySize.y / 2.);
1536 job->clip.UR.x = job->clip.LL.x + job->pageSize.x;
1537 job->clip.UR.y = job->clip.LL.y + job->pageSize.y;
1538 }
1539
1540 /* CAUTION - job->translation was difficult to get right. */
1541 // Test with and without asymmetric margins, e.g: -Gmargin="1,0"
1542 if (job->rotation) {
1543 job->translation.y = -job->clip.UR.y - job->canvasBox.LL.y / job->zoom;
1544 if ((job->flags & GVRENDER_Y_GOES_DOWN) || Y_invert)
1545 job->translation.x = -job->clip.UR.x - job->canvasBox.LL.x / job->zoom;
1546 else
1547 job->translation.x = -job->clip.LL.x + job->canvasBox.LL.x / job->zoom;
1548 } else {
1549 /* pre unscale margins to keep them constant under scaling */
1550 job->translation.x = -job->clip.LL.x + job->canvasBox.LL.x / job->zoom;
1551 if ((job->flags & GVRENDER_Y_GOES_DOWN) || Y_invert)
1552 job->translation.y = -job->clip.UR.y - job->canvasBox.LL.y / job->zoom;
1553 else
1554 job->translation.y = -job->clip.LL.y + job->canvasBox.LL.y / job->zoom;
1555 }
1556}
1557
1558static bool node_in_layer(GVJ_t *job, graph_t *g, node_t *n) {
1559 if (job->numLayers <= 1)
1560 return true;
1561 const char *const pn = late_string(n, N_layer, "");
1562 if (selectedlayer(job, pn))
1563 return true;
1564 if (!streq(pn, ""))
1565 return false;
1566 if (agfstedge(g, n) == NULL)
1567 return true;
1568 for (edge_t *e = agfstedge(g, n); e; e = agnxtedge(g, e, n)) {
1569 const char *const pe = late_string(e, E_layer, "");
1570 if (streq(pe, "") || selectedlayer(job, pe))
1571 return true;
1572 }
1573 return false;
1574}
1575
1576static bool edge_in_layer(GVJ_t *job, edge_t *e) {
1577 if (job->numLayers <= 1)
1578 return true;
1579 const char *const pe = late_string(e, E_layer, "");
1580 if (selectedlayer(job, pe))
1581 return true;
1582 if (!streq(pe, ""))
1583 return false;
1584 for (int cnt = 0; cnt < 2; cnt++) {
1585 const char *const pn =
1586 late_string(cnt < 1 ? agtail(e) : aghead(e), N_layer, "");
1587 if (streq(pn, "") || selectedlayer(job, pn))
1588 return true;
1589 }
1590 return false;
1591}
1592
1593static bool clust_in_layer(GVJ_t *job, graph_t *sg) {
1594 if (job->numLayers <= 1)
1595 return true;
1596 const char *const pg =
1597 late_string(sg, agattr_text(sg, AGRAPH, "layer", 0), "");
1598 if (selectedlayer(job, pg))
1599 return true;
1600 if (!streq(pg, ""))
1601 return false;
1602 for (node_t *n = agfstnode(sg); n; n = agnxtnode(sg, n))
1603 if (node_in_layer(job, sg, n))
1604 return true;
1605 return false;
1606}
1607
1608static bool node_in_box(node_t *n, boxf b) { return boxf_overlap(ND_bb(n), b); }
1609
1611
1612static void emit_begin_node(GVJ_t *job, node_t *n) {
1613 obj_state_t *obj;
1614 int flags = job->flags;
1615 int shape;
1616 size_t nump = 0;
1617 polygon_t *poly = NULL;
1618 pointf *vertices, *p = NULL;
1619 pointf coord;
1620 char *s;
1621
1622 obj = push_obj_state(job);
1623 obj->type = NODE_OBJTYPE;
1624 obj->u.n = n;
1625 obj->emit_state = EMIT_NDRAW;
1626
1627 if (flags & GVRENDER_DOES_Z) {
1628 if (GD_odim(agraphof(n)) >= 3)
1629 obj->z = POINTS(ND_pos(n)[2]);
1630 else
1631 obj->z = 0.0;
1632 }
1633 initObjMapData(job, ND_label(n), n);
1635 (obj->url || obj->explicit_tooltip)) {
1636
1637 /* checking shape of node */
1638 shape = shapeOf(n);
1639 /* node coordinate */
1640 coord = ND_coord(n);
1641 /* checking if filled style has been set for node */
1642 bool filled = isFilled(n);
1643
1644 bool is_rect = false;
1645 if (shape == SH_POLY || shape == SH_POINT) {
1646 poly = ND_shape_info(n);
1647
1648 /* checking if polygon is regular rectangle */
1649 if (isRect(poly) && (poly->peripheries || filled))
1650 is_rect = true;
1651 }
1652
1653 /* When node has polygon shape and requested output supports polygons
1654 * we use a polygon to map the clickable region that is a:
1655 * circle, ellipse, polygon with n side, or point.
1656 * For regular rectangular shape we have use node's bounding box to map
1657 * clickable region
1658 */
1659 if (poly && !is_rect && (flags & GVRENDER_DOES_MAP_POLYGON)) {
1660
1661 const size_t sides = poly->sides < 3 ? 1 : poly->sides;
1662 const size_t peripheries = poly->peripheries < 2 ? 1 : poly->peripheries;
1663
1664 vertices = poly->vertices;
1665
1666 int nump_int = 0;
1667 if ((s = agget(n, "samplepoints")))
1668 nump_int = atoi(s);
1669 /* We want at least 4 points. For server-side maps, at most 100
1670 * points are allowed. To simplify things to fit with the 120 points
1671 * used for skewed ellipses, we set the bound at 60.
1672 */
1673 nump = (nump_int < 4 || nump_int > 60) ? DFLT_SAMPLE : (size_t)nump_int;
1674 /* use bounding box of text label or node image for mapping
1675 * when polygon has no peripheries and node is not filled
1676 */
1677 if (poly->peripheries == 0 && !filled) {
1679 nump = 2;
1680 p = gv_calloc(nump, sizeof(pointf));
1681 P2RECT(coord, p, ND_lw(n), ND_ht(n) / 2.0);
1682 }
1683 /* circle or ellipse */
1684 else if (poly->sides < 3 && is_exactly_pos_zero(poly->skew) &&
1685 is_exactly_pos_zero(poly->distortion)) {
1686 if (poly->regular) {
1688 nump = 2; /* center of circle and top right corner of bb */
1689 p = gv_calloc(nump, sizeof(pointf));
1690 p[0].x = coord.x;
1691 p[0].y = coord.y;
1692 /* even vertices contain LL corner of bb */
1693 /* odd vertices contain UR corner of bb */
1694 p[1].x = coord.x + vertices[2 * peripheries - 1].x;
1695 p[1].y = coord.y + vertices[2 * peripheries - 1].y;
1696 } else { /* ellipse is treated as polygon */
1698 p = pEllipse(vertices[2 * peripheries - 1].x,
1699 vertices[2 * peripheries - 1].y, nump);
1700 for (size_t i = 0; i < nump; i++) {
1701 p[i].x += coord.x;
1702 p[i].y += coord.y;
1703 }
1704 }
1705 }
1706 /* all other polygonal shape */
1707 else {
1708 assert(peripheries >= 1);
1709 size_t offset = (peripheries - 1) * poly->sides;
1711 /* distorted or skewed ellipses and circles are polygons with 120
1712 * sides. For mapping we convert them into polygon with sample sides
1713 */
1714 if (poly->sides >= nump) {
1715 size_t delta = poly->sides / nump;
1716 p = gv_calloc(nump, sizeof(pointf));
1717 for (size_t i = 0, j = 0; j < nump; i += delta, j++) {
1718 p[j].x = coord.x + vertices[i + offset].x;
1719 p[j].y = coord.y + vertices[i + offset].y;
1720 }
1721 } else {
1722 nump = sides;
1723 p = gv_calloc(nump, sizeof(pointf));
1724 for (size_t i = 0; i < nump; i++) {
1725 p[i].x = coord.x + vertices[i + offset].x;
1726 p[i].y = coord.y + vertices[i + offset].y;
1727 }
1728 }
1729 }
1730 } else {
1731 /* we have to use the node's bounding box to map clickable region
1732 * when requested output format is not capable of polygons.
1733 */
1735 nump = 2;
1736 p = gv_calloc(nump, sizeof(pointf));
1737 p[0].x = coord.x - ND_lw(n);
1738 p[0].y = coord.y - (ND_ht(n) / 2);
1739 p[1].x = coord.x + ND_rw(n);
1740 p[1].y = coord.y + (ND_ht(n) / 2);
1741 }
1743 gvrender_ptf_A(job, p, p, nump);
1744 obj->url_map_p = p;
1745 obj->url_map_n = nump;
1746 }
1747
1748 saved_color_scheme = setColorScheme(agget(n, "colorscheme"));
1750}
1751
1752static void emit_end_node(GVJ_t *job) {
1753 gvrender_end_node(job);
1754
1755 char *color_scheme = setColorScheme(saved_color_scheme);
1756 free(color_scheme);
1759
1760 pop_obj_state(job);
1761}
1762
1763static void emit_node(GVJ_t *job, node_t *n) {
1764 GVC_t *gvc = job->gvc;
1765 char *s;
1766 char *style;
1767 char **styles = NULL;
1768 char **sp;
1769 char *p;
1770
1771 if (ND_shape(n) /* node has a shape */
1772 && node_in_layer(job, agraphof(n), n) /* and is in layer */
1773 && node_in_box(n, job->clip) /* and is in page/view */
1774 && ND_state(n) != gvc->common.viewNum) /* and not already drawn */
1775 {
1776 ND_state(n) = gvc->common.viewNum; /* mark node as drawn */
1777
1778 gvrender_comment(job, agnameof(n));
1779 s = late_string(n, N_comment, "");
1780 if (s[0])
1781 gvrender_comment(job, s);
1782
1783 style = late_string(n, N_style, "");
1784 if (style[0]) {
1785 styles = parse_style(style);
1786 sp = styles;
1787 while ((p = *sp++)) {
1788 if (streq(p, "invis"))
1789 return;
1790 }
1791 }
1792
1793 emit_begin_node(job, n);
1794 ND_shape(n)->fns->codefn(job, n);
1795 if (ND_xlabel(n) && ND_xlabel(n)->set)
1797 emit_end_node(job);
1798 }
1799}
1800
1801/* calculate an offset vector, length d, perpendicular to line p,q */
1802static pointf computeoffset_p(pointf p, pointf q, double d) {
1803 pointf res;
1804 double x = p.x - q.x, y = p.y - q.y;
1805
1806 /* keep d finite as line length approaches 0 */
1807 d /= sqrt(x * x + y * y + EPSILON);
1808 res.x = y * d;
1809 res.y = -x * d;
1810 return res;
1811}
1812
1813/* calculate offset vector, length d, perpendicular to spline p,q,r,s at q&r */
1815 double d) {
1816 pointf res;
1817 double len;
1818 double x = q.x - r.x, y = q.y - r.y;
1819
1820 len = hypot(x, y);
1821 if (len < EPSILON) {
1822 /* control points are on top of each other
1823 use slope between endpoints instead */
1824 x = p.x - s.x, y = p.y - s.y;
1825 /* keep d finite as line length approaches 0 */
1826 len = sqrt(x * x + y * y + EPSILON);
1827 }
1828 d /= len;
1829 res.x = y * d;
1830 res.y = -x * d;
1831 return res;
1832}
1833
1834static void emit_attachment(GVJ_t *job, textlabel_t *lp, splines *spl) {
1835 pointf sz, AF[3];
1836 const char *s;
1837
1838 for (s = lp->text; *s; s++) {
1839 if (!gv_isspace(*s))
1840 break;
1841 }
1842 if (*s == '\0')
1843 return;
1844
1845 sz = lp->dimen;
1846 AF[0] = (pointf){lp->pos.x + sz.x / 2., lp->pos.y - sz.y / 2.};
1847 AF[1] = (pointf){AF[0].x - sz.x, AF[0].y};
1848 AF[2] = dotneato_closest(spl, lp->pos);
1849 /* Don't use edge style to draw attachment */
1851 /* Use font color to draw attachment
1852 - need something unambiguous in case of multicolored parallel edges
1853 - defaults to black for html-like labels
1854 */
1856 gvrender_polyline(job, AF, 3);
1857}
1858
1859/* edges’ colors can be multiple colors separated by ":"
1860 * so we compute a default pencolor with the same number of colors. */
1861static char *default_pencolor(agxbuf *buf, const char *pencolor,
1862 const char *deflt) {
1863 agxbput(buf, deflt);
1864 for (const char *p = pencolor; *p; p++) {
1865 if (*p == ':')
1866 agxbprint(buf, ":%s", deflt);
1867 }
1868 return agxbuse(buf);
1869}
1870
1871static double approxLen(pointf *pts) {
1872 return DIST(pts[0], pts[1]) + DIST(pts[1], pts[2]) + DIST(pts[2], pts[3]);
1873}
1874
1875/* Given B-spline bz and 0 < t < 1, split bz so that left corresponds to
1876 * the fraction t of the arc length. The new parts are store in left and right.
1877 * The caller needs to free the allocated points.
1878 *
1879 * In the current implementation, we find the Bézier that should contain t by
1880 * treating the control points as a polyline.
1881 * We then split that Bézier.
1882 */
1883static void splitBSpline(bezier *bz, double t, bezier *left, bezier *right) {
1884 const size_t cnt = (bz->size - 1) / 3;
1885 double last, len, sum;
1886 pointf *pts;
1887
1888 if (cnt == 1) {
1889 left->size = 4;
1890 left->list = gv_calloc(4, sizeof(pointf));
1891 right->size = 4;
1892 right->list = gv_calloc(4, sizeof(pointf));
1893 Bezier(bz->list, t, left->list, right->list);
1894 return;
1895 }
1896
1897 double *lens = gv_calloc(cnt, sizeof(double));
1898 sum = 0;
1899 pts = bz->list;
1900 for (size_t i = 0; i < cnt; i++) {
1901 lens[i] = approxLen(pts);
1902 sum += lens[i];
1903 pts += 3;
1904 }
1905 len = t * sum;
1906 sum = 0;
1907 size_t i;
1908 for (i = 0; i < cnt; i++) {
1909 sum += lens[i];
1910 if (sum >= len)
1911 break;
1912 }
1913
1914 left->size = 3 * (i + 1) + 1;
1915 left->list = gv_calloc(left->size, sizeof(pointf));
1916 right->size = 3 * (cnt - i) + 1;
1917 right->list = gv_calloc(right->size, sizeof(pointf));
1918 size_t j;
1919 for (j = 0; j < left->size; j++)
1920 left->list[j] = bz->list[j];
1921 size_t k = j - 4;
1922 for (j = 0; j < right->size; j++)
1923 right->list[j] = bz->list[k++];
1924
1925 last = lens[i];
1926 const double r = (len - (sum - last)) / last;
1927 Bezier(bz->list + 3 * i, r, left->list + 3 * i, right->list);
1928
1929 free(lens);
1930}
1931
1932/* Draw an edge as a sequence of colors.
1933 * Not sure how to handle multiple B-splines, so do a naive
1934 * implementation.
1935 * Return non-zero if color spec is incorrect
1936 */
1937static int multicolor(GVJ_t *job, edge_t *e, char **styles, const char *colors,
1938 double arrowsize, double penwidth) {
1939 bezier bz;
1940 bezier bz0, bz_l, bz_r;
1941 int rv;
1942 colorsegs_t segs;
1943 char *endcolor = NULL;
1944 double left;
1945 int first; /* first segment with t > 0 */
1946
1947 rv = parseSegs(colors, &segs);
1948 if (rv > 1) {
1949 Agraph_t *g = agraphof(agtail(e));
1950 agerr(AGPREV, "in edge %s%s%s\n", agnameof(agtail(e)),
1951 (agisdirected(g) ? " -> " : " -- "), agnameof(aghead(e)));
1952
1953 if (rv == 2)
1954 return 1;
1955 } else if (rv == 1)
1956 return 1;
1957
1958 for (size_t i = 0; i < ED_spl(e)->size; i++) {
1959 left = 1;
1960 bz = ED_spl(e)->list[i];
1961 first = 1;
1962 for (size_t j = 0; j < LIST_SIZE(&segs); ++j) {
1963 const colorseg_t s = LIST_GET(&segs, j);
1964 if (s.color == NULL)
1965 break;
1966 if (AEQ0(s.t))
1967 continue;
1968 gvrender_set_pencolor(job, s.color);
1969 left -= s.t;
1970 endcolor = s.color;
1971 if (first) {
1972 first = 0;
1973 splitBSpline(&bz, s.t, &bz_l, &bz_r);
1974 gvrender_beziercurve(job, bz_l.list, bz_l.size, 0);
1975 free(bz_l.list);
1976 if (AEQ0(left)) {
1977 free(bz_r.list);
1978 break;
1979 }
1980 } else if (AEQ0(left)) {
1981 gvrender_beziercurve(job, bz_r.list, bz_r.size, 0);
1982 free(bz_r.list);
1983 break;
1984 } else {
1985 bz0 = bz_r;
1986 splitBSpline(&bz0, s.t / (left + s.t), &bz_l, &bz_r);
1987 free(bz0.list);
1988 gvrender_beziercurve(job, bz_l.list, bz_l.size, 0);
1989 free(bz_l.list);
1990 }
1991 }
1992 /* arrow_gen resets the job style (How? FIXME)
1993 * If we have more splines to do, restore the old one.
1994 * Use local copy of penwidth to work around reset.
1995 */
1996 if (bz.sflag) {
1999 arrow_gen(job, EMIT_TDRAW, bz.sp, bz.list[0], arrowsize, penwidth,
2000 bz.sflag);
2001 }
2002 if (bz.eflag) {
2003 gvrender_set_pencolor(job, endcolor);
2004 gvrender_set_fillcolor(job, endcolor);
2005 arrow_gen(job, EMIT_HDRAW, bz.ep, bz.list[bz.size - 1], arrowsize,
2006 penwidth, bz.eflag);
2007 }
2008 if (ED_spl(e)->size > 1 && (bz.sflag || bz.eflag) && styles)
2009 gvrender_set_style(job, styles);
2010 }
2011 LIST_FREE(&segs);
2012 return 0;
2013}
2014
2015static void free_stroke(stroke_t sp) { free(sp.vertices); }
2016
2017typedef double (*radfunc_t)(double, double, double);
2018
2019static double forfunc(double curlen, double totallen, double initwid) {
2020 return (1 - curlen / totallen) * initwid / 2.0;
2021}
2022
2023static double revfunc(double curlen, double totallen, double initwid) {
2024 return curlen / totallen * initwid / 2.0;
2025}
2026
2027static double nonefunc(double curlen, double totallen, double initwid) {
2028 (void)curlen;
2029 (void)totallen;
2030
2031 return initwid / 2.0;
2032}
2033
2034static double bothfunc(double curlen, double totallen, double initwid) {
2035 double fr = curlen / totallen;
2036 if (fr <= 0.5)
2037 return fr * initwid;
2038 return (1 - fr) * initwid;
2039}
2040
2042 char *attr;
2043 if (E_dir && ((attr = agxget(e, E_dir)))[0]) {
2044 if (streq(attr, "forward"))
2045 return forfunc;
2046 if (streq(attr, "back"))
2047 return revfunc;
2048 if (streq(attr, "both"))
2049 return bothfunc;
2050 if (streq(attr, "none"))
2051 return nonefunc;
2052 }
2054}
2055
2056/* find_prev_distinct:
2057 * Find the previous point that is not a duplicate of pts[i].
2058 * Returns `SIZE_MAX` if no such point exists.
2059 */
2060static size_t find_prev_distinct(const pointf *pts, size_t i) {
2061 const double TOLERANCE = 0.01;
2062 for (size_t j = i - 1; j != SIZE_MAX; j--) {
2063 double dx = pts[j].x - pts[i].x;
2064 double dy = pts[j].y - pts[i].y;
2065 if (hypot(dx, dy) > TOLERANCE) {
2066 return j;
2067 }
2068 }
2069 return SIZE_MAX;
2070}
2071
2072/* find_next_distinct:
2073 * Find the next point that is not a duplicate of pts[i].
2074 * Returns `SIZE_MAX` if no such point exists.
2075 */
2076static size_t find_next_distinct(const pointf *pts, size_t i, size_t n) {
2077 const double TOLERANCE = 0.01;
2078 for (size_t j = i + 1; j < n; j++) {
2079 double dx = pts[j].x - pts[i].x;
2080 double dy = pts[j].y - pts[i].y;
2081 if (hypot(dx, dy) > TOLERANCE) {
2082 return j;
2083 }
2084 }
2085 return SIZE_MAX;
2086}
2087
2088/* Structure to hold corner information for truncation */
2089typedef struct {
2090 size_t idx; /* Index of corner point */
2091 pointf trunc_prev; /* Truncation point toward previous segment */
2092 pointf trunc_next; /* Truncation point toward next segment */
2093 pointf wedge_center; /* Center of arc wedge */
2094 double angle1, angle2; /* Arc angles */
2096
2097/* Comparison function for sorting corners by index */
2098static int compare_corners(const void *a, const void *b) {
2099 const corner_info_t *ca = a;
2100 const corner_info_t *cb = b;
2101 if (ca->idx < cb->idx)
2102 return -1;
2103 if (ca->idx > cb->idx)
2104 return 1;
2105 return 0;
2106}
2107
2108/* calculate_wedge_parameters:
2109 * Calculate the wedge center and angles for an orthogonal corner based on
2110 * the normalized direction vectors.
2111 */
2113 double dx1, double dy1, double dx2,
2114 double dy2, double radius,
2115 bool seg1_horiz, bool seg2_vert) {
2116 if (seg1_horiz && seg2_vert) {
2117 if (dx1 > 0 && dy2 < 0) {
2118 /* Right then down */
2119 ci->wedge_center.x = curr.x - radius;
2120 ci->wedge_center.y = curr.y - radius;
2121 ci->angle1 = 0;
2122 ci->angle2 = M_PI / 2;
2123 } else if (dx1 > 0 && dy2 > 0) {
2124 /* Right then up */
2125 ci->wedge_center.x = curr.x - radius;
2126 ci->wedge_center.y = curr.y + radius;
2127 ci->angle1 = -M_PI / 2;
2128 ci->angle2 = 0;
2129 } else if (dx1 < 0 && dy2 < 0) {
2130 /* Left then down */
2131 ci->wedge_center.x = curr.x + radius;
2132 ci->wedge_center.y = curr.y - radius;
2133 ci->angle1 = M_PI / 2;
2134 ci->angle2 = M_PI;
2135 } else {
2136 /* Left then up */
2137 ci->wedge_center.x = curr.x + radius;
2138 ci->wedge_center.y = curr.y + radius;
2139 ci->angle1 = M_PI;
2140 ci->angle2 = 3 * M_PI / 2;
2141 }
2142 } else {
2143 if (dy1 < 0 && dx2 > 0) {
2144 /* Down then right */
2145 ci->wedge_center.x = curr.x + radius;
2146 ci->wedge_center.y = curr.y + radius;
2147 ci->angle1 = M_PI;
2148 ci->angle2 = 3 * M_PI / 2;
2149 } else if (dy1 < 0 && dx2 < 0) {
2150 /* Down then left */
2151 ci->wedge_center.x = curr.x - radius;
2152 ci->wedge_center.y = curr.y + radius;
2153 ci->angle1 = 3 * M_PI / 2;
2154 ci->angle2 = 2 * M_PI;
2155 } else if (dy1 > 0 && dx2 > 0) {
2156 /* Up then right */
2157 ci->wedge_center.x = curr.x + radius;
2158 ci->wedge_center.y = curr.y - radius;
2159 ci->angle1 = M_PI / 2;
2160 ci->angle2 = M_PI;
2161 } else {
2162 /* Up then left */
2163 ci->wedge_center.x = curr.x - radius;
2164 ci->wedge_center.y = curr.y - radius;
2165 ci->angle1 = 0;
2166 ci->angle2 = M_PI / 2;
2167 }
2168 }
2169}
2170
2171typedef LIST(corner_info_t) corners_t;
2172
2173/* process_corner:
2174 * Process a detected orthogonal corner and add it to the corners array.
2175 * Returns true if the corner was added, false if it was a duplicate.
2176 */
2177static bool process_corner(corners_t *corners, const pointf *pts, size_t i,
2178 pointf curr, double dx1, double dy1, double dx2,
2179 double dy2, double radius, bool seg1_horiz,
2180 bool seg2_vert) {
2181 /* Check if we already detected this corner (skip duplicates) */
2182 const double DUP_TOL = 0.01;
2183 for (size_t j = 0; j < LIST_SIZE(corners); j++) {
2184 const corner_info_t ci = LIST_GET(corners, j);
2185 pointf existing_corner = pts[ci.idx];
2186 if (hypot(curr.x - existing_corner.x, curr.y - existing_corner.y) <
2187 DUP_TOL) {
2188 return false;
2189 }
2190 }
2191
2192 LIST_APPEND(corners, (corner_info_t){0});
2193 corner_info_t *const ci = LIST_BACK(corners);
2194 ci->idx = i;
2195
2196 /* Normalize direction vectors */
2197 double len1 = hypot(dx1, dy1);
2198 double len2 = hypot(dx2, dy2);
2199 dx1 /= len1;
2200 dy1 /= len1;
2201 dx2 /= len2;
2202 dy2 /= len2;
2203
2204 /* Calculate truncation points (move radius distance away from corner) */
2205 ci->trunc_prev.x = curr.x - dx1 * radius;
2206 ci->trunc_prev.y = curr.y - dy1 * radius;
2207 ci->trunc_next.x = curr.x + dx2 * radius;
2208 ci->trunc_next.y = curr.y + dy2 * radius;
2209
2210 /* Calculate wedge center and angles */
2211 calculate_wedge_parameters(ci, curr, dx1, dy1, dx2, dy2, radius, seg1_horiz,
2212 seg2_vert);
2213
2214 return true;
2215}
2216
2217/* find_ortho_corners:
2218 * Identify all orthogonal corners and compute truncation/arc information.
2219 * Fills corners array.
2220 * Caller must pre-allocate corners array with at least n elements.
2221 */
2222static void find_ortho_corners(const pointf *pts, size_t n, double radius,
2223 corners_t *corners) {
2224 const double TOL = 0.1;
2225
2226 for (size_t i = 0; i < n; i++) {
2227 const size_t prev_idx = find_prev_distinct(pts, i);
2228 const size_t next_idx = find_next_distinct(pts, i, n);
2229
2230 if (prev_idx == SIZE_MAX || next_idx == SIZE_MAX)
2231 continue;
2232
2233 pointf prev = pts[prev_idx];
2234 pointf curr = pts[i];
2235 pointf next = pts[next_idx];
2236
2237 /* Get direction vectors */
2238 double dx1 = curr.x - prev.x;
2239 double dy1 = curr.y - prev.y;
2240 double dx2 = next.x - curr.x;
2241 double dy2 = next.y - curr.y;
2242
2243 /* Check if this is an orthogonal corner */
2244 bool seg1_horiz = fabs(dy1) < TOL && fabs(dx1) > TOL;
2245 bool seg1_vert = fabs(dx1) < TOL && fabs(dy1) > TOL;
2246 bool seg2_horiz = fabs(dy2) < TOL && fabs(dx2) > TOL;
2247 bool seg2_vert = fabs(dx2) < TOL && fabs(dy2) > TOL;
2248
2249 bool is_corner = (seg1_horiz && seg2_vert) || (seg1_vert && seg2_horiz);
2250
2251 if (is_corner) {
2252 process_corner(corners, pts, i, curr, dx1, dy1, dx2, dy2, radius,
2253 seg1_horiz, seg2_vert);
2254 }
2255 }
2256}
2257
2258/* render_corner_arc:
2259 * Extract and render the arc portion from a wedge polyline.
2260 * The wedge includes center point and return paths which we skip.
2261 */
2262static void render_corner_arc(GVJ_t *job, const Ppolyline_t *wedge,
2263 size_t arc_start_idx, size_t arc_point_count,
2264 char *edge_color) {
2265 LIST(pointf) arc_points = {0};
2266 LIST_RESERVE(&arc_points, arc_point_count);
2267 for (size_t j = 0; j < arc_point_count; j++) {
2268 LIST_APPEND(&arc_points, wedge->ps[arc_start_idx + j]);
2269 }
2270
2271 /* Draw only the arc curve (no straight edges back to center) */
2272 if (edge_color && edge_color[0]) {
2273 gvrender_set_pencolor(job, edge_color);
2274 } else {
2276 }
2277 gvrender_polyline(job, LIST_FRONT(&arc_points), arc_point_count);
2278
2279 LIST_FREE(&arc_points);
2280}
2281
2282/* draw_ortho_corner_markers:
2283 * Draw 90-degree arc curves at orthogonal edge corners.
2284 * Draws only the arc portion (not the straight wedge edges).
2285 */
2286static void draw_ortho_corner_markers(GVJ_t *job, const corners_t *corners,
2287 double radius, char *edge_color) {
2288 for (size_t i = 0; i < LIST_SIZE(corners); i++) {
2289 const corner_info_t ci = LIST_GET(corners, i);
2290
2291 /* Generate wedge path */
2292 Ppolyline_t *wedge =
2293 ellipticWedge(ci.wedge_center, radius, radius, ci.angle1, ci.angle2);
2294
2295 if (wedge && wedge->pn > 4) {
2296 /* Extract only the arc portion (skip center at start and close path at
2297 * end) */
2298 /* Skip duplicates and straight edges: wedge path includes center and
2299 * return paths */
2300 size_t arc_start_idx =
2301 3; /* Skip center, first arc point, AND duplicate */
2302 size_t arc_end_idx =
2303 wedge->pn -
2304 4; /* Skip duplicate endpoint, last arc point, AND center */
2305 size_t arc_point_count =
2306 arc_end_idx >= arc_start_idx ? arc_end_idx - arc_start_idx + 1 : 0;
2307
2308 if (arc_point_count >= 2) {
2309 render_corner_arc(job, wedge, arc_start_idx, arc_point_count,
2310 edge_color);
2311 }
2312
2313 free(wedge->ps);
2314 free(wedge);
2315 }
2316 }
2317}
2318
2319static void emit_edge_graphics(GVJ_t *job, edge_t *e, char **styles) {
2320 int cnum, numsemi = 0;
2321 char *color, *pencolor, *fillcolor;
2322 char *headcolor, *tailcolor, *lastcolor;
2323 char *colors = NULL;
2324 bezier bz;
2325 splines offspl, tmpspl;
2326 pointf pf0, pf1, pf2 = {0, 0}, pf3, *offlist, *tmplist;
2327 double arrowsize, numc2, penwidth = job->obj->penwidth;
2328 char *p;
2329 bool tapered = false;
2330 agxbuf buf = {0};
2331
2332#define SEP 2.0
2333
2334 if (ED_spl(e)) {
2335 arrowsize = late_double(e, E_arrowsz, 1.0, 0.0);
2336 color = late_string(e, E_color, "");
2337
2338 if (styles) {
2339 char **sp = styles;
2340 while ((p = *sp++)) {
2341 if (streq(p, "tapered")) {
2342 tapered = true;
2343 break;
2344 }
2345 }
2346 }
2347
2348 /* need to know how many colors separated by ':' */
2349 size_t numc = 0;
2350 for (p = color; *p; p++) {
2351 if (*p == ':')
2352 numc++;
2353 else if (*p == ';')
2354 numsemi++;
2355 }
2356
2357 if (numsemi && numc) {
2358 if (multicolor(job, e, styles, color, arrowsize, penwidth)) {
2360 } else
2361 goto done;
2362 }
2363
2364 pencolor = color;
2365 if (ED_gui_state(e) & GUI_STATE_ACTIVE) {
2366 pencolor = default_pencolor(&buf, pencolor, DEFAULT_ACTIVEPENCOLOR);
2367 fillcolor = DEFAULT_ACTIVEFILLCOLOR;
2368 } else if (ED_gui_state(e) & GUI_STATE_SELECTED) {
2369 pencolor = default_pencolor(&buf, pencolor, DEFAULT_SELECTEDPENCOLOR);
2370 fillcolor = DEFAULT_SELECTEDFILLCOLOR;
2371 } else if (ED_gui_state(e) & GUI_STATE_DELETED) {
2372 pencolor = default_pencolor(&buf, pencolor, DEFAULT_DELETEDPENCOLOR);
2373 fillcolor = DEFAULT_DELETEDFILLCOLOR;
2374 } else if (ED_gui_state(e) & GUI_STATE_VISITED) {
2375 pencolor = default_pencolor(&buf, pencolor, DEFAULT_VISITEDPENCOLOR);
2376 fillcolor = DEFAULT_VISITEDFILLCOLOR;
2377 } else
2378 fillcolor = late_nnstring(e, E_fillcolor, color);
2379 if (pencolor != color)
2380 gvrender_set_pencolor(job, pencolor);
2381 if (fillcolor != color)
2382 gvrender_set_fillcolor(job, fillcolor);
2383 color = pencolor;
2384
2385 if (tapered) {
2386 if (*color == '\0')
2388 if (*fillcolor == '\0')
2389 fillcolor = DEFAULT_COLOR;
2390 gvrender_set_pencolor(job, "transparent");
2392 bz = ED_spl(e)->list[0];
2393 stroke_t stp = taper(&bz, taperfun(e), penwidth);
2394 assert(stp.nvertices <= INT_MAX);
2395 gvrender_polygon(job, stp.vertices, stp.nvertices, 1);
2396 free_stroke(stp);
2398 if (fillcolor != color)
2399 gvrender_set_fillcolor(job, fillcolor);
2400 if (bz.sflag) {
2401 arrow_gen(job, EMIT_TDRAW, bz.sp, bz.list[0], arrowsize, penwidth,
2402 bz.sflag);
2403 }
2404 if (bz.eflag) {
2405 arrow_gen(job, EMIT_HDRAW, bz.ep, bz.list[bz.size - 1], arrowsize,
2406 penwidth, bz.eflag);
2407 }
2408 }
2409 /* if more than one color - then generate parallel Béziers, one per color */
2410 else if (numc) {
2411 /* calculate and save offset vector spline and initialize first offset
2412 * spline */
2413 tmpspl.size = offspl.size = ED_spl(e)->size;
2414 offspl.list = gv_calloc(offspl.size, sizeof(bezier));
2415 tmpspl.list = gv_calloc(tmpspl.size, sizeof(bezier));
2416 numc2 = (2 + (double)numc) / 2.0;
2417 for (size_t i = 0; i < offspl.size; i++) {
2418 bz = ED_spl(e)->list[i];
2419 tmpspl.list[i].size = offspl.list[i].size = bz.size;
2420 offlist = offspl.list[i].list = gv_calloc(bz.size, sizeof(pointf));
2421 tmplist = tmpspl.list[i].list = gv_calloc(bz.size, sizeof(pointf));
2422 pf3 = bz.list[0];
2423 size_t j;
2424 for (j = 0; j < bz.size - 1; j += 3) {
2425 pf0 = pf3;
2426 pf1 = bz.list[j + 1];
2427 /* calculate perpendicular vectors for each Bézier point */
2428 if (j == 0) /* first segment, no previous pf2 */
2429 offlist[j] = computeoffset_p(pf0, pf1, SEP);
2430 else /* i.e. pf2 is available from previous segment */
2431 offlist[j] = computeoffset_p(pf2, pf1, SEP);
2432 pf2 = bz.list[j + 2];
2433 pf3 = bz.list[j + 3];
2434 offlist[j + 1] = offlist[j + 2] =
2435 computeoffset_qr(pf0, pf1, pf2, pf3, SEP);
2436 /* initialize tmpspl to outermost position */
2437 tmplist[j].x = pf0.x - numc2 * offlist[j].x;
2438 tmplist[j].y = pf0.y - numc2 * offlist[j].y;
2439 tmplist[j + 1].x = pf1.x - numc2 * offlist[j + 1].x;
2440 tmplist[j + 1].y = pf1.y - numc2 * offlist[j + 1].y;
2441 tmplist[j + 2].x = pf2.x - numc2 * offlist[j + 2].x;
2442 tmplist[j + 2].y = pf2.y - numc2 * offlist[j + 2].y;
2443 }
2444 /* last segment, no next pf1 */
2445 offlist[j] = computeoffset_p(pf2, pf3, SEP);
2446 tmplist[j].x = pf3.x - numc2 * offlist[j].x;
2447 tmplist[j].y = pf3.y - numc2 * offlist[j].y;
2448 }
2449 lastcolor = headcolor = tailcolor = color;
2450 colors = gv_strdup(color);
2451 for (cnum = 0, color = strtok(colors, ":"); color;
2452 cnum++, color = strtok(0, ":")) {
2453 if (!color[0])
2455 if (color != lastcolor) {
2459 }
2460 lastcolor = color;
2461 }
2462 if (cnum == 0)
2463 headcolor = tailcolor = color;
2464 if (cnum == 1)
2465 tailcolor = color;
2466 for (size_t i = 0; i < tmpspl.size; i++) {
2467 tmplist = tmpspl.list[i].list;
2468 offlist = offspl.list[i].list;
2469 for (size_t j = 0; j < tmpspl.list[i].size; j++) {
2470 tmplist[j].x += offlist[j].x;
2471 tmplist[j].y += offlist[j].y;
2472 }
2473 gvrender_beziercurve(job, tmplist, tmpspl.list[i].size, 0);
2474 }
2475 }
2476 if (bz.sflag) {
2477 if (color != tailcolor) {
2478 color = tailcolor;
2482 }
2483 }
2484 arrow_gen(job, EMIT_TDRAW, bz.sp, bz.list[0], arrowsize, penwidth,
2485 bz.sflag);
2486 }
2487 if (bz.eflag) {
2488 if (color != headcolor) {
2489 color = headcolor;
2493 }
2494 }
2495 arrow_gen(job, EMIT_HDRAW, bz.ep, bz.list[bz.size - 1], arrowsize,
2496 penwidth, bz.eflag);
2497 }
2498 free(colors);
2499 for (size_t i = 0; i < offspl.size; i++) {
2500 free(offspl.list[i].list);
2501 free(tmpspl.list[i].list);
2502 }
2503 free(offspl.list);
2504 free(tmpspl.list);
2505 } else {
2507 if (color[0]) {
2509 gvrender_set_fillcolor(job, fillcolor);
2510 } else {
2512 if (fillcolor[0])
2513 gvrender_set_fillcolor(job, fillcolor);
2514 else
2516 }
2517 }
2518 for (size_t i = 0; i < ED_spl(e)->size; i++) {
2519 bz = ED_spl(e)->list[i];
2520
2521 /* Check if this edge has orthogonal routing and wants rounded corners
2522 */
2523 char *splines_attr = agget(agraphof(aghead(e)), "splines");
2524 bool is_ortho = splines_attr && streq(splines_attr, "ortho");
2525
2526 /* Check for rounded style or explicit radius attribute */
2527 bool want_rounded = false;
2528 double radius = 0.0;
2529
2530 /* First check if style=rounded */
2531 if (styles) {
2532 for (char **sp = styles; *sp; sp++) {
2533 if (streq(*sp, "rounded")) {
2534 want_rounded = true;
2535 break;
2536 }
2537 }
2538 }
2539
2540 /* Then check for explicit radius attribute (overrides style) */
2541 char *radius_attr = agget(e, "radius");
2542 if (radius_attr && radius_attr[0]) {
2543 radius = atof(radius_attr);
2544 want_rounded = radius > 0;
2545 }
2546
2547 /* If no explicit radius, use default when style=rounded */
2548 if (want_rounded && radius == 0.0) {
2549 radius = fmax(12.0, penwidth * 8.0);
2550 }
2551
2552 if (is_ortho && want_rounded && radius > 0) {
2553 /* Truncate edge at corners and draw arcs */
2554 corners_t corners = {0};
2555 LIST_RESERVE(&corners, bz.size);
2556 find_ortho_corners(bz.list, bz.size, radius, &corners);
2557
2558 if (!LIST_IS_EMPTY(&corners)) {
2559 /* Sort corners by index */
2560 LIST_SORT(&corners, compare_corners);
2561
2562 /* Render segments between corners */
2563 const double CORNER_TOL = 0.01;
2564 size_t seg_start_idx = 0;
2565 pointf seg_start_pt = bz.list[0];
2566
2567 for (size_t c = 0; c <= LIST_SIZE(&corners); c++) {
2568 size_t seg_end_idx;
2569 pointf seg_end_pt;
2570
2571 if (c < LIST_SIZE(&corners)) {
2572 /* Segment ends at this corner's trunc_prev */
2573 seg_end_idx = LIST_GET(&corners, c).idx;
2574 seg_end_pt = LIST_GET(&corners, c).trunc_prev;
2575 } else {
2576 /* Last segment ends at final point */
2577 seg_end_idx = bz.size - 1;
2578 seg_end_pt = bz.list[bz.size - 1];
2579 }
2580
2581 /* Build segment */
2582 LIST(pointf) seg_pts = {0};
2583 LIST_APPEND(&seg_pts, seg_start_pt);
2584 for (size_t pt = seg_start_idx + 1; pt < seg_end_idx; pt++) {
2585 bool at_corner = false;
2586 for (size_t cc = 0; cc < LIST_SIZE(&corners); cc++) {
2587 pointf corner_pt = bz.list[LIST_GET(&corners, cc).idx];
2588 if (hypot(bz.list[pt].x - corner_pt.x,
2589 bz.list[pt].y - corner_pt.y) < CORNER_TOL) {
2590 at_corner = true;
2591 break;
2592 }
2593 }
2594 if (!at_corner) {
2595 LIST_APPEND(&seg_pts, bz.list[pt]);
2596 }
2597 }
2598 LIST_APPEND(&seg_pts, seg_end_pt);
2599
2600 /* Render this segment as polyline (straight lines, not bezier) */
2601 gvrender_polyline(job, LIST_FRONT(&seg_pts), LIST_SIZE(&seg_pts));
2602 LIST_FREE(&seg_pts);
2603
2604 /* Prepare for next segment */
2605 if (c < LIST_SIZE(&corners)) {
2606 /* Skip all duplicates of this corner */
2607 size_t next_idx = LIST_GET(&corners, c).idx + 1;
2608 while (next_idx < bz.size) {
2609 bool at_corner = false;
2610 for (size_t cc = 0; cc < LIST_SIZE(&corners); cc++) {
2611 pointf corner_pt = bz.list[LIST_GET(&corners, cc).idx];
2612 if (hypot(bz.list[next_idx].x - corner_pt.x,
2613 bz.list[next_idx].y - corner_pt.y) < CORNER_TOL) {
2614 at_corner = true;
2615 break;
2616 }
2617 }
2618 if (!at_corner)
2619 break;
2620 next_idx++;
2621 }
2622 seg_start_idx = next_idx;
2623 seg_start_pt = LIST_GET(&corners, c).trunc_next;
2624 }
2625 }
2626
2627 /* Draw corner arcs to fill the gaps */
2628 draw_ortho_corner_markers(job, &corners, radius, color);
2629 } else {
2630 /* No corners found, render normally */
2631 gvrender_beziercurve(job, bz.list, bz.size, 0);
2632 }
2633 LIST_FREE(&corners);
2634 } else {
2635 /* Non-orthogonal edge, render normally */
2636 gvrender_beziercurve(job, bz.list, bz.size, 0);
2637 }
2638
2639 if (bz.sflag) {
2640 arrow_gen(job, EMIT_TDRAW, bz.sp, bz.list[0], arrowsize, penwidth,
2641 bz.sflag);
2642 }
2643 if (bz.eflag) {
2644 arrow_gen(job, EMIT_HDRAW, bz.ep, bz.list[bz.size - 1], arrowsize,
2645 penwidth, bz.eflag);
2646 }
2647 if (ED_spl(e)->size > 1 && (bz.sflag || bz.eflag) && styles)
2648 gvrender_set_style(job, styles);
2649 }
2650 }
2651 }
2652
2653done:
2654 agxbfree(&buf);
2655}
2656
2657static bool edge_in_box(edge_t *e, boxf b) {
2658 splines *spl;
2659 textlabel_t *lp;
2660
2661 spl = ED_spl(e);
2662 if (spl && boxf_overlap(spl->bb, b))
2663 return true;
2664
2665 lp = ED_label(e);
2666 if (lp && overlap_label(lp, b))
2667 return true;
2668
2669 lp = ED_xlabel(e);
2670 if (lp && lp->set && overlap_label(lp, b))
2671 return true;
2672
2673 return false;
2674}
2675
2676static void emit_begin_edge(GVJ_t *job, edge_t *e, char **styles) {
2677 obj_state_t *obj;
2678 int flags = job->flags;
2679 char *s;
2680 textlabel_t *lab = NULL, *tlab = NULL, *hlab = NULL;
2681 char *dflt_url = NULL;
2682 char *dflt_target = NULL;
2683 double penwidth;
2684
2685 obj = push_obj_state(job);
2686 obj->type = EDGE_OBJTYPE;
2687 obj->u.e = e;
2688 obj->emit_state = EMIT_EDRAW;
2689 if (ED_label(e) && !ED_label(e)->html && mapbool(agget(e, "labelaligned")))
2690 obj->labeledgealigned = true;
2691
2692 /* We handle the edge style and penwidth here because the width
2693 * is needed below for calculating polygonal image maps
2694 */
2695 if (styles && ED_spl(e))
2696 gvrender_set_style(job, styles);
2697
2698 if (E_penwidth && (s = agxget(e, E_penwidth)) && s[0]) {
2699 penwidth = late_double(e, E_penwidth, 1.0, 0.0);
2701 }
2702
2703 if (flags & GVRENDER_DOES_Z) {
2704 if (GD_odim(agraphof(agtail(e))) >= 3) {
2705 obj->tail_z = POINTS(ND_pos(agtail(e))[2]);
2706 obj->head_z = POINTS(ND_pos(aghead(e))[2]);
2707 } else {
2708 obj->tail_z = obj->head_z = 0.0;
2709 }
2710 }
2711
2713 if ((lab = ED_label(e)))
2714 obj->label = lab->text;
2715 obj->taillabel = obj->headlabel = obj->xlabel = obj->label;
2716 if ((tlab = ED_xlabel(e)))
2717 obj->xlabel = tlab->text;
2718 if ((tlab = ED_tail_label(e)))
2719 obj->taillabel = tlab->text;
2720 if ((hlab = ED_head_label(e)))
2721 obj->headlabel = hlab->text;
2722 }
2723
2724 if (flags & GVRENDER_DOES_MAPS) {
2725 agxbuf xb = {0};
2726
2727 s = getObjId(job, e, &xb);
2728 obj->id = strdup_and_subst_obj(s, e);
2729 agxbfree(&xb);
2730
2731 if (((s = agget(e, "href")) && s[0]) || ((s = agget(e, "URL")) && s[0]))
2732 dflt_url = strdup_and_subst_obj(s, e);
2733 if (((s = agget(e, "edgehref")) && s[0]) ||
2734 ((s = agget(e, "edgeURL")) && s[0]))
2735 obj->url = strdup_and_subst_obj(s, e);
2736 else if (dflt_url)
2737 obj->url = gv_strdup(dflt_url);
2738 if (((s = agget(e, "labelhref")) && s[0]) ||
2739 ((s = agget(e, "labelURL")) && s[0]))
2740 obj->labelurl = strdup_and_subst_obj(s, e);
2741 else if (dflt_url)
2742 obj->labelurl = gv_strdup(dflt_url);
2743 if (((s = agget(e, "tailhref")) && s[0]) ||
2744 ((s = agget(e, "tailURL")) && s[0])) {
2745 obj->tailurl = strdup_and_subst_obj(s, e);
2746 obj->explicit_tailurl = true;
2747 } else if (dflt_url)
2748 obj->tailurl = gv_strdup(dflt_url);
2749 if (((s = agget(e, "headhref")) && s[0]) ||
2750 ((s = agget(e, "headURL")) && s[0])) {
2751 obj->headurl = strdup_and_subst_obj(s, e);
2752 obj->explicit_headurl = true;
2753 } else if (dflt_url)
2754 obj->headurl = gv_strdup(dflt_url);
2755 }
2756
2758 if ((s = agget(e, "target")) && s[0])
2759 dflt_target = strdup_and_subst_obj(s, e);
2760 if ((s = agget(e, "edgetarget")) && s[0]) {
2761 obj->explicit_edgetarget = true;
2762 obj->target = strdup_and_subst_obj(s, e);
2763 } else if (dflt_target)
2764 obj->target = gv_strdup(dflt_target);
2765 if ((s = agget(e, "labeltarget")) && s[0])
2767 else if (dflt_target)
2768 obj->labeltarget = gv_strdup(dflt_target);
2769 if ((s = agget(e, "tailtarget")) && s[0]) {
2771 obj->explicit_tailtarget = true;
2772 } else if (dflt_target)
2773 obj->tailtarget = gv_strdup(dflt_target);
2774 if ((s = agget(e, "headtarget")) && s[0]) {
2775 obj->explicit_headtarget = true;
2777 } else if (dflt_target)
2778 obj->headtarget = gv_strdup(dflt_target);
2779 }
2780
2782 if (((s = agget(e, "tooltip")) && s[0]) ||
2783 ((s = agget(e, "edgetooltip")) && s[0])) {
2784 char *tooltip = preprocessTooltip(s, e);
2785 obj->tooltip = strdup_and_subst_obj(tooltip, e);
2786 free(tooltip);
2787 obj->explicit_tooltip = true;
2788 } else if (obj->label)
2789 obj->tooltip = gv_strdup(obj->label);
2790
2791 if ((s = agget(e, "labeltooltip")) && s[0]) {
2792 char *tooltip = preprocessTooltip(s, e);
2793 obj->labeltooltip = strdup_and_subst_obj(tooltip, e);
2794 free(tooltip);
2795 obj->explicit_labeltooltip = true;
2796 } else if (obj->label)
2797 obj->labeltooltip = gv_strdup(obj->label);
2798
2799 if ((s = agget(e, "tailtooltip")) && s[0]) {
2800 char *tooltip = preprocessTooltip(s, e);
2801 obj->tailtooltip = strdup_and_subst_obj(tooltip, e);
2802 free(tooltip);
2803 obj->explicit_tailtooltip = true;
2804 } else if (obj->taillabel)
2805 obj->tailtooltip = gv_strdup(obj->taillabel);
2806
2807 if ((s = agget(e, "headtooltip")) && s[0]) {
2808 char *tooltip = preprocessTooltip(s, e);
2809 obj->headtooltip = strdup_and_subst_obj(tooltip, e);
2810 free(tooltip);
2811 obj->explicit_headtooltip = true;
2812 } else if (obj->headlabel)
2813 obj->headtooltip = gv_strdup(obj->headlabel);
2814 }
2815
2816 free(dflt_url);
2817 free(dflt_target);
2818
2820 if (ED_spl(e) && (obj->url || obj->tooltip) &&
2822 splines *spl;
2823 double w2 = fmax(job->obj->penwidth / 2.0, 2.0);
2824
2825 spl = ED_spl(e);
2826 const size_t ns = spl->size; /* number of splines */
2827 points_t pbs = {0};
2828 pbs_size_t pbs_n = {0};
2829 for (size_t i = 0; i < ns; i++)
2830 map_output_bspline(&pbs, &pbs_n, spl->list + i, w2);
2831 if (!(flags & GVRENDER_DOES_TRANSFORM)) {
2832 size_t nump = 0;
2833 for (size_t i = 0; i < LIST_SIZE(&pbs_n); ++i) {
2834 nump += LIST_GET(&pbs_n, i);
2835 }
2836 gvrender_ptf_A(job, LIST_FRONT(&pbs), LIST_FRONT(&pbs), nump);
2837 }
2838 obj->url_bsplinemap_p = LIST_FRONT(&pbs);
2840 LIST_DETACH(&pbs, &obj->url_map_p, NULL);
2841 obj->url_map_n = *LIST_FRONT(&pbs_n);
2843 }
2844 }
2845
2847 if (obj->url || obj->explicit_tooltip)
2848 gvrender_begin_anchor(job, obj->url, obj->tooltip, obj->target, obj->id);
2849}
2850
2851static void emit_edge_label(GVJ_t *job, textlabel_t *lbl, emit_state_t lkind,
2852 int explicit, char *url, char *tooltip,
2853 char *target, char *id, splines *spl) {
2854 int flags = job->flags;
2855 emit_state_t old_emit_state;
2856 char *newid;
2857 agxbuf xb = {0};
2858 char *type;
2859
2860 if (lbl == NULL || !lbl->set)
2861 return;
2862 if (id) { /* non-NULL if needed */
2863 switch (lkind) {
2864 case EMIT_ELABEL:
2865 type = "label";
2866 break;
2867 case EMIT_HLABEL:
2868 type = "headlabel";
2869 break;
2870 case EMIT_TLABEL:
2871 type = "taillabel";
2872 break;
2873 default:
2874 UNREACHABLE();
2875 }
2876 agxbprint(&xb, "%s-%s", id, type);
2877 newid = agxbuse(&xb);
2878 } else
2879 newid = NULL;
2880 old_emit_state = job->obj->emit_state;
2881 job->obj->emit_state = lkind;
2882 if ((url || explicit) && !(flags & EMIT_CLUSTERS_LAST)) {
2883 map_label(job, lbl);
2884 gvrender_begin_anchor(job, url, tooltip, target, newid);
2885 }
2886 emit_label(job, lkind, lbl);
2887 if (spl)
2888 emit_attachment(job, lbl, spl);
2889 if (url || explicit) {
2890 if (flags & EMIT_CLUSTERS_LAST) {
2891 map_label(job, lbl);
2892 gvrender_begin_anchor(job, url, tooltip, target, newid);
2893 }
2895 }
2896 agxbfree(&xb);
2897 job->obj->emit_state = old_emit_state;
2898}
2899
2900/* Common logic for setting hot spots at the beginning and end of
2901 * an edge.
2902 * If we are given a value (url, tooltip, target) explicitly set for
2903 * the head/tail, we use that.
2904 * Otherwise, if we are given a value explicitly set for the edge,
2905 * we use that.
2906 * Otherwise, we use whatever the argument value is.
2907 * We also note whether or not the tooltip was explicitly set.
2908 * If the url is non-NULL or the tooltip was explicit, we set
2909 * a hot spot around point p.
2910 */
2911static void nodeIntersect(GVJ_t *job, pointf p, bool explicit_iurl, char *iurl,
2912 bool explicit_itooltip) {
2913 obj_state_t *obj = job->obj;
2914 char *url;
2915 bool explicit;
2916
2917 if (explicit_iurl)
2918 url = iurl;
2919 else
2920 url = obj->url;
2921 if (explicit_itooltip) {
2922 explicit = true;
2923 } else if (obj->explicit_tooltip) {
2924 explicit = true;
2925 } else {
2926 explicit = false;
2927 }
2928
2929 if (url || explicit) {
2930 map_point(job, p);
2931 }
2932}
2933
2934static void emit_end_edge(GVJ_t *job) {
2935 obj_state_t *obj = job->obj;
2936 edge_t *e = obj->u.e;
2937
2938 if (obj->url || obj->explicit_tooltip) {
2940 if (obj->url_bsplinemap_poly_n) {
2941 for (size_t nump = obj->url_bsplinemap_n[0], i = 1;
2942 i < obj->url_bsplinemap_poly_n; i++) {
2943 /* additional polygon maps around remaining Bézier pieces */
2944 obj->url_map_n = obj->url_bsplinemap_n[i];
2945 obj->url_map_p = &(obj->url_bsplinemap_p[nump]);
2946 gvrender_begin_anchor(job, obj->url, obj->tooltip, obj->target,
2947 obj->id);
2949 nump += obj->url_bsplinemap_n[i];
2950 }
2951 }
2952 }
2953 obj->url_map_n = 0; /* null out copy so that it doesn't get freed twice */
2954 obj->url_map_p = NULL;
2955
2956 if (ED_spl(e)) {
2957 pointf p;
2958 bezier bz;
2959
2960 /* process intersection with tail node */
2961 bz = ED_spl(e)->list[0];
2962 if (bz.sflag) /* Arrow at start of splines */
2963 p = bz.sp;
2964 else /* No arrow at start of splines */
2965 p = bz.list[0];
2966 nodeIntersect(job, p, obj->explicit_tailurl != 0, obj->tailurl,
2967 obj->explicit_tailtooltip != 0);
2968
2969 /* process intersection with head node */
2970 bz = ED_spl(e)->list[ED_spl(e)->size - 1];
2971 if (bz.eflag) /* Arrow at end of splines */
2972 p = bz.ep;
2973 else /* No arrow at end of splines */
2974 p = bz.list[bz.size - 1];
2975 nodeIntersect(job, p, obj->explicit_headurl != 0, obj->headurl,
2976 obj->explicit_headtooltip != 0);
2977 }
2978
2980 obj->labelurl, obj->labeltooltip, obj->labeltarget, obj->id,
2981 ((mapbool(late_string(e, E_decorate, "false")) && ED_spl(e))
2982 ? ED_spl(e)
2983 : 0));
2985 obj->labelurl, obj->labeltooltip, obj->labeltarget, obj->id,
2986 ((mapbool(late_string(e, E_decorate, "false")) && ED_spl(e))
2987 ? ED_spl(e)
2988 : 0));
2990 obj->headurl, obj->headtooltip, obj->headtarget, obj->id, 0);
2992 obj->tailurl, obj->tailtooltip, obj->tailtarget, obj->id, 0);
2993
2994 gvrender_end_edge(job);
2995 pop_obj_state(job);
2996}
2997
2998static void emit_edge(GVJ_t *job, edge_t *e) {
2999 char *s;
3000 char *style;
3001 char **styles = NULL;
3002 char **sp;
3003 char *p;
3004
3005 if (edge_in_box(e, job->clip) && edge_in_layer(job, e)) {
3006
3007 agxbuf edge = {0};
3008 agxbput(&edge, agnameof(agtail(e)));
3009 if (agisdirected(agraphof(aghead(e))))
3010 agxbput(&edge, "->");
3011 else
3012 agxbput(&edge, "--");
3013 agxbput(&edge, agnameof(aghead(e)));
3015 agxbfree(&edge);
3016
3017 s = late_string(e, E_comment, "");
3018 if (s[0])
3019 gvrender_comment(job, s);
3020
3021 style = late_string(e, E_style, "");
3022 /* We shortcircuit drawing an invisible edge because the arrowhead
3023 * code resets the style to solid, and most of the code generators
3024 * (except PostScript) won't honor a previous style of invis.
3025 */
3026 if (style[0]) {
3027 styles = parse_style(style);
3028 sp = styles;
3029 while ((p = *sp++)) {
3030 if (streq(p, "invis"))
3031 return;
3032 }
3033 }
3034
3035 char *const previous_color_scheme = setColorScheme(agget(e, "colorscheme"));
3036 emit_begin_edge(job, e, styles);
3037 emit_edge_graphics(job, e, styles);
3038 emit_end_edge(job);
3039 char *const our_color_scheme = setColorScheme(previous_color_scheme);
3040 free(previous_color_scheme);
3041 free(our_color_scheme);
3042 }
3043}
3044
3045static const char adjust[] = {'l', 'n', 'r'};
3046
3047static void expandBB(boxf *bb, pointf p) {
3048 bb->UR.x = fmax(bb->UR.x, p.x);
3049 bb->LL.x = fmin(bb->LL.x, p.x);
3050 bb->UR.y = fmax(bb->UR.y, p.y);
3051 bb->LL.y = fmin(bb->LL.y, p.y);
3052}
3053
3054static boxf ptsBB(xdot_point *inpts, size_t numpts, boxf *bb) {
3055 boxf opbb;
3056
3057 opbb.LL.x = opbb.UR.x = inpts->x;
3058 opbb.LL.y = opbb.UR.y = inpts->y;
3059 for (size_t i = 1; i < numpts; i++) {
3060 inpts++;
3061 if (inpts->x < opbb.LL.x)
3062 opbb.LL.x = inpts->x;
3063 else if (inpts->x > opbb.UR.x)
3064 opbb.UR.x = inpts->x;
3065 if (inpts->y < opbb.LL.y)
3066 opbb.LL.y = inpts->y;
3067 else if (inpts->y > opbb.UR.y)
3068 opbb.UR.y = inpts->y;
3069 }
3070 expandBB(bb, opbb.LL);
3071 expandBB(bb, opbb.UR);
3072 return opbb;
3073}
3074
3075static boxf textBB(double x, double y, textspan_t *span) {
3076 boxf bb;
3077 pointf sz = span->size;
3078
3079 switch (span->just) {
3080 case 'l':
3081 bb.LL.x = x;
3082 bb.UR.x = bb.LL.x + sz.x;
3083 break;
3084 case 'n':
3085 bb.LL.x = x - sz.x / 2.0;
3086 bb.UR.x = x + sz.x / 2.0;
3087 break;
3088 case 'r':
3089 bb.UR.x = x;
3090 bb.LL.x = bb.UR.x - sz.x;
3091 break;
3092 default:
3093 UNREACHABLE();
3094 }
3095 bb.UR.y = y + span->yoffset_layout;
3096 bb.LL.y = bb.UR.y - sz.y;
3097 return bb;
3098}
3099
3100static void freePara(xdot_op *xop) {
3101 exdot_op *const op = (exdot_op *)((char *)xop - offsetof(exdot_op, op));
3102 if (op->op.kind == xd_text)
3103 free_textspan(op->span, 1);
3104}
3105
3107 GVC_t *gvc = GD_gvc(g);
3108 exdot_op *op;
3109 double fontsize = 0.0;
3110 char *fontname = NULL;
3111 pointf pts[2];
3112 boxf bb0;
3113 boxf bb = GD_bb(g);
3114 xdot *xd = GD_drawing(g)->xdots;
3115 textfont_t tf, null_tf = {0};
3116 unsigned fontflags = 0;
3117
3118 if (!xd)
3119 return bb;
3120
3121 if (bb.LL.x == bb.UR.x && bb.LL.y == bb.UR.y) {
3122 bb.LL.x = bb.LL.y = DBL_MAX;
3123 bb.UR.x = bb.UR.y = -DBL_MAX;
3124 }
3125
3126 op = (exdot_op *)xd->ops;
3127 for (size_t i = 0; i < xd->cnt; i++) {
3128 tf = null_tf;
3129 switch (op->op.kind) {
3130 case xd_filled_ellipse:
3132 pts[0].x = op->op.u.ellipse.x - op->op.u.ellipse.w;
3133 pts[0].y = op->op.u.ellipse.y - op->op.u.ellipse.h;
3134 pts[1].x = op->op.u.ellipse.x + op->op.u.ellipse.w;
3135 pts[1].y = op->op.u.ellipse.y + op->op.u.ellipse.h;
3136 op->bb.LL = pts[0];
3137 op->bb.UR = pts[1];
3138 expandBB(&bb, pts[0]);
3139 expandBB(&bb, pts[1]);
3140 break;
3141 case xd_filled_polygon:
3143 op->bb = ptsBB(op->op.u.polygon.pts, op->op.u.polygon.cnt, &bb);
3144 break;
3145 case xd_filled_bezier:
3146 case xd_unfilled_bezier:
3147 op->bb = ptsBB(op->op.u.polygon.pts, op->op.u.polygon.cnt, &bb);
3148 break;
3149 case xd_polyline:
3150 op->bb = ptsBB(op->op.u.polygon.pts, op->op.u.polygon.cnt, &bb);
3151 break;
3152 case xd_text:
3153 op->span = gv_alloc(sizeof(textspan_t));
3154 op->span->str = gv_strdup(op->op.u.text.text);
3155 op->span->just = adjust[op->op.u.text.align];
3156 tf.name = fontname;
3157 tf.size = fontsize;
3158 tf.flags = fontflags;
3159 op->span->font = dtinsert(gvc->textfont_dt, &tf);
3160 textspan_size(gvc, op->span);
3161 bb0 = textBB(op->op.u.text.x, op->op.u.text.y, op->span);
3162 op->bb = bb0;
3163 expandBB(&bb, bb0.LL);
3164 expandBB(&bb, bb0.UR);
3165 if (!xd->freefunc)
3166 xd->freefunc = freePara;
3167 break;
3168 case xd_font:
3169 fontsize = op->op.u.font.size;
3170 fontname = op->op.u.font.name;
3171 break;
3172 case xd_fontchar:
3173 fontflags = op->op.u.fontchar;
3174 break;
3175 default:
3176 break;
3177 }
3178 op++;
3179 }
3180 return bb;
3181}
3182
3183static void init_gvc(GVC_t *gvc, graph_t *g) {
3184 double xf, yf;
3185 char *p;
3186 int i;
3187
3188 gvc->g = g;
3189
3190 /* margins */
3191 gvc->graph_sets_margin = false;
3192 if ((p = agget(g, "margin"))) {
3193 i = sscanf(p, "%lf,%lf", &xf, &yf);
3194 if (i > 0) {
3195 gvc->margin.x = gvc->margin.y = xf * POINTS_PER_INCH;
3196 if (i > 1)
3197 gvc->margin.y = yf * POINTS_PER_INCH;
3198 gvc->graph_sets_margin = true;
3199 }
3200 }
3201
3202 /* pad */
3203 gvc->graph_sets_pad = false;
3204 if ((p = agget(g, "pad"))) {
3205 i = sscanf(p, "%lf,%lf", &xf, &yf);
3206 if (i > 0) {
3207 gvc->pad.x = gvc->pad.y = xf * POINTS_PER_INCH;
3208 if (i > 1)
3209 gvc->pad.y = yf * POINTS_PER_INCH;
3210 gvc->graph_sets_pad = true;
3211 }
3212 }
3213
3214 /* pagesize */
3215 gvc->graph_sets_pageSize = false;
3216 gvc->pageSize = GD_drawing(g)->page;
3217 if (GD_drawing(g)->page.x > 0.001 && GD_drawing(g)->page.y > 0.001)
3218 gvc->graph_sets_pageSize = true;
3219
3220 /* rotation */
3221 if (GD_drawing(g)->landscape)
3222 gvc->rotation = 90;
3223 else
3224 gvc->rotation = 0;
3225
3226 /* pagedir */
3227 gvc->pagedir = "BL";
3228 if ((p = agget(g, "pagedir")) && p[0])
3229 gvc->pagedir = p;
3230
3231 /* bounding box */
3232 gvc->bb = GD_bb(g);
3233
3234 /* clusters have peripheries */
3235 G_peripheries = agfindgraphattr(g, "peripheries");
3236 G_penwidth = agfindgraphattr(g, "penwidth");
3237
3238 /* default font */
3242
3243 /* default line style */
3245
3246 gvc->graphname = agnameof(g);
3247}
3248
3249static void init_job_pad(GVJ_t *job) {
3250 GVC_t *gvc = job->gvc;
3251
3252 if (gvc->graph_sets_pad) {
3253 job->pad = gvc->pad;
3254 } else {
3255 switch (job->output_lang) {
3256 case GVRENDER_PLUGIN:
3257 job->pad.x = job->pad.y = job->render.features->default_pad;
3258 break;
3259 default:
3260 job->pad.x = job->pad.y = DEFAULT_GRAPH_PAD;
3261 break;
3262 }
3263 }
3264}
3265
3266static void init_job_margin(GVJ_t *job) {
3267 GVC_t *gvc = job->gvc;
3268
3269 if (gvc->graph_sets_margin) {
3270 job->margin = gvc->margin;
3271 } else {
3272 /* set default margins depending on format */
3273 switch (job->output_lang) {
3274 case GVRENDER_PLUGIN:
3275 job->margin = job->device.features->default_margin;
3276 break;
3277 case PCL:
3278 case MIF:
3279 case METAPOST:
3280 case VTX:
3281 case QPDF:
3282 job->margin.x = job->margin.y = DEFAULT_PRINT_MARGIN;
3283 break;
3284 default:
3285 job->margin.x = job->margin.y = DEFAULT_EMBED_MARGIN;
3286 break;
3287 }
3288 }
3289}
3290
3291static void init_job_dpi(GVJ_t *job, graph_t *g) {
3292 GVJ_t *firstjob = job->gvc->active_jobs;
3293
3294 if (GD_drawing(g)->dpi > 0) {
3295 job->dpi.x = job->dpi.y = GD_drawing(g)->dpi;
3296 } else if (firstjob && firstjob->device_sets_dpi) {
3297 job->dpi = firstjob->device_dpi; /* some devices set dpi in initialize() */
3298 } else {
3299 /* set default margins depending on format */
3300 switch (job->output_lang) {
3301 case GVRENDER_PLUGIN:
3302 job->dpi = job->device.features->default_dpi;
3303 break;
3304 default:
3305 job->dpi.x = job->dpi.y = DEFAULT_DPI;
3306 break;
3307 }
3308 }
3309}
3310
3311static void init_job_viewport(GVJ_t *job, graph_t *g) {
3312 GVC_t *gvc = job->gvc;
3313 pointf LL, UR, size, sz;
3314 double Z;
3315 int rv;
3316 Agnode_t *n;
3317 char *str, *nodename = NULL;
3318
3319 UR = gvc->bb.UR;
3320 LL = gvc->bb.LL;
3321 job->bb.LL = sub_pointf(
3322 LL, job->pad); // job->bb is bb of graph and padding - graph units
3323 job->bb.UR = add_pointf(UR, job->pad);
3324 sz = sub_pointf(job->bb.UR,
3325 job->bb.LL); // size, including padding - graph units
3326
3327 /* determine final drawing size and scale to apply. */
3328 /* N.B. size given by user is not rotated by landscape mode */
3329 /* start with "natural" size of layout */
3330
3331 Z = 1.0;
3332 if (GD_drawing(g)->size.x > 0.001 &&
3333 GD_drawing(g)->size.y > 0.001) { /* graph size was given by user... */
3334 size = GD_drawing(g)->size;
3335 if (sz.x <= 0.001)
3336 sz.x = size.x;
3337 if (sz.y <= 0.001)
3338 sz.y = size.y;
3339 if (size.x < sz.x ||
3340 size.y < sz.y /* drawing is too big (in either axis) ... */
3341 || (GD_drawing(g)->filled /* or ratio=filled requested and ... */
3342 && size.x > sz.x &&
3343 size.y > sz.y)) /* drawing is too small (in both axes) ... */
3344 Z = fmin(size.x / sz.x, size.y / sz.y);
3345 }
3346
3347 /* default focus, in graph units = center of bb */
3348 pointf xy = scale(0.5, add_pointf(LL, UR));
3349
3350 /* rotate and scale bb to give default absolute size in points*/
3351 job->rotation = job->gvc->rotation;
3352 pointf XY = scale(Z, sz);
3353
3354 /* user can override */
3355 if ((str = agget(g, "viewport"))) {
3356 nodename = gv_alloc(strlen(str) + 1);
3357 rv = sscanf(str, "%lf,%lf,%lf,\'%[^\']\'", &XY.x, &XY.y, &Z, nodename);
3358 if (rv == 4) {
3359 n = agfindnode(g->root, nodename);
3360 if (n) {
3361 xy = ND_coord(n);
3362 }
3363 } else {
3364 rv = sscanf(str, "%lf,%lf,%lf,%[^,]%c", &XY.x, &XY.y, &Z, nodename,
3365 &(char){0});
3366 if (rv == 4) {
3367 n = agfindnode(g->root, nodename);
3368 if (n) {
3369 xy = ND_coord(n);
3370 }
3371 } else {
3372 sscanf(str, "%lf,%lf,%lf,%lf,%lf", &XY.x, &XY.y, &Z, &xy.x, &xy.y);
3373 }
3374 }
3375 free(nodename);
3376 }
3377 /* rv is ignored since args retain previous values if not scanned */
3378
3379 /* job->view gives port size in graph units, unscaled or rotated
3380 * job->zoom gives scaling factor.
3381 * job->focus gives the position in the graph of the center of the port
3382 */
3383 job->view = XY;
3384 job->zoom = Z; /* scaling factor */
3385 job->focus = xy;
3386}
3387
3388static void emit_cluster_colors(GVJ_t *job, graph_t *g) {
3389 graph_t *sg;
3390 int c;
3391 char *str;
3392
3393 for (c = 1; c <= GD_n_cluster(g); c++) {
3394 sg = GD_clust(g)[c];
3395 emit_cluster_colors(job, sg);
3396 if (((str = agget(sg, "color")) != 0) && str[0])
3398 if (((str = agget(sg, "pencolor")) != 0) && str[0])
3400 if (((str = agget(sg, "bgcolor")) != 0) && str[0])
3402 if (((str = agget(sg, "fillcolor")) != 0) && str[0])
3404 if (((str = agget(sg, "fontcolor")) != 0) && str[0])
3406 }
3407}
3408
3409static void emit_colors(GVJ_t *job, graph_t *g) {
3410 node_t *n;
3411 edge_t *e;
3412 char *str, *colors;
3413
3415 if (((str = agget(g, "bgcolor")) != 0) && str[0])
3417 if (((str = agget(g, "fontcolor")) != 0) && str[0])
3419
3420 emit_cluster_colors(job, g);
3421 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
3422 if (((str = agget(n, "color")) != 0) && str[0])
3424 if (((str = agget(n, "pencolor")) != 0) && str[0])
3426 if (((str = agget(n, "fillcolor")) != 0) && str[0]) {
3427 if (strchr(str, ':')) {
3428 colors = gv_strdup(str);
3429 for (str = strtok(colors, ":"); str; str = strtok(0, ":")) {
3430 if (str[0])
3432 }
3433 free(colors);
3434 } else {
3436 }
3437 }
3438 if (((str = agget(n, "fontcolor")) != 0) && str[0])
3440 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
3441 if (((str = agget(e, "color")) != 0) && str[0]) {
3442 if (strchr(str, ':')) {
3443 colors = gv_strdup(str);
3444 for (str = strtok(colors, ":"); str; str = strtok(0, ":")) {
3445 if (str[0])
3447 }
3448 free(colors);
3449 } else {
3451 }
3452 }
3453 if (((str = agget(e, "fontcolor")) != 0) && str[0])
3455 }
3456 }
3457}
3458
3459static void emit_view(GVJ_t *job, graph_t *g, int flags) {
3460 GVC_t *gvc = job->gvc;
3461 node_t *n;
3462 edge_t *e;
3463
3464 gvc->common.viewNum++;
3465 /* when drawing, lay clusters down before nodes and edges */
3466 if (!(flags & EMIT_CLUSTERS_LAST))
3467 emit_clusters(job, g, flags);
3468 if (flags & EMIT_SORTED) {
3469 /* output all nodes, then all edges */
3471 for (n = agfstnode(g); n; n = agnxtnode(g, n))
3472 emit_node(job, n);
3473 gvrender_end_nodes(job);
3475 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
3476 for (e = agfstout(g, n); e; e = agnxtout(g, e))
3477 emit_edge(job, e);
3478 }
3479 gvrender_end_edges(job);
3480 } else if (flags & EMIT_EDGE_SORTED) {
3481 /* output all edges, then all nodes */
3483 for (n = agfstnode(g); n; n = agnxtnode(g, n))
3484 for (e = agfstout(g, n); e; e = agnxtout(g, e))
3485 emit_edge(job, e);
3486 gvrender_end_edges(job);
3488 for (n = agfstnode(g); n; n = agnxtnode(g, n))
3489 emit_node(job, n);
3490 gvrender_end_nodes(job);
3491 } else if (flags & EMIT_PREORDER) {
3493 for (n = agfstnode(g); n; n = agnxtnode(g, n))
3494 if (write_node_test(g, n))
3495 emit_node(job, n);
3496 gvrender_end_nodes(job);
3498
3499 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
3500 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
3501 if (write_edge_test(g, e))
3502 emit_edge(job, e);
3503 }
3504 }
3505 gvrender_end_edges(job);
3506 } else {
3507 /* output in breadth first graph walk order */
3508 for (n = agfstnode(g); n; n = agnxtnode(g, n)) {
3509 emit_node(job, n);
3510 for (e = agfstout(g, n); e; e = agnxtout(g, e)) {
3511 emit_node(job, aghead(e));
3512 emit_edge(job, e);
3513 }
3514 }
3515 }
3516 /* when mapping, detect events on clusters after nodes and edges */
3518 emit_clusters(job, g, flags);
3519}
3520
3521static void emit_begin_graph(GVJ_t *job, graph_t *g) {
3522 obj_state_t *obj;
3523
3524 obj = push_obj_state(job);
3525 obj->type = ROOTGRAPH_OBJTYPE;
3526 obj->u.g = g;
3527 obj->emit_state = EMIT_GDRAW;
3528
3529 initObjMapData(job, GD_label(g), g);
3530
3532}
3533
3534static void emit_end_graph(GVJ_t *job) {
3535 gvrender_end_graph(job);
3536 pop_obj_state(job);
3537}
3538
3539static bool NotFirstPage(const GVJ_t *j) {
3540 return j->layerNum > 1 || j->pagesArrayElem.x > 0 || j->pagesArrayElem.y > 0;
3541}
3542
3543static void emit_page(GVJ_t *job, graph_t *g) {
3544 obj_state_t *obj = job->obj;
3545 int flags = job->flags;
3546 size_t nump = 0;
3547 textlabel_t *lab;
3548 pointf *p = NULL;
3549 char *saveid;
3550 agxbuf xb = {0};
3551
3552 /* For the first page, we can use the values generated in emit_begin_graph.
3553 * For multiple pages, we need to generate a new id.
3554 */
3555 bool obj_id_needs_restore = false;
3556 if (NotFirstPage(job)) {
3557 saveid = obj->id;
3558 layerPagePrefix(job, &xb);
3559 agxbput(&xb, saveid == NULL ? "layer" : saveid);
3560 obj->id = agxbuse(&xb);
3561 obj_id_needs_restore = true;
3562 } else
3563 saveid = NULL;
3564
3565 char *previous_color_scheme = setColorScheme(agget(g, "colorscheme"));
3566 setup_page(job);
3571 (obj->url || obj->explicit_tooltip)) {
3575 nump = 2;
3576 } else {
3578 nump = 4;
3579 }
3580 p = gv_calloc(nump, sizeof(pointf));
3581 p[0] = job->pageBox.LL;
3582 p[1] = job->pageBox.UR;
3584 rect2poly(p);
3585 }
3587 gvrender_ptf_A(job, p, p, nump);
3588 obj->url_map_p = p;
3589 obj->url_map_n = nump;
3590 }
3591 if ((flags & GVRENDER_DOES_LABELS) && ((lab = GD_label(g))))
3592 /* do graph label on every page and rely on clipping to show it on the right
3593 * one(s) */
3594 obj->label = lab->text;
3595 /* If EMIT_CLUSTERS_LAST is set, we assume any URL or tooltip
3596 * attached to the root graph is emitted either in begin_page
3597 * or end_page of renderer.
3598 */
3599 if (!(flags & EMIT_CLUSTERS_LAST) && (obj->url || obj->explicit_tooltip)) {
3600 emit_map_rect(job, job->clip);
3601 gvrender_begin_anchor(job, obj->url, obj->tooltip, obj->target, obj->id);
3602 }
3603 emit_background(job, g);
3604 if (GD_label(g))
3606 if (!(flags & EMIT_CLUSTERS_LAST) && (obj->url || obj->explicit_tooltip))
3608 emit_view(job, g, flags);
3609 gvrender_end_page(job);
3610 if (obj_id_needs_restore) {
3611 obj->id = saveid;
3612 }
3613 agxbfree(&xb);
3614
3615 char *color_scheme = setColorScheme(previous_color_scheme);
3616 free(color_scheme);
3617 free(previous_color_scheme);
3618}
3619
3620void emit_graph(GVJ_t *job, graph_t *g) {
3621 node_t *n;
3622 char *s;
3623 int flags = job->flags;
3624 int *lp;
3625
3626 /* device dpi is now known */
3627 job->scale.x = job->zoom * job->dpi.x / POINTS_PER_INCH;
3628 job->scale.y = job->zoom * job->dpi.y / POINTS_PER_INCH;
3629
3630 job->devscale.x = job->dpi.x / POINTS_PER_INCH;
3631 job->devscale.y = job->dpi.y / POINTS_PER_INCH;
3632 if ((job->flags & GVRENDER_Y_GOES_DOWN) || (Y_invert))
3633 job->devscale.y *= -1;
3634
3635 /* compute current view in graph units */
3636 if (job->rotation) {
3637 job->view.y = job->width / job->scale.y;
3638 job->view.x = job->height / job->scale.x;
3639 } else {
3640 job->view.x = job->width / job->scale.x;
3641 job->view.y = job->height / job->scale.y;
3642 }
3643
3644 s = late_string(g, agattr_text(g, AGRAPH, "comment", 0), "");
3645 gvrender_comment(job, s);
3646
3647 job->layerNum = 0;
3648 emit_begin_graph(job, g);
3649
3650 if (flags & EMIT_COLORS)
3651 emit_colors(job, g);
3652
3653 /* reset node state */
3654 for (n = agfstnode(g); n; n = agnxtnode(g, n))
3655 ND_state(n) = 0;
3656 /* iterate layers */
3657 for (firstlayer(job, &lp); validlayer(job); nextlayer(job, &lp)) {
3658 if (numPhysicalLayers(job) > 1)
3660
3661 /* iterate pages */
3662 for (firstpage(job); validpage(job); nextpage(job))
3663 emit_page(job, g);
3664
3665 if (numPhysicalLayers(job) > 1)
3666 gvrender_end_layer(job);
3667 }
3668 emit_end_graph(job);
3669}
3670
3673 .link = -1, // link - allocate separate holder objects
3674 .freef = free,
3675};
3676
3677bool emit_once(char *str) {
3678 // use stderr as a mutual exclusion mechanism for `strings`
3679 lockfile(stderr);
3680
3681 if (strings == 0)
3683 if (!dtsearch(strings, str)) {
3685 unlockfile(stderr);
3686 return true;
3687 }
3688 unlockfile(stderr);
3689 return false;
3690}
3691
3693 // use stderr as a mutual exclusion mechanism for `strings`
3694 lockfile(stderr);
3695
3696 if (strings) {
3698 strings = 0;
3699 }
3700 unlockfile(stderr);
3701}
3702
3703static void emit_begin_cluster(GVJ_t *job, Agraph_t *sg) {
3704 obj_state_t *obj;
3705
3706 obj = push_obj_state(job);
3707 obj->type = CLUSTER_OBJTYPE;
3708 obj->u.sg = sg;
3709 obj->emit_state = EMIT_CDRAW;
3710
3711 initObjMapData(job, GD_label(sg), sg);
3712
3714}
3715
3716static void emit_end_cluster(GVJ_t *job) {
3718 pop_obj_state(job);
3719}
3720
3721void emit_clusters(GVJ_t *job, Agraph_t *g, int flags) {
3722 int doPerim, c, filled;
3723 pointf AF[4];
3724 char *color, *fillcolor, *pencolor, **style, *s;
3725 graph_t *sg;
3726 node_t *n;
3727 edge_t *e;
3728 obj_state_t *obj;
3729 textlabel_t *lab;
3730 int doAnchor;
3731 double penwidth;
3732
3733 for (c = 1; c <= GD_n_cluster(g); c++) {
3734 sg = GD_clust(g)[c];
3735 if (!clust_in_layer(job, sg))
3736 continue;
3737 /* when mapping, detect events on clusters after sub_clusters */
3739 emit_clusters(job, sg, flags);
3740 emit_begin_cluster(job, sg);
3741 obj = job->obj;
3742 doAnchor = obj->url || obj->explicit_tooltip;
3743 char *previous_color_scheme = setColorScheme(agget(sg, "colorscheme"));
3744 if (doAnchor && !(flags & EMIT_CLUSTERS_LAST)) {
3745 emit_map_rect(job, GD_bb(sg));
3746 gvrender_begin_anchor(job, obj->url, obj->tooltip, obj->target, obj->id);
3747 }
3748 filled = 0;
3749 graphviz_polygon_style_t istyle = {0};
3750 if ((style = checkClusterStyle(sg, &istyle))) {
3751 gvrender_set_style(job, style);
3752 if (istyle.filled)
3753 filled = FILL;
3754 }
3755 fillcolor = pencolor = 0;
3756
3757 if (GD_gui_state(sg) & GUI_STATE_ACTIVE) {
3758 pencolor = DEFAULT_ACTIVEPENCOLOR;
3759 fillcolor = DEFAULT_ACTIVEFILLCOLOR;
3760 filled = FILL;
3761 } else if (GD_gui_state(sg) & GUI_STATE_SELECTED) {
3762 pencolor = DEFAULT_SELECTEDPENCOLOR;
3763 fillcolor = DEFAULT_SELECTEDFILLCOLOR;
3764 filled = FILL;
3765 } else if (GD_gui_state(sg) & GUI_STATE_DELETED) {
3766 pencolor = DEFAULT_DELETEDPENCOLOR;
3767 fillcolor = DEFAULT_DELETEDFILLCOLOR;
3768 filled = FILL;
3769 } else if (GD_gui_state(sg) & GUI_STATE_VISITED) {
3770 pencolor = DEFAULT_VISITEDPENCOLOR;
3771 fillcolor = DEFAULT_VISITEDFILLCOLOR;
3772 filled = FILL;
3773 } else {
3774 if ((color = agget(sg, "color")) != 0 && color[0])
3775 fillcolor = pencolor = color;
3776 if ((color = agget(sg, "pencolor")) != 0 && color[0])
3777 pencolor = color;
3778 if ((color = agget(sg, "fillcolor")) != 0 && color[0])
3779 fillcolor = color;
3780 /* bgcolor is supported for backward compatibility
3781 if fill is set, fillcolor trumps bgcolor, so
3782 don't bother checking.
3783 if gradient is set fillcolor trumps bgcolor
3784 */
3785 if ((filled == 0 || !fillcolor) && (color = agget(sg, "bgcolor")) != 0 &&
3786 color[0]) {
3787 fillcolor = color;
3788 filled = FILL;
3789 }
3790 }
3791 if (!pencolor)
3792 pencolor = DEFAULT_COLOR;
3793 if (!fillcolor)
3794 fillcolor = DEFAULT_FILL;
3795 char *clrs[2] = {0};
3796 if (filled != 0) {
3797 double frac;
3798 if (findStopColor(fillcolor, clrs, &frac)) {
3799 gvrender_set_fillcolor(job, clrs[0]);
3800 if (clrs[1])
3801 gvrender_set_gradient_vals(job, clrs[1],
3802 late_int(sg, G_gradientangle, 0, 0), frac);
3803 else
3805 late_int(sg, G_gradientangle, 0, 0), frac);
3806 if (istyle.radial)
3807 filled = RGRADIENT;
3808 else
3809 filled = GRADIENT;
3810 } else
3811 gvrender_set_fillcolor(job, fillcolor);
3812 }
3813
3814 if (G_penwidth && ((s = agxget(sg, G_penwidth)) && s[0])) {
3815 penwidth = late_double(sg, G_penwidth, 1.0, 0.0);
3817 }
3818
3819 if (istyle.rounded) {
3820 if ((doPerim = late_int(sg, G_peripheries, 1, 0)) || filled != 0) {
3821 AF[0] = GD_bb(sg).LL;
3822 AF[2] = GD_bb(sg).UR;
3823 AF[1].x = AF[2].x;
3824 AF[1].y = AF[0].y;
3825 AF[3].x = AF[0].x;
3826 AF[3].y = AF[2].y;
3827 if (doPerim)
3828 gvrender_set_pencolor(job, pencolor);
3829 else
3830 gvrender_set_pencolor(job, "transparent");
3831 round_corners(job, AF, 4, istyle, filled);
3832 }
3833 } else if (istyle.striped) {
3834 AF[0] = GD_bb(sg).LL;
3835 AF[2] = GD_bb(sg).UR;
3836 AF[1].x = AF[2].x;
3837 AF[1].y = AF[0].y;
3838 AF[3].x = AF[0].x;
3839 AF[3].y = AF[2].y;
3840 if (late_int(sg, G_peripheries, 1, 0) == 0)
3841 gvrender_set_pencolor(job, "transparent");
3842 else
3843 gvrender_set_pencolor(job, pencolor);
3844 if (stripedBox(job, AF, fillcolor, 0) > 1)
3845 agerr(AGPREV, "in cluster %s\n", agnameof(sg));
3846 gvrender_box(job, GD_bb(sg), 0);
3847 } else {
3848 if (late_int(sg, G_peripheries, 1, 0)) {
3849 gvrender_set_pencolor(job, pencolor);
3850 gvrender_box(job, GD_bb(sg), filled);
3851 } else if (filled != 0) {
3852 gvrender_set_pencolor(job, "transparent");
3853 gvrender_box(job, GD_bb(sg), filled);
3854 }
3855 }
3856
3857 free(clrs[0]);
3858 free(clrs[1]);
3859 if ((lab = GD_label(sg)))
3860 emit_label(job, EMIT_CLABEL, lab);
3861
3862 if (doAnchor) {
3863 if (flags & EMIT_CLUSTERS_LAST) {
3864 emit_map_rect(job, GD_bb(sg));
3865 gvrender_begin_anchor(job, obj->url, obj->tooltip, obj->target,
3866 obj->id);
3867 }
3869 }
3870
3871 if (flags & EMIT_PREORDER) {
3872 for (n = agfstnode(sg); n; n = agnxtnode(sg, n)) {
3873 emit_node(job, n);
3874 for (e = agfstout(sg, n); e; e = agnxtout(sg, e))
3875 emit_edge(job, e);
3876 }
3877 }
3878 emit_end_cluster(job);
3879 /* when drawing, lay down clusters before sub_clusters */
3880 if (!(flags & EMIT_CLUSTERS_LAST))
3881 emit_clusters(job, sg, flags);
3882
3883 char *color_scheme = setColorScheme(previous_color_scheme);
3884 free(color_scheme);
3885 free(previous_color_scheme);
3886 }
3887}
3888
3889static bool is_style_delim(int c) {
3890 switch (c) {
3891 case '(':
3892 case ')':
3893 case ',':
3894 case '\0':
3895 return true;
3896 default:
3897 return false;
3898 }
3899}
3900
3901#define SID 1
3902
3907typedef struct {
3908 int type;
3909 const char *start;
3910 size_t size;
3911} token_t;
3912
3913static token_t style_token(char **s) {
3914 char *p = *s;
3915 int token;
3916
3917 while (gv_isspace(*p) || *p == ',')
3918 p++;
3919 const char *start = p;
3920 switch (*p) {
3921 case '\0':
3922 token = 0;
3923 break;
3924 case '(':
3925 case ')':
3926 token = *p++;
3927 break;
3928 default:
3929 token = SID;
3930 while (!is_style_delim(*p)) {
3931 p++;
3932 }
3933 }
3934 *s = p;
3935 assert(start <= p);
3936 size_t size = (size_t)(p - start);
3937 return (token_t){.type = token, .start = start, .size = size};
3938}
3939
3940#define FUNLIMIT 64
3941
3942/* This is one of the worst internal designs in graphviz.
3943 * The use of '\0' characters within strings seems cute but it
3944 * makes all of the standard functions useless if not dangerous.
3945 * Plus the function uses static memory for both the array and
3946 * the character buffer. One hopes all of the values are used
3947 * before the function is called again.
3948 */
3949char **parse_style(char *s) {
3950 static char *parse[FUNLIMIT];
3951 size_t parse_offsets[sizeof(parse) / sizeof(parse[0])];
3952 size_t fun = 0;
3953 bool in_parens = false;
3954 char *p;
3955 static agxbuf ps_xb;
3956
3957 p = s;
3958 while (true) {
3959 token_t c = style_token(&p);
3960 if (c.type == 0) {
3961 break;
3962 }
3963 switch (c.type) {
3964 case '(':
3965 if (in_parens) {
3966 agerrorf("nesting not allowed in style: %s\n", s);
3967 parse[0] = NULL;
3968 return parse;
3969 }
3970 in_parens = true;
3971 break;
3972
3973 case ')':
3974 if (!in_parens) {
3975 agerrorf("unmatched ')' in style: %s\n", s);
3976 parse[0] = NULL;
3977 return parse;
3978 }
3979 in_parens = false;
3980 break;
3981
3982 default:
3983 if (!in_parens) {
3984 if (fun == FUNLIMIT - 1) {
3985 agwarningf("truncating style '%s'\n", s);
3986 parse[fun] = NULL;
3987 return parse;
3988 }
3989 agxbputc(&ps_xb, '\0'); /* terminate previous */
3990 parse_offsets[fun++] = agxblen(&ps_xb);
3991 }
3992 agxbput_n(&ps_xb, c.start, c.size);
3993 agxbputc(&ps_xb, '\0');
3994 }
3995 }
3996
3997 if (in_parens) {
3998 agerrorf("unmatched '(' in style: %s\n", s);
3999 parse[0] = NULL;
4000 return parse;
4001 }
4002
4003 char *base = agxbuse(&ps_xb); // add final '\0' to buffer
4004
4005 // construct list of style strings
4006 for (size_t i = 0; i < fun; ++i) {
4007 parse[i] = base + parse_offsets[i];
4008 }
4009 parse[fun] = NULL;
4010
4011 return parse;
4012}
4013
4015 pointf p, p1, p2;
4016 boxf bb;
4017
4018 assert(bz.size > 0);
4019 assert(bz.size % 3 == 1);
4020 bb.LL = bb.UR = bz.list[0];
4021 for (size_t i = 1; i < bz.size;) {
4022 /* take mid-point between two control points for bb calculation */
4023 p1 = bz.list[i];
4024 i++;
4025 p2 = bz.list[i];
4026 i++;
4027 p.x = (p1.x + p2.x) / 2;
4028 p.y = (p1.y + p2.y) / 2;
4029 expandbp(&bb, p);
4030
4031 p = bz.list[i];
4032 expandbp(&bb, p);
4033 i++;
4034 }
4035 return bb;
4036}
4037
4038static void init_splines_bb(splines *spl) {
4039 assert(spl->size > 0);
4040 bezier bz = spl->list[0];
4041 boxf bb = bezier_bb(bz);
4042 for (size_t i = 0; i < spl->size; i++) {
4043 if (i > 0) {
4044 bz = spl->list[i];
4045 const boxf b = bezier_bb(bz);
4046 EXPANDBB(&bb, b);
4047 }
4048 if (bz.sflag) {
4049 const boxf b = arrow_bb(bz.sp, bz.list[0], 1);
4050 EXPANDBB(&bb, b);
4051 }
4052 if (bz.eflag) {
4053 const boxf b = arrow_bb(bz.ep, bz.list[bz.size - 1], 1);
4054 EXPANDBB(&bb, b);
4055 }
4056 }
4057 spl->bb = bb;
4058}
4059
4060static void init_bb_edge(edge_t *e) {
4061 splines *const spl = ED_spl(e);
4062 if (spl)
4063 init_splines_bb(spl);
4064}
4065
4066static void init_bb_node(graph_t *g, node_t *n) {
4067 ND_bb(n).LL.x = ND_coord(n).x - ND_lw(n);
4068 ND_bb(n).LL.y = ND_coord(n).y - ND_ht(n) / 2.;
4069 ND_bb(n).UR.x = ND_coord(n).x + ND_rw(n);
4070 ND_bb(n).UR.y = ND_coord(n).y + ND_ht(n) / 2.;
4071
4072 for (edge_t *e = agfstout(g, n); e; e = agnxtout(g, e))
4073 init_bb_edge(e);
4074
4075 /* IDEA - could also save in the node the bb of the node and
4076 all of its outedges, then the scan time would be proportional
4077 to just the number of nodes for many graphs.
4078 Wouldn't work so well if the edges are sprawling all over the place
4079 because then the boxes would overlap a lot and require more tests,
4080 but perhaps that wouldn't add much to the cost before trying individual
4081 nodes and edges. */
4082}
4083
4084static void init_bb(graph_t *g) {
4085 for (node_t *n = agfstnode(g); n; n = agnxtnode(g, n))
4086 init_bb_node(g, n);
4087}
4088
4090extern const size_t gvevent_key_binding_size;
4092
4093/* Set LC_NUMERIC to "C" to get expected interpretation of %f
4094 * in printf functions. Languages like postscript and dot expect
4095 * floating point numbers to use a decimal point.
4096 *
4097 * If set is non-zero, the "C" locale set;
4098 * if set is zero, the original locale is reset.
4099 * Calls to the function can nest.
4100 */
4101void gv_fixLocale(int set) {
4102 static char *save_locale;
4103 static int cnt;
4104
4105 if (set) {
4106 cnt++;
4107 if (cnt == 1) {
4108 save_locale = gv_strdup(setlocale(LC_NUMERIC, NULL));
4109 setlocale(LC_NUMERIC, "C");
4110 }
4111 } else if (cnt > 0) {
4112 cnt--;
4113 if (cnt == 0) {
4114 setlocale(LC_NUMERIC, save_locale);
4115 free(save_locale);
4116 }
4117 }
4118}
4119
4120#define FINISH() \
4121 GV_DEBUG("gvRenderJobs %s: %.2f secs.", agnameof(g), elapsed_sec())
4122
4124 static GVJ_t *prevjob;
4125 GVJ_t *job, *firstjob;
4126
4127 if (Verbose)
4128 start_timer();
4129
4130 if (!LAYOUT_DONE(g)) {
4131 agerrorf("Layout was not done. Missing layout plugins? \n");
4132 FINISH();
4133 return -1;
4134 }
4135
4136 init_bb(g);
4137 init_gvc(gvc, g);
4138 init_layering(gvc, g);
4139
4140 gv_fixLocale(1);
4141 for (job = gvjobs_first(gvc); job; job = gvjobs_next(gvc)) {
4142 if (gvc->gvg) {
4144 job->graph_index = gvc->gvg->graph_index;
4145 } else {
4146 job->input_filename = NULL;
4147 job->graph_index = 0;
4148 }
4149 job->common = &gvc->common;
4150 job->layout_type = gvc->layout.type;
4153 if (!GD_drawing(g)) {
4154 agerrorf("layout was not done\n");
4155 gv_fixLocale(0);
4156 FINISH();
4157 return -1;
4158 }
4159
4161 if (job->output_lang == NO_SUPPORT) {
4162 agerrorf("renderer for %s is unavailable\n", job->output_langname);
4163 gv_fixLocale(0);
4164 FINISH();
4165 return -1;
4166 }
4167
4168 switch (job->output_lang) {
4169 case VTX:
4170 /* output sorted, i.e. all nodes then all edges */
4171 job->flags |= EMIT_SORTED;
4172 break;
4173 default:
4174 job->flags |= chkOrder(g);
4175 break;
4176 }
4177
4178 // if we already have an active job list and the device doesn't support
4179 // multiple output files, or we are about to write to a different output
4180 // device
4181 firstjob = gvc->active_jobs;
4182 if (firstjob) {
4183 if (!(firstjob->flags & GVDEVICE_DOES_PAGES) ||
4184 strcmp(job->output_langname, firstjob->output_langname)) {
4185
4186 gvrender_end_job(firstjob);
4187
4188 gvc->active_jobs = NULL; /* clear active list */
4189 gvc->common.viewNum = 0;
4190 prevjob = NULL;
4191 }
4192 } else {
4193 prevjob = NULL;
4194 }
4195
4196 if (prevjob) {
4197 prevjob->next_active = job; /* insert job in active list */
4198 job->output_file = prevjob->output_file; /* FIXME - this is dumb ! */
4199 } else {
4200 if (gvrender_begin_job(job))
4201 continue;
4202 gvc->active_jobs = job; /* first job of new list */
4203 }
4204 job->next_active = NULL; /* terminate active list */
4206
4207 init_job_pad(job);
4208 init_job_margin(job);
4209 init_job_dpi(job, g);
4210 init_job_viewport(job, g);
4211 init_job_pagination(job, g);
4212
4213 if (!(job->flags & GVDEVICE_EVENTS)) {
4214 if (debug) {
4215 // Show_boxes is not defined, if at all, until splines are generated in
4216 // dot
4219// FIXME: remove the cast and change `show_boxes` to a `char **` at the next API
4220// break
4221#ifdef __GNUC__
4222#pragma GCC diagnostic push
4223#pragma GCC diagnostic ignored "-Wcast-qual"
4224#endif
4225 job->common->show_boxes = (const char **)LIST_FRONT(&Show_boxes);
4226#ifdef __GNUC__
4227#pragma GCC diagnostic pop
4228#endif
4229 }
4230 emit_graph(job, g);
4231 }
4232
4233 /* the last job, after all input graphs are processed,
4234 * is finalized from gvFinalize()
4235 */
4236 prevjob = job;
4237 }
4238 gv_fixLocale(0);
4239 free(gvc->layerlist);
4240 gvc->layerlist = NULL;
4241 FINISH();
4242 return 0;
4243}
4244
4245/* Check for colon in colorlist. If one exists, and not the first
4246 * character, store the characters before the colon in clrs[0] and
4247 * the characters after the colon (and before the next or end-of-string)
4248 * in clrs[1]. If there are no characters after the first colon, clrs[1]
4249 * is NULL. Return TRUE.
4250 * If there is no non-trivial string before a first colon, set clrs[0] to
4251 * NULL and return FALSE.
4252 *
4253 * Note that memory for clrs must be freed by calling function.
4254 */
4255bool findStopColor(const char *colorlist, char *clrs[2], double *frac) {
4256 colorsegs_t segs = {.dtor = freeSeg};
4257 int rv;
4258 clrs[0] = NULL;
4259 clrs[1] = NULL;
4260
4261 rv = parseSegs(colorlist, &segs);
4262 if (rv || LIST_SIZE(&segs) < 2 || LIST_FRONT(&segs)->color == NULL) {
4263 LIST_FREE(&segs);
4264 return false;
4265 }
4266
4267 if (LIST_SIZE(&segs) > 2)
4268 agwarningf(
4269 "More than 2 colors specified for a gradient - ignoring remaining\n");
4270
4271 clrs[0] = gv_strdup(LIST_FRONT(&segs)->color);
4272 if (LIST_GET(&segs, 1).color) {
4273 clrs[1] = gv_strdup(LIST_GET(&segs, 1).color);
4274 }
4275
4276 if (LIST_FRONT(&segs)->hasFraction)
4277 *frac = LIST_FRONT(&segs)->t;
4278 else if (LIST_GET(&segs, 1).hasFraction)
4279 *frac = 1 - LIST_GET(&segs, 1).t;
4280 else
4281 *frac = 0;
4282
4283 LIST_FREE(&segs);
4284 return true;
4285}
static agxbuf last
last message
Definition agerror.c:31
Dynamically expanding string buffers.
static void agxbfree(agxbuf *xb)
free any malloced resources
Definition agxbuf.h:97
static size_t agxbput_n(agxbuf *xb, const char *s, size_t ssz)
append string s of length ssz into xb
Definition agxbuf.h:268
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
Definition agxbuf.h:252
static WUR char * agxbuse(agxbuf *xb)
Definition agxbuf.h:325
static size_t agxblen(const agxbuf *xb)
return number of characters currently stored
Definition agxbuf.h:108
static int agxbputc(agxbuf *xb, char c)
add character to buffer
Definition agxbuf.h:295
Memory allocation wrappers that exit on failure.
static char * gv_strdup(const char *original)
Definition alloc.h:101
static void * gv_calloc(size_t nmemb, size_t size)
Definition alloc.h:26
static void * gv_alloc(size_t size)
Definition alloc.h:47
#define BETWEEN(a, b, c)
Definition arith.h:38
#define M_PI
Definition arith.h:41
boxf arrow_bb(pointf p, pointf u, double arrowsize)
Definition arrows.c:1107
void arrow_gen(GVJ_t *job, emit_state_t emit_state, pointf p, pointf u, double arrowsize, double penwidth, uint32_t flag)
Definition arrows.c:1145
container data types API
#define dtsearch(d, o)
Definition cdt.h:184
#define dtinsert(d, o)
Definition cdt.h:186
CDT_API int dtclose(Dt_t *)
Definition dtclose.c:10
CDT_API Dtmethod_t * Dtoset
ordered set (self-adjusting tree)
Definition dttree.c:306
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
Definition dtopen.c:11
#define parent(i)
Definition closest.c:75
#define right(i)
Definition closest.c:74
COLORPROCS_API char * setColorScheme(const char *s)
Definition colxlate.c:397
char * late_nnstring(void *obj, attrsym_t *attr, char *defaultValue)
Definition utils.c:92
bool mapbool(const char *p)
Definition utils.c:321
char * late_string(void *obj, attrsym_t *attr, char *defaultValue)
Definition utils.c:86
int late_int(void *obj, attrsym_t *attr, int defaultValue, int minimum)
Definition utils.c:39
pointf Bezier(const pointf *V, double t, pointf *Left, pointf *Right)
Definition utils.c:171
bool overlap_label(textlabel_t *lp, boxf b)
Definition utils.c:1261
double late_double(void *obj, attrsym_t *attr, double defaultValue, double minimum)
Definition utils.c:54
pointf dotneato_closest(splines *spl, pointf pt)
Definition utils.c:323
char * latin1ToUTF8(char *s)
Converts string from Latin1 encoding to utf8. Also translates HTML entities.
Definition utils.c:1201
char * htmlEntityUTF8(char *s, graph_t *g)
Definition utils.c:1122
#define DEFAULT_SELECTEDFILLCOLOR
Definition const.h:53
#define VTX
Definition const.h:132
#define CHAR_LATIN1
Definition const.h:188
#define DEFAULT_LAYERLISTSEP
Definition const.h:83
#define NO_SUPPORT
Definition const.h:138
#define METAPOST
Definition const.h:133
#define PCL
Definition const.h:129
#define DEFAULT_COLOR
Definition const.h:48
#define QPDF
Definition const.h:135
#define DEFAULT_EMBED_MARGIN
Definition const.h:94
#define DEFAULT_ACTIVEFILLCOLOR
Definition const.h:50
#define MIF
Definition const.h:130
#define DEFAULT_FONTSIZE
Definition const.h:61
#define MIN_FONTSIZE
Definition const.h:63
#define DEFAULT_PRINT_MARGIN
Definition const.h:92
#define DEFAULT_FONTNAME
Definition const.h:67
#define GVRENDER_PLUGIN
Definition const.h:137
#define DEFAULT_FILL
Definition const.h:69
#define DEFAULT_DELETEDFILLCOLOR
Definition const.h:56
#define DFLT_SAMPLE
Definition const.h:105
#define DEFAULT_SELECTEDPENCOLOR
Definition const.h:52
#define DEFAULT_LAYERSEP
Definition const.h:82
#define GRADIENT
Definition const.h:223
#define DEFAULT_VISITEDFILLCOLOR
Definition const.h:59
#define DEFAULT_DELETEDPENCOLOR
Definition const.h:55
#define DEFAULT_GRAPH_PAD
Definition const.h:96
#define RGRADIENT
Definition const.h:224
#define DEFAULT_VISITEDPENCOLOR
Definition const.h:58
#define DEFAULT_ACTIVEPENCOLOR
Definition const.h:49
helpers for verbose/debug printing
static float dy
Definition draw.c:43
static float dx
Definition draw.c:42
#define left
Definition dthdr.h:12
static void ins(Dict_t *d, Dtlink_t **set, Agedge_t *e)
Definition edge.c:143
static void del(Dict_t *d, Dtlink_t **set, Agedge_t *e)
Definition edge.c:149
Ppolyline_t * ellipticWedge(pointf ctr, double xsemi, double ysemi, double angle0, double angle1)
Definition ellipse.c:274
#define EPSILON
Definition emit.c:57
static void render_corner_arc(GVJ_t *job, const Ppolyline_t *wedge, size_t arc_start_idx, size_t arc_point_count, char *edge_color)
Definition emit.c:2262
bool emit_once(char *str)
Definition emit.c:3677
static size_t find_prev_distinct(const pointf *pts, size_t i)
Definition emit.c:2060
static bool node_in_box(node_t *n, boxf b)
Definition emit.c:1608
static bool write_edge_test(Agraph_t *g, Agedge_t *e)
Definition emit.c:1303
static void free_stroke(stroke_t sp)
Definition emit.c:2015
static void map_point(GVJ_t *job, pointf pf)
Definition emit.c:331
static radfunc_t taperfun(edge_t *e)
Definition emit.c:2041
static int * parse_layerselect(GVC_t *gvc, const char *p)
Definition emit.c:998
static void emit_xdot(GVJ_t *job, xdot *xd)
Definition emit.c:1336
static void emit_end_graph(GVJ_t *job)
Definition emit.c:3534
static void emit_end_cluster(GVJ_t *job)
Definition emit.c:3716
static int compare_corners(const void *a, const void *b)
Definition emit.c:2098
static void emit_edge_graphics(GVJ_t *job, edge_t *e, char **styles)
Definition emit.c:2319
void emit_clusters(GVJ_t *job, Agraph_t *g, int flags)
Definition emit.c:3721
static Dict_t * strings
Definition emit.c:3671
int stripedBox(GVJ_t *job, pointf *AF, const char *clrs, int rotate)
Definition emit.c:582
static void emit_cluster_colors(GVJ_t *job, graph_t *g)
Definition emit.c:3388
static double revfunc(double curlen, double totallen, double initwid)
Definition emit.c:2023
static void nodeIntersect(GVJ_t *job, pointf p, bool explicit_iurl, char *iurl, bool explicit_itooltip)
Definition emit.c:2911
static void calculate_wedge_parameters(corner_info_t *ci, pointf curr, double dx1, double dy1, double dx2, double dy2, double radius, bool seg1_horiz, bool seg2_vert)
Definition emit.c:2112
static char * defaultlinestyle[3]
Definition emit.c:107
static void init_splines_bb(splines *spl)
Definition emit.c:4038
void gv_fixLocale(int set)
Definition emit.c:4101
static void freePara(xdot_op *xop)
Definition emit.c:3100
static void nextlayer(GVJ_t *job, int **listp)
Definition emit.c:1132
static void layerPagePrefix(GVJ_t *job, agxbuf *xb)
Definition emit.c:194
static bool selectedLayer(GVC_t *gvc, int layerNum, int numLayers, const char *spec)
Definition emit.c:941
static void init_bb(graph_t *g)
Definition emit.c:4084
static void emit_end_node(GVJ_t *job)
Definition emit.c:1752
static pointf computeoffset_qr(pointf p, pointf q, pointf r, pointf s, double d)
Definition emit.c:1814
static bool edge_in_layer(GVJ_t *job, edge_t *e)
Definition emit.c:1576
@ debug
Definition emit.c:62
static double forfunc(double curlen, double totallen, double initwid)
Definition emit.c:2019
#define FUZZ
Definition emit.c:56
static char ** checkClusterStyle(graph_t *sg, graphviz_polygon_style_t *flagp)
Definition emit.c:354
static bool isFilled(node_t *n)
Definition emit.c:690
static void map_output_bspline(points_t *pbs, pbs_size_t *pbs_n, bezier *bp, double w2)
Definition emit.c:888
static void emit_background(GVJ_t *job, graph_t *g)
Definition emit.c:1450
static void init_bb_edge(edge_t *e)
Definition emit.c:4060
static char * preprocessTooltip(char *s, void *gobj)
Definition emit.c:292
static int parse_layers(GVC_t *gvc, graph_t *g, char *p)
Definition emit.c:1025
static char * interpretCRNL(char *ins)
Definition emit.c:252
static boxf bezier_bb(bezier bz)
Definition emit.c:4014
static bool is_style_delim(int c)
Definition emit.c:3889
static void expandBB(boxf *bb, pointf p)
Definition emit.c:3047
static void find_ortho_corners(const pointf *pts, size_t n, double radius, corners_t *corners)
Definition emit.c:2222
bool findStopColor(const char *colorlist, char *clrs[2], double *frac)
Definition emit.c:4255
static bool clust_in_layer(GVJ_t *job, graph_t *sg)
Definition emit.c:1593
static bool isRect(polygon_t *p)
Definition emit.c:681
static void emit_edge(GVJ_t *job, edge_t *e)
Definition emit.c:2998
static const char adjust[]
Definition emit.c:3045
static pointf * pEllipse(double a, double b, size_t np)
Definition emit.c:710
static void freeSeg(colorseg_t seg)
Definition emit.c:405
static Dtdisc_t stringdict
Definition emit.c:3672
static void init_bb_node(graph_t *g, node_t *n)
Definition emit.c:4066
static double bothfunc(double curlen, double totallen, double initwid)
Definition emit.c:2034
static int multicolor(GVJ_t *job, edge_t *e, char **styles, const char *colors, double arrowsize, double penwidth)
Definition emit.c:1937
#define AEQ0(x)
Definition emit.c:438
static void approx_bezier(pointf *cp, points_t *lp)
Definition emit.c:819
#define FUNLIMIT
Definition emit.c:3940
static bool NotFirstPage(const GVJ_t *j)
Definition emit.c:3539
static void draw_ortho_corner_markers(GVJ_t *job, const corners_t *corners, double radius, char *edge_color)
Definition emit.c:2286
static bool selectedlayer(GVJ_t *job, const char *spec)
Definition emit.c:979
static void emit_view(GVJ_t *job, graph_t *g, int flags)
Definition emit.c:3459
#define SID
Definition emit.c:3901
#define THIN_LINE
Definition emit.c:525
static boxf textBB(double x, double y, textspan_t *span)
Definition emit.c:3075
static void emit_begin_node(GVJ_t *job, node_t *n)
Definition emit.c:1612
static double approxLen(pointf *pts)
Definition emit.c:1871
static int numPhysicalLayers(GVJ_t *job)
Return number of physical layers to be emitted.
Definition emit.c:1102
static void init_job_dpi(GVJ_t *job, graph_t *g)
Definition emit.c:3291
static void map_label(GVJ_t *job, textlabel_t *lab)
Definition emit.c:654
static bool node_in_layer(GVJ_t *job, graph_t *g, node_t *n)
Definition emit.c:1558
static void firstpage(GVJ_t *job)
Definition emit.c:1281
static void splitBSpline(bezier *bz, double t, bezier *left, bezier *right)
Definition emit.c:1883
static char * saved_color_scheme
Definition emit.c:1610
void * init_xdot(Agraph_t *g)
Definition emit.c:71
static void emit_edge_label(GVJ_t *job, textlabel_t *lbl, emit_state_t lkind, int explicit, char *url, char *tooltip, char *target, char *id, splines *spl)
Definition emit.c:2851
static void initObjMapData(GVJ_t *job, textlabel_t *lab, void *gobj)
Definition emit.c:308
static void init_job_margin(GVJ_t *job)
Definition emit.c:3266
static bool validpage(GVJ_t *job)
Definition emit.c:1285
static int chkOrder(graph_t *g)
Definition emit.c:1070
static void init_job_viewport(GVJ_t *job, graph_t *g)
Definition emit.c:3311
static void emit_colors(GVJ_t *job, graph_t *g)
Definition emit.c:3409
#define SEP
static void emit_begin_cluster(GVJ_t *job, Agraph_t *sg)
Definition emit.c:3703
static void setup_page(GVJ_t *job)
Definition emit.c:1505
static int layer_index(GVC_t *gvc, char *str, int all)
Definition emit.c:927
static bool validlayer(GVJ_t *job)
Definition emit.c:1130
static void init_gvc(GVC_t *gvc, graph_t *g)
Definition emit.c:3183
static bool check_control_points(const pointf *cp)
Definition emit.c:729
static bool is_natural_number(const char *sstr)
Definition emit.c:918
obj_state_t * push_obj_state(GVJ_t *job)
Definition emit.c:110
static void emit_attachment(GVJ_t *job, textlabel_t *lp, splines *spl)
Definition emit.c:1834
#define FINISH()
Definition emit.c:4120
static void emit_page(GVJ_t *job, graph_t *g)
Definition emit.c:3543
gvevent_key_binding_t gvevent_key_binding[]
Definition gvevent.c:519
char ** parse_style(char *s)
Definition emit.c:3949
static void firstlayer(GVJ_t *job, int **listp)
Definition emit.c:1109
static char * default_pencolor(agxbuf *buf, const char *pencolor, const char *deflt)
Definition emit.c:1861
void emit_once_reset(void)
Definition emit.c:3692
void emit_map_rect(GVJ_t *job, boxf b)
Definition emit.c:630
static void emit_end_edge(GVJ_t *job)
Definition emit.c:2934
void update_bb_bz(boxf *bb, const pointf *cp)
Definition emit.c:770
static void init_layering(GVC_t *gvc, graph_t *g)
Definition emit.c:1081
static void init_job_pagination(GVJ_t *job, graph_t *g)
Definition emit.c:1165
static void update_bb_bz_core(boxf *bb, const pointf *cp, size_t recurse)
Definition emit.c:735
static double nonefunc(double curlen, double totallen, double initwid)
Definition emit.c:2027
int wedgedEllipse(GVJ_t *job, pointf *pf, const char *clrs)
Definition emit.c:536
static boxf ptsBB(xdot_point *inpts, size_t numpts, boxf *bb)
Definition emit.c:3054
void pop_obj_state(GVJ_t *job)
Definition emit.c:132
static void nextpage(GVJ_t *job)
Definition emit.c:1292
static pointf * copyPts(xdot_point *inpts, size_t numpts)
Definition emit.c:1327
static point pagecode(GVJ_t *job, char c)
Definition emit.c:1141
static bool edge_in_box(edge_t *e, boxf b)
Definition emit.c:2657
gvdevice_callbacks_t gvdevice_callbacks
Definition gvevent.c:539
#define HW
Definition emit.c:723
char * getObjId(GVJ_t *job, void *obj, agxbuf *xb)
Use id of root graph if any, plus kind and internal id of object.
Definition emit.c:204
const size_t gvevent_key_binding_size
Definition gvevent.c:536
static void emit_begin_edge(GVJ_t *job, edge_t *e, char **styles)
Definition emit.c:2676
static token_t style_token(char **s)
Definition emit.c:3913
static void mkSegPts(const pointf *prv, pointf cur, const pointf *nxt, pointf *p1, pointf *p2, double w2)
Definition emit.c:855
static void emit_begin_graph(GVJ_t *job, graph_t *g)
Definition emit.c:3521
static bool write_node_test(Agraph_t *g, Agnode_t *n)
Definition emit.c:1315
static void emit_node(GVJ_t *job, node_t *n)
Definition emit.c:1763
#define P2RECT(p, pr, sx, sy)
Definition emit.c:53
void emit_graph(GVJ_t *job, graph_t *g)
Definition emit.c:3620
boxf xdotBB(Agraph_t *g)
Definition emit.c:3106
double(* radfunc_t)(double, double, double)
Definition emit.c:2017
static size_t find_next_distinct(const pointf *pts, size_t i, size_t n)
Definition emit.c:2076
static void init_job_pad(GVJ_t *job)
Definition emit.c:3249
static double bisect(pointf pp, pointf cp, pointf np)
Definition emit.c:837
static int parseSegs(const char *clrs, colorsegs_t *psegs)
Definition emit.c:453
static pointf computeoffset_p(pointf p, pointf q, double d)
Definition emit.c:1802
bool initMapData(GVJ_t *job, char *lbl, char *url, char *tooltip, char *target, char *id, void *gobj)
Definition emit.c:162
expr procedure type
Definition exparse.y:208
static int recurse
Definition gc.c:59
static int flags
Definition gc.c:63
void rect2poly(pointf *p)
Definition geom.c:122
double ptToLine2(pointf a, pointf b, pointf p)
Definition geom.c:181
#define POINTS(a_inches)
Definition geom.h:62
struct pointf_s pointf
#define DIST(p, q)
Definition geom.h:56
#define POINTS_PER_INCH
Definition geom.h:58
geometric functions (e.g. on points and boxes)
static void expandbp(boxf *b, pointf p)
expand box b as needed to enclose point p
Definition geomprocs.h:45
static WUR point exch_xy(point p)
Definition geomprocs.h:120
static WUR pointf mid_pointf(pointf p, pointf q)
Definition geomprocs.h:104
static WUR pointf sub_pointf(pointf p, pointf q)
Definition geomprocs.h:96
static WUR pointf add_pointf(pointf p, pointf q)
Definition geomprocs.h:88
static WUR pointf exch_xyf(pointf p)
Definition geomprocs.h:128
#define EXPANDBB(b0, b1)
Definition geomprocs.h:65
static WUR pointf scale(double c, pointf p)
Definition geomprocs.h:148
static WUR bool boxf_overlap(boxf b0, boxf b1)
Definition geomprocs.h:136
show_boxes_t Show_boxes
Definition globals.c:23
Agsym_t * N_fontsize
Definition globals.h:78
Agsym_t * N_layer
Definition globals.h:81
Agsym_t * E_comment
Definition globals.h:86
Agsym_t * G_peripheries
Definition globals.h:75
Agsym_t * E_decorate
Definition globals.h:85
Agsym_t * E_style
Definition globals.h:85
Agsym_t * N_fontname
Definition globals.h:78
Agsym_t * N_comment
Definition globals.h:81
Agsym_t * N_style
Definition globals.h:79
Agsym_t * E_fillcolor
Definition globals.h:83
Agsym_t * E_dir
Definition globals.h:84
Agsym_t * E_color
Definition globals.h:83
Agsym_t * E_arrowsz
Definition globals.h:85
Agsym_t * G_gradientangle
Definition globals.h:76
Agsym_t * G_penwidth
Definition globals.h:75
bool Y_invert
invert y in dot & plain output
Definition globals.h:71
Agsym_t * E_penwidth
Definition globals.h:88
Agsym_t * E_layer
Definition globals.h:85
static double len(glCompPoint p)
Definition glutils.c:138
static bool Verbose
Definition gml2gv.c:26
void free(void *)
#define FILL
Definition gmlparse.h:119
edge
Definition gmlparse.y:246
#define SIZE_MAX
Definition gmlscan.c:347
node NULL
Definition grammar.y:181
static int cnt(Dict_t *d, Dtlink_t **set)
Definition graph.c:204
Agsym_t * agattr_text(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up text attributes of a graph
Definition attr.c:333
char * agget(void *obj, char *name)
Definition attr.c:447
char * agxget(void *obj, Agsym_t *sym)
Definition attr.c:457
#define ED_xlabel(e)
Definition types.h:590
#define ED_head_label(e)
Definition types.h:587
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Definition edge.c:28
#define ED_gui_state(e)
Definition types.h:586
#define ED_spl(e)
Definition types.h:595
#define agtail(e)
Definition cgraph.h:982
Agedge_t * agnxtedge(Agraph_t *g, Agedge_t *e, Agnode_t *n)
Definition edge.c:93
#define ED_tail_label(e)
Definition types.h:596
#define aghead(e)
Definition cgraph.h:983
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
Definition edge.c:42
Agedge_t * agfstedge(Agraph_t *g, Agnode_t *n)
Definition edge.c:85
#define ED_label(e)
Definition types.h:589
void agwarningf(const char *fmt,...)
Definition agerror.c:175
void agerrorf(const char *fmt,...)
Definition agerror.c:167
int agerr(agerrlevel_t level, const char *fmt,...)
Definition agerror.c:157
@ AGPREV
Definition cgraph.h:951
#define agfindgraphattr(g, a)
Definition types.h:613
#define GD_drawing(g)
Definition types.h:353
int agisdirected(Agraph_t *g)
Definition graph.c:184
#define GD_clust(g)
Definition types.h:360
#define GD_bb(g)
Definition types.h:354
#define GD_n_cluster(g)
Definition types.h:389
#define GD_label(g)
Definition types.h:374
#define GD_charset(g)
Definition types.h:367
#define GD_gvc(g)
Definition types.h:355
#define GD_odim(g)
Definition types.h:391
#define GD_gui_state(g)
Definition types.h:366
#define ND_ht(n)
Definition types.h:500
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Definition node.c:50
#define ND_bb(n)
Definition types.h:488
Agnode_t * agfstnode(Agraph_t *g)
Definition node.c:43
#define ND_state(n)
Definition types.h:531
#define ND_label(n)
Definition types.h:502
#define ND_rw(n)
Definition types.h:525
#define ND_lw(n)
Definition types.h:506
#define ND_xlabel(n)
Definition types.h:503
#define ND_shape_info(n)
Definition types.h:529
#define ND_pos(n)
Definition types.h:520
#define agfindnode(g, n)
Definition types.h:611
#define ND_coord(n)
Definition types.h:490
#define ND_shape(n)
Definition types.h:528
Agraph_t * agraphof(void *obj)
Definition obj.c:187
char * agnameof(void *)
returns a string descriptor for the object.
Definition id.c:145
int agcontains(Agraph_t *, void *obj)
returns non-zero if obj is a member of (sub)graph
Definition obj.c:235
int agobjkind(void *obj)
Definition obj.c:254
Agraph_t * agroot(void *obj)
Definition obj.c:170
#define AGSEQ(obj)
Definition cgraph.h:225
@ AGEDGE
Definition cgraph.h:207
@ AGNODE
Definition cgraph.h:207
@ AGRAPH
Definition cgraph.h:207
#define LAYOUT_DONE(g)
Definition gvc.h:52
int gvRenderJobs(GVC_t *gvc, graph_t *g)
Definition emit.c:4123
static uint64_t id
Definition gv2gml.c:42
static GVC_t * gvc
Definition gv.cpp:27
replacements for ctype.h functions
static bool gv_isdigit(int c)
Definition gv_ctype.h:41
static bool gv_isspace(int c)
Definition gv_ctype.h:55
Arithmetic helper functions.
static int d2i(double v)
Definition gv_math.h:153
static unsigned d2u(double v)
Definition gv_math.h:189
static bool is_exactly_pos_zero(double v)
is a value precisely +0.0?
Definition gv_math.h:66
#define SWAP(a, b)
Definition gv_math.h:133
Graphviz context library.
#define EMIT_CLUSTERS_LAST
Definition gvcjob.h:84
@ PEN_SOLID
Definition gvcjob.h:35
#define EMIT_SORTED
Definition gvcjob.h:82
#define GVRENDER_DOES_TOOLTIPS
Definition gvcjob.h:103
#define GVRENDER_DOES_Z
Definition gvcjob.h:105
#define EMIT_EDGE_SORTED
Definition gvcjob.h:86
#define GVRENDER_DOES_LABELS
Definition gvcjob.h:96
#define GVRENDER_NO_WHITE_BG
Definition gvcjob.h:106
@ MAP_CIRCLE
Definition gvcjob.h:166
@ MAP_POLYGON
Definition gvcjob.h:166
@ MAP_RECTANGLE
Definition gvcjob.h:166
#define GVDEVICE_DOES_PAGES
Definition gvcjob.h:87
#define GVDEVICE_DOES_LAYERS
Definition gvcjob.h:88
#define GVDEVICE_DOES_TRUECOLOR
Definition gvcjob.h:90
@ FILL_NONE
Definition gvcjob.h:36
#define EMIT_PREORDER
Definition gvcjob.h:85
emit_state_t
Definition gvcjob.h:173
@ EMIT_CDRAW
Definition gvcjob.h:174
@ EMIT_NDRAW
Definition gvcjob.h:176
@ EMIT_TDRAW
Definition gvcjob.h:174
@ EMIT_HDRAW
Definition gvcjob.h:174
@ EMIT_HLABEL
Definition gvcjob.h:175
@ EMIT_GDRAW
Definition gvcjob.h:174
@ EMIT_NLABEL
Definition gvcjob.h:176
@ EMIT_GLABEL
Definition gvcjob.h:175
@ EMIT_ELABEL
Definition gvcjob.h:176
@ EMIT_EDRAW
Definition gvcjob.h:176
@ EMIT_CLABEL
Definition gvcjob.h:175
@ EMIT_TLABEL
Definition gvcjob.h:175
#define GVDEVICE_EVENTS
Definition gvcjob.h:89
#define GVRENDER_DOES_MAPS
Definition gvcjob.h:97
#define GVRENDER_DOES_TARGETS
Definition gvcjob.h:104
@ CLUSTER_OBJTYPE
Definition gvcjob.h:168
@ EDGE_OBJTYPE
Definition gvcjob.h:168
@ ROOTGRAPH_OBJTYPE
Definition gvcjob.h:168
@ NODE_OBJTYPE
Definition gvcjob.h:168
#define PENWIDTH_NORMAL
Definition gvcjob.h:40
#define GVRENDER_DOES_TRANSFORM
Definition gvcjob.h:95
#define GVRENDER_Y_GOES_DOWN
Definition gvcjob.h:94
#define EMIT_COLORS
Definition gvcjob.h:83
#define GVRENDER_DOES_MAP_POLYGON
Definition gvcjob.h:100
#define GVRENDER_DOES_MAP_RECTANGLE
Definition gvcjob.h:98
static void color(Agraph_t *g)
Definition gvcolor.c:118
void gvrender_end_nodes(GVJ_t *job)
Definition gvrender.c:305
void gvrender_begin_nodes(GVJ_t *job)
Definition gvrender.c:295
void gvrender_end_job(GVJ_t *job)
Definition gvrender.c:116
void gvrender_beziercurve(GVJ_t *job, pointf *AF, size_t n, int filled)
Definition gvrender.c:579
void gvrender_comment(GVJ_t *job, char *str)
Definition gvrender.c:613
void gvrender_end_graph(GVJ_t *job)
Definition gvrender.c:225
void gvrender_set_style(GVJ_t *job, char **s)
Definition gvrender.c:481
void gvrender_set_fillcolor(GVJ_t *job, char *name)
Definition gvrender.c:450
void gvrender_polyline(GVJ_t *job, pointf *AF, size_t n)
Definition gvrender.c:596
void gvrender_begin_edges(GVJ_t *job)
Definition gvrender.c:315
pointf * gvrender_ptf_A(GVJ_t *job, pointf *af, pointf *AF, size_t n)
Definition gvrender.c:154
void gvrender_polygon(GVJ_t *job, pointf *af, size_t n, int filled)
Definition gvrender.c:537
void gvrender_end_edges(GVJ_t *job)
Definition gvrender.c:325
void gvrender_begin_graph(GVJ_t *job)
Definition gvrender.c:215
void gvrender_end_page(GVJ_t *job)
Definition gvrender.c:246
void gvrender_end_layer(GVJ_t *job)
Definition gvrender.c:267
void gvrender_box(GVJ_t *job, boxf BF, int filled)
Definition gvrender.c:565
void gvrender_begin_cluster(GVJ_t *job)
Definition gvrender.c:277
void gvrender_set_gradient_vals(GVJ_t *job, char *stopcolor, int angle, double frac)
Definition gvrender.c:467
void gvrender_ellipse(GVJ_t *job, pointf *AF, int filled)
Definition gvrender.c:520
void gvrender_end_edge(GVJ_t *job)
Definition gvrender.c:363
void gvrender_begin_anchor(GVJ_t *job, char *href, char *tooltip, char *target, char *id)
Definition gvrender.c:373
void gvrender_end_anchor(GVJ_t *job)
Definition gvrender.c:384
void gvrender_begin_layer(GVJ_t *job)
Definition gvrender.c:256
void gvrender_begin_page(GVJ_t *job)
Definition gvrender.c:236
void gvrender_begin_edge(GVJ_t *job)
Definition gvrender.c:354
GVJ_t * gvjobs_first(GVC_t *gvc)
Definition gvjobs.c:86
void gvrender_textspan(GVJ_t *job, pointf p, textspan_t *span)
Definition gvrender.c:414
void gvrender_begin_node(GVJ_t *job)
Definition gvrender.c:335
int gvrender_begin_job(GVJ_t *job)
Definition gvrender.c:103
void gvrender_end_cluster(GVJ_t *job)
Definition gvrender.c:286
GVJ_t * gvjobs_next(GVC_t *gvc)
Definition gvjobs.c:91
void gvrender_set_penwidth(GVJ_t *job, double penwidth)
Definition gvrender.c:798
int gvrender_select(GVJ_t *job, const char *lang)
Definition gvrender.c:40
void gvrender_end_node(GVJ_t *job)
Definition gvrender.c:344
void gvrender_set_pencolor(GVJ_t *job, char *name)
Definition gvrender.c:433
agxbput(xb, staging)
static xdot_state_t * xd
static double penwidth[]
$2 prev
Definition htmlparse.y:291
textitem scanner parser str
Definition htmlparse.y:218
char * strdup_and_subst_obj(char *str, void *obj)
Processes graph object escape sequences; also collapses \ to .
Definition labels.c:387
void free_textspan(textspan_t *tl, size_t cnt)
Definition labels.c:191
void emit_label(GVJ_t *job, emit_state_t emit_state, textlabel_t *lp)
Definition labels.c:217
type-generic dynamically expanding list
#define LIST_DETACH(list, datap, sizep)
Definition list.h:504
#define LIST_AT(list, index)
Definition list.h:210
#define LIST_APPEND(list,...)
Definition list.h:151
#define LIST(type)
Definition list.h:66
#define LIST_BACK(list)
Definition list.h:233
#define LIST_SIZE(list)
Definition list.h:92
#define LIST_DROP_BACK(list)
Definition list.h:483
#define LIST_FREE(list)
Definition list.h:413
#define LIST_RESERVE(list, capacity)
Definition list.h:324
#define LIST_SORT(list, cmp)
Definition list.h:381
#define LIST_FRONT(list)
Definition list.h:222
#define LIST_IS_EMPTY(list)
Definition list.h:102
#define LIST_SYNC(list)
Definition list.h:370
#define LIST_GET(list, index)
Definition list.h:197
platform abstraction over flockfile
static void unlockfile(FILE *file)
Definition lockfile.h:16
static void lockfile(FILE *file)
Definition lockfile.h:8
static void add_point(int *n, int igrp, double **x, int *nmax, double point[], int **groups)
Definition make_map.c:1157
#define delta
Definition maze.c:138
void freePath(Ppolyline_t *p)
Definition util.c:19
#define PRISIZE_T
Definition prisize_t.h:25
void round_corners(GVJ_t *job, pointf *AF, size_t sides, graphviz_polygon_style_t style, int filled)
Handle some special graphical cases, such as rounding the shape, adding diagonals at corners,...
Definition shapes.c:710
pointf textspan_size(GVC_t *gvc, textspan_t *span)
Estimates size of a textspan, in points.
Definition textspan.c:73
shape_kind shapeOf(node_t *)
Definition shapes.c:1909
pointf coord(node_t *n)
Definition utils.c:154
stroke_t taper(bezier *, double(*radfunc_t)(double, double, double), double initwid)
Definition taper.c:186
static void rotate(int n, int dim, double *x, double angle)
static bool streq(const char *a, const char *b)
are a and b equal?
Definition streq.h:11
graph or subgraph
Definition cgraph.h:424
Agraph_t * root
subgraphs - ancestors
Definition cgraph.h:433
const char ** show_boxes
emit code for correct box coordinates
Definition gvcommon.h:25
int viewNum
rendering state
Definition gvcommon.h:29
Definition gvcint.h:81
char * graphname
Definition gvcint.h:123
bool graph_sets_pageSize
Definition gvcint.h:134
char ** defaultlinestyle
Definition gvcint.h:149
bool graph_sets_margin
Definition gvcint.h:134
GVJ_t * active_jobs
Definition gvcint.h:124
pointf pad
Definition gvcint.h:129
GVCOMMON_t common
Definition gvcint.h:82
double defaultfontsize
Definition gvcint.h:146
char * defaultfontname
Definition gvcint.h:145
GVG_t * gvg
Definition gvcint.h:93
bool graph_sets_pad
Definition gvcint.h:134
char * layerListDelims
Definition gvcint.h:138
pointf pageSize
Definition gvcint.h:130
char * layerDelims
Definition gvcint.h:137
int numLayers
Definition gvcint.h:141
char * pagedir
Definition gvcint.h:127
pointf margin
Definition gvcint.h:128
int rotation
Definition gvcint.h:133
gvplugin_active_layout_t layout
Definition gvcint.h:121
Dt_t * textfont_dt
Definition gvcint.h:108
boxf bb
Definition gvcint.h:132
graph_t * g
Definition gvcint.h:118
char * layers
Definition gvcint.h:139
char ** layerIDs
Definition gvcint.h:140
int * layerlist
Definition gvcint.h:142
char * input_filename
Definition gvcint.h:74
int graph_index
Definition gvcint.h:75
int rotation
Definition gvcjob.h:319
int flags
Definition gvcjob.h:299
boxf clip
Definition gvcjob.h:313
pointf margin
Definition gvcjob.h:323
pointf pageSize
Definition gvcjob.h:315
point pagesArraySize
Definition gvcjob.h:304
pointf dpi
Definition gvcjob.h:325
gvdevice_callbacks_t * callbacks
Definition gvcjob.h:288
int output_lang
Definition gvcjob.h:283
obj_state_t * obj
Definition gvcjob.h:269
boxf bb
Definition gvcjob.h:311
gvplugin_active_device_t device
Definition gvcjob.h:286
gvevent_key_binding_t * keybindings
Definition gvcjob.h:356
point pagesArrayElem
Definition gvcjob.h:308
gvplugin_active_render_t render
Definition gvcjob.h:285
point pagesArrayMinor
Definition gvcjob.h:307
pointf view
Definition gvcjob.h:321
pointf devscale
Definition gvcjob.h:334
point pagesArrayMajor
Definition gvcjob.h:306
pointf focus
Definition gvcjob.h:316
GVCOMMON_t * common
Definition gvcjob.h:267
point pagesArrayFirst
Definition gvcjob.h:305
FILE * output_file
Definition gvcjob.h:277
pointf device_dpi
Definition gvcjob.h:289
box pageBoundingBox
Definition gvcjob.h:329
double zoom
Definition gvcjob.h:318
box boundingBox
Definition gvcjob.h:330
pointf scale
Definition gvcjob.h:332
const char * layout_type
Definition gvcjob.h:274
boxf canvasBox
Definition gvcjob.h:322
GVC_t * gvc
Definition gvcjob.h:263
int layerNum
Definition gvcjob.h:302
unsigned int width
Definition gvcjob.h:327
int numLayers
Definition gvcjob.h:301
int numPages
Definition gvcjob.h:309
boxf pageBox
Definition gvcjob.h:314
bool device_sets_dpi
Definition gvcjob.h:290
char * input_filename
Definition gvcjob.h:271
const char * output_langname
Definition gvcjob.h:282
int graph_index
Definition gvcjob.h:272
pointf pad
Definition gvcjob.h:312
size_t numkeys
Definition gvcjob.h:357
pointf translation
Definition gvcjob.h:333
GVJ_t * next_active
Definition gvcjob.h:265
unsigned int height
Definition gvcjob.h:328
size_t pn
Definition pathgeom.h:47
Ppoint_t * ps
Definition pathgeom.h:46
char * style
Definition xdot.h:158
union _xdot_op::@106 u
xdot_font font
Definition xdot.h:157
xdot_polyline polygon
Definition xdot.h:150
xdot_rect ellipse
Definition xdot.h:149
char * color
Definition xdot.h:155
unsigned int fontchar
Definition xdot.h:159
xdot_kind kind
Definition xdot.h:147
xdot_text text
Definition xdot.h:153
xdot_polyline bezier
Definition xdot.h:152
xdot_polyline polyline
Definition xdot.h:151
xdot_color grad_color
Definition xdot.h:156
Definition types.h:89
size_t size
Definition types.h:91
pointf sp
Definition types.h:94
pointf * list
Definition types.h:90
uint32_t eflag
Definition types.h:93
pointf ep
Definition types.h:95
uint32_t sflag
Definition types.h:92
point LL
Definition geom.h:39
point UR
Definition geom.h:39
Definition geom.h:41
pointf UR
Definition geom.h:41
pointf LL
Definition geom.h:41
double t
segment size >= 0
Definition emit.c:401
char * color
Definition emit.c:400
bool hasFraction
Definition emit.c:402
pointf trunc_prev
Definition emit.c:2091
pointf trunc_next
Definition emit.c:2092
pointf wedge_center
Definition emit.c:2093
size_t idx
Definition emit.c:2090
double angle1
Definition emit.c:2094
double angle2
Definition emit.c:2094
Definition cdt.h:98
int link
Definition cdt.h:87
boxf bb
Definition emit.c:67
xdot_op op
Definition emit.c:66
textspan_t * span
Definition emit.c:68
pointf default_margin
Definition gvcjob.h:120
pointf default_pagesize
Definition gvcjob.h:121
gvdevice_features_t * features
Definition gvcjob.h:130
const char * type
Definition gvcint.h:43
gvrender_features_t * features
Definition gvcjob.h:137
char * headlabel
Definition gvcjob.h:208
graph_t * g
Definition gvcjob.h:186
unsigned explicit_tailtarget
Definition gvcjob.h:230
edge_t * e
Definition gvcjob.h:189
pointf * url_map_p
Definition gvcjob.h:240
gvcolor_t fillcolor
Definition gvcjob.h:194
char * tooltip
Definition gvcjob.h:216
unsigned explicit_edgetarget
Definition gvcjob.h:232
char * taillabel
Definition gvcjob.h:207
size_t url_bsplinemap_poly_n
Definition gvcjob.h:243
double z
Definition gvcjob.h:202
char * url
Definition gvcjob.h:210
unsigned explicit_tooltip
Definition gvcjob.h:226
char * labelurl
Definition gvcjob.h:212
char * tailurl
Definition gvcjob.h:213
char * xlabel
Definition gvcjob.h:206
char * labeltooltip
Definition gvcjob.h:217
char * headtarget
Definition gvcjob.h:224
char * target
Definition gvcjob.h:221
obj_type type
Definition gvcjob.h:184
size_t * url_bsplinemap_n
Definition gvcjob.h:245
char * tailtooltip
Definition gvcjob.h:218
gvcolor_t stopcolor
Definition gvcjob.h:194
pen_type pen
Definition gvcjob.h:197
char * headtooltip
Definition gvcjob.h:219
unsigned explicit_labeltooltip
Definition gvcjob.h:229
map_shape_t url_map_shape
Definition gvcjob.h:238
unsigned explicit_tailurl
Definition gvcjob.h:233
pointf * url_bsplinemap_p
Definition gvcjob.h:247
unsigned explicit_tailtooltip
Definition gvcjob.h:227
node_t * n
Definition gvcjob.h:188
union obj_state_s::@65 u
unsigned explicit_headurl
Definition gvcjob.h:234
unsigned explicit_headtarget
Definition gvcjob.h:231
graph_t * sg
Definition gvcjob.h:187
char * headurl
Definition gvcjob.h:214
gvcolor_t pencolor
Definition gvcjob.h:194
char * id
Definition gvcjob.h:211
int gradient_angle
Definition gvcjob.h:195
emit_state_t emit_state
Definition gvcjob.h:192
char * labeltarget
Definition gvcjob.h:222
obj_state_t * parent
Definition gvcjob.h:182
double tail_z
Definition gvcjob.h:202
char * tailtarget
Definition gvcjob.h:223
double head_z
Definition gvcjob.h:202
unsigned explicit_headtooltip
Definition gvcjob.h:228
unsigned labeledgealigned
Definition gvcjob.h:235
char * label
Definition gvcjob.h:205
size_t url_map_n
Definition gvcjob.h:239
fill_type fill
Definition gvcjob.h:198
double penwidth
Definition gvcjob.h:199
Definition geom.h:27
int y
Definition geom.h:27
int x
Definition geom.h:27
double x
Definition geom.h:29
double y
Definition geom.h:29
size_t sides
number of sides
Definition types.h:146
double skew
Definition types.h:149
double orientation
Definition types.h:147
double distortion
Definition types.h:148
bezier * list
Definition types.h:99
boxf bb
Definition types.h:101
size_t size
Definition types.h:100
pointf * vertices
Definition types.h:175
size_t nvertices
number of points in the stroke
Definition types.h:174
a non-owning string reference
Definition strview.h:20
char * name
Definition textspan.h:56
unsigned int flags
Definition textspan.h:61
double size
Definition textspan.h:59
pointf pos
Definition types.h:114
char * fontcolor
Definition types.h:107
char * text
Definition types.h:105
bool set
Definition types.h:123
pointf dimen
Definition types.h:110
double yoffset_layout
Definition textspan.h:72
char * str
Definition textspan.h:68
char just
'l' 'n' 'r'
Definition textspan.h:74
pointf size
Definition textspan.h:73
textfont_t * font
Definition textspan.h:69
state for an in-progress string tokenization
Definition tokenize.h:36
const char * start
Beginning of the token content.
Definition emit.c:3909
int type
Token category.
Definition emit.c:3908
size_t size
Number of bytes in the token content.
Definition emit.c:3910
double frac
Definition xdot.h:49
char * color
Definition xdot.h:50
xdot_grad_type type
Definition xdot.h:68
xdot_linear_grad ling
Definition xdot.h:71
xdot_radial_grad ring
Definition xdot.h:72
union xdot_color::@105 u
double size
Definition xdot.h:104
char * name
Definition xdot.h:105
double y1
Definition xdot.h:55
xdot_color_stop * stops
Definition xdot.h:57
double y0
Definition xdot.h:54
double x0
Definition xdot.h:54
double x1
Definition xdot.h:55
double x
Definition xdot.h:79
double y
Definition xdot.h:79
size_t cnt
Definition xdot.h:87
xdot_point * pts
Definition xdot.h:88
double r0
Definition xdot.h:61
double x0
Definition xdot.h:61
double y0
Definition xdot.h:61
double x1
Definition xdot.h:62
double y1
Definition xdot.h:62
xdot_color_stop * stops
Definition xdot.h:64
double x
Definition xdot.h:83
double w
Definition xdot.h:83
double y
Definition xdot.h:83
double h
Definition xdot.h:83
size_t n_polygon_pts
Definition xdot.h:178
size_t cnt
Definition xdot.h:175
size_t n_text
Definition xdot.h:183
size_t n_polyline_pts
Definition xdot.h:180
size_t n_bezier
Definition xdot.h:181
size_t n_polygon
Definition xdot.h:177
size_t n_polyline
Definition xdot.h:179
size_t n_ellipse
Definition xdot.h:176
size_t n_bezier_pts
Definition xdot.h:182
char * text
Definition xdot.h:95
double x
Definition xdot.h:92
xdot_align align
Definition xdot.h:93
double y
Definition xdot.h:92
Definition xdot.h:166
Non-owning string references.
static char * strview_str(strview_t source)
make a heap-allocated string from this string view
Definition strview.h:41
double elapsed_sec(void)
Definition timing.c:23
void start_timer(void)
Definition timing.c:21
String tokenization.
static strview_t tok_get(const tok_t *t)
get the current token
Definition tokenize.h:76
static tok_t tok(const char *input, const char *separators)
begin tokenization of a new string
Definition tokenize.h:43
static bool tok_end(const tok_t *t)
is this tokenizer exhausted?
Definition tokenize.h:68
static void tok_next(tok_t *t)
advance to the next token in the string being scanned
Definition tokenize.h:85
#define GUI_STATE_ACTIVE
Definition types.h:256
@ SH_POINT
Definition types.h:187
@ SH_POLY
Definition types.h:187
#define GUI_STATE_SELECTED
Definition types.h:257
#define GUI_STATE_DELETED
Definition types.h:259
#define GUI_STATE_VISITED
Definition types.h:258
Definition grammar.c:90
#define UNREACHABLE()
Definition unreachable.h:30
abstraction for squashing compiler warnings for unused symbols
#define UNUSED
Definition unused.h:25
int(* pf)(void *, char *,...)
Definition xdot.c:392
int statXDot(xdot *x, xdot_stats *sp)
Definition xdot.c:788
xdot * parseXDotF(char *s, drawfunc_t fns[], size_t sz)
Definition xdot.c:386
parsing and deparsing of xdot operations
@ xd_radial
Definition xdot.h:46
@ xd_filled_polygon
Definition xdot.h:111
@ xd_pen_color
Definition xdot.h:118
@ xd_unfilled_ellipse
Definition xdot.h:110
@ xd_fontchar
Definition xdot.h:124
@ xd_font
Definition xdot.h:119
@ xd_fill_color
Definition xdot.h:117
@ xd_unfilled_bezier
Definition xdot.h:114
@ xd_grad_fill_color
Definition xdot.h:122
@ xd_polyline
Definition xdot.h:115
@ xd_text
Definition xdot.h:116
@ xd_filled_ellipse
Definition xdot.h:109
@ xd_image
Definition xdot.h:121
@ xd_unfilled_polygon
Definition xdot.h:112
@ xd_grad_pen_color
Definition xdot.h:123
@ xd_filled_bezier
Definition xdot.h:113
@ xd_style
Definition xdot.h:120