50#define strtok_r strtok_s
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, \
75 if (!((p =
agget(g,
"_background")) && p[0])) {
76 if (!((p =
agget(g,
"_draw_")) && p[0])) {
86 agwarningf(
"Could not parse \"_background\" attribute in graph %s\n",
94 fprintf(stderr,
"%" PRISIZE_T " ops %.2f sec\n", stats.
cnt, et);
163 char *
id,
void *gobj) {
166 bool assigned =
false;
178 if (tooltip && tooltip[0]) {
182 }
else if (obj->
label) {
213 id =
agget(obj,
"id");
214 if (
id && *
id !=
'\0') {
219 if (obj != root && gid) {
256 bool backslash_seen =
false;
258 while ((c = *
ins++)) {
259 if (backslash_seen) {
272 backslash_seen =
false;
275 backslash_seen =
true;
310 char *url =
agget(gobj,
"href");
311 char *tooltip =
agget(gobj,
"tooltip");
312 char *target =
agget(gobj,
"target");
321 url =
agget(gobj,
"URL");
325 initMapData(job, lbl, url, tooltip, target,
id, gobj);
356 char **pstyle =
NULL;
359 if ((style =
agget(sg,
"style")) != 0 && style[0]) {
365 if (strcmp(p,
"filled") == 0) {
368 }
else if (strcmp(p,
"radial") == 0) {
376 }
else if (strcmp(p,
"striped") == 0) {
383 }
else if (strcmp(p,
"rounded") == 0) {
416 char *p = memchr(
s->data,
';',
s->size);
423 s->size = (size_t)(p -
s->data);
429 v = strtod(p, &endp);
438#define AEQ0(x) (((x) < EPS) && ((x) > -EPS))
453static int parseSegs(
const char *clrs, colorsegs_t *psegs) {
454 colorsegs_t segs = {.dtor =
freeSeg};
456 static atomic_flag warned;
461 if ((v = getSegLen(&
color)) >= 0) {
464 if (!
AEQ0(
del) && !atomic_flag_test_and_set(&warned)) {
465 agwarningf(
"Total size > 1 in \"%s\" color spec ", clrs);
473 s.hasFraction =
true;
478 if (!atomic_flag_test_and_set(&warned)) {
479 agerrorf(
"Illegal value in \"%s\" color attribute; float expected "
498 for (
size_t i = 0; i <
LIST_SIZE(&segs); ++i) {
504 for (
size_t i = 0; i <
LIST_SIZE(&segs); ++i) {
541 double angle0, angle1;
544 if (rv == 1 || rv == 2)
552 for (
size_t i = 0; i <
LIST_SIZE(&segs); ++i) {
563 angle1 = angle0 + 2 *
M_PI *
s.t;
591 if (rv == 1 || rv == 2)
605 xdelta = (pts[1].
x - pts[0].
x);
606 pts[1].
x = pts[2].
x = pts[0].
x;
610 for (
size_t i = 0; i <
LIST_SIZE(&segs); ++i) {
618 pts[1].
x = pts[2].
x = lastx;
620 pts[1].
x = pts[2].
x = pts[0].
x + xdelta * (
s.t);
622 pts[0].
x = pts[3].
x = pts[1].
x;
691 char *style, *p, **pp;
697 if (strcmp(p,
"filled") == 0)
712 double deltheta = 2 *
M_PI / (double)np;
715 for (
size_t i = 0; i < np; i++) {
716 ps[i].
x = a * cos(theta);
717 ps[i].
y = b * sin(theta);
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;
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) {
748 for (
int i = 0; i < 4; i++) {
749 if (cp[i].x > bb->
UR.
x)
751 else if (cp[i].x < bb->LL.
x)
753 if (cp[i].y > bb->
UR.
y)
755 else if (cp[i].y < bb->LL.
y)
773 const size_t ATTEMPTS = 10;
780static UNUSED void psmapOutput(
const points_t *ps,
size_t start,
size_t n) {
782 fprintf(stdout,
"newpath %f %f moveto\n", first.
x, first.
y);
783 for (
size_t i = start + 1; i < start + n; ++i) {
785 fprintf(stdout,
"%f %f lineto\n", pt.
x, pt.
y);
787 fprintf(stdout,
"closepath stroke\n");
790typedef LIST(
size_t) pbs_size_t;
795static void map_bspline_poly(points_t *pbs_p, pbs_size_t *pbs_n,
size_t n,
800 for (
size_t i = 0; i < n; i++) {
803 for (
size_t i = 0; i < n; i++) {
806#if defined(DEBUG) && DEBUG == 2
807 psmapOutput(pbs_p, nump, 2 * n);
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);
845 return phi + ang / 2.0;
875 const double theta =
bisect(pp, cp, np);
876 const pointf del = {.
x = w2 * cos(theta), .y = w2 * sin(theta)};
890 points_t segments = {0};
891 pointf pts[4], pt1[50], pt2[50];
893 const size_t nc = (bp->
size - 1) / 3;
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];
901 for (
size_t i = 0,
cnt = 0; i <
LIST_SIZE(&segments); ++i) {
908 map_bspline_poly(pbs, pbs_n,
cnt, pt1, pt2);
909 pt1[0] = pt1[
cnt - 1];
910 pt2[0] = pt2[
cnt - 1];
919 const char *
str = sstr;
945 char *buf_part_p =
NULL, *buf_p =
NULL, *cur, *part_in_p;
950 part_in_p = spec_copy;
961 if (n0 >= 0 || n1 >= 0) {
965 rval =
BETWEEN(n0, layerNum, n1);
967 }
else if (w0 !=
NULL) {
969 rval = (n0 == layerNum);
1010 agwarningf(
"The layerselect attribute \"%s\" does not match any layer "
1011 "specifed by the layers attribute - ignored.\n",
1037 agwarningf(
"The character \'%c\' appears in both the layersep and "
1038 "layerlistsep attributes - layerlistsep ignored.\n",
1044 LIST(
char *) layerIDs = {0};
1054 assert(
LIST_SIZE(&layerIDs) - 1 <= INT_MAX);
1055 int ntok = (int)(
LIST_SIZE(&layerIDs) - 1);
1071 char *p =
agget(g,
"outputorder");
1073 if (!strcmp(p,
"nodesfirst"))
1075 if (!strcmp(p,
"edgesfirst"))
1091 if ((
str =
agget(g,
"layers")) != 0) {
1093 if ((
str =
agget(g,
"layerselect")) != 0 && *
str) {
1204 imageSize.
x = fmin(imageSize.
x, pageSize.
x);
1205 imageSize.
y = fmin(imageSize.
y, pageSize.
y);
1211 pageSize.
x = fmax(pageSize.
x, 0);
1212 pageSize.
y = fmax(pageSize.
y, 0);
1214 pageSize.
x = pageSize.
y = 0.;
1217 pageSize.
x = fmax(pageSize.
x, imageSize.
x);
1218 pageSize.
y = fmax(pageSize.
y, imageSize.
y);
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;
1329 for (
size_t i = 0; i < numpts; i++) {
1330 pts[i].
x = inpts[i].
x;
1331 pts[i].
y = inpts[i].
y;
1339 char **styles =
NULL;
1343 for (
size_t i = 0; i <
xd->cnt; i++) {
1361 "polygon count exceeds gvrender_polygon support");
1403 if (p->
x1 == p->
x0 && p->
y1 == p->
y0) {
1406 angle = (int)(180 * acos((p->
x0 - p->
x1) / p->
r0) /
M_PI);
1416 angle = (int)(180 * atan2(p->
y1 - p->
y0, p->
x1 - p->
x0) /
M_PI);
1423 agwarningf(
"gradient pen colors not yet supported.\n");
1437 agwarningf(
"Images unsupported in \"background\" attribute\n");
1472 char *clrs[2] = {0};
1510 pagesArrayElem =
exch_xy(pagesArrayElem);
1511 pagesArraySize =
exch_xy(pagesArraySize);
1533 pagesArraySize.x / 2.);
1535 pagesArraySize.y / 2.);
1585 const char *
const pn =
1596 const char *
const pg =
1644 bool is_rect =
false;
1661 const size_t sides =
poly->sides < 3 ? 1 :
poly->sides;
1662 const size_t peripheries =
poly->peripheries < 2 ? 1 :
poly->peripheries;
1664 vertices =
poly->vertices;
1667 if ((
s =
agget(n,
"samplepoints")))
1673 nump = (nump_int < 4 || nump_int > 60) ?
DFLT_SAMPLE : (size_t)nump_int;
1677 if (
poly->peripheries == 0 && !filled) {
1686 if (
poly->regular) {
1694 p[1].
x =
coord.
x + vertices[2 * peripheries - 1].
x;
1695 p[1].
y =
coord.
y + vertices[2 * peripheries - 1].
y;
1698 p =
pEllipse(vertices[2 * peripheries - 1].x,
1699 vertices[2 * peripheries - 1].y, nump);
1700 for (
size_t i = 0; i < nump; i++) {
1708 assert(peripheries >= 1);
1709 size_t offset = (peripheries - 1) *
poly->sides;
1714 if (
poly->sides >= nump) {
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;
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;
1767 char **styles =
NULL;
1787 while ((p = *sp++)) {
1788 if (
streq(p,
"invis"))
1804 double x = p.
x - q.
x, y = p.
y - q.
y;
1807 d /= sqrt(x * x + y * y +
EPSILON);
1818 double x = q.
x - r.
x, y = q.
y - r.
y;
1824 x = p.
x -
s.x, y = p.
y -
s.y;
1847 AF[1] = (
pointf){AF[0].
x - sz.
x, AF[0].
y};
1862 const char *deflt) {
1864 for (
const char *p = pencolor; *p; p++) {
1872 return DIST(pts[0], pts[1]) +
DIST(pts[1], pts[2]) +
DIST(pts[2], pts[3]);
1884 const size_t cnt = (bz->
size - 1) / 3;
1900 for (
size_t i = 0; i <
cnt; i++) {
1908 for (i = 0; i <
cnt; i++) {
1914 left->size = 3 * (i + 1) + 1;
1919 for (j = 0; j <
left->size; j++)
1922 for (j = 0; j <
right->size; j++)
1938 double arrowsize,
double penwidth) {
1943 char *endcolor =
NULL;
1958 for (
size_t i = 0; i <
ED_spl(e)->size; i++) {
1962 for (
size_t j = 0; j <
LIST_SIZE(&segs); ++j) {
1964 if (
s.color ==
NULL)
2019static double forfunc(
double curlen,
double totallen,
double initwid) {
2020 return (1 - curlen / totallen) * initwid / 2.0;
2023static double revfunc(
double curlen,
double totallen,
double initwid) {
2024 return curlen / totallen * initwid / 2.0;
2027static double nonefunc(
double curlen,
double totallen,
double initwid) {
2031 return initwid / 2.0;
2034static double bothfunc(
double curlen,
double totallen,
double initwid) {
2035 double fr = curlen / totallen;
2037 return fr * initwid;
2038 return (1 - fr) * initwid;
2044 if (
streq(attr,
"forward"))
2046 if (
streq(attr,
"back"))
2048 if (
streq(attr,
"both"))
2050 if (
streq(attr,
"none"))
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) {
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) {
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) {
2123 }
else if (dx1 > 0 && dy2 > 0) {
2129 }
else if (dx1 < 0 && dy2 < 0) {
2143 if (dy1 < 0 && dx2 > 0) {
2149 }
else if (dy1 < 0 && dx2 < 0) {
2155 }
else if (dy1 > 0 && dx2 > 0) {
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,
2182 const double DUP_TOL = 0.01;
2183 for (
size_t j = 0; j <
LIST_SIZE(corners); j++) {
2186 if (hypot(curr.
x - existing_corner.
x, curr.
y - existing_corner.
y) <
2197 double len1 = hypot(dx1, dy1);
2198 double len2 = hypot(dx2, dy2);
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;
2223 corners_t *corners) {
2224 const double TOL = 0.1;
2226 for (
size_t i = 0; i < n; i++) {
2235 pointf next = pts[next_idx];
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;
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;
2249 bool is_corner = (seg1_horiz && seg2_vert) || (seg1_vert && seg2_horiz);
2252 process_corner(corners, pts, i, curr, dx1, dy1, dx2, dy2, radius,
2253 seg1_horiz, seg2_vert);
2263 size_t arc_start_idx,
size_t arc_point_count,
2267 for (
size_t j = 0; j < arc_point_count; j++) {
2272 if (edge_color && edge_color[0]) {
2287 double radius,
char *edge_color) {
2288 for (
size_t i = 0; i <
LIST_SIZE(corners); i++) {
2295 if (wedge && wedge->
pn > 4) {
2300 size_t arc_start_idx =
2302 size_t arc_end_idx =
2305 size_t arc_point_count =
2306 arc_end_idx >= arc_start_idx ? arc_end_idx - arc_start_idx + 1 : 0;
2308 if (arc_point_count >= 2) {
2320 int cnum, numsemi = 0;
2321 char *
color, *pencolor, *fillcolor;
2322 char *headcolor, *tailcolor, *lastcolor;
2323 char *colors =
NULL;
2326 pointf pf0, pf1, pf2 = {0, 0}, pf3, *offlist, *tmplist;
2329 bool tapered =
false;
2340 while ((p = *sp++)) {
2341 if (
streq(p,
"tapered")) {
2350 for (p =
color; *p; p++) {
2357 if (numsemi && numc) {
2379 if (pencolor !=
color)
2381 if (fillcolor !=
color)
2388 if (*fillcolor ==
'\0')
2398 if (fillcolor !=
color)
2416 numc2 = (2 + (double)numc) / 2.0;
2417 for (
size_t i = 0; i < offspl.
size; i++) {
2424 for (j = 0; j < bz.
size - 1; j += 3) {
2426 pf1 = bz.
list[j + 1];
2432 pf2 = bz.
list[j + 2];
2433 pf3 = bz.
list[j + 3];
2434 offlist[j + 1] = offlist[j + 2] =
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;
2446 tmplist[j].x = pf3.x - numc2 * offlist[j].x;
2447 tmplist[j].y = pf3.y - numc2 * offlist[j].y;
2449 lastcolor = headcolor = tailcolor =
color;
2451 for (cnum = 0,
color = strtok(colors,
":");
color;
2452 cnum++,
color = strtok(0,
":")) {
2455 if (
color != lastcolor) {
2463 headcolor = tailcolor =
color;
2466 for (
size_t i = 0; i < tmpspl.
size; i++) {
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;
2477 if (
color != tailcolor) {
2488 if (
color != headcolor) {
2499 for (
size_t i = 0; i < offspl.
size; i++) {
2518 for (
size_t i = 0; i <
ED_spl(e)->size; i++) {
2524 bool is_ortho = splines_attr &&
streq(splines_attr,
"ortho");
2527 bool want_rounded =
false;
2528 double radius = 0.0;
2532 for (
char **sp = styles; *sp; sp++) {
2533 if (
streq(*sp,
"rounded")) {
2534 want_rounded =
true;
2541 char *radius_attr =
agget(e,
"radius");
2542 if (radius_attr && radius_attr[0]) {
2543 radius = atof(radius_attr);
2544 want_rounded = radius > 0;
2548 if (want_rounded && radius == 0.0) {
2549 radius = fmax(12.0,
penwidth * 8.0);
2552 if (is_ortho && want_rounded && radius > 0) {
2554 corners_t corners = {0};
2563 const double CORNER_TOL = 0.01;
2564 size_t seg_start_idx = 0;
2567 for (
size_t c = 0; c <=
LIST_SIZE(&corners); c++) {
2573 seg_end_idx =
LIST_GET(&corners, c).idx;
2574 seg_end_pt =
LIST_GET(&corners, c).trunc_prev;
2577 seg_end_idx = bz.
size - 1;
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++) {
2588 if (hypot(bz.
list[pt].
x - corner_pt.
x,
2589 bz.
list[pt].
y - corner_pt.
y) < CORNER_TOL) {
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++) {
2612 if (hypot(bz.
list[next_idx].
x - corner_pt.
x,
2613 bz.
list[next_idx].
y - corner_pt.
y) < CORNER_TOL) {
2622 seg_start_idx = next_idx;
2623 seg_start_pt =
LIST_GET(&corners, c).trunc_next;
2681 char *dflt_url =
NULL;
2682 char *dflt_target =
NULL;
2717 obj->
xlabel = tlab->text;
2731 if (((
s =
agget(e,
"href")) &&
s[0]) || ((
s =
agget(e,
"URL")) &&
s[0]))
2733 if (((
s =
agget(e,
"edgehref")) &&
s[0]) ||
2734 ((
s =
agget(e,
"edgeURL")) &&
s[0]))
2738 if (((
s =
agget(e,
"labelhref")) &&
s[0]) ||
2739 ((
s =
agget(e,
"labelURL")) &&
s[0]))
2743 if (((
s =
agget(e,
"tailhref")) &&
s[0]) ||
2744 ((
s =
agget(e,
"tailURL")) &&
s[0])) {
2747 }
else if (dflt_url)
2749 if (((
s =
agget(e,
"headhref")) &&
s[0]) ||
2750 ((
s =
agget(e,
"headURL")) &&
s[0])) {
2753 }
else if (dflt_url)
2758 if ((
s =
agget(e,
"target")) &&
s[0])
2760 if ((
s =
agget(e,
"edgetarget")) &&
s[0]) {
2763 }
else if (dflt_target)
2765 if ((
s =
agget(e,
"labeltarget")) &&
s[0])
2767 else if (dflt_target)
2769 if ((
s =
agget(e,
"tailtarget")) &&
s[0]) {
2772 }
else if (dflt_target)
2774 if ((
s =
agget(e,
"headtarget")) &&
s[0]) {
2777 }
else if (dflt_target)
2782 if (((
s =
agget(e,
"tooltip")) &&
s[0]) ||
2783 ((
s =
agget(e,
"edgetooltip")) &&
s[0])) {
2788 }
else if (obj->
label)
2791 if ((
s =
agget(e,
"labeltooltip")) &&
s[0]) {
2796 }
else if (obj->
label)
2799 if ((
s =
agget(e,
"tailtooltip")) &&
s[0]) {
2807 if ((
s =
agget(e,
"headtooltip")) &&
s[0]) {
2826 const size_t ns = spl->
size;
2828 pbs_size_t pbs_n = {0};
2829 for (
size_t i = 0; i < ns; i++)
2833 for (
size_t i = 0; i <
LIST_SIZE(&pbs_n); ++i) {
2852 int explicit,
char *url,
char *tooltip,
2853 char *target,
char *
id,
splines *spl) {
2889 if (url ||
explicit) {
2912 bool explicit_itooltip) {
2921 if (explicit_itooltip) {
2929 if (url ||
explicit) {
3001 char **styles =
NULL;
3029 while ((p = *sp++)) {
3030 if (
streq(p,
"invis"))
3039 char *
const our_color_scheme =
setColorScheme(previous_color_scheme);
3040 free(previous_color_scheme);
3041 free(our_color_scheme);
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);
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++) {
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;
3079 switch (span->
just) {
3085 bb.
LL.
x = x - sz.
x / 2.0;
3086 bb.
UR.
x = x + sz.
x / 2.0;
3109 double fontsize = 0.0;
3110 char *fontname =
NULL;
3116 unsigned fontflags = 0;
3122 bb.
LL.
x = bb.
LL.
y = DBL_MAX;
3123 bb.
UR.
x = bb.
UR.
y = -DBL_MAX;
3127 for (
size_t i = 0; i <
xd->cnt; i++) {
3158 tf.
flags = fontflags;
3192 if ((p =
agget(g,
"margin"))) {
3193 i = sscanf(p,
"%lf,%lf", &xf, &yf);
3204 if ((p =
agget(g,
"pad"))) {
3205 i = sscanf(p,
"%lf,%lf", &xf, &yf);
3228 if ((p =
agget(g,
"pagedir")) && p[0])
3305 job->
dpi.
x = job->
dpi.
y = DEFAULT_DPI;
3339 if (size.
x < sz.
x ||
3344 Z = fmin(size.
x / sz.
x, size.
y / sz.
y);
3355 if ((
str =
agget(g,
"viewport"))) {
3357 rv = sscanf(
str,
"%lf,%lf,%lf,\'%[^\']\'", &XY.
x, &XY.
y, &Z, nodename);
3364 rv = sscanf(
str,
"%lf,%lf,%lf,%[^,]%c", &XY.
x, &XY.
y, &Z, nodename,
3372 sscanf(
str,
"%lf,%lf,%lf,%lf,%lf", &XY.
x, &XY.
y, &Z, &xy.
x, &xy.
y);
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])
3417 if (((
str =
agget(g,
"fontcolor")) != 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,
':')) {
3429 for (
str = strtok(colors,
":");
str;
str = strtok(0,
":")) {
3438 if (((
str =
agget(n,
"fontcolor")) != 0) &&
str[0])
3442 if (strchr(
str,
':')) {
3444 for (
str = strtok(colors,
":");
str;
str = strtok(0,
":")) {
3453 if (((
str =
agget(e,
"fontcolor")) != 0) &&
str[0])
3555 bool obj_id_needs_restore =
false;
3561 obj_id_needs_restore =
true;
3610 if (obj_id_needs_restore) {
3617 free(previous_color_scheme);
3722 int doPerim, c, filled;
3724 char *
color, *fillcolor, *pencolor, **style, *
s;
3755 fillcolor = pencolor = 0;
3775 fillcolor = pencolor =
color;
3785 if ((filled == 0 || !fillcolor) && (
color =
agget(sg,
"bgcolor")) != 0 &&
3795 char *clrs[2] = {0};
3821 AF[0] =
GD_bb(sg).LL;
3822 AF[2] =
GD_bb(sg).UR;
3834 AF[0] =
GD_bb(sg).LL;
3835 AF[2] =
GD_bb(sg).UR;
3851 }
else if (filled != 0) {
3885 free(previous_color_scheme);
3919 const char *start = p;
3936 size_t size = (size_t)(p - start);
3937 return (
token_t){.type = token, .start = start, .size = size};
3951 size_t parse_offsets[
sizeof(parse) /
sizeof(parse[0])];
3953 bool in_parens =
false;
3966 agerrorf(
"nesting not allowed in style: %s\n",
s);
3975 agerrorf(
"unmatched ')' in style: %s\n",
s);
3990 parse_offsets[fun++] =
agxblen(&ps_xb);
3998 agerrorf(
"unmatched '(' in style: %s\n",
s);
4006 for (
size_t i = 0; i < fun; ++i) {
4007 parse[i] = base + parse_offsets[i];
4018 assert(bz.
size > 0);
4019 assert(bz.
size % 3 == 1);
4021 for (
size_t i = 1; i < bz.
size;) {
4027 p.
x = (p1.
x + p2.
x) / 2;
4028 p.
y = (p1.
y + p2.
y) / 2;
4039 assert(spl->
size > 0);
4042 for (
size_t i = 0; i < spl->
size; i++) {
4102 static char *save_locale;
4109 setlocale(LC_NUMERIC,
"C");
4111 }
else if (
cnt > 0) {
4114 setlocale(LC_NUMERIC, save_locale);
4121 GV_DEBUG("gvRenderJobs %s: %.2f secs.", agnameof(g), elapsed_sec())
4124 static GVJ_t *prevjob;
4125 GVJ_t *job, *firstjob;
4131 agerrorf(
"Layout was not done. Missing layout plugins? \n");
4222#pragma GCC diagnostic push
4223#pragma GCC diagnostic ignored "-Wcast-qual"
4227#pragma GCC diagnostic pop
4256 colorsegs_t segs = {.dtor =
freeSeg};
4269 "More than 2 colors specified for a gradient - ignoring remaining\n");
4278 else if (
LIST_GET(&segs, 1).hasFraction)
static agxbuf last
last message
Dynamically expanding string buffers.
static void agxbfree(agxbuf *xb)
free any malloced resources
static size_t agxbput_n(agxbuf *xb, const char *s, size_t ssz)
append string s of length ssz into xb
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
static WUR char * agxbuse(agxbuf *xb)
static size_t agxblen(const agxbuf *xb)
return number of characters currently stored
static int agxbputc(agxbuf *xb, char c)
add character to buffer
Memory allocation wrappers that exit on failure.
static char * gv_strdup(const char *original)
static void * gv_calloc(size_t nmemb, size_t size)
static void * gv_alloc(size_t size)
boxf arrow_bb(pointf p, pointf u, double arrowsize)
void arrow_gen(GVJ_t *job, emit_state_t emit_state, pointf p, pointf u, double arrowsize, double penwidth, uint32_t flag)
CDT_API int dtclose(Dt_t *)
CDT_API Dtmethod_t * Dtoset
ordered set (self-adjusting tree)
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
COLORPROCS_API char * setColorScheme(const char *s)
char * late_nnstring(void *obj, attrsym_t *attr, char *defaultValue)
bool mapbool(const char *p)
char * late_string(void *obj, attrsym_t *attr, char *defaultValue)
int late_int(void *obj, attrsym_t *attr, int defaultValue, int minimum)
pointf Bezier(const pointf *V, double t, pointf *Left, pointf *Right)
bool overlap_label(textlabel_t *lp, boxf b)
double late_double(void *obj, attrsym_t *attr, double defaultValue, double minimum)
pointf dotneato_closest(splines *spl, pointf pt)
char * latin1ToUTF8(char *s)
Converts string from Latin1 encoding to utf8. Also translates HTML entities.
char * htmlEntityUTF8(char *s, graph_t *g)
#define DEFAULT_SELECTEDFILLCOLOR
#define DEFAULT_LAYERLISTSEP
#define DEFAULT_EMBED_MARGIN
#define DEFAULT_ACTIVEFILLCOLOR
#define DEFAULT_PRINT_MARGIN
#define DEFAULT_DELETEDFILLCOLOR
#define DEFAULT_SELECTEDPENCOLOR
#define DEFAULT_VISITEDFILLCOLOR
#define DEFAULT_DELETEDPENCOLOR
#define DEFAULT_GRAPH_PAD
#define DEFAULT_VISITEDPENCOLOR
#define DEFAULT_ACTIVEPENCOLOR
helpers for verbose/debug printing
static void ins(Dict_t *d, Dtlink_t **set, Agedge_t *e)
static void del(Dict_t *d, Dtlink_t **set, Agedge_t *e)
Ppolyline_t * ellipticWedge(pointf ctr, double xsemi, double ysemi, double angle0, double angle1)
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)
bool emit_once(char *str)
static size_t find_prev_distinct(const pointf *pts, size_t i)
static bool node_in_box(node_t *n, boxf b)
static bool write_edge_test(Agraph_t *g, Agedge_t *e)
static void free_stroke(stroke_t sp)
static void map_point(GVJ_t *job, pointf pf)
static radfunc_t taperfun(edge_t *e)
static int * parse_layerselect(GVC_t *gvc, const char *p)
static void emit_xdot(GVJ_t *job, xdot *xd)
static void emit_end_graph(GVJ_t *job)
static void emit_end_cluster(GVJ_t *job)
static int compare_corners(const void *a, const void *b)
static void emit_edge_graphics(GVJ_t *job, edge_t *e, char **styles)
void emit_clusters(GVJ_t *job, Agraph_t *g, int flags)
int stripedBox(GVJ_t *job, pointf *AF, const char *clrs, int rotate)
static void emit_cluster_colors(GVJ_t *job, graph_t *g)
static double revfunc(double curlen, double totallen, double initwid)
static void nodeIntersect(GVJ_t *job, pointf p, bool explicit_iurl, char *iurl, bool explicit_itooltip)
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)
static char * defaultlinestyle[3]
static void init_splines_bb(splines *spl)
void gv_fixLocale(int set)
static void freePara(xdot_op *xop)
static void nextlayer(GVJ_t *job, int **listp)
static void layerPagePrefix(GVJ_t *job, agxbuf *xb)
static bool selectedLayer(GVC_t *gvc, int layerNum, int numLayers, const char *spec)
static void init_bb(graph_t *g)
static void emit_end_node(GVJ_t *job)
static pointf computeoffset_qr(pointf p, pointf q, pointf r, pointf s, double d)
static bool edge_in_layer(GVJ_t *job, edge_t *e)
static double forfunc(double curlen, double totallen, double initwid)
static char ** checkClusterStyle(graph_t *sg, graphviz_polygon_style_t *flagp)
static bool isFilled(node_t *n)
static void map_output_bspline(points_t *pbs, pbs_size_t *pbs_n, bezier *bp, double w2)
static void emit_background(GVJ_t *job, graph_t *g)
static void init_bb_edge(edge_t *e)
static char * preprocessTooltip(char *s, void *gobj)
static int parse_layers(GVC_t *gvc, graph_t *g, char *p)
static char * interpretCRNL(char *ins)
static boxf bezier_bb(bezier bz)
static bool is_style_delim(int c)
static void expandBB(boxf *bb, pointf p)
static void find_ortho_corners(const pointf *pts, size_t n, double radius, corners_t *corners)
bool findStopColor(const char *colorlist, char *clrs[2], double *frac)
static bool clust_in_layer(GVJ_t *job, graph_t *sg)
static bool isRect(polygon_t *p)
static void emit_edge(GVJ_t *job, edge_t *e)
static const char adjust[]
static pointf * pEllipse(double a, double b, size_t np)
static void freeSeg(colorseg_t seg)
static Dtdisc_t stringdict
static void init_bb_node(graph_t *g, node_t *n)
static double bothfunc(double curlen, double totallen, double initwid)
static int multicolor(GVJ_t *job, edge_t *e, char **styles, const char *colors, double arrowsize, double penwidth)
static void approx_bezier(pointf *cp, points_t *lp)
static bool NotFirstPage(const GVJ_t *j)
static void draw_ortho_corner_markers(GVJ_t *job, const corners_t *corners, double radius, char *edge_color)
static bool selectedlayer(GVJ_t *job, const char *spec)
static void emit_view(GVJ_t *job, graph_t *g, int flags)
static boxf textBB(double x, double y, textspan_t *span)
static void emit_begin_node(GVJ_t *job, node_t *n)
static double approxLen(pointf *pts)
static int numPhysicalLayers(GVJ_t *job)
Return number of physical layers to be emitted.
static void init_job_dpi(GVJ_t *job, graph_t *g)
static void map_label(GVJ_t *job, textlabel_t *lab)
static bool node_in_layer(GVJ_t *job, graph_t *g, node_t *n)
static void firstpage(GVJ_t *job)
static void splitBSpline(bezier *bz, double t, bezier *left, bezier *right)
static char * saved_color_scheme
void * init_xdot(Agraph_t *g)
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)
static void initObjMapData(GVJ_t *job, textlabel_t *lab, void *gobj)
static void init_job_margin(GVJ_t *job)
static bool validpage(GVJ_t *job)
static int chkOrder(graph_t *g)
static void init_job_viewport(GVJ_t *job, graph_t *g)
static void emit_colors(GVJ_t *job, graph_t *g)
static void emit_begin_cluster(GVJ_t *job, Agraph_t *sg)
static void setup_page(GVJ_t *job)
static int layer_index(GVC_t *gvc, char *str, int all)
static bool validlayer(GVJ_t *job)
static void init_gvc(GVC_t *gvc, graph_t *g)
static bool check_control_points(const pointf *cp)
static bool is_natural_number(const char *sstr)
obj_state_t * push_obj_state(GVJ_t *job)
static void emit_attachment(GVJ_t *job, textlabel_t *lp, splines *spl)
static void emit_page(GVJ_t *job, graph_t *g)
gvevent_key_binding_t gvevent_key_binding[]
char ** parse_style(char *s)
static void firstlayer(GVJ_t *job, int **listp)
static char * default_pencolor(agxbuf *buf, const char *pencolor, const char *deflt)
void emit_once_reset(void)
void emit_map_rect(GVJ_t *job, boxf b)
static void emit_end_edge(GVJ_t *job)
void update_bb_bz(boxf *bb, const pointf *cp)
static void init_layering(GVC_t *gvc, graph_t *g)
static void init_job_pagination(GVJ_t *job, graph_t *g)
static void update_bb_bz_core(boxf *bb, const pointf *cp, size_t recurse)
static double nonefunc(double curlen, double totallen, double initwid)
int wedgedEllipse(GVJ_t *job, pointf *pf, const char *clrs)
static boxf ptsBB(xdot_point *inpts, size_t numpts, boxf *bb)
void pop_obj_state(GVJ_t *job)
static void nextpage(GVJ_t *job)
static pointf * copyPts(xdot_point *inpts, size_t numpts)
static point pagecode(GVJ_t *job, char c)
static bool edge_in_box(edge_t *e, boxf b)
gvdevice_callbacks_t gvdevice_callbacks
char * getObjId(GVJ_t *job, void *obj, agxbuf *xb)
Use id of root graph if any, plus kind and internal id of object.
const size_t gvevent_key_binding_size
static void emit_begin_edge(GVJ_t *job, edge_t *e, char **styles)
static token_t style_token(char **s)
static void mkSegPts(const pointf *prv, pointf cur, const pointf *nxt, pointf *p1, pointf *p2, double w2)
static void emit_begin_graph(GVJ_t *job, graph_t *g)
static bool write_node_test(Agraph_t *g, Agnode_t *n)
static void emit_node(GVJ_t *job, node_t *n)
#define P2RECT(p, pr, sx, sy)
void emit_graph(GVJ_t *job, graph_t *g)
double(* radfunc_t)(double, double, double)
static size_t find_next_distinct(const pointf *pts, size_t i, size_t n)
static void init_job_pad(GVJ_t *job)
static double bisect(pointf pp, pointf cp, pointf np)
static int parseSegs(const char *clrs, colorsegs_t *psegs)
static pointf computeoffset_p(pointf p, pointf q, double d)
bool initMapData(GVJ_t *job, char *lbl, char *url, char *tooltip, char *target, char *id, void *gobj)
void rect2poly(pointf *p)
double ptToLine2(pointf a, pointf b, pointf p)
geometric functions (e.g. on points and boxes)
static void expandbp(boxf *b, pointf p)
expand box b as needed to enclose point p
static WUR point exch_xy(point p)
static WUR pointf mid_pointf(pointf p, pointf q)
static WUR pointf sub_pointf(pointf p, pointf q)
static WUR pointf add_pointf(pointf p, pointf q)
static WUR pointf exch_xyf(pointf p)
static WUR pointf scale(double c, pointf p)
static WUR bool boxf_overlap(boxf b0, boxf b1)
Agsym_t * G_gradientangle
bool Y_invert
invert y in dot & plain output
static double len(glCompPoint p)
static int cnt(Dict_t *d, Dtlink_t **set)
Agsym_t * agattr_text(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up text attributes of a graph
char * agget(void *obj, char *name)
char * agxget(void *obj, Agsym_t *sym)
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Agedge_t * agnxtedge(Agraph_t *g, Agedge_t *e, Agnode_t *n)
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
Agedge_t * agfstedge(Agraph_t *g, Agnode_t *n)
void agwarningf(const char *fmt,...)
void agerrorf(const char *fmt,...)
int agerr(agerrlevel_t level, const char *fmt,...)
#define agfindgraphattr(g, a)
int agisdirected(Agraph_t *g)
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Agnode_t * agfstnode(Agraph_t *g)
Agraph_t * agraphof(void *obj)
char * agnameof(void *)
returns a string descriptor for the object.
int agcontains(Agraph_t *, void *obj)
returns non-zero if obj is a member of (sub)graph
Agraph_t * agroot(void *obj)
int gvRenderJobs(GVC_t *gvc, graph_t *g)
replacements for ctype.h functions
static bool gv_isdigit(int c)
static bool gv_isspace(int c)
Arithmetic helper functions.
static unsigned d2u(double v)
static bool is_exactly_pos_zero(double v)
is a value precisely +0.0?
Graphviz context library.
#define EMIT_CLUSTERS_LAST
#define GVRENDER_DOES_TOOLTIPS
#define GVRENDER_DOES_LABELS
#define GVRENDER_NO_WHITE_BG
#define GVDEVICE_DOES_PAGES
#define GVDEVICE_DOES_LAYERS
#define GVDEVICE_DOES_TRUECOLOR
#define GVRENDER_DOES_MAPS
#define GVRENDER_DOES_TARGETS
#define GVRENDER_DOES_TRANSFORM
#define GVRENDER_Y_GOES_DOWN
#define GVRENDER_DOES_MAP_POLYGON
#define GVRENDER_DOES_MAP_RECTANGLE
static void color(Agraph_t *g)
void gvrender_end_nodes(GVJ_t *job)
void gvrender_begin_nodes(GVJ_t *job)
void gvrender_end_job(GVJ_t *job)
void gvrender_beziercurve(GVJ_t *job, pointf *AF, size_t n, int filled)
void gvrender_comment(GVJ_t *job, char *str)
void gvrender_end_graph(GVJ_t *job)
void gvrender_set_style(GVJ_t *job, char **s)
void gvrender_set_fillcolor(GVJ_t *job, char *name)
void gvrender_polyline(GVJ_t *job, pointf *AF, size_t n)
void gvrender_begin_edges(GVJ_t *job)
pointf * gvrender_ptf_A(GVJ_t *job, pointf *af, pointf *AF, size_t n)
void gvrender_polygon(GVJ_t *job, pointf *af, size_t n, int filled)
void gvrender_end_edges(GVJ_t *job)
void gvrender_begin_graph(GVJ_t *job)
void gvrender_end_page(GVJ_t *job)
void gvrender_end_layer(GVJ_t *job)
void gvrender_box(GVJ_t *job, boxf BF, int filled)
void gvrender_begin_cluster(GVJ_t *job)
void gvrender_set_gradient_vals(GVJ_t *job, char *stopcolor, int angle, double frac)
void gvrender_ellipse(GVJ_t *job, pointf *AF, int filled)
void gvrender_end_edge(GVJ_t *job)
void gvrender_begin_anchor(GVJ_t *job, char *href, char *tooltip, char *target, char *id)
void gvrender_end_anchor(GVJ_t *job)
void gvrender_begin_layer(GVJ_t *job)
void gvrender_begin_page(GVJ_t *job)
void gvrender_begin_edge(GVJ_t *job)
GVJ_t * gvjobs_first(GVC_t *gvc)
void gvrender_textspan(GVJ_t *job, pointf p, textspan_t *span)
void gvrender_begin_node(GVJ_t *job)
int gvrender_begin_job(GVJ_t *job)
void gvrender_end_cluster(GVJ_t *job)
GVJ_t * gvjobs_next(GVC_t *gvc)
void gvrender_set_penwidth(GVJ_t *job, double penwidth)
int gvrender_select(GVJ_t *job, const char *lang)
void gvrender_end_node(GVJ_t *job)
void gvrender_set_pencolor(GVJ_t *job, char *name)
textitem scanner parser str
char * strdup_and_subst_obj(char *str, void *obj)
Processes graph object escape sequences; also collapses \ to .
void free_textspan(textspan_t *tl, size_t cnt)
void emit_label(GVJ_t *job, emit_state_t emit_state, textlabel_t *lp)
type-generic dynamically expanding list
#define LIST_DETACH(list, datap, sizep)
#define LIST_AT(list, index)
#define LIST_APPEND(list,...)
#define LIST_DROP_BACK(list)
#define LIST_RESERVE(list, capacity)
#define LIST_SORT(list, cmp)
#define LIST_IS_EMPTY(list)
#define LIST_GET(list, index)
platform abstraction over flockfile
static void unlockfile(FILE *file)
static void lockfile(FILE *file)
static void add_point(int *n, int igrp, double **x, int *nmax, double point[], int **groups)
void freePath(Ppolyline_t *p)
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,...
pointf textspan_size(GVC_t *gvc, textspan_t *span)
Estimates size of a textspan, in points.
shape_kind shapeOf(node_t *)
stroke_t taper(bezier *, double(*radfunc_t)(double, double, double), double initwid)
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?
Agraph_t * root
subgraphs - ancestors
const char ** show_boxes
emit code for correct box coordinates
int viewNum
rendering state
gvplugin_active_layout_t layout
gvdevice_callbacks_t * callbacks
gvplugin_active_device_t device
gvevent_key_binding_t * keybindings
gvplugin_active_render_t render
const char * output_langname
double t
segment size >= 0
gvdevice_features_t * features
gvrender_features_t * features
unsigned explicit_tailtarget
unsigned explicit_edgetarget
size_t url_bsplinemap_poly_n
unsigned explicit_tooltip
size_t * url_bsplinemap_n
unsigned explicit_labeltooltip
map_shape_t url_map_shape
unsigned explicit_tailurl
pointf * url_bsplinemap_p
unsigned explicit_tailtooltip
unsigned explicit_headurl
unsigned explicit_headtarget
unsigned explicit_headtooltip
unsigned labeledgealigned
size_t sides
number of sides
size_t nvertices
number of points in the stroke
a non-owning string reference
state for an in-progress string tokenization
const char * start
Beginning of the token content.
size_t size
Number of bytes in the token content.
Non-owning string references.
static char * strview_str(strview_t source)
make a heap-allocated string from this string view
static strview_t tok_get(const tok_t *t)
get the current token
static tok_t tok(const char *input, const char *separators)
begin tokenization of a new string
static bool tok_end(const tok_t *t)
is this tokenizer exhausted?
static void tok_next(tok_t *t)
advance to the next token in the string being scanned
#define GUI_STATE_SELECTED
#define GUI_STATE_DELETED
#define GUI_STATE_VISITED
abstraction for squashing compiler warnings for unused symbols
int(* pf)(void *, char *,...)
int statXDot(xdot *x, xdot_stats *sp)
xdot * parseXDotF(char *s, drawfunc_t fns[], size_t sz)
parsing and deparsing of xdot operations