Graphviz 16.1.1~dev.20261017.1642
Loading...
Searching...
No Matches
htmltable.c
Go to the documentation of this file.
1
3/*************************************************************************
4 * Copyright (c) 2011 AT&T Intellectual Property
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v2.0
7 * which accompanies this distribution, and is available at
8 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
9 *
10 * Contributors: Details at https://graphviz.org
11 *************************************************************************/
12
13// Implementation of HTML-like tables.
14//
15// The (now purged) CodeGen graphics model, especially with integral
16// coordinates, is not adequate to handle this as we would like. In particular,
17// it is difficult to handle notions of adjacency and correct rounding to
18// pixels. For example, if 2 adjacent boxes bb1.UR.x == bb2.LL.x, the rectangles
19// may be drawn overlapping. However, if we use bb1.UR.x+1 == bb2.LL.x
20// there may or may not be a gap between them, even in the same device
21// depending on their positions. When CELLSPACING > 1, this isn't as much
22// of a problem.
23//
24// We allow negative spacing as a hack to allow overlapping cell boundaries.
25// For the reasons discussed above, this is difficult to get correct.
26// This is an important enough case we should extend the table model to
27// support it correctly. This could be done by allowing a table attribute,
28// e.g., CELLGRID=n, which sets CELLBORDER=0 and has the border drawing
29// handled correctly by the table.
30
31#include "config.h"
32
33#include <assert.h>
34#include <common/render.h>
35#include <common/htmltable.h>
36#include <common/pointset.h>
37#include <cdt/cdt.h>
38#include <float.h>
39#include <inttypes.h>
40#include <limits.h>
41#include <math.h>
42#include <stddef.h>
43#include <stdbool.h>
44#include <stdint.h>
45#include <stdio.h>
46#include <util/agxbuf.h>
47#include <util/alloc.h>
48#include <util/bitarray.h>
49#include <util/exit.h>
50#include <util/gv_math.h>
51#include <util/prisize_t.h>
52#include <util/strcasecmp.h>
53#include <util/streq.h>
54#include <util/unreachable.h>
55
56#define DEFAULT_BORDER 1
57#define DEFAULT_CELLPADDING 2
58#define DEFAULT_CELLSPACING 2
59
60typedef struct {
61 char *url;
62 char *tooltip;
63 char *target;
64 char *id;
69
70#ifdef DEBUG
71static void printCell(htmlcell_t * cp, int ind);
72#endif
73
74/* Replace current font attributes in env with ones from fp,
75 * storing old attributes in savp. We only deal with attributes
76 * set in env. The attributes are restored via popFontInfo.
77 */
78static void
80{
81 if (env->finfo.name) {
82 if (fp->name) {
83 savp->name = env->finfo.name;
84 env->finfo.name = fp->name;
85 } else
86 savp->name = NULL;
87 }
88 if (env->finfo.color) {
89 if (fp->color) {
90 savp->color = env->finfo.color;
91 env->finfo.color = fp->color;
92 } else
93 savp->color = NULL;
94 }
95 if (env->finfo.size >= 0) {
96 if (fp->size >= 0) {
97 savp->size = env->finfo.size;
98 env->finfo.size = fp->size;
99 } else
100 savp->size = -1.0;
101 }
102}
103
104/* Restore saved font attributes.
105 * Copy only set values.
106 */
107static void popFontInfo(htmlenv_t * env, textfont_t * savp)
108{
109 if (savp->name)
110 env->finfo.name = savp->name;
111 if (savp->color)
112 env->finfo.color = savp->color;
113 if (savp->size >= 0.0)
114 env->finfo.size = savp->size;
115}
116
117static void
118emit_htextspans(GVJ_t *job, size_t nspans, htextspan_t *spans, pointf p,
119 double halfwidth_x, textfont_t finfo, boxf b, int simple)
120{
121 double center_x, left_x, right_x;
122 textspan_t tl;
123 textfont_t tf;
124 pointf p_ = { 0.0, 0.0 };
125 textspan_t *ti;
126
127 center_x = p.x;
128 left_x = center_x - halfwidth_x;
129 right_x = center_x + halfwidth_x;
130
131 /* Initial p is in center of text block; set initial baseline
132 * to top of text block.
133 */
134 p_.y = p.y + (b.UR.y - b.LL.y) / 2.0;
135
137 for (size_t i = 0; i < nspans; i++) {
138 /* set p.x to leftmost point where the line of text begins */
139 switch (spans[i].just) {
140 case 'l':
141 p.x = left_x;
142 break;
143 case 'r':
144 p.x = right_x - spans[i].size;
145 break;
146 default:
147 case 'n':
148 p.x = center_x - spans[i].size / 2.0;
149 break;
150 }
151 p_.y -= spans[i].lfsize; /* move to current base line */
152
153 ti = spans[i].items;
154 for (size_t j = 0; j < spans[i].nitems; j++) {
155 if (ti->font && ti->font->size > 0)
156 tf.size = ti->font->size;
157 else
158 tf.size = finfo.size;
159 if (ti->font && ti->font->name)
160 tf.name = ti->font->name;
161 else
162 tf.name = finfo.name;
163 if (ti->font && ti->font->color)
164 tf.color = ti->font->color;
165 else
166 tf.color = finfo.color;
167 if (ti->font && ti->font->flags)
168 tf.flags = ti->font->flags;
169 else
170 tf.flags = 0;
171
173
174 tl.str = ti->str;
175 tl.font = &tf;
177 if (simple)
179 else
180 tl.yoffset_centerline = 1;
182 tl.layout = ti->layout;
183 tl.size.x = ti->size.x;
184 tl.size.y = spans[i].lfsize;
185 tl.just = 'l';
186
187 p_.x = p.x;
188 gvrender_textspan(job, p_, &tl);
189 p.x += ti->size.x;
190 ti++;
191 }
192 }
193
195}
196
197static void emit_html_txt(GVJ_t * job, htmltxt_t * tp, htmlenv_t * env)
198{
199 double halfwidth_x;
200 pointf p;
201
202 /* make sure that there is something to do */
203 if (tp->nspans < 1)
204 return;
205
206 halfwidth_x = (tp->box.UR.x - tp->box.LL.x) / 2.0;
207 p.x = env->pos.x + (tp->box.UR.x + tp->box.LL.x) / 2.0;
208 p.y = env->pos.y + (tp->box.UR.y + tp->box.LL.y) / 2.0;
209
210 emit_htextspans(job, tp->nspans, tp->spans, p, halfwidth_x, env->finfo,
211 tp->box, tp->simple);
212}
213
214static void doSide(GVJ_t * job, pointf p, double wd, double ht)
215{
216 boxf BF;
217
218 BF.LL = p;
219 BF.UR.x = p.x + wd;
220 BF.UR.y = p.y + ht;
221 gvrender_box(job, BF, 1);
222}
223
224/* Convert boxf into four corner points
225 * If border is > 1, inset the points by half the border.
226 * It is assumed AF is pointf[4], so the data is store there
227 * and AF is returned.
228 */
229static pointf *mkPts(pointf * AF, boxf b, int border)
230{
231 AF[0] = b.LL;
232 AF[2] = b.UR;
233 if (border > 1) {
234 const double delta = border / 2.0;
235 AF[0].x += delta;
236 AF[0].y += delta;
237 AF[2].x -= delta;
238 AF[2].y -= delta;
239 }
240 AF[1].x = AF[2].x;
241 AF[1].y = AF[0].y;
242 AF[3].x = AF[0].x;
243 AF[3].y = AF[2].y;
244
245 return AF;
246}
247
248/* Draw a rectangular border for the box b.
249 * Handles dashed and dotted styles, rounded corners.
250 * Also handles thick lines.
251 * Assume dp->border > 0
252 */
253static void doBorder(GVJ_t * job, htmldata_t * dp, boxf b)
254{
255 pointf AF[7];
256 char *sptr[2];
257 char *color = dp->pencolor ? dp->pencolor : DEFAULT_COLOR;
258 unsigned short sides;
259
261 if (dp->style.dashed || dp->style.dotted) {
262 sptr[0] = sptr[1] = NULL;
263 if (dp->style.dashed)
264 sptr[0] = "dashed";
265 else if (dp->style.dotted)
266 sptr[0] = "dotted";
267 gvrender_set_style(job, sptr);
268 } else
271
272 if (dp->style.rounded)
273 round_corners(job, mkPts(AF, b, dp->border), 4,
274 (graphviz_polygon_style_t){.rounded = true}, 0);
275 else if ((sides = (dp->flags & BORDER_MASK))) {
276 mkPts (AF+1, b, dp->border); /* AF[1-4] has LL=SW,SE,UR=NE,NW */
277 switch (sides) {
278 case BORDER_BOTTOM :
279 gvrender_polyline(job, AF+1, 2);
280 break;
281 case BORDER_RIGHT :
282 gvrender_polyline(job, AF+2, 2);
283 break;
284 case BORDER_TOP :
285 gvrender_polyline(job, AF+3, 2);
286 break;
287 case BORDER_LEFT :
288 AF[0] = AF[4];
289 gvrender_polyline(job, AF, 2);
290 break;
292 gvrender_polyline(job, AF+1, 3);
293 break;
295 gvrender_polyline(job, AF+2, 3);
296 break;
298 AF[5] = AF[1];
299 gvrender_polyline(job, AF+3, 3);
300 break;
302 AF[0] = AF[4];
303 gvrender_polyline(job, AF, 3);
304 break;
306 gvrender_polyline(job, AF+1, 4);
307 break;
309 AF[5] = AF[1];
310 gvrender_polyline(job, AF+2, 4);
311 break;
313 AF[5] = AF[1];
314 AF[6] = AF[2];
315 gvrender_polyline(job, AF+3, 4);
316 break;
318 AF[0] = AF[4];
319 gvrender_polyline(job, AF, 4);
320 break;
322 gvrender_polyline(job, AF+1, 2);
323 gvrender_polyline(job, AF+3, 2);
324 break;
326 AF[0] = AF[4];
327 gvrender_polyline(job, AF, 2);
328 gvrender_polyline(job, AF+2, 2);
329 break;
330 default:
331 break;
332 }
333 } else {
334 if (dp->border > 1) {
335 const double delta = dp->border / 2.0;
336 b.LL.x += delta;
337 b.LL.y += delta;
338 b.UR.x -= delta;
339 b.UR.y -= delta;
340 }
341 gvrender_box(job, b, 0);
342 }
343}
344
345/* Set up fill values from given color; make pen transparent.
346 * Return type of fill required.
347 */
348static int setFill(GVJ_t *job, char *color, int angle, htmlstyle_t style,
349 char *clrs[2]) {
350 int filled;
351 double frac;
352 if (findStopColor(color, clrs, &frac)) {
353 gvrender_set_fillcolor(job, clrs[0]);
354 if (clrs[1])
355 gvrender_set_gradient_vals(job, clrs[1], angle, frac);
356 else
357 gvrender_set_gradient_vals(job, DEFAULT_COLOR, angle, frac);
358 if (style.radial)
359 filled = RGRADIENT;
360 else
361 filled = GRADIENT;
362 } else {
364 filled = FILL;
365 }
366 gvrender_set_pencolor(job, "transparent");
367 return filled;
368}
369
370/* Save current map values.
371 * Initialize fields in job->obj pertaining to anchors.
372 * In particular, this also sets the output rectangle.
373 * If there is something to do,
374 * start the anchor and returns 1.
375 * Otherwise, it returns 0.
376 *
377 * FIX: Should we provide a tooltip if none is set, as is done
378 * for nodes, edges, etc. ?
379 */
380static int
381initAnchor(GVJ_t * job, htmlenv_t * env, htmldata_t * data, boxf b,
382 htmlmap_data_t * save)
383{
384 obj_state_t *obj = job->obj;
385 char *id;
386 static int anchorId;
387 agxbuf xb = {0};
388
389 save->url = obj->url;
390 save->tooltip = obj->tooltip;
391 save->target = obj->target;
392 save->id = obj->id;
393 save->explicit_tooltip = obj->explicit_tooltip != 0;
394 id = data->id;
395 if (!id || !*id) { /* no external id, so use the internal one */
396 if (!env->objid) {
397 env->objid = gv_strdup(getObjId(job, obj->u.n, &xb));
398 env->objid_set = true;
399 }
400 agxbprint(&xb, "%s_%d", env->objid, anchorId++);
401 id = agxbuse(&xb);
402 }
403 const bool changed =
404 initMapData(job, NULL, data->href, data->title, data->target, id,
405 obj->u.g);
406 agxbfree(&xb);
407
408 if (changed) {
409 if (obj->url || obj->explicit_tooltip) {
410 emit_map_rect(job, b);
412 obj->url, obj->tooltip, obj->target,
413 obj->id);
414 }
415 }
416 return changed;
417}
418
419#define RESET(fld) \
420 if(obj->fld != save->fld) {free(obj->fld); obj->fld = save->fld;}
421
422/* Pop context pushed by initAnchor.
423 * This is done by ending current anchor, restoring old values and
424 * freeing new.
425 *
426 * NB: We don't save or restore geometric map info. This is because
427 * this preservation of map context is only necessary for SVG-like
428 * systems where graphical items are wrapped in an anchor, and we map
429 * top-down. For ordinary map anchors, this is all done bottom-up, so
430 * the geometric map info at the higher level hasn't been emitted yet.
431 */
432static void endAnchor(GVJ_t * job, htmlmap_data_t * save)
433{
434 obj_state_t *obj = job->obj;
435
436 if (obj->url || obj->explicit_tooltip)
438 RESET(url);
439 RESET(tooltip);
440 RESET(target);
441 RESET(id);
443}
444
445static void emit_html_cell(GVJ_t * job, htmlcell_t * cp, htmlenv_t * env);
446
447/* place vertical and horizontal lines between adjacent cells and
448 * extend the lines to intersect the rounded table boundary
449 */
450static void
451emit_html_rules(GVJ_t * job, htmlcell_t * cp, htmlenv_t * env, char *color, htmlcell_t* nextc)
452{
453 pointf rule_pt;
454 double rule_length;
455 double base;
456 pointf pos = env->pos;
457
458 if (!color)
462
463 boxf pts = cp->data.box;
464 pts.LL.x += pos.x;
465 pts.UR.x += pos.x;
466 pts.LL.y += pos.y;
467 pts.UR.y += pos.y;
468
469 //Determine vertical line coordinate and length
470 if (cp->vruled && cp->col + cp->colspan < cp->parent->column_count) {
471 if (cp->row == 0) { // first row
472 // extend to center of table border and add half cell spacing
473 base = cp->parent->data.border + cp->parent->data.space / 2;
474 rule_pt.y = pts.LL.y - cp->parent->data.space / 2;
475 } else if (cp->row + cp->rowspan == cp->parent->row_count) { // bottom row
476 // extend to center of table border and add half cell spacing
477 base = cp->parent->data.border + cp->parent->data.space / 2;
478 rule_pt.y = pts.LL.y - cp->parent->data.space / 2 - base;
479 } else {
480 base = 0;
481 rule_pt.y = pts.LL.y - cp->parent->data.space / 2;
482 }
483 rule_pt.x = pts.UR.x + cp->parent->data.space / 2;
484 rule_length = base + pts.UR.y - pts.LL.y + cp->parent->data.space;
485 doSide(job, rule_pt, 0, rule_length);
486 }
487 //Determine the horizontal coordinate and length
488 if (cp->hruled && cp->row + cp->rowspan < cp->parent->row_count) {
489 if (cp->col == 0) { // first column
490 // extend to center of table border and add half cell spacing
491 base = cp->parent->data.border + cp->parent->data.space / 2;
492 rule_pt.x = pts.LL.x - base - cp->parent->data.space / 2;
493 if (cp->col + cp->colspan == cp->parent->column_count) // also last column
494 base *= 2;
495 /* incomplete row of cells; extend line to end */
496 else if (nextc && nextc->row != cp->row) {
497 base += cp->parent->data.box.UR.x + pos.x - (pts.UR.x + cp->parent->data.space / 2);
498 }
499 } else if (cp->col + cp->colspan == cp->parent->column_count) { // last column
500 // extend to center of table border and add half cell spacing
501 base = cp->parent->data.border + cp->parent->data.space / 2;
502 rule_pt.x = pts.LL.x - cp->parent->data.space / 2;
503 } else {
504 base = 0;
505 rule_pt.x = pts.LL.x - cp->parent->data.space / 2;
506 /* incomplete row of cells; extend line to end */
507 if (nextc && nextc->row != cp->row) {
508 base += cp->parent->data.box.UR.x + pos.x - (pts.UR.x + cp->parent->data.space / 2);
509 }
510 }
511 rule_pt.y = pts.LL.y - cp->parent->data.space / 2;
512 rule_length = base + pts.UR.x - pts.LL.x + cp->parent->data.space;
513 doSide(job, rule_pt, rule_length, 0);
514 }
515}
516
517static void emit_html_tbl(GVJ_t * job, htmltbl_t * tbl, htmlenv_t * env)
518{
519 boxf pts = tbl->data.box;
520 pointf pos = env->pos;
521 htmlcell_t *cp;
522 static textfont_t savef;
523 htmlmap_data_t saved;
524 int anchor; /* if true, we need to undo anchor settings. */
525 const bool doAnchor = tbl->data.href || tbl->data.target || tbl->data.title;
526 pointf AF[4];
527
528 if (tbl->font)
529 pushFontInfo(env, tbl->font, &savef);
530
531 pts.LL.x += pos.x;
532 pts.UR.x += pos.x;
533 pts.LL.y += pos.y;
534 pts.UR.y += pos.y;
535
536 if (doAnchor && !(job->flags & EMIT_CLUSTERS_LAST))
537 anchor = initAnchor(job, env, &tbl->data, pts, &saved);
538 else
539 anchor = 0;
540
541 if (!tbl->data.style.invisible) {
542
543 /* Fill first */
544 if (tbl->data.bgcolor) {
545 char *clrs[2] = {0};
546 int filled =
547 setFill(job, tbl->data.bgcolor, tbl->data.gradientangle,
548 tbl->data.style, clrs);
549 if (tbl->data.style.rounded) {
550 round_corners(job, mkPts(AF, pts, tbl->data.border), 4,
551 (graphviz_polygon_style_t){.rounded = true}, filled);
552 } else
553 gvrender_box(job, pts, filled);
554 free(clrs[0]);
555 free(clrs[1]);
556 }
557
558 /* Draw table rules and border.
559 * Draw before emitting cell contents so text is always painted above
560 * table-level shapes in output formats that use source order for z-order.
561 * At present, we set the penwidth to 1 for rules until we provide the calculations to take
562 * into account wider rules.
563 */
564 gvrender_set_penwidth(job, 1.0);
565 for (htmlcell_t **cells = tbl->cells; (cp = *cells++); ) {
566 if (cp->hruled || cp->vruled)
567 emit_html_rules(job, cp, env, tbl->data.pencolor, *cells);
568 }
569
570 if (tbl->data.border)
571 doBorder(job, &tbl->data, pts);
572
573 for (htmlcell_t **cells = tbl->cells; *cells; ++cells) {
574 emit_html_cell(job, *cells, env);
575 }
576
577 }
578
579 if (anchor)
580 endAnchor(job, &saved);
581
582 if (doAnchor && (job->flags & EMIT_CLUSTERS_LAST)) {
583 if (initAnchor(job, env, &tbl->data, pts, &saved))
584 endAnchor(job, &saved);
585 }
586
587 if (tbl->font)
588 popFontInfo(env, &savef);
589}
590
591/* The image will be centered in the given box.
592 * Scaling is determined by either the image's scale attribute,
593 * or the imagescale attribute of the graph object being drawn.
594 */
595static void emit_html_img(GVJ_t * job, htmlimg_t * cp, htmlenv_t * env)
596{
597 pointf A[4];
598 boxf bb = cp->box;
599 char *scale;
600
601 bb.LL.x += env->pos.x;
602 bb.LL.y += env->pos.y;
603 bb.UR.x += env->pos.x;
604 bb.UR.y += env->pos.y;
605
606 A[0] = bb.UR;
607 A[2] = bb.LL;
608 A[1].x = A[2].x;
609 A[1].y = A[0].y;
610 A[3].x = A[0].x;
611 A[3].y = A[2].y;
612
613 if (cp->scale)
614 scale = cp->scale;
615 else
616 scale = env->imgscale;
617 assert(cp->src);
618 assert(cp->src[0]);
619 gvrender_usershape(job, cp->src, A, 4, true, scale, "mc");
620}
621
622static void emit_html_cell(GVJ_t * job, htmlcell_t * cp, htmlenv_t * env)
623{
624 htmlmap_data_t saved;
625 boxf pts = cp->data.box;
626 pointf pos = env->pos;
627 int inAnchor;
628 const bool doAnchor = cp->data.href || cp->data.target || cp->data.title;
629 pointf AF[4];
630
631 pts.LL.x += pos.x;
632 pts.UR.x += pos.x;
633 pts.LL.y += pos.y;
634 pts.UR.y += pos.y;
635
636 if (doAnchor && !(job->flags & EMIT_CLUSTERS_LAST))
637 inAnchor = initAnchor(job, env, &cp->data, pts, &saved);
638 else
639 inAnchor = 0;
640
641 if (!cp->data.style.invisible) {
642 if (cp->data.bgcolor) {
643 char *clrs[2];
644 int filled =
645 setFill(job, cp->data.bgcolor, cp->data.gradientangle,
646 cp->data.style, clrs);
647 if (cp->data.style.rounded) {
648 round_corners(job, mkPts(AF, pts, cp->data.border), 4,
649 (graphviz_polygon_style_t){.rounded = true}, filled);
650 } else
651 gvrender_box(job, pts, filled);
652 free(clrs[0]);
653 }
654
655 if (cp->data.border)
656 doBorder(job, &cp->data, pts);
657
658 if (cp->child.kind == HTML_TBL)
659 emit_html_tbl(job, cp->child.u.tbl, env);
660 else if (cp->child.kind == HTML_IMAGE)
661 emit_html_img(job, cp->child.u.img, env);
662 else
663 emit_html_txt(job, cp->child.u.txt, env);
664 }
665
666 if (inAnchor)
667 endAnchor(job, &saved);
668
669 if (doAnchor && (job->flags & EMIT_CLUSTERS_LAST)) {
670 if (initAnchor(job, env, &cp->data, pts, &saved))
671 endAnchor(job, &saved);
672 }
673}
674
675/* Push new obj on stack to be used in common by all
676 * html elements with anchors.
677 * This inherits the type, emit_state, and object of the
678 * parent, as well as the url, explicit, target and tooltip.
679 */
680static void allocObj(GVJ_t * job)
681{
682 obj_state_t *obj;
684
685 obj = push_obj_state(job);
686 parent = obj->parent;
687 obj->type = parent->type;
688 obj->emit_state = parent->emit_state;
689 switch (obj->type) {
690 case NODE_OBJTYPE:
691 obj->u.n = parent->u.n;
692 break;
694 obj->u.g = parent->u.g;
695 break;
696 case CLUSTER_OBJTYPE:
697 obj->u.sg = parent->u.sg;
698 break;
699 case EDGE_OBJTYPE:
700 obj->u.e = parent->u.e;
701 break;
702 default:
703 UNREACHABLE();
704 }
705 obj->url = parent->url;
706 obj->tooltip = parent->tooltip;
707 obj->target = parent->target;
708 obj->explicit_tooltip = parent->explicit_tooltip;
709}
710
711static void freeObj(GVJ_t * job)
712{
713 obj_state_t *obj = job->obj;
714
715 obj->url = NULL;
716 obj->tooltip = NULL;
717 obj->target = NULL;
718 obj->id = NULL;
719 pop_obj_state(job);
720}
721
722static double
724{
725 double sz = 0.0;
726
727 switch (lp->kind) {
728 case HTML_TBL:
729 sz = lp->u.tbl->data.box.UR.y - lp->u.tbl->data.box.LL.y;
730 break;
731 case HTML_IMAGE:
732 sz = lp->u.img->box.UR.y - lp->u.img->box.LL.y;
733 break;
734 case HTML_TEXT:
735 sz = lp->u.txt->box.UR.y - lp->u.txt->box.LL.y;
736 break;
737 default:
738 UNREACHABLE();
739 }
740 return sz;
741}
742
744{
745 htmlenv_t env;
746 pointf p;
747
748 allocObj(job);
749
750 p = tp->pos;
751 switch (tp->valign) {
752 case 't':
753 p.y = tp->pos.y + (tp->space.y - heightOfLbl(lp))/ 2.0 - 1;
754 break;
755 case 'b':
756 p.y = tp->pos.y - (tp->space.y - heightOfLbl(lp))/ 2.0 - 1;
757 break;
758 default:
759 /* no-op */
760 break;
761 }
762 env.pos = p;
763 env.finfo.color = tp->fontcolor;
764 env.finfo.name = tp->fontname;
765 env.finfo.size = tp->fontsize;
766 env.imgscale = agget(job->obj->u.n, "imagescale");
767 env.objid = job->obj->id;
768 env.objid_set = false;
769 if (env.imgscale == NULL || env.imgscale[0] == '\0')
770 env.imgscale = "false";
771 if (lp->kind == HTML_TBL) {
772 htmltbl_t *tbl = lp->u.tbl;
773
774 /* set basic graphics context */
775 /* Need to override line style set by node. */
777 if (tbl->data.pencolor)
779 else
781 emit_html_tbl(job, tbl, &env);
782 } else {
783 emit_html_txt(job, lp->u.txt, &env);
784 }
785 if (env.objid_set)
786 free(env.objid);
787 freeObj(job);
788}
789
791{
792 free(dp->href);
793 free(dp->port);
794 free(dp->target);
795 free(dp->id);
796 free(dp->title);
797 free(dp->bgcolor);
798 free(dp->pencolor);
799}
800
802{
803 if (!t)
804 return;
805
806 htextspan_t *const tl = t->spans;
807 for (size_t i = 0; i < t->nspans; i++) {
808 textspan_t *const ti = tl[i].items;
809 for (size_t j = 0; j < tl[i].nitems; j++) {
810 free(ti[j].str);
811 if (ti[j].layout && ti[j].free_layout)
812 ti[j].free_layout(ti[j].layout);
813 }
814 free(ti);
815 }
816 free(tl);
817 free(t);
818}
819
820static void free_html_img(htmlimg_t * ip)
821{
822 free(ip->src);
823 free(ip);
824}
825
826static void free_html_cell(htmlcell_t * cp)
827{
828 free_html_label(&cp->child, 0);
829 free_html_data(&cp->data);
830 free(cp);
831}
832
833/* If tbl->row_count is `SIZE_MAX`, table is in initial state from
834 * HTML parse, with data stored in `tbl->prev` and `tbl->rows`. Once run through
835 * processTbl, data is stored in `tbl->parent` and `tbl->cells`, and
836 * tbl->row_count is < `SIZE_MAX`.
837 */
838static void free_html_tbl(htmltbl_t * tbl)
839{
840 htmlcell_t **cells;
841
842 if (tbl->row_count == SIZE_MAX) { // raw, parsed table
843 LIST_FREE(&tbl->rows);
844 } else {
845 cells = tbl->cells;
846
847 free(tbl->heights);
848 free(tbl->widths);
849 while (*cells) {
850 free_html_cell(*cells);
851 cells++;
852 }
853 free(tbl->cells);
854 }
855 free_html_data(&tbl->data);
856 free(tbl);
857}
858
859void free_html_label(htmllabel_t * lp, int root)
860{
861 if (lp->kind == HTML_TBL)
862 free_html_tbl(lp->u.tbl);
863 else if (lp->kind == HTML_IMAGE)
864 free_html_img(lp->u.img);
865 else
866 free_html_text(lp->u.txt);
867 if (root)
868 free(lp);
869}
870
871static htmldata_t *portToTbl(htmltbl_t *, char *);
872
873static htmldata_t *portToCell(htmlcell_t * cp, char *id)
874{
875 htmldata_t *rv;
876
877 if (cp->data.port && strcasecmp(cp->data.port, id) == 0)
878 rv = &cp->data;
879 else if (cp->child.kind == HTML_TBL)
880 rv = portToTbl(cp->child.u.tbl, id);
881 else
882 rv = NULL;
883
884 return rv;
885}
886
887/* See if tp or any of its child cells has the given port id.
888 * If true, return corresponding box.
889 */
890static htmldata_t *portToTbl(htmltbl_t * tp, char *id)
891{
892 htmldata_t *rv;
893 htmlcell_t **cells;
894 htmlcell_t *cp;
895
896 if (tp->data.port && strcasecmp(tp->data.port, id) == 0)
897 rv = &tp->data;
898 else {
899 rv = NULL;
900 cells = tp->cells;
901 while ((cp = *cells++)) {
902 if ((rv = portToCell(cp, id)))
903 break;
904 }
905 }
906
907 return rv;
908}
909
910/* See if edge port corresponds to part of the html node.
911 * If successful, return pointer to port's box.
912 * Else return NULL.
913 */
914boxf *html_port(node_t *n, char *pname, unsigned char *sides){
915 assert(pname != NULL && !streq(pname, ""));
916 htmldata_t *tp;
917 htmllabel_t *lbl = ND_label(n)->u.html;
918 boxf *rv = NULL;
919
920 if (lbl->kind == HTML_TEXT)
921 return NULL;
922
923 tp = portToTbl(lbl->u.tbl, pname);
924 if (tp) {
925 rv = &tp->box;
926 *sides = tp->sides;
927 }
928 return rv;
929
930}
931
932static int size_html_txt(GVC_t *gvc, htmltxt_t * ftxt, htmlenv_t * env)
933{
934 double xsize = 0.0; /* width of text block */
935 double ysize = 0.0; /* height of text block */
936 double lsize; /* height of current line */
937 double mxfsize = 0.0; /* max. font size for the current line */
938 double curbline = 0.0; /* dist. of current base line from top */
939 pointf sz;
940 double width;
941 textspan_t lp;
942 textfont_t tf = {NULL,NULL,NULL,0.0,0,0};
943 double maxoffset, maxlayout, mxysize = 0.0;
944 bool simple = true; // one item per span, same font size/face, no flags
945 double prev_fsize = -1;
946 char* prev_fname = NULL;
947
948 for (size_t i = 0; i < ftxt->nspans; i++) {
949 if (ftxt->spans[i].nitems > 1) {
950 simple = false;
951 break;
952 }
953 if (ftxt->spans[i].items[0].font) {
954 if (ftxt->spans[i].items[0].font->flags) {
955 simple = false;
956 break;
957 }
958 if (ftxt->spans[i].items[0].font->size > 0)
959 tf.size = ftxt->spans[i].items[0].font->size;
960 else
961 tf.size = env->finfo.size;
962 if (ftxt->spans[i].items[0].font->name)
963 tf.name = ftxt->spans[i].items[0].font->name;
964 else
965 tf.name = env->finfo.name;
966 }
967 else {
968 tf.size = env->finfo.size;
969 tf.name = env->finfo.name;
970 }
971 if (i == 0)
972 prev_fsize = tf.size;
973 else if (tf.size != prev_fsize) {
974 simple = false;
975 break;
976 }
977 if (prev_fname == NULL)
978 prev_fname = tf.name;
979 else if (strcmp(tf.name,prev_fname)) {
980 simple = false;
981 break;
982 }
983 }
984 ftxt->simple = simple;
985
986 for (size_t i = 0; i < ftxt->nspans; i++) {
987 width = 0;
988 mxysize = maxoffset = maxlayout = mxfsize = 0;
989 for (size_t j = 0; j < ftxt->spans[i].nitems; j++) {
990 lp.str =
992 env->obj);
993 if (ftxt->spans[i].items[j].font) {
994 if (ftxt->spans[i].items[j].font->flags)
995 tf.flags = ftxt->spans[i].items[j].font->flags;
996 else if (env->finfo.flags > 0)
997 tf.flags = env->finfo.flags;
998 else
999 tf.flags = 0;
1000 if (ftxt->spans[i].items[j].font->size > 0)
1001 tf.size = ftxt->spans[i].items[j].font->size;
1002 else
1003 tf.size = env->finfo.size;
1004 if (ftxt->spans[i].items[j].font->name)
1005 tf.name = ftxt->spans[i].items[j].font->name;
1006 else
1007 tf.name = env->finfo.name;
1008 if (ftxt->spans[i].items[j].font->color)
1009 tf.color = ftxt->spans[i].items[j].font->color;
1010 else
1011 tf.color = env->finfo.color;
1012 } else {
1013 tf.size = env->finfo.size;
1014 tf.name = env->finfo.name;
1015 tf.color = env->finfo.color;
1016 tf.flags = env->finfo.flags;
1017 }
1018 lp.font = dtinsert(gvc->textfont_dt, &tf);
1019 sz = textspan_size(gvc, &lp);
1020 free(ftxt->spans[i].items[j].str);
1021 ftxt->spans[i].items[j].str = lp.str;
1022 ftxt->spans[i].items[j].size.x = sz.x;
1023 ftxt->spans[i].items[j].yoffset_layout = lp.yoffset_layout;
1025 ftxt->spans[i].items[j].font = lp.font;
1026 ftxt->spans[i].items[j].layout = lp.layout;
1027 ftxt->spans[i].items[j].free_layout = lp.free_layout;
1028 width += sz.x;
1029 mxfsize = MAX(tf.size, mxfsize);
1030 mxysize = MAX(sz.y, mxysize);
1031 maxoffset = MAX(lp.yoffset_centerline, maxoffset);
1032 maxlayout = MAX(lp.yoffset_layout, maxlayout);
1033 }
1034 /* lsize = mxfsize * LINESPACING; */
1035 ftxt->spans[i].size = width;
1036 /* ysize - curbline is the distance from the previous
1037 * baseline to the bottom of the previous line.
1038 * Then, in the current line, we set the baseline to
1039 * be 5/6 of the max. font size. Thus, lfsize gives the
1040 * distance from the previous baseline to the new one.
1041 */
1042 /* ftxt->spans[i].lfsize = 5*mxfsize/6 + ysize - curbline; */
1043 if (simple) {
1044 lsize = mxysize;
1045 if (i == 0)
1046 /* Place baseline using actual font metrics: centers the pango
1047 * logical rectangle in the cell rather than approximating with
1048 * raw font size. maxlayout = baseline distance from box top
1049 * (yoffset_layout from the text layout engine); maxoffset =
1050 * yoffset_centerline (small above-baseline correction applied
1051 * by the renderer to convert from rendering origin to baseline). */
1052 ftxt->spans[i].lfsize = maxlayout + maxoffset;
1053 else
1054 ftxt->spans[i].lfsize = mxysize;
1055 }
1056 else {
1057 lsize = mxfsize;
1058 if (i == 0)
1059 ftxt->spans[i].lfsize = mxfsize - maxoffset;
1060 else
1061 ftxt->spans[i].lfsize = mxfsize + ysize - curbline - maxoffset;
1062 }
1063 curbline += ftxt->spans[i].lfsize;
1064 xsize = MAX(width, xsize);
1065 ysize += lsize;
1066 }
1067 ftxt->box.UR.x = xsize;
1068 if (ftxt->nspans == 1)
1069 ftxt->box.UR.y = mxysize;
1070 else
1071 ftxt->box.UR.y = ysize;
1072 return 0;
1073}
1074
1075static int size_html_tbl(graph_t * g, htmltbl_t * tbl, htmlcell_t * parent,
1076 htmlenv_t * env);
1077
1078static int size_html_img(htmlimg_t * img, htmlenv_t * env)
1079{
1080 box b;
1081 int rv;
1082
1083 b.LL.x = b.LL.y = 0;
1084 b.UR = gvusershape_size(env->g, img->src);
1085 if (b.UR.x == -1 && b.UR.y == -1) {
1086 rv = 1;
1087 b.UR.x = b.UR.y = 0;
1088 agerrorf("No or improper image file=\"%s\"\n", img->src);
1089 } else {
1090 rv = 0;
1091 GD_has_images(env->g) = true;
1092 }
1093
1094 B2BF(b, img->box);
1095 return rv;
1096}
1097
1098static int
1100 htmlenv_t * env)
1101{
1102 int rv;
1103 pointf sz, child_sz;
1104 int margin;
1105
1106 cp->parent = parent;
1107 if (!(cp->data.flags & PAD_SET)) {
1108 if (parent->data.flags & PAD_SET)
1109 cp->data.pad = parent->data.pad;
1110 else
1112 }
1113 if (!(cp->data.flags & BORDER_SET)) {
1114 if (parent->cellborder >= 0)
1115 cp->data.border = (unsigned char)parent->cellborder;
1116 else if (parent->data.flags & BORDER_SET)
1117 cp->data.border = parent->data.border;
1118 else
1120 }
1121
1122 if (cp->child.kind == HTML_TBL) {
1123 rv = size_html_tbl(g, cp->child.u.tbl, cp, env);
1124 child_sz = cp->child.u.tbl->data.box.UR;
1125 } else if (cp->child.kind == HTML_IMAGE) {
1126 rv = size_html_img(cp->child.u.img, env);
1127 child_sz = cp->child.u.img->box.UR;
1128 } else {
1129 rv = size_html_txt(GD_gvc(g), cp->child.u.txt, env);
1130 child_sz = cp->child.u.txt->box.UR;
1131 }
1132
1133 margin = 2 * (cp->data.pad + cp->data.border);
1134 sz.x = child_sz.x + margin;
1135 sz.y = child_sz.y + margin;
1136
1137 if (cp->data.flags & FIXED_FLAG) {
1138 if (cp->data.width && cp->data.height) {
1139 if ((cp->data.width < sz.x || cp->data.height < sz.y) && cp->child.kind != HTML_IMAGE) {
1140 agwarningf("cell size too small for content\n");
1141 rv = 1;
1142 }
1143 sz.x = sz.y = 0;
1144
1145 } else {
1146 agwarningf(
1147 "fixed cell size with unspecified width or height\n");
1148 rv = 1;
1149 }
1150 }
1151 cp->data.box.UR.x = MAX(sz.x, cp->data.width);
1152 cp->data.box.UR.y = MAX(sz.y, cp->data.height);
1153 return rv;
1154}
1155
1156static uint16_t findCol(PointSet *ps, int row, int col, htmlcell_t *cellp) {
1157 int notFound = 1;
1158 int lastc;
1159 int i, j, c;
1160 int end = cellp->colspan - 1;
1161
1162 while (notFound) {
1163 lastc = col + end;
1164 for (c = lastc; c >= col; c--) {
1165 if (isInPS(ps, c, row))
1166 break;
1167 }
1168 if (c >= col) /* conflict : try column after */
1169 col = c + 1;
1170 else
1171 notFound = 0;
1172 }
1173 for (j = col; j < col + cellp->colspan; j++) {
1174 for (i = row; i < row + cellp->rowspan; i++) {
1175 addPS(ps, j, i);
1176 }
1177 }
1178 assert(col >= 0 && col <= UINT16_MAX);
1179 return (uint16_t)col;
1180}
1181
1182/* Convert parser representation of cells into final form.
1183 * Find column and row positions of cells.
1184 * Recursively size cells.
1185 * Return 1 if problem sizing a cell.
1186 */
1187static int processTbl(graph_t * g, htmltbl_t * tbl, htmlenv_t * env)
1188{
1189 htmlcell_t **cells;
1190 rows_t rows = tbl->rows;
1191 int rv = 0;
1192 size_t n_rows = 0;
1193 size_t n_cols = 0;
1194 PointSet *ps = newPS();
1195 bitarray_t is = bitarray_new((size_t)UINT16_MAX + 1);
1196
1197 size_t cnt = 0;
1198 for (uint16_t r = 0; r < LIST_SIZE(&rows); ++r) {
1199 row_t *rp = LIST_GET(&rows, r);
1200 cnt += LIST_SIZE(&rp->rp);
1201 if (rp->ruled) {
1202 bitarray_set(&is, r + 1, true);
1203 }
1204 }
1205
1206 cells = tbl->cells = gv_calloc(cnt + 1, sizeof(htmlcell_t *));
1207 for (uint16_t r = 0; r < LIST_SIZE(&rows); ++r) {
1208 row_t *rp = LIST_GET(&rows, r);
1209 uint16_t c = 0;
1210 for (size_t i = 0; i < LIST_SIZE(&rp->rp); ++i) {
1211 htmlcell_t *cellp = LIST_GET(&rp->rp, i);
1212 *cells++ = cellp;
1213 rv |= size_html_cell(g, cellp, tbl, env);
1214 c = findCol(ps, r, c, cellp);
1215 cellp->row = r;
1216 cellp->col = c;
1217 c += cellp->colspan;
1218 n_cols = MAX(c, n_cols);
1219 n_rows = MAX(r + cellp->rowspan, n_rows);
1220 if (bitarray_get(is, r + cellp->rowspan))
1221 cellp->hruled = true;
1222 }
1223 }
1224 tbl->row_count = n_rows;
1225 tbl->column_count = n_cols;
1226 LIST_FREE(&rows);
1227 bitarray_reset(&is);
1228 freePS(ps);
1229 return rv;
1230}
1231
1251
1252 // `processTbl` has already done step 1, “1. Calculate the minimum content
1253 // width (MCW) of each cell”, and stored it in `.data.box.UR.x`.
1254
1255 // Allocate space for minimum column widths. Note that we add an extra entry
1256 // to allow later code to make references like `table->widths[col + colspan]`.
1257 assert(table->widths == NULL && "table widths computed twice");
1258 table->widths = gv_calloc(table->column_count + 1, sizeof(double));
1259
1260 // “2. For each column, determine a … minimum column width from the cells that
1261 // span only that column. The minimum is that required by the cell with the
1262 // largest minimum cell width …”. Note that this loop and the following one
1263 // could be fused, but this would make the implementation harder to relate
1264 // back to the specification.
1265 for (htmlcell_t **i = table->cells; *i != NULL; ++i) {
1266 const htmlcell_t cell = **i;
1267 if (cell.colspan > 1) {
1268 continue;
1269 }
1270 assert(cell.col < table->column_count && "out of range cell");
1271 table->widths[cell.col] = fmax(table->widths[cell.col], cell.data.box.UR.x);
1272 }
1273
1274 // “3. For each cell that spans more than one column, increase the minimum
1275 // widths of the columns it spans so that together, they are at least as wide
1276 // as the cell. … If possible, widen all spanned columns by approximately the
1277 // same amount.”
1278 for (htmlcell_t **i = table->cells; *i != NULL; ++i) {
1279 const htmlcell_t cell = **i;
1280 if (cell.colspan == 1) {
1281 continue;
1282 }
1283
1284 // what is the current width of this cell’s column(s)’ span?
1285 double span_width = 0;
1286 assert(cell.col + cell.colspan <= table->column_count &&
1287 "cell spans wider than containing table");
1288 for (size_t j = 0; j < cell.colspan; ++j) {
1289 span_width += table->widths[cell.col + j];
1290 }
1291
1292 // if it is wider than its span (including cell spacing), widen the span
1293 const double spacing = (cell.colspan - 1) * table->data.space;
1294 if (span_width + spacing < cell.data.box.UR.x) {
1295 const double widen_by =
1296 (cell.data.box.UR.x - spacing - span_width) / cell.colspan;
1297 for (size_t j = 0; j < cell.colspan; ++j) {
1298 table->widths[cell.col + j] += widen_by;
1299 }
1300 }
1301 }
1302
1303 // take the minimum width for each column and apply it to its contained cells
1304 for (htmlcell_t **i = table->cells; *i != NULL; ++i) {
1305 htmlcell_t *cell = *i;
1306
1307 // what is the current width of this cell’s column(s)’ span?
1308 double min_width = 0;
1309 assert(cell->col + cell->colspan <= table->column_count &&
1310 "cell spans wider than containing table");
1311 for (size_t j = 0; j < cell->colspan; ++j) {
1312 min_width += table->widths[cell->col + j];
1313 }
1314
1315 // widen the cell if necessary
1316 const double spacing = (cell->colspan - 1) * table->data.space;
1317 cell->data.box.UR.x = fmax(cell->data.box.UR.x, min_width + spacing);
1318 }
1319}
1320
1327
1328 assert(table->heights == NULL && "table heights computed twice");
1329 table->heights = gv_calloc(table->row_count + 1, sizeof(double));
1330
1331 for (htmlcell_t **i = table->cells; *i != NULL; ++i) {
1332 const htmlcell_t cell = **i;
1333 if (cell.rowspan > 1) {
1334 continue;
1335 }
1336 assert(cell.row < table->row_count && "out of range cell");
1337 table->heights[cell.row] =
1338 fmax(table->heights[cell.row], cell.data.box.UR.y);
1339 }
1340
1341 for (htmlcell_t **i = table->cells; *i != NULL; ++i) {
1342 const htmlcell_t cell = **i;
1343 if (cell.rowspan == 1) {
1344 continue;
1345 }
1346
1347 double span_height = 0;
1348 assert(cell.row + cell.rowspan <= table->row_count &&
1349 "cell spans higher than containing table");
1350 for (size_t j = 0; j < cell.rowspan; ++j) {
1351 span_height += table->heights[cell.row + j];
1352 }
1353
1354 const double spacing = (cell.rowspan - 1) * table->data.space;
1355 if (span_height + spacing < cell.data.box.UR.y) {
1356 const double heighten_by =
1357 (cell.data.box.UR.y - spacing - span_height) / cell.rowspan;
1358 for (size_t j = 0; j < cell.rowspan; ++j) {
1359 table->heights[cell.row + j] += heighten_by;
1360 }
1361 }
1362 }
1363
1364 for (htmlcell_t **i = table->cells; *i != NULL; ++i) {
1365 htmlcell_t *cell = *i;
1366
1367 double min_height = 0;
1368 assert(cell->row + cell->rowspan <= table->row_count &&
1369 "cell spans higher than containing table");
1370 for (size_t j = 0; j < cell->rowspan; ++j) {
1371 min_height += table->heights[cell->row + j];
1372 }
1373
1374 const double spacing = (cell->rowspan - 1) * table->data.space;
1375 cell->data.box.UR.y = fmax(cell->data.box.UR.y, min_height + spacing);
1376 }
1377}
1378
1379static void pos_html_tbl(htmltbl_t *, boxf, unsigned char);
1380
1381/* Place image in cell
1382 * storing allowed space handed by parent cell.
1383 * How this space is used is handled in emit_html_img.
1384 */
1385static void pos_html_img(htmlimg_t * cp, boxf pos)
1386{
1387 cp->box = pos;
1388}
1389
1391static void pos_html_txt(htmltxt_t * ftxt, char c)
1392{
1393 for (size_t i = 0; i < ftxt->nspans; i++) {
1394 if (ftxt->spans[i].just == UNSET_ALIGN) /* unset */
1395 ftxt->spans[i].just = c;
1396 }
1397}
1398
1399static void pos_html_cell(htmlcell_t *cp, boxf pos, unsigned char sides) {
1400 double delx, dely;
1401 pointf oldsz;
1402 boxf cbox;
1403
1404 if (!cp->data.pencolor && cp->parent->data.pencolor)
1406
1407 /* If fixed, align cell */
1408 if (cp->data.flags & FIXED_FLAG) {
1409 oldsz = cp->data.box.UR;
1410 delx = pos.UR.x - pos.LL.x - oldsz.x;
1411 if (delx > 0) {
1412 switch (cp->data.flags & HALIGN_MASK) {
1413 case HALIGN_LEFT:
1414 pos.UR.x = pos.LL.x + oldsz.x;
1415 break;
1416 case HALIGN_RIGHT:
1417 pos.UR.x += delx;
1418 pos.LL.x += delx;
1419 break;
1420 default:
1421 pos.LL.x += delx / 2;
1422 pos.UR.x -= delx / 2;
1423 break;
1424 }
1425 }
1426 dely = pos.UR.y - pos.LL.y - oldsz.y;
1427 if (dely > 0) {
1428 switch (cp->data.flags & VALIGN_MASK) {
1429 case VALIGN_BOTTOM:
1430 pos.UR.y = pos.LL.y + oldsz.y;
1431 break;
1432 case VALIGN_TOP:
1433 pos.UR.y += dely;
1434 pos.LL.y += dely;
1435 break;
1436 default:
1437 pos.LL.y += dely / 2;
1438 pos.UR.y -= dely / 2;
1439 break;
1440 }
1441 }
1442 }
1443 cp->data.box = pos;
1444 cp->data.sides = sides;
1445
1446 /* set up child's position */
1447 cbox.LL.x = pos.LL.x + cp->data.border + cp->data.pad;
1448 cbox.LL.y = pos.LL.y + cp->data.border + cp->data.pad;
1449 cbox.UR.x = pos.UR.x - cp->data.border - cp->data.pad;
1450 cbox.UR.y = pos.UR.y - cp->data.border - cp->data.pad;
1451
1452 if (cp->child.kind == HTML_TBL) {
1453 pos_html_tbl(cp->child.u.tbl, cbox, sides);
1454 } else if (cp->child.kind == HTML_IMAGE) {
1455 /* Note that alignment trumps scaling */
1456 oldsz = cp->child.u.img->box.UR;
1457 delx = cbox.UR.x - cbox.LL.x - oldsz.x;
1458 if (delx > 0) {
1459 switch (cp->data.flags & HALIGN_MASK) {
1460 case HALIGN_LEFT:
1461 cbox.UR.x -= delx;
1462 break;
1463 case HALIGN_RIGHT:
1464 cbox.LL.x += delx;
1465 break;
1466 default:
1467 break;
1468 }
1469 }
1470
1471 dely = cbox.UR.y - cbox.LL.y - oldsz.y;
1472 if (dely > 0) {
1473 switch (cp->data.flags & VALIGN_MASK) {
1474 case VALIGN_BOTTOM:
1475 cbox.UR.y -= dely;
1476 break;
1477 case VALIGN_TOP:
1478 cbox.LL.y += dely;
1479 break;
1480 default:
1481 break;
1482 }
1483 }
1484 pos_html_img(cp->child.u.img, cbox);
1485 } else {
1486 char dfltalign;
1487 int af;
1488
1489 oldsz = cp->child.u.txt->box.UR;
1490 delx = cbox.UR.x - cbox.LL.x - oldsz.x;
1491 /* If the cell is larger than the text block and alignment is
1492 * done at textblock level, the text box is shrunk accordingly.
1493 */
1494 if (delx > 0 && (af = (cp->data.flags & HALIGN_MASK)) != HALIGN_TEXT) {
1495 switch (af) {
1496 case HALIGN_LEFT:
1497 cbox.UR.x -= delx;
1498 break;
1499 case HALIGN_RIGHT:
1500 cbox.LL.x += delx;
1501 break;
1502 default:
1503 cbox.LL.x += delx / 2;
1504 cbox.UR.x -= delx / 2;
1505 break;
1506 }
1507 }
1508
1509 dely = cbox.UR.y - cbox.LL.y - oldsz.y;
1510 if (dely > 0) {
1511 switch (cp->data.flags & VALIGN_MASK) {
1512 case VALIGN_BOTTOM:
1513 cbox.UR.y -= dely;
1514 break;
1515 case VALIGN_TOP:
1516 cbox.LL.y += dely;
1517 break;
1518 default:
1519 cbox.LL.y += dely / 2;
1520 cbox.UR.y -= dely / 2;
1521 break;
1522 }
1523 }
1524 cp->child.u.txt->box = cbox;
1525
1526 /* Set default text alignment
1527 */
1528 switch (cp->data.flags & BALIGN_MASK) {
1529 case BALIGN_LEFT:
1530 dfltalign = 'l';
1531 break;
1532 case BALIGN_RIGHT:
1533 dfltalign = 'r';
1534 break;
1535 default:
1536 dfltalign = 'n';
1537 break;
1538 }
1539 pos_html_txt(cp->child.u.txt, dfltalign);
1540 }
1541}
1542
1543/* Position table given its box, then calculate
1544 * the position of each cell. In addition, set the sides
1545 * attribute indicating which external sides of the node
1546 * are accessible to the table.
1547 */
1548static void pos_html_tbl(htmltbl_t *tbl, boxf pos, unsigned char sides) {
1549 int plus;
1550 htmlcell_t **cells = tbl->cells;
1551 htmlcell_t *cp;
1552 boxf cbox;
1553
1554 if (tbl->parent && tbl->parent->data.pencolor && !tbl->data.pencolor)
1555 tbl->data.pencolor = gv_strdup(tbl->parent->data.pencolor);
1556
1557 double oldsz = tbl->data.box.UR.x;
1558 double delx = fmax(pos.UR.x - pos.LL.x - oldsz, 0);
1559 oldsz = tbl->data.box.UR.y;
1560 double dely = fmax(pos.UR.y - pos.LL.y - oldsz, 0);
1561
1562 /* If fixed, align box */
1563 if (tbl->data.flags & FIXED_FLAG) {
1564 if (delx > 0) {
1565 switch (tbl->data.flags & HALIGN_MASK) {
1566 case HALIGN_LEFT:
1567 pos.UR.x = pos.LL.x + oldsz;
1568 break;
1569 case HALIGN_RIGHT:
1570 pos.UR.x += delx;
1571 pos.LL.x += delx;
1572 break;
1573 default:
1574 pos.LL.x += delx / 2;
1575 pos.UR.x -= delx / 2;
1576 break;
1577 }
1578 delx = 0;
1579 }
1580 if (dely > 0) {
1581 switch (tbl->data.flags & VALIGN_MASK) {
1582 case VALIGN_BOTTOM:
1583 pos.UR.y = pos.LL.y + oldsz;
1584 break;
1585 case VALIGN_TOP:
1586 pos.LL.y += dely;
1587 pos.UR.y = pos.LL.y + oldsz;
1588 break;
1589 default:
1590 pos.LL.y += dely / 2;
1591 pos.UR.y -= dely / 2;
1592 break;
1593 }
1594 dely = 0;
1595 }
1596 }
1597
1598 /* change sizes to start positions and distribute extra space */
1599 double x = pos.LL.x + tbl->data.border + tbl->data.space;
1600 assert(tbl->column_count <= DBL_MAX);
1601 double extra = delx / (double)tbl->column_count;
1602 plus = ROUND(delx - extra * (double)tbl->column_count);
1603 for (size_t i = 0; i <= tbl->column_count; i++) {
1604 delx = tbl->widths[i] + extra + ((i <= INT_MAX && (int)i < plus) ? 1 : 0);
1605 tbl->widths[i] = x;
1606 x += delx + tbl->data.space;
1607 }
1608 double y = pos.UR.y - tbl->data.border - tbl->data.space;
1609 assert(tbl->row_count <= DBL_MAX);
1610 extra = dely / (double)tbl->row_count;
1611 plus = ROUND(dely - extra * (double)tbl->row_count);
1612 for (size_t i = 0; i <= tbl->row_count; i++) {
1613 dely = tbl->heights[i] + extra + ((i <= INT_MAX && (int)i < plus) ? 1 : 0);
1614 tbl->heights[i] = y;
1615 y -= dely + tbl->data.space;
1616 }
1617
1618 while ((cp = *cells++)) {
1619 unsigned char mask = 0;
1620 if (sides) {
1621 if (cp->col == 0)
1622 mask |= LEFT;
1623 if (cp->row == 0)
1624 mask |= TOP;
1625 if (cp->col + cp->colspan == tbl->column_count)
1626 mask |= RIGHT;
1627 if (cp->row + cp->rowspan == tbl->row_count)
1628 mask |= BOTTOM;
1629 }
1630 cbox.LL.x = tbl->widths[cp->col];
1631 cbox.UR.x = tbl->widths[cp->col + cp->colspan] - tbl->data.space;
1632 cbox.UR.y = tbl->heights[cp->row];
1633 cbox.LL.y = tbl->heights[cp->row + cp->rowspan] + tbl->data.space;
1634 pos_html_cell(cp, cbox, sides & mask);
1635 }
1636
1637 tbl->data.sides = sides;
1638 tbl->data.box = pos;
1639}
1640
1641/* Determine the size of a table by first determining the
1642 * size of each cell.
1643 */
1644static int
1646 htmlenv_t * env)
1647{
1648 int rv = 0;
1649 static textfont_t savef;
1650
1651 if (tbl->font)
1652 pushFontInfo(env, tbl->font, &savef);
1653 tbl->parent = parent;
1654 rv = processTbl(g, tbl, env);
1655
1656 /* Set up border and spacing */
1657 if (!(tbl->data.flags & SPACE_SET)) {
1659 }
1660 if (!(tbl->data.flags & BORDER_SET)) {
1661 tbl->data.border = DEFAULT_BORDER;
1662 }
1663
1664 set_cell_widths(tbl);
1665 set_cell_heights(tbl);
1666
1667 assert(tbl->column_count <= DBL_MAX);
1668 double wd = ((double)tbl->column_count + 1) * tbl->data.space + 2 * tbl->data.border;
1669 assert(tbl->row_count <= DBL_MAX);
1670 double ht = ((double)tbl->row_count + 1) * tbl->data.space + 2 * tbl->data.border;
1671 for (size_t i = 0; i < tbl->column_count; i++)
1672 wd += tbl->widths[i];
1673 for (size_t i = 0; i < tbl->row_count; i++)
1674 ht += tbl->heights[i];
1675
1676 if (tbl->data.flags & FIXED_FLAG) {
1677 if (tbl->data.width && tbl->data.height) {
1678 if (tbl->data.width < wd || tbl->data.height < ht) {
1679 agwarningf("table size too small for content\n");
1680 rv = 1;
1681 }
1682 wd = 0;
1683 ht = 0;
1684 } else {
1685 agwarningf(
1686 "fixed table size with unspecified width or height\n");
1687 rv = 1;
1688 }
1689 }
1690 tbl->data.box.UR.x = fmax(wd, tbl->data.width);
1691 tbl->data.box.UR.y = fmax(ht, tbl->data.height);
1692
1693 if (tbl->font)
1694 popFontInfo(env, &savef);
1695 return rv;
1696}
1697
1698static char *nameOf(void *obj, agxbuf * xb)
1699{
1700 Agedge_t *ep;
1701 switch (agobjkind(obj)) {
1702 case AGRAPH:
1703 agxbput(xb, agnameof(obj));
1704 break;
1705 case AGNODE:
1706 agxbput(xb, agnameof(obj));
1707 break;
1708 case AGEDGE:
1709 ep = obj;
1710 agxbput(xb, agnameof(agtail(ep)));
1711 agxbput(xb, agnameof(aghead(ep)));
1712 if (agisdirected(agraphof(aghead(ep))))
1713 agxbput(xb, "->");
1714 else
1715 agxbput(xb, "--");
1716 break;
1717 }
1718 return agxbuse(xb);
1719}
1720
1721#ifdef DEBUG
1722void indent(int i)
1723{
1724 while (i--)
1725 fprintf(stderr, " ");
1726}
1727
1728void printBox(boxf b)
1729{
1730 fprintf(stderr, "(%f,%f)(%f,%f)", b.LL.x, b.LL.y, b.UR.x, b.UR.y);
1731}
1732
1733void printImage(htmlimg_t * ip, int ind)
1734{
1735 indent(ind);
1736 fprintf(stderr, "img: %s\n", ip->src);
1737}
1738
1739void printTxt(htmltxt_t * txt, int ind)
1740{
1741 indent(ind);
1742 fprintf(stderr, "txt spans = %" PRISIZE_T " \n", txt->nspans);
1743 for (size_t i = 0; i < txt->nspans; i++) {
1744 indent(ind + 1);
1745 fprintf(stderr, "[%" PRISIZE_T "] %" PRISIZE_T " items\n", i,
1746 txt->spans[i].nitems);
1747 for (size_t j = 0; j < txt->spans[i].nitems; j++) {
1748 indent(ind + 2);
1749 fprintf(stderr, "[%" PRISIZE_T "] (%f,%f) \"%s\" ",
1750 j, txt->spans[i].items[j].size.x,
1751 txt->spans[i].items[j].size.y,
1752 txt->spans[i].items[j].str);
1753 if (txt->spans[i].items[j].font)
1754 fprintf(stderr, "font %s color %s size %f\n",
1755 txt->spans[i].items[j].font->name,
1756 txt->spans[i].items[j].font->color,
1757 txt->spans[i].items[j].font->size);
1758 else
1759 fprintf(stderr, "\n");
1760 }
1761 }
1762}
1763
1764void printData(htmldata_t * dp)
1765{
1766 unsigned char flags = dp->flags;
1767 char c;
1768
1769 fprintf(stderr, "s%d(%d) ", dp->space, (flags & SPACE_SET ? 1 : 0));
1770 fprintf(stderr, "b%d(%d) ", dp->border, (flags & BORDER_SET ? 1 : 0));
1771 fprintf(stderr, "p%d(%d) ", dp->pad, (flags & PAD_SET ? 1 : 0));
1772 switch (flags & HALIGN_MASK) {
1773 case HALIGN_RIGHT:
1774 c = 'r';
1775 break;
1776 case HALIGN_LEFT:
1777 c = 'l';
1778 break;
1779 default:
1780 c = 'n';
1781 break;
1782 }
1783 fprintf(stderr, "%c", c);
1784 switch (flags & VALIGN_MASK) {
1785 case VALIGN_TOP:
1786 c = 't';
1787 break;
1788 case VALIGN_BOTTOM:
1789 c = 'b';
1790 break;
1791 default:
1792 c = 'c';
1793 break;
1794 }
1795 fprintf(stderr, "%c ", c);
1796 printBox(dp->box);
1797}
1798
1799void printTbl(htmltbl_t * tbl, int ind)
1800{
1801 htmlcell_t **cells = tbl->cells;
1802 indent(ind);
1803 fprintf(stderr, "tbl (%p) %" PRISIZE_T " %" PRISIZE_T " ", tbl, tbl->column_count, tbl->row_count);
1804 printData(&tbl->data);
1805 fputs("\n", stderr);
1806 while (*cells)
1807 printCell(*cells++, ind + 1);
1808}
1809
1810static void printCell(htmlcell_t * cp, int ind)
1811{
1812 indent(ind);
1813 fprintf(stderr, "cell %" PRIu16 " %" PRIu16 " %" PRIu16 " %" PRIu16 " ", cp->colspan,
1814 cp->colspan, cp->rowspan, cp->col, cp->row);
1815 printData(&cp->data);
1816 fputs("\n", stderr);
1817 switch (cp->child.kind) {
1818 case HTML_TBL:
1819 printTbl(cp->child.u.tbl, ind + 1);
1820 break;
1821 case HTML_TEXT:
1822 printTxt(cp->child.u.txt, ind + 1);
1823 break;
1824 case HTML_IMAGE:
1825 printImage(cp->child.u.img, ind + 1);
1826 break;
1827 default:
1828 break;
1829 }
1830}
1831
1832void printLbl(htmllabel_t * lbl)
1833{
1834 if (lbl->kind == HTML_TBL)
1835 printTbl(lbl->u.tbl, 0);
1836 else
1837 printTxt(lbl->u.txt, 0);
1838}
1839#endif /* DEBUG */
1840
1841static char *getPenColor(void *obj)
1842{
1843 char *str;
1844
1845 if ((str = agget(obj, "pencolor")) != 0 && str[0])
1846 return str;
1847 else if ((str = agget(obj, "color")) != 0 && str[0])
1848 return str;
1849 else
1850 return NULL;
1851}
1852
1854int make_html_label(void *obj, textlabel_t * lp)
1855{
1856 int rv;
1857 double wd2, ht2;
1858 graph_t *g;
1859 htmllabel_t *lbl;
1860 htmlenv_t env;
1861 char *s;
1862
1863 env.obj = obj;
1864 switch (agobjkind(obj)) {
1865 case AGRAPH:
1866 env.g = ((Agraph_t *) obj)->root;
1867 break;
1868 case AGNODE:
1869 env.g = agraphof(obj);
1870 break;
1871 case AGEDGE:
1872 env.g = agraphof(aghead(((Agedge_t *) obj)));
1873 break;
1874 }
1875 g = env.g->root;
1876
1877 env.finfo.size = lp->fontsize;
1878 env.finfo.name = lp->fontname;
1879 env.finfo.color = lp->fontcolor;
1880 env.finfo.flags = 0;
1881 lbl = parseHTML(lp->text, &rv, &env);
1882 if (!lbl) {
1883 if (rv == 3) {
1884 // fatal error; `parseHTML` will have printed detail of it
1885 lp->html = false;
1886 return rv;
1887 }
1888 /* Parse of label failed; revert to simple text label */
1889 agxbuf xb = {0};
1890 lp->html = false;
1891 free(lp->text);
1892 lp->text = gv_strdup(nameOf(obj, &xb));
1893 switch (lp->charset) {
1894 case CHAR_LATIN1:
1895 s = latin1ToUTF8(lp->text);
1896 break;
1897 default: /* UTF8 */
1898 s = htmlEntityUTF8(lp->text, env.g);
1899 break;
1900 }
1901 free(lp->text);
1902 lp->text = s;
1903 make_simple_label(GD_gvc(g), lp);
1904 agxbfree(&xb);
1905 return rv;
1906 }
1907
1908 if (lbl->kind == HTML_TBL) {
1909 if (!lbl->u.tbl->data.pencolor && getPenColor(obj))
1910 lbl->u.tbl->data.pencolor = gv_strdup(getPenColor(obj));
1911 rv |= size_html_tbl(g, lbl->u.tbl, NULL, &env);
1912 wd2 = lbl->u.tbl->data.box.UR.x / 2;
1913 ht2 = lbl->u.tbl->data.box.UR.y / 2;
1914 boxf b = {{-wd2, -ht2}, {wd2, ht2}};
1915 pos_html_tbl(lbl->u.tbl, b, BOTTOM | RIGHT | TOP | LEFT);
1916 lp->dimen.x = b.UR.x - b.LL.x;
1917 lp->dimen.y = b.UR.y - b.LL.y;
1918 } else {
1919 rv |= size_html_txt(GD_gvc(g), lbl->u.txt, &env);
1920 wd2 = lbl->u.txt->box.UR.x / 2;
1921 ht2 = lbl->u.txt->box.UR.y / 2;
1922 boxf b = {{-wd2, -ht2}, {wd2, ht2}};
1923 lbl->u.txt->box = b;
1924 lp->dimen.x = b.UR.x - b.LL.x;
1925 lp->dimen.y = b.UR.y - b.LL.y;
1926 }
1927
1928 lp->u.html = lbl;
1929
1930 /* If the label is a table, replace label text because this may
1931 * be used for the title and alt fields in image maps.
1932 */
1933 if (lbl->kind == HTML_TBL) {
1934 free(lp->text);
1935 lp->text = gv_strdup("<TABLE>");
1936 }
1937
1938 return rv;
1939}
Dynamically expanding string buffers.
static void agxbfree(agxbuf *xb)
free any malloced resources
Definition agxbuf.h:97
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
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
#define ROUND(f)
Definition arith.h:48
#define MAX(a, b)
Definition arith.h:33
API for compacted arrays of booleans.
static bitarray_t bitarray_new(size_t size_bits)
create an array of the given element length
Definition bitarray.h:47
static bool bitarray_get(bitarray_t self, size_t index)
get the value of the given element
Definition bitarray.h:65
static void bitarray_set(bitarray_t *self, size_t index, bool value)
set or clear the value of the given element
Definition bitarray.h:80
static void bitarray_reset(bitarray_t *self)
free underlying resources and leave a bit array empty
Definition bitarray.h:114
container data types API
#define dtinsert(d, o)
Definition cdt.h:186
#define parent(i)
Definition closest.c:75
char * latin1ToUTF8(char *s)
Converts string from Latin1 encoding to utf8. Also translates HTML entities.
Definition utils.c:1249
char * htmlEntityUTF8(char *s, graph_t *g)
Definition utils.c:1172
#define CHAR_LATIN1
Definition const.h:188
#define LEFT
Definition const.h:120
#define DEFAULT_COLOR
Definition const.h:48
#define RIGHT
Definition const.h:118
#define GRADIENT
Definition const.h:223
#define BOTTOM
Definition const.h:117
#define RGRADIENT
Definition const.h:224
#define TOP
Definition const.h:119
bool findStopColor(const char *colorlist, char *clrs[2], double *frac)
Definition emit.c:4337
obj_state_t * push_obj_state(GVJ_t *job)
Definition emit.c:108
void emit_map_rect(GVJ_t *job, boxf b)
Definition emit.c:640
void pop_obj_state(GVJ_t *job)
Definition emit.c:132
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:209
bool initMapData(GVJ_t *job, char *lbl, char *url, char *tooltip, char *target, char *id, void *gobj)
Definition emit.c:163
#define A(n, t)
Definition expr.h:76
static int flags
Definition gc.c:63
#define B2BF(b, bf)
Definition geom.h:69
static WUR pointf scale(double c, pointf p)
Definition geomprocs.h:148
void free(void *)
#define FILL
Definition gmlparse.h:119
#define SIZE_MAX
Definition gmlscan.c:347
#define UINT16_MAX
Definition gmlscan.c:340
node NULL
Definition grammar.y:181
simple
Definition grammar.y:174
static int cnt(Dict_t *d, Dtlink_t **set)
Definition graph.c:204
char * agget(void *obj, char *name)
Definition attr.c:447
#define agtail(e)
Definition cgraph.h:982
#define aghead(e)
Definition cgraph.h:983
void agwarningf(const char *fmt,...)
Definition agerror.c:175
void agerrorf(const char *fmt,...)
Definition agerror.c:167
int agisdirected(Agraph_t *g)
Definition graph.c:184
#define GD_has_images(g)
Definition types.h:369
#define GD_gvc(g)
Definition types.h:355
#define ND_label(n)
Definition types.h:502
Agraph_t * agraphof(void *obj)
Definition obj.c:187
char * agnameof(void *)
returns a string descriptor for the object.
Definition id.c:145
int agobjkind(void *obj)
Definition obj.c:254
@ AGEDGE
Definition cgraph.h:207
@ AGNODE
Definition cgraph.h:207
@ AGRAPH
Definition cgraph.h:207
static uint64_t id
Definition gv2gml.c:42
static void indent(int ix)
Definition gv2gml.c:96
static GVC_t * gvc
Definition gv.cpp:27
Arithmetic helper functions.
#define EMIT_CLUSTERS_LAST
Definition gvcjob.h:84
@ LABEL_HTML
Definition gvcjob.h:38
@ CLUSTER_OBJTYPE
Definition gvcjob.h:168
@ EDGE_OBJTYPE
Definition gvcjob.h:168
@ ROOTGRAPH_OBJTYPE
Definition gvcjob.h:168
@ NODE_OBJTYPE
Definition gvcjob.h:168
static void color(Agraph_t *g)
Definition gvcolor.c:118
void gvrender_end_label(GVJ_t *job)
Definition gvrender.c:404
void gvrender_usershape(GVJ_t *job, char *name, pointf *AF, size_t n, bool filled, char *imagescale, char *imagepos)
Definition gvrender.c:670
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
point gvusershape_size(graph_t *g, char *name)
void gvrender_box(GVJ_t *job, boxf BF, int filled)
Definition gvrender.c:565
void gvrender_set_gradient_vals(GVJ_t *job, char *stopcolor, int angle, double frac)
Definition gvrender.c:467
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_textspan(GVJ_t *job, pointf p, textspan_t *span)
Definition gvrender.c:414
void gvrender_begin_label(GVJ_t *job, label_type type)
Definition gvrender.c:394
void gvrender_set_penwidth(GVJ_t *job, double penwidth)
Definition gvrender.c:798
void gvrender_set_pencolor(GVJ_t *job, char *name)
Definition gvrender.c:433
agxbput(xb, staging)
htmllabel_t * parseHTML(char *txt, int *warn, htmlenv_t *env)
Definition htmlparse.c:2010
textitem scanner parser str
Definition htmlparse.y:218
rows row
Definition htmlparse.y:320
cell HTML_TBL
Definition htmlparse.y:332
$2 rows
Definition htmlparse.y:292
static void free_html_img(htmlimg_t *ip)
Definition htmltable.c:820
static void endAnchor(GVJ_t *job, htmlmap_data_t *save)
Definition htmltable.c:432
static int size_html_tbl(graph_t *g, htmltbl_t *tbl, htmlcell_t *parent, htmlenv_t *env)
Definition htmltable.c:1645
static void pos_html_cell(htmlcell_t *cp, boxf pos, unsigned char sides)
Definition htmltable.c:1399
static void pushFontInfo(htmlenv_t *env, textfont_t *fp, textfont_t *savp)
Definition htmltable.c:79
static void pos_html_txt(htmltxt_t *ftxt, char c)
Set default alignment.
Definition htmltable.c:1391
static void set_cell_widths(htmltbl_t *table)
Definition htmltable.c:1250
#define RESET(fld)
Definition htmltable.c:419
static char * nameOf(void *obj, agxbuf *xb)
Definition htmltable.c:1698
static void allocObj(GVJ_t *job)
Definition htmltable.c:680
boxf * html_port(node_t *n, char *pname, unsigned char *sides)
Definition htmltable.c:914
static void pos_html_tbl(htmltbl_t *, boxf, unsigned char)
Definition htmltable.c:1548
static double heightOfLbl(htmllabel_t *lp)
Definition htmltable.c:723
int make_html_label(void *obj, textlabel_t *lp)
Return non-zero if problem parsing HTML. In this case, use object name.
Definition htmltable.c:1854
static void emit_html_img(GVJ_t *job, htmlimg_t *cp, htmlenv_t *env)
Definition htmltable.c:595
static void pos_html_img(htmlimg_t *cp, boxf pos)
Definition htmltable.c:1385
#define DEFAULT_CELLSPACING
Definition htmltable.c:58
#define DEFAULT_CELLPADDING
Definition htmltable.c:57
static int size_html_cell(graph_t *g, htmlcell_t *cp, htmltbl_t *parent, htmlenv_t *env)
Definition htmltable.c:1099
static void doBorder(GVJ_t *job, htmldata_t *dp, boxf b)
Definition htmltable.c:253
static void set_cell_heights(htmltbl_t *table)
Definition htmltable.c:1326
static pointf * mkPts(pointf *AF, boxf b, int border)
Definition htmltable.c:229
static void freeObj(GVJ_t *job)
Definition htmltable.c:711
static int processTbl(graph_t *g, htmltbl_t *tbl, htmlenv_t *env)
Definition htmltable.c:1187
static htmldata_t * portToTbl(htmltbl_t *, char *)
Definition htmltable.c:890
static void emit_html_txt(GVJ_t *job, htmltxt_t *tp, htmlenv_t *env)
Definition htmltable.c:197
static htmldata_t * portToCell(htmlcell_t *cp, char *id)
Definition htmltable.c:873
void free_html_text(htmltxt_t *t)
Definition htmltable.c:801
static void free_html_cell(htmlcell_t *cp)
Definition htmltable.c:826
static void emit_html_tbl(GVJ_t *job, htmltbl_t *tbl, htmlenv_t *env)
Definition htmltable.c:517
static void popFontInfo(htmlenv_t *env, textfont_t *savp)
Definition htmltable.c:107
static int size_html_txt(GVC_t *gvc, htmltxt_t *ftxt, htmlenv_t *env)
Definition htmltable.c:932
void free_html_label(htmllabel_t *lp, int root)
Definition htmltable.c:859
static void emit_html_cell(GVJ_t *job, htmlcell_t *cp, htmlenv_t *env)
Definition htmltable.c:622
static uint16_t findCol(PointSet *ps, int row, int col, htmlcell_t *cellp)
Definition htmltable.c:1156
void emit_html_label(GVJ_t *job, htmllabel_t *lp, textlabel_t *tp)
Definition htmltable.c:743
static void emit_htextspans(GVJ_t *job, size_t nspans, htextspan_t *spans, pointf p, double halfwidth_x, textfont_t finfo, boxf b, int simple)
Definition htmltable.c:118
static int initAnchor(GVJ_t *job, htmlenv_t *env, htmldata_t *data, boxf b, htmlmap_data_t *save)
Definition htmltable.c:381
void free_html_data(htmldata_t *dp)
Definition htmltable.c:790
static int setFill(GVJ_t *job, char *color, int angle, htmlstyle_t style, char *clrs[2])
Definition htmltable.c:348
static void doSide(GVJ_t *job, pointf p, double wd, double ht)
Definition htmltable.c:214
#define DEFAULT_BORDER
Definition htmltable.c:56
static void emit_html_rules(GVJ_t *job, htmlcell_t *cp, htmlenv_t *env, char *color, htmlcell_t *nextc)
Definition htmltable.c:451
static void free_html_tbl(htmltbl_t *tbl)
Definition htmltable.c:838
static int size_html_img(htmlimg_t *img, htmlenv_t *env)
Definition htmltable.c:1078
static char * getPenColor(void *obj)
Definition htmltable.c:1841
#define PAD_SET
Definition htmltable.h:35
#define BORDER_RIGHT
Definition htmltable.h:42
#define BORDER_TOP
Definition htmltable.h:41
#define HALIGN_TEXT
Definition htmltable.h:30
#define UNSET_ALIGN
Definition htmltable.h:46
#define HALIGN_LEFT
Definition htmltable.h:28
#define VALIGN_BOTTOM
Definition htmltable.h:32
#define BALIGN_MASK
Definition htmltable.h:39
#define BALIGN_RIGHT
Definition htmltable.h:37
#define HALIGN_MASK
Definition htmltable.h:29
#define BALIGN_LEFT
Definition htmltable.h:38
#define BORDER_BOTTOM
Definition htmltable.h:43
@ HTML_TEXT
Definition htmltable.h:103
@ HTML_IMAGE
Definition htmltable.h:103
#define SPACE_SET
Definition htmltable.h:36
#define VALIGN_MASK
Definition htmltable.h:33
#define BORDER_SET
Definition htmltable.h:34
#define BORDER_LEFT
Definition htmltable.h:40
#define BORDER_MASK
Definition htmltable.h:44
#define HALIGN_RIGHT
Definition htmltable.h:27
#define VALIGN_TOP
Definition htmltable.h:31
#define FIXED_FLAG
Definition htmltable.h:26
char * strdup_and_subst_obj(char *str, void *obj)
Processes graph object escape sequences; also collapses \ to .
Definition labels.c:387
void make_simple_label(GVC_t *gvc, textlabel_t *lp)
Definition labels.c:57
static int layout(graph_t *g, layout_info *infop, size_t *counter)
Definition layout.c:800
#define LIST_SIZE(list)
Definition list.h:92
#define LIST_FREE(list)
Definition list.h:413
#define LIST_GET(list, index)
Definition list.h:197
#define delta
Definition maze.c:138
static const int table[NTYPES][NTYPES]
Definition mincross.c:1707
void addPS(PointSet *ps, double x, double y)
Definition pointset.c:88
PointSet * newPS(void)
Definition pointset.c:70
void freePS(PointSet *ps)
Definition pointset.c:75
int isInPS(PointSet *ps, double x, double y)
Definition pointset.c:101
point containers PointSet and PointMap
static void printData(object_t *objs, size_t n_objs, xlabel_t *lbls, size_t n_lbls, label_params_t *params)
Definition postproc.c:217
#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
platform abstraction for case-insensitive string functions
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
Definition gvcint.h:81
char ** defaultlinestyle
Definition gvcint.h:149
Dt_t * textfont_dt
Definition gvcint.h:108
int flags
Definition gvcjob.h:299
obj_state_t * obj
Definition gvcjob.h:269
GVC_t * gvc
Definition gvcjob.h:263
Definition geom.h:39
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
result of partitioning available space, part of maze
Definition grid.h:33
Definition cdt.h:98
double lfsize
Definition htmltable.h:59
size_t nitems
Definition htmltable.h:56
textspan_t * items
Definition htmltable.h:55
double size
Definition htmltable.h:58
uint16_t rowspan
Definition htmltable.h:160
htmllabel_t child
Definition htmltable.h:163
uint16_t colspan
Definition htmltable.h:159
htmltbl_t * parent
Definition htmltable.h:164
bool vruled
vertically ruled?
Definition htmltable.h:165
bool hruled
horizontally ruled?
Definition htmltable.h:166
uint16_t col
Definition htmltable.h:161
uint16_t row
Definition htmltable.h:162
htmldata_t data
Definition htmltable.h:158
char * bgcolor
Definition htmltable.h:89
unsigned char border
Definition htmltable.h:93
char * target
Definition htmltable.h:86
char * id
Definition htmltable.h:88
signed char space
Definition htmltable.h:92
unsigned short width
Definition htmltable.h:97
unsigned short height
Definition htmltable.h:98
int gradientangle
Definition htmltable.h:91
char * port
Definition htmltable.h:85
unsigned short flags
Definition htmltable.h:96
unsigned char sides
Definition htmltable.h:95
char * href
Definition htmltable.h:84
unsigned char pad
Definition htmltable.h:94
char * pencolor
Definition htmltable.h:90
htmlstyle_t style
Definition htmltable.h:99
char * title
Definition htmltable.h:87
graph_t * g
Definition htmltable.h:173
textfont_t finfo
Definition htmltable.h:171
pointf pos
Definition htmltable.h:170
bool objid_set
Definition htmltable.h:176
char * objid
Definition htmltable.h:175
char * imgscale
Definition htmltable.h:174
void * obj
Definition htmltable.h:172
char * scale
Definition htmltable.h:72
char * src
Definition htmltable.h:71
boxf box
Definition htmltable.h:70
htmltxt_t * txt
Definition htmltable.h:151
htmltbl_t * tbl
Definition htmltable.h:150
htmlimg_t * img
Definition htmltable.h:152
label_type_t kind
Definition htmltable.h:154
union htmllabel_t::@50 u
bool explicit_tooltip
Definition htmltable.c:65
char * tooltip
Definition htmltable.c:62
char * target
Definition htmltable.c:63
bool dashed
Definition htmltable.h:80
bool dotted
Definition htmltable.h:79
bool rounded
Definition htmltable.h:77
bool radial
Definition htmltable.h:76
bool invisible
Definition htmltable.h:78
textfont_t * font
Definition htmltable.h:143
size_t row_count
number of rows
Definition htmltable.h:141
double * widths
widths of the columns
Definition htmltable.h:140
htmlcell_t ** cells
Definition htmltable.h:131
htmldata_t data
Definition htmltable.h:127
rows_t rows
cells
Definition htmltable.h:135
htmlcell_t * parent
Definition htmltable.h:130
double * heights
heights of the rows
Definition htmltable.h:139
size_t column_count
number of columns
Definition htmltable.h:142
boxf box
Definition htmltable.h:66
size_t nspans
Definition htmltable.h:64
char simple
Definition htmltable.h:65
htextspan_t * spans
Definition htmltable.h:63
graph_t * g
Definition gvcjob.h:186
edge_t * e
Definition gvcjob.h:189
char * tooltip
Definition gvcjob.h:216
char * url
Definition gvcjob.h:210
unsigned explicit_tooltip
Definition gvcjob.h:226
char * target
Definition gvcjob.h:221
obj_type type
Definition gvcjob.h:184
node_t * n
Definition gvcjob.h:188
union obj_state_s::@65 u
graph_t * sg
Definition gvcjob.h:187
char * id
Definition gvcjob.h:211
emit_state_t emit_state
Definition gvcjob.h:192
obj_state_t * parent
Definition gvcjob.h:182
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
bool ruled
Definition htmltable.h:115
char * color
Definition textspan.h:57
char * name
Definition textspan.h:56
PostscriptAlias * postscript_alias
Definition textspan.h:58
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
int charset
Definition types.h:108
char valign
Definition types.h:122
union textlabel_t::@54 u
double fontsize
Definition types.h:109
pointf space
Definition types.h:111
htmllabel_t * html
Definition types.h:120
char * fontname
Definition types.h:106
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
void * layout
Definition textspan.h:70
pointf size
Definition textspan.h:73
textfont_t * font
Definition textspan.h:69
double yoffset_centerline
Definition textspan.h:72
void(* free_layout)(void *layout)
Definition textspan.h:71
Definition grammar.c:90
#define UNREACHABLE()
Definition unreachable.h:30