Graphviz 14.1.3~dev.20260228.0625
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 v1.0
7 * which accompanies this distribution, and is available at
8 * https://www.eclipse.org/legal/epl-v10.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 **cells = tbl->cells;
522 htmlcell_t *cp;
523 static textfont_t savef;
524 htmlmap_data_t saved;
525 int anchor; /* if true, we need to undo anchor settings. */
526 const bool doAnchor = tbl->data.href || tbl->data.target || tbl->data.title;
527 pointf AF[4];
528
529 if (tbl->font)
530 pushFontInfo(env, tbl->font, &savef);
531
532 pts.LL.x += pos.x;
533 pts.UR.x += pos.x;
534 pts.LL.y += pos.y;
535 pts.UR.y += pos.y;
536
537 if (doAnchor && !(job->flags & EMIT_CLUSTERS_LAST))
538 anchor = initAnchor(job, env, &tbl->data, pts, &saved);
539 else
540 anchor = 0;
541
542 if (!tbl->data.style.invisible) {
543
544 /* Fill first */
545 if (tbl->data.bgcolor) {
546 char *clrs[2] = {0};
547 int filled =
548 setFill(job, tbl->data.bgcolor, tbl->data.gradientangle,
549 tbl->data.style, clrs);
550 if (tbl->data.style.rounded) {
551 round_corners(job, mkPts(AF, pts, tbl->data.border), 4,
552 (graphviz_polygon_style_t){.rounded = true}, filled);
553 } else
554 gvrender_box(job, pts, filled);
555 free(clrs[0]);
556 free(clrs[1]);
557 }
558
559 while (*cells) {
560 emit_html_cell(job, *cells, env);
561 cells++;
562 }
563
564 /* Draw table rules and border.
565 * Draw after cells so we can draw over any fill.
566 * At present, we set the penwidth to 1 for rules until we provide the calculations to take
567 * into account wider rules.
568 */
569 cells = tbl->cells;
570 gvrender_set_penwidth(job, 1.0);
571 while ((cp = *cells++)) {
572 if (cp->hruled || cp->vruled)
573 emit_html_rules(job, cp, env, tbl->data.pencolor, *cells);
574 }
575
576 if (tbl->data.border)
577 doBorder(job, &tbl->data, pts);
578
579 }
580
581 if (anchor)
582 endAnchor(job, &saved);
583
584 if (doAnchor && (job->flags & EMIT_CLUSTERS_LAST)) {
585 if (initAnchor(job, env, &tbl->data, pts, &saved))
586 endAnchor(job, &saved);
587 }
588
589 if (tbl->font)
590 popFontInfo(env, &savef);
591}
592
593/* The image will be centered in the given box.
594 * Scaling is determined by either the image's scale attribute,
595 * or the imagescale attribute of the graph object being drawn.
596 */
597static void emit_html_img(GVJ_t * job, htmlimg_t * cp, htmlenv_t * env)
598{
599 pointf A[4];
600 boxf bb = cp->box;
601 char *scale;
602
603 bb.LL.x += env->pos.x;
604 bb.LL.y += env->pos.y;
605 bb.UR.x += env->pos.x;
606 bb.UR.y += env->pos.y;
607
608 A[0] = bb.UR;
609 A[2] = bb.LL;
610 A[1].x = A[2].x;
611 A[1].y = A[0].y;
612 A[3].x = A[0].x;
613 A[3].y = A[2].y;
614
615 if (cp->scale)
616 scale = cp->scale;
617 else
618 scale = env->imgscale;
619 assert(cp->src);
620 assert(cp->src[0]);
621 gvrender_usershape(job, cp->src, A, 4, true, scale, "mc");
622}
623
624static void emit_html_cell(GVJ_t * job, htmlcell_t * cp, htmlenv_t * env)
625{
626 htmlmap_data_t saved;
627 boxf pts = cp->data.box;
628 pointf pos = env->pos;
629 int inAnchor;
630 const bool doAnchor = cp->data.href || cp->data.target || cp->data.title;
631 pointf AF[4];
632
633 pts.LL.x += pos.x;
634 pts.UR.x += pos.x;
635 pts.LL.y += pos.y;
636 pts.UR.y += pos.y;
637
638 if (doAnchor && !(job->flags & EMIT_CLUSTERS_LAST))
639 inAnchor = initAnchor(job, env, &cp->data, pts, &saved);
640 else
641 inAnchor = 0;
642
643 if (!cp->data.style.invisible) {
644 if (cp->data.bgcolor) {
645 char *clrs[2];
646 int filled =
647 setFill(job, cp->data.bgcolor, cp->data.gradientangle,
648 cp->data.style, clrs);
649 if (cp->data.style.rounded) {
650 round_corners(job, mkPts(AF, pts, cp->data.border), 4,
651 (graphviz_polygon_style_t){.rounded = true}, filled);
652 } else
653 gvrender_box(job, pts, filled);
654 free(clrs[0]);
655 }
656
657 if (cp->data.border)
658 doBorder(job, &cp->data, pts);
659
660 if (cp->child.kind == HTML_TBL)
661 emit_html_tbl(job, cp->child.u.tbl, env);
662 else if (cp->child.kind == HTML_IMAGE)
663 emit_html_img(job, cp->child.u.img, env);
664 else
665 emit_html_txt(job, cp->child.u.txt, env);
666 }
667
668 if (inAnchor)
669 endAnchor(job, &saved);
670
671 if (doAnchor && (job->flags & EMIT_CLUSTERS_LAST)) {
672 if (initAnchor(job, env, &cp->data, pts, &saved))
673 endAnchor(job, &saved);
674 }
675}
676
677/* Push new obj on stack to be used in common by all
678 * html elements with anchors.
679 * This inherits the type, emit_state, and object of the
680 * parent, as well as the url, explicit, target and tooltip.
681 */
682static void allocObj(GVJ_t * job)
683{
684 obj_state_t *obj;
686
687 obj = push_obj_state(job);
688 parent = obj->parent;
689 obj->type = parent->type;
690 obj->emit_state = parent->emit_state;
691 switch (obj->type) {
692 case NODE_OBJTYPE:
693 obj->u.n = parent->u.n;
694 break;
696 obj->u.g = parent->u.g;
697 break;
698 case CLUSTER_OBJTYPE:
699 obj->u.sg = parent->u.sg;
700 break;
701 case EDGE_OBJTYPE:
702 obj->u.e = parent->u.e;
703 break;
704 default:
705 UNREACHABLE();
706 }
707 obj->url = parent->url;
708 obj->tooltip = parent->tooltip;
709 obj->target = parent->target;
710 obj->explicit_tooltip = parent->explicit_tooltip;
711}
712
713static void freeObj(GVJ_t * job)
714{
715 obj_state_t *obj = job->obj;
716
717 obj->url = NULL;
718 obj->tooltip = NULL;
719 obj->target = NULL;
720 obj->id = NULL;
721 pop_obj_state(job);
722}
723
724static double
726{
727 double sz = 0.0;
728
729 switch (lp->kind) {
730 case HTML_TBL:
731 sz = lp->u.tbl->data.box.UR.y - lp->u.tbl->data.box.LL.y;
732 break;
733 case HTML_IMAGE:
734 sz = lp->u.img->box.UR.y - lp->u.img->box.LL.y;
735 break;
736 case HTML_TEXT:
737 sz = lp->u.txt->box.UR.y - lp->u.txt->box.LL.y;
738 break;
739 default:
740 UNREACHABLE();
741 }
742 return sz;
743}
744
746{
747 htmlenv_t env;
748 pointf p;
749
750 allocObj(job);
751
752 p = tp->pos;
753 switch (tp->valign) {
754 case 't':
755 p.y = tp->pos.y + (tp->space.y - heightOfLbl(lp))/ 2.0 - 1;
756 break;
757 case 'b':
758 p.y = tp->pos.y - (tp->space.y - heightOfLbl(lp))/ 2.0 - 1;
759 break;
760 default:
761 /* no-op */
762 break;
763 }
764 env.pos = p;
765 env.finfo.color = tp->fontcolor;
766 env.finfo.name = tp->fontname;
767 env.finfo.size = tp->fontsize;
768 env.imgscale = agget(job->obj->u.n, "imagescale");
769 env.objid = job->obj->id;
770 env.objid_set = false;
771 if (env.imgscale == NULL || env.imgscale[0] == '\0')
772 env.imgscale = "false";
773 if (lp->kind == HTML_TBL) {
774 htmltbl_t *tbl = lp->u.tbl;
775
776 /* set basic graphics context */
777 /* Need to override line style set by node. */
779 if (tbl->data.pencolor)
781 else
783 emit_html_tbl(job, tbl, &env);
784 } else {
785 emit_html_txt(job, lp->u.txt, &env);
786 }
787 if (env.objid_set)
788 free(env.objid);
789 freeObj(job);
790}
791
793{
794 free(dp->href);
795 free(dp->port);
796 free(dp->target);
797 free(dp->id);
798 free(dp->title);
799 free(dp->bgcolor);
800 free(dp->pencolor);
801}
802
804{
805 if (!t)
806 return;
807
808 htextspan_t *const tl = t->spans;
809 for (size_t i = 0; i < t->nspans; i++) {
810 textspan_t *const ti = tl[i].items;
811 for (size_t j = 0; j < tl[i].nitems; j++) {
812 free(ti[j].str);
813 if (ti[j].layout && ti[j].free_layout)
814 ti[j].free_layout(ti[j].layout);
815 }
816 free(ti);
817 }
818 free(tl);
819 free(t);
820}
821
822static void free_html_img(htmlimg_t * ip)
823{
824 free(ip->src);
825 free(ip);
826}
827
828static void free_html_cell(htmlcell_t * cp)
829{
830 free_html_label(&cp->child, 0);
831 free_html_data(&cp->data);
832 free(cp);
833}
834
835/* If tbl->row_count is `SIZE_MAX`, table is in initial state from
836 * HTML parse, with data stored in `tbl->prev` and `tbl->rows`. Once run through
837 * processTbl, data is stored in `tbl->parent` and `tbl->cells`, and
838 * tbl->row_count is < `SIZE_MAX`.
839 */
840static void free_html_tbl(htmltbl_t * tbl)
841{
842 htmlcell_t **cells;
843
844 if (tbl->row_count == SIZE_MAX) { // raw, parsed table
845 LIST_FREE(&tbl->rows);
846 } else {
847 cells = tbl->cells;
848
849 free(tbl->heights);
850 free(tbl->widths);
851 while (*cells) {
852 free_html_cell(*cells);
853 cells++;
854 }
855 free(tbl->cells);
856 }
857 free_html_data(&tbl->data);
858 free(tbl);
859}
860
861void free_html_label(htmllabel_t * lp, int root)
862{
863 if (lp->kind == HTML_TBL)
864 free_html_tbl(lp->u.tbl);
865 else if (lp->kind == HTML_IMAGE)
866 free_html_img(lp->u.img);
867 else
868 free_html_text(lp->u.txt);
869 if (root)
870 free(lp);
871}
872
873static htmldata_t *portToTbl(htmltbl_t *, char *);
874
875static htmldata_t *portToCell(htmlcell_t * cp, char *id)
876{
877 htmldata_t *rv;
878
879 if (cp->data.port && strcasecmp(cp->data.port, id) == 0)
880 rv = &cp->data;
881 else if (cp->child.kind == HTML_TBL)
882 rv = portToTbl(cp->child.u.tbl, id);
883 else
884 rv = NULL;
885
886 return rv;
887}
888
889/* See if tp or any of its child cells has the given port id.
890 * If true, return corresponding box.
891 */
892static htmldata_t *portToTbl(htmltbl_t * tp, char *id)
893{
894 htmldata_t *rv;
895 htmlcell_t **cells;
896 htmlcell_t *cp;
897
898 if (tp->data.port && strcasecmp(tp->data.port, id) == 0)
899 rv = &tp->data;
900 else {
901 rv = NULL;
902 cells = tp->cells;
903 while ((cp = *cells++)) {
904 if ((rv = portToCell(cp, id)))
905 break;
906 }
907 }
908
909 return rv;
910}
911
912/* See if edge port corresponds to part of the html node.
913 * If successful, return pointer to port's box.
914 * Else return NULL.
915 */
916boxf *html_port(node_t *n, char *pname, unsigned char *sides){
917 assert(pname != NULL && !streq(pname, ""));
918 htmldata_t *tp;
919 htmllabel_t *lbl = ND_label(n)->u.html;
920 boxf *rv = NULL;
921
922 if (lbl->kind == HTML_TEXT)
923 return NULL;
924
925 tp = portToTbl(lbl->u.tbl, pname);
926 if (tp) {
927 rv = &tp->box;
928 *sides = tp->sides;
929 }
930 return rv;
931
932}
933
934static int size_html_txt(GVC_t *gvc, htmltxt_t * ftxt, htmlenv_t * env)
935{
936 double xsize = 0.0; /* width of text block */
937 double ysize = 0.0; /* height of text block */
938 double lsize; /* height of current line */
939 double mxfsize = 0.0; /* max. font size for the current line */
940 double curbline = 0.0; /* dist. of current base line from top */
941 pointf sz;
942 double width;
943 textspan_t lp;
944 textfont_t tf = {NULL,NULL,NULL,0.0,0,0};
945 double maxoffset, maxlayout, mxysize = 0.0;
946 bool simple = true; // one item per span, same font size/face, no flags
947 double prev_fsize = -1;
948 char* prev_fname = NULL;
949
950 for (size_t i = 0; i < ftxt->nspans; i++) {
951 if (ftxt->spans[i].nitems > 1) {
952 simple = false;
953 break;
954 }
955 if (ftxt->spans[i].items[0].font) {
956 if (ftxt->spans[i].items[0].font->flags) {
957 simple = false;
958 break;
959 }
960 if (ftxt->spans[i].items[0].font->size > 0)
961 tf.size = ftxt->spans[i].items[0].font->size;
962 else
963 tf.size = env->finfo.size;
964 if (ftxt->spans[i].items[0].font->name)
965 tf.name = ftxt->spans[i].items[0].font->name;
966 else
967 tf.name = env->finfo.name;
968 }
969 else {
970 tf.size = env->finfo.size;
971 tf.name = env->finfo.name;
972 }
973 if (i == 0)
974 prev_fsize = tf.size;
975 else if (tf.size != prev_fsize) {
976 simple = false;
977 break;
978 }
979 if (prev_fname == NULL)
980 prev_fname = tf.name;
981 else if (strcmp(tf.name,prev_fname)) {
982 simple = false;
983 break;
984 }
985 }
986 ftxt->simple = simple;
987
988 for (size_t i = 0; i < ftxt->nspans; i++) {
989 width = 0;
990 mxysize = maxoffset = maxlayout = mxfsize = 0;
991 for (size_t j = 0; j < ftxt->spans[i].nitems; j++) {
992 lp.str =
994 env->obj);
995 if (ftxt->spans[i].items[j].font) {
996 if (ftxt->spans[i].items[j].font->flags)
997 tf.flags = ftxt->spans[i].items[j].font->flags;
998 else if (env->finfo.flags > 0)
999 tf.flags = env->finfo.flags;
1000 else
1001 tf.flags = 0;
1002 if (ftxt->spans[i].items[j].font->size > 0)
1003 tf.size = ftxt->spans[i].items[j].font->size;
1004 else
1005 tf.size = env->finfo.size;
1006 if (ftxt->spans[i].items[j].font->name)
1007 tf.name = ftxt->spans[i].items[j].font->name;
1008 else
1009 tf.name = env->finfo.name;
1010 if (ftxt->spans[i].items[j].font->color)
1011 tf.color = ftxt->spans[i].items[j].font->color;
1012 else
1013 tf.color = env->finfo.color;
1014 } else {
1015 tf.size = env->finfo.size;
1016 tf.name = env->finfo.name;
1017 tf.color = env->finfo.color;
1018 tf.flags = env->finfo.flags;
1019 }
1020 lp.font = dtinsert(gvc->textfont_dt, &tf);
1021 sz = textspan_size(gvc, &lp);
1022 free(ftxt->spans[i].items[j].str);
1023 ftxt->spans[i].items[j].str = lp.str;
1024 ftxt->spans[i].items[j].size.x = sz.x;
1025 ftxt->spans[i].items[j].yoffset_layout = lp.yoffset_layout;
1027 ftxt->spans[i].items[j].font = lp.font;
1028 ftxt->spans[i].items[j].layout = lp.layout;
1029 ftxt->spans[i].items[j].free_layout = lp.free_layout;
1030 width += sz.x;
1031 mxfsize = MAX(tf.size, mxfsize);
1032 mxysize = MAX(sz.y, mxysize);
1033 maxoffset = MAX(lp.yoffset_centerline, maxoffset);
1034 maxlayout = MAX(lp.yoffset_layout, maxlayout);
1035 }
1036 /* lsize = mxfsize * LINESPACING; */
1037 ftxt->spans[i].size = width;
1038 /* ysize - curbline is the distance from the previous
1039 * baseline to the bottom of the previous line.
1040 * Then, in the current line, we set the baseline to
1041 * be 5/6 of the max. font size. Thus, lfsize gives the
1042 * distance from the previous baseline to the new one.
1043 */
1044 /* ftxt->spans[i].lfsize = 5*mxfsize/6 + ysize - curbline; */
1045 if (simple) {
1046 lsize = mxysize;
1047 if (i == 0)
1048 /* Place baseline using actual font metrics: centers the pango
1049 * logical rectangle in the cell rather than approximating with
1050 * raw font size. maxlayout = baseline distance from box top
1051 * (yoffset_layout from the text layout engine); maxoffset =
1052 * yoffset_centerline (small above-baseline correction applied
1053 * by the renderer to convert from rendering origin to baseline). */
1054 ftxt->spans[i].lfsize = maxlayout + maxoffset;
1055 else
1056 ftxt->spans[i].lfsize = mxysize;
1057 }
1058 else {
1059 lsize = mxfsize;
1060 if (i == 0)
1061 ftxt->spans[i].lfsize = mxfsize - maxoffset;
1062 else
1063 ftxt->spans[i].lfsize = mxfsize + ysize - curbline - maxoffset;
1064 }
1065 curbline += ftxt->spans[i].lfsize;
1066 xsize = MAX(width, xsize);
1067 ysize += lsize;
1068 }
1069 ftxt->box.UR.x = xsize;
1070 if (ftxt->nspans == 1)
1071 ftxt->box.UR.y = mxysize;
1072 else
1073 ftxt->box.UR.y = ysize;
1074 return 0;
1075}
1076
1077static int size_html_tbl(graph_t * g, htmltbl_t * tbl, htmlcell_t * parent,
1078 htmlenv_t * env);
1079
1080static int size_html_img(htmlimg_t * img, htmlenv_t * env)
1081{
1082 box b;
1083 int rv;
1084
1085 b.LL.x = b.LL.y = 0;
1086 b.UR = gvusershape_size(env->g, img->src);
1087 if (b.UR.x == -1 && b.UR.y == -1) {
1088 rv = 1;
1089 b.UR.x = b.UR.y = 0;
1090 agerrorf("No or improper image file=\"%s\"\n", img->src);
1091 } else {
1092 rv = 0;
1093 GD_has_images(env->g) = true;
1094 }
1095
1096 B2BF(b, img->box);
1097 return rv;
1098}
1099
1100static int
1102 htmlenv_t * env)
1103{
1104 int rv;
1105 pointf sz, child_sz;
1106 int margin;
1107
1108 cp->parent = parent;
1109 if (!(cp->data.flags & PAD_SET)) {
1110 if (parent->data.flags & PAD_SET)
1111 cp->data.pad = parent->data.pad;
1112 else
1114 }
1115 if (!(cp->data.flags & BORDER_SET)) {
1116 if (parent->cellborder >= 0)
1117 cp->data.border = (unsigned char)parent->cellborder;
1118 else if (parent->data.flags & BORDER_SET)
1119 cp->data.border = parent->data.border;
1120 else
1122 }
1123
1124 if (cp->child.kind == HTML_TBL) {
1125 rv = size_html_tbl(g, cp->child.u.tbl, cp, env);
1126 child_sz = cp->child.u.tbl->data.box.UR;
1127 } else if (cp->child.kind == HTML_IMAGE) {
1128 rv = size_html_img(cp->child.u.img, env);
1129 child_sz = cp->child.u.img->box.UR;
1130 } else {
1131 rv = size_html_txt(GD_gvc(g), cp->child.u.txt, env);
1132 child_sz = cp->child.u.txt->box.UR;
1133 }
1134
1135 margin = 2 * (cp->data.pad + cp->data.border);
1136 sz.x = child_sz.x + margin;
1137 sz.y = child_sz.y + margin;
1138
1139 if (cp->data.flags & FIXED_FLAG) {
1140 if (cp->data.width && cp->data.height) {
1141 if ((cp->data.width < sz.x || cp->data.height < sz.y) && cp->child.kind != HTML_IMAGE) {
1142 agwarningf("cell size too small for content\n");
1143 rv = 1;
1144 }
1145 sz.x = sz.y = 0;
1146
1147 } else {
1148 agwarningf(
1149 "fixed cell size with unspecified width or height\n");
1150 rv = 1;
1151 }
1152 }
1153 cp->data.box.UR.x = MAX(sz.x, cp->data.width);
1154 cp->data.box.UR.y = MAX(sz.y, cp->data.height);
1155 return rv;
1156}
1157
1158static uint16_t findCol(PointSet *ps, int row, int col, htmlcell_t *cellp) {
1159 int notFound = 1;
1160 int lastc;
1161 int i, j, c;
1162 int end = cellp->colspan - 1;
1163
1164 while (notFound) {
1165 lastc = col + end;
1166 for (c = lastc; c >= col; c--) {
1167 if (isInPS(ps, c, row))
1168 break;
1169 }
1170 if (c >= col) /* conflict : try column after */
1171 col = c + 1;
1172 else
1173 notFound = 0;
1174 }
1175 for (j = col; j < col + cellp->colspan; j++) {
1176 for (i = row; i < row + cellp->rowspan; i++) {
1177 addPS(ps, j, i);
1178 }
1179 }
1180 assert(col >= 0 && col <= UINT16_MAX);
1181 return (uint16_t)col;
1182}
1183
1184/* Convert parser representation of cells into final form.
1185 * Find column and row positions of cells.
1186 * Recursively size cells.
1187 * Return 1 if problem sizing a cell.
1188 */
1189static int processTbl(graph_t * g, htmltbl_t * tbl, htmlenv_t * env)
1190{
1191 htmlcell_t **cells;
1192 rows_t rows = tbl->rows;
1193 int rv = 0;
1194 size_t n_rows = 0;
1195 size_t n_cols = 0;
1196 PointSet *ps = newPS();
1197 bitarray_t is = bitarray_new((size_t)UINT16_MAX + 1);
1198
1199 size_t cnt = 0;
1200 for (uint16_t r = 0; r < LIST_SIZE(&rows); ++r) {
1201 row_t *rp = LIST_GET(&rows, r);
1202 cnt += LIST_SIZE(&rp->rp);
1203 if (rp->ruled) {
1204 bitarray_set(&is, r + 1, true);
1205 }
1206 }
1207
1208 cells = tbl->cells = gv_calloc(cnt + 1, sizeof(htmlcell_t *));
1209 for (uint16_t r = 0; r < LIST_SIZE(&rows); ++r) {
1210 row_t *rp = LIST_GET(&rows, r);
1211 uint16_t c = 0;
1212 for (size_t i = 0; i < LIST_SIZE(&rp->rp); ++i) {
1213 htmlcell_t *cellp = LIST_GET(&rp->rp, i);
1214 *cells++ = cellp;
1215 rv |= size_html_cell(g, cellp, tbl, env);
1216 c = findCol(ps, r, c, cellp);
1217 cellp->row = r;
1218 cellp->col = c;
1219 c += cellp->colspan;
1220 n_cols = MAX(c, n_cols);
1221 n_rows = MAX(r + cellp->rowspan, n_rows);
1222 if (bitarray_get(is, r + cellp->rowspan))
1223 cellp->hruled = true;
1224 }
1225 }
1226 tbl->row_count = n_rows;
1227 tbl->column_count = n_cols;
1228 LIST_FREE(&rows);
1229 bitarray_reset(&is);
1230 freePS(ps);
1231 return rv;
1232}
1233
1253
1254 // `processTbl` has already done step 1, “1. Calculate the minimum content
1255 // width (MCW) of each cell”, and stored it in `.data.box.UR.x`.
1256
1257 // Allocate space for minimum column widths. Note that we add an extra entry
1258 // to allow later code to make references like `table->widths[col + colspan]`.
1259 assert(table->widths == NULL && "table widths computed twice");
1260 table->widths = gv_calloc(table->column_count + 1, sizeof(double));
1261
1262 // “2. For each column, determine a … minimum column width from the cells that
1263 // span only that column. The minimum is that required by the cell with the
1264 // largest minimum cell width …”. Note that this loop and the following one
1265 // could be fused, but this would make the implementation harder to relate
1266 // back to the specification.
1267 for (htmlcell_t **i = table->cells; *i != NULL; ++i) {
1268 const htmlcell_t cell = **i;
1269 if (cell.colspan > 1) {
1270 continue;
1271 }
1272 assert(cell.col < table->column_count && "out of range cell");
1273 table->widths[cell.col] = fmax(table->widths[cell.col], cell.data.box.UR.x);
1274 }
1275
1276 // “3. For each cell that spans more than one column, increase the minimum
1277 // widths of the columns it spans so that together, they are at least as wide
1278 // as the cell. … If possible, widen all spanned columns by approximately the
1279 // same amount.”
1280 for (htmlcell_t **i = table->cells; *i != NULL; ++i) {
1281 const htmlcell_t cell = **i;
1282 if (cell.colspan == 1) {
1283 continue;
1284 }
1285
1286 // what is the current width of this cell’s column(s)’ span?
1287 double span_width = 0;
1288 assert(cell.col + cell.colspan <= table->column_count &&
1289 "cell spans wider than containing table");
1290 for (size_t j = 0; j < cell.colspan; ++j) {
1291 span_width += table->widths[cell.col + j];
1292 }
1293
1294 // if it is wider than its span (including cell spacing), widen the span
1295 const double spacing = (cell.colspan - 1) * table->data.space;
1296 if (span_width + spacing < cell.data.box.UR.x) {
1297 const double widen_by =
1298 (cell.data.box.UR.x - spacing - span_width) / cell.colspan;
1299 for (size_t j = 0; j < cell.colspan; ++j) {
1300 table->widths[cell.col + j] += widen_by;
1301 }
1302 }
1303 }
1304
1305 // take the minimum width for each column and apply it to its contained cells
1306 for (htmlcell_t **i = table->cells; *i != NULL; ++i) {
1307 htmlcell_t *cell = *i;
1308
1309 // what is the current width of this cell’s column(s)’ span?
1310 double min_width = 0;
1311 assert(cell->col + cell->colspan <= table->column_count &&
1312 "cell spans wider than containing table");
1313 for (size_t j = 0; j < cell->colspan; ++j) {
1314 min_width += table->widths[cell->col + j];
1315 }
1316
1317 // widen the cell if necessary
1318 const double spacing = (cell->colspan - 1) * table->data.space;
1319 cell->data.box.UR.x = fmax(cell->data.box.UR.x, min_width + spacing);
1320 }
1321}
1322
1329
1330 assert(table->heights == NULL && "table heights computed twice");
1331 table->heights = gv_calloc(table->row_count + 1, sizeof(double));
1332
1333 for (htmlcell_t **i = table->cells; *i != NULL; ++i) {
1334 const htmlcell_t cell = **i;
1335 if (cell.rowspan > 1) {
1336 continue;
1337 }
1338 assert(cell.row < table->row_count && "out of range cell");
1339 table->heights[cell.row] =
1340 fmax(table->heights[cell.row], cell.data.box.UR.y);
1341 }
1342
1343 for (htmlcell_t **i = table->cells; *i != NULL; ++i) {
1344 const htmlcell_t cell = **i;
1345 if (cell.rowspan == 1) {
1346 continue;
1347 }
1348
1349 double span_height = 0;
1350 assert(cell.row + cell.rowspan <= table->row_count &&
1351 "cell spans higher than containing table");
1352 for (size_t j = 0; j < cell.rowspan; ++j) {
1353 span_height += table->heights[cell.row + j];
1354 }
1355
1356 const double spacing = (cell.rowspan - 1) * table->data.space;
1357 if (span_height + spacing < cell.data.box.UR.y) {
1358 const double heighten_by =
1359 (cell.data.box.UR.y - spacing - span_height) / cell.rowspan;
1360 for (size_t j = 0; j < cell.rowspan; ++j) {
1361 table->heights[cell.row + j] += heighten_by;
1362 }
1363 }
1364 }
1365
1366 for (htmlcell_t **i = table->cells; *i != NULL; ++i) {
1367 htmlcell_t *cell = *i;
1368
1369 double min_height = 0;
1370 assert(cell->row + cell->rowspan <= table->row_count &&
1371 "cell spans higher than containing table");
1372 for (size_t j = 0; j < cell->rowspan; ++j) {
1373 min_height += table->heights[cell->row + j];
1374 }
1375
1376 const double spacing = (cell->rowspan - 1) * table->data.space;
1377 cell->data.box.UR.y = fmax(cell->data.box.UR.y, min_height + spacing);
1378 }
1379}
1380
1381static void pos_html_tbl(htmltbl_t *, boxf, unsigned char);
1382
1383/* Place image in cell
1384 * storing allowed space handed by parent cell.
1385 * How this space is used is handled in emit_html_img.
1386 */
1387static void pos_html_img(htmlimg_t * cp, boxf pos)
1388{
1389 cp->box = pos;
1390}
1391
1393static void pos_html_txt(htmltxt_t * ftxt, char c)
1394{
1395 for (size_t i = 0; i < ftxt->nspans; i++) {
1396 if (ftxt->spans[i].just == UNSET_ALIGN) /* unset */
1397 ftxt->spans[i].just = c;
1398 }
1399}
1400
1401static void pos_html_cell(htmlcell_t *cp, boxf pos, unsigned char sides) {
1402 double delx, dely;
1403 pointf oldsz;
1404 boxf cbox;
1405
1406 if (!cp->data.pencolor && cp->parent->data.pencolor)
1408
1409 /* If fixed, align cell */
1410 if (cp->data.flags & FIXED_FLAG) {
1411 oldsz = cp->data.box.UR;
1412 delx = pos.UR.x - pos.LL.x - oldsz.x;
1413 if (delx > 0) {
1414 switch (cp->data.flags & HALIGN_MASK) {
1415 case HALIGN_LEFT:
1416 pos.UR.x = pos.LL.x + oldsz.x;
1417 break;
1418 case HALIGN_RIGHT:
1419 pos.UR.x += delx;
1420 pos.LL.x += delx;
1421 break;
1422 default:
1423 pos.LL.x += delx / 2;
1424 pos.UR.x -= delx / 2;
1425 break;
1426 }
1427 }
1428 dely = pos.UR.y - pos.LL.y - oldsz.y;
1429 if (dely > 0) {
1430 switch (cp->data.flags & VALIGN_MASK) {
1431 case VALIGN_BOTTOM:
1432 pos.UR.y = pos.LL.y + oldsz.y;
1433 break;
1434 case VALIGN_TOP:
1435 pos.UR.y += dely;
1436 pos.LL.y += dely;
1437 break;
1438 default:
1439 pos.LL.y += dely / 2;
1440 pos.UR.y -= dely / 2;
1441 break;
1442 }
1443 }
1444 }
1445 cp->data.box = pos;
1446 cp->data.sides = sides;
1447
1448 /* set up child's position */
1449 cbox.LL.x = pos.LL.x + cp->data.border + cp->data.pad;
1450 cbox.LL.y = pos.LL.y + cp->data.border + cp->data.pad;
1451 cbox.UR.x = pos.UR.x - cp->data.border - cp->data.pad;
1452 cbox.UR.y = pos.UR.y - cp->data.border - cp->data.pad;
1453
1454 if (cp->child.kind == HTML_TBL) {
1455 pos_html_tbl(cp->child.u.tbl, cbox, sides);
1456 } else if (cp->child.kind == HTML_IMAGE) {
1457 /* Note that alignment trumps scaling */
1458 oldsz = cp->child.u.img->box.UR;
1459 delx = cbox.UR.x - cbox.LL.x - oldsz.x;
1460 if (delx > 0) {
1461 switch (cp->data.flags & HALIGN_MASK) {
1462 case HALIGN_LEFT:
1463 cbox.UR.x -= delx;
1464 break;
1465 case HALIGN_RIGHT:
1466 cbox.LL.x += delx;
1467 break;
1468 default:
1469 break;
1470 }
1471 }
1472
1473 dely = cbox.UR.y - cbox.LL.y - oldsz.y;
1474 if (dely > 0) {
1475 switch (cp->data.flags & VALIGN_MASK) {
1476 case VALIGN_BOTTOM:
1477 cbox.UR.y -= dely;
1478 break;
1479 case VALIGN_TOP:
1480 cbox.LL.y += dely;
1481 break;
1482 default:
1483 break;
1484 }
1485 }
1486 pos_html_img(cp->child.u.img, cbox);
1487 } else {
1488 char dfltalign;
1489 int af;
1490
1491 oldsz = cp->child.u.txt->box.UR;
1492 delx = cbox.UR.x - cbox.LL.x - oldsz.x;
1493 /* If the cell is larger than the text block and alignment is
1494 * done at textblock level, the text box is shrunk accordingly.
1495 */
1496 if (delx > 0 && (af = (cp->data.flags & HALIGN_MASK)) != HALIGN_TEXT) {
1497 switch (af) {
1498 case HALIGN_LEFT:
1499 cbox.UR.x -= delx;
1500 break;
1501 case HALIGN_RIGHT:
1502 cbox.LL.x += delx;
1503 break;
1504 default:
1505 cbox.LL.x += delx / 2;
1506 cbox.UR.x -= delx / 2;
1507 break;
1508 }
1509 }
1510
1511 dely = cbox.UR.y - cbox.LL.y - oldsz.y;
1512 if (dely > 0) {
1513 switch (cp->data.flags & VALIGN_MASK) {
1514 case VALIGN_BOTTOM:
1515 cbox.UR.y -= dely;
1516 break;
1517 case VALIGN_TOP:
1518 cbox.LL.y += dely;
1519 break;
1520 default:
1521 cbox.LL.y += dely / 2;
1522 cbox.UR.y -= dely / 2;
1523 break;
1524 }
1525 }
1526 cp->child.u.txt->box = cbox;
1527
1528 /* Set default text alignment
1529 */
1530 switch (cp->data.flags & BALIGN_MASK) {
1531 case BALIGN_LEFT:
1532 dfltalign = 'l';
1533 break;
1534 case BALIGN_RIGHT:
1535 dfltalign = 'r';
1536 break;
1537 default:
1538 dfltalign = 'n';
1539 break;
1540 }
1541 pos_html_txt(cp->child.u.txt, dfltalign);
1542 }
1543}
1544
1545/* Position table given its box, then calculate
1546 * the position of each cell. In addition, set the sides
1547 * attribute indicating which external sides of the node
1548 * are accessible to the table.
1549 */
1550static void pos_html_tbl(htmltbl_t *tbl, boxf pos, unsigned char sides) {
1551 int plus;
1552 htmlcell_t **cells = tbl->cells;
1553 htmlcell_t *cp;
1554 boxf cbox;
1555
1556 if (tbl->parent && tbl->parent->data.pencolor && !tbl->data.pencolor)
1557 tbl->data.pencolor = gv_strdup(tbl->parent->data.pencolor);
1558
1559 double oldsz = tbl->data.box.UR.x;
1560 double delx = fmax(pos.UR.x - pos.LL.x - oldsz, 0);
1561 oldsz = tbl->data.box.UR.y;
1562 double dely = fmax(pos.UR.y - pos.LL.y - oldsz, 0);
1563
1564 /* If fixed, align box */
1565 if (tbl->data.flags & FIXED_FLAG) {
1566 if (delx > 0) {
1567 switch (tbl->data.flags & HALIGN_MASK) {
1568 case HALIGN_LEFT:
1569 pos.UR.x = pos.LL.x + oldsz;
1570 break;
1571 case HALIGN_RIGHT:
1572 pos.UR.x += delx;
1573 pos.LL.x += delx;
1574 break;
1575 default:
1576 pos.LL.x += delx / 2;
1577 pos.UR.x -= delx / 2;
1578 break;
1579 }
1580 delx = 0;
1581 }
1582 if (dely > 0) {
1583 switch (tbl->data.flags & VALIGN_MASK) {
1584 case VALIGN_BOTTOM:
1585 pos.UR.y = pos.LL.y + oldsz;
1586 break;
1587 case VALIGN_TOP:
1588 pos.LL.y += dely;
1589 pos.UR.y = pos.LL.y + oldsz;
1590 break;
1591 default:
1592 pos.LL.y += dely / 2;
1593 pos.UR.y -= dely / 2;
1594 break;
1595 }
1596 dely = 0;
1597 }
1598 }
1599
1600 /* change sizes to start positions and distribute extra space */
1601 double x = pos.LL.x + tbl->data.border + tbl->data.space;
1602 assert(tbl->column_count <= DBL_MAX);
1603 double extra = delx / (double)tbl->column_count;
1604 plus = ROUND(delx - extra * (double)tbl->column_count);
1605 for (size_t i = 0; i <= tbl->column_count; i++) {
1606 delx = tbl->widths[i] + extra + ((i <= INT_MAX && (int)i < plus) ? 1 : 0);
1607 tbl->widths[i] = x;
1608 x += delx + tbl->data.space;
1609 }
1610 double y = pos.UR.y - tbl->data.border - tbl->data.space;
1611 assert(tbl->row_count <= DBL_MAX);
1612 extra = dely / (double)tbl->row_count;
1613 plus = ROUND(dely - extra * (double)tbl->row_count);
1614 for (size_t i = 0; i <= tbl->row_count; i++) {
1615 dely = tbl->heights[i] + extra + ((i <= INT_MAX && (int)i < plus) ? 1 : 0);
1616 tbl->heights[i] = y;
1617 y -= dely + tbl->data.space;
1618 }
1619
1620 while ((cp = *cells++)) {
1621 unsigned char mask = 0;
1622 if (sides) {
1623 if (cp->col == 0)
1624 mask |= LEFT;
1625 if (cp->row == 0)
1626 mask |= TOP;
1627 if (cp->col + cp->colspan == tbl->column_count)
1628 mask |= RIGHT;
1629 if (cp->row + cp->rowspan == tbl->row_count)
1630 mask |= BOTTOM;
1631 }
1632 cbox.LL.x = tbl->widths[cp->col];
1633 cbox.UR.x = tbl->widths[cp->col + cp->colspan] - tbl->data.space;
1634 cbox.UR.y = tbl->heights[cp->row];
1635 cbox.LL.y = tbl->heights[cp->row + cp->rowspan] + tbl->data.space;
1636 pos_html_cell(cp, cbox, sides & mask);
1637 }
1638
1639 tbl->data.sides = sides;
1640 tbl->data.box = pos;
1641}
1642
1643/* Determine the size of a table by first determining the
1644 * size of each cell.
1645 */
1646static int
1648 htmlenv_t * env)
1649{
1650 int rv = 0;
1651 static textfont_t savef;
1652
1653 if (tbl->font)
1654 pushFontInfo(env, tbl->font, &savef);
1655 tbl->parent = parent;
1656 rv = processTbl(g, tbl, env);
1657
1658 /* Set up border and spacing */
1659 if (!(tbl->data.flags & SPACE_SET)) {
1661 }
1662 if (!(tbl->data.flags & BORDER_SET)) {
1663 tbl->data.border = DEFAULT_BORDER;
1664 }
1665
1666 set_cell_widths(tbl);
1667 set_cell_heights(tbl);
1668
1669 assert(tbl->column_count <= DBL_MAX);
1670 double wd = ((double)tbl->column_count + 1) * tbl->data.space + 2 * tbl->data.border;
1671 assert(tbl->row_count <= DBL_MAX);
1672 double ht = ((double)tbl->row_count + 1) * tbl->data.space + 2 * tbl->data.border;
1673 for (size_t i = 0; i < tbl->column_count; i++)
1674 wd += tbl->widths[i];
1675 for (size_t i = 0; i < tbl->row_count; i++)
1676 ht += tbl->heights[i];
1677
1678 if (tbl->data.flags & FIXED_FLAG) {
1679 if (tbl->data.width && tbl->data.height) {
1680 if (tbl->data.width < wd || tbl->data.height < ht) {
1681 agwarningf("table size too small for content\n");
1682 rv = 1;
1683 }
1684 wd = 0;
1685 ht = 0;
1686 } else {
1687 agwarningf(
1688 "fixed table size with unspecified width or height\n");
1689 rv = 1;
1690 }
1691 }
1692 tbl->data.box.UR.x = fmax(wd, tbl->data.width);
1693 tbl->data.box.UR.y = fmax(ht, tbl->data.height);
1694
1695 if (tbl->font)
1696 popFontInfo(env, &savef);
1697 return rv;
1698}
1699
1700static char *nameOf(void *obj, agxbuf * xb)
1701{
1702 Agedge_t *ep;
1703 switch (agobjkind(obj)) {
1704 case AGRAPH:
1705 agxbput(xb, agnameof(obj));
1706 break;
1707 case AGNODE:
1708 agxbput(xb, agnameof(obj));
1709 break;
1710 case AGEDGE:
1711 ep = obj;
1712 agxbput(xb, agnameof(agtail(ep)));
1713 agxbput(xb, agnameof(aghead(ep)));
1714 if (agisdirected(agraphof(aghead(ep))))
1715 agxbput(xb, "->");
1716 else
1717 agxbput(xb, "--");
1718 break;
1719 }
1720 return agxbuse(xb);
1721}
1722
1723#ifdef DEBUG
1724void indent(int i)
1725{
1726 while (i--)
1727 fprintf(stderr, " ");
1728}
1729
1730void printBox(boxf b)
1731{
1732 fprintf(stderr, "(%f,%f)(%f,%f)", b.LL.x, b.LL.y, b.UR.x, b.UR.y);
1733}
1734
1735void printImage(htmlimg_t * ip, int ind)
1736{
1737 indent(ind);
1738 fprintf(stderr, "img: %s\n", ip->src);
1739}
1740
1741void printTxt(htmltxt_t * txt, int ind)
1742{
1743 indent(ind);
1744 fprintf(stderr, "txt spans = %" PRISIZE_T " \n", txt->nspans);
1745 for (size_t i = 0; i < txt->nspans; i++) {
1746 indent(ind + 1);
1747 fprintf(stderr, "[%" PRISIZE_T "] %" PRISIZE_T " items\n", i,
1748 txt->spans[i].nitems);
1749 for (size_t j = 0; j < txt->spans[i].nitems; j++) {
1750 indent(ind + 2);
1751 fprintf(stderr, "[%" PRISIZE_T "] (%f,%f) \"%s\" ",
1752 j, txt->spans[i].items[j].size.x,
1753 txt->spans[i].items[j].size.y,
1754 txt->spans[i].items[j].str);
1755 if (txt->spans[i].items[j].font)
1756 fprintf(stderr, "font %s color %s size %f\n",
1757 txt->spans[i].items[j].font->name,
1758 txt->spans[i].items[j].font->color,
1759 txt->spans[i].items[j].font->size);
1760 else
1761 fprintf(stderr, "\n");
1762 }
1763 }
1764}
1765
1766void printData(htmldata_t * dp)
1767{
1768 unsigned char flags = dp->flags;
1769 char c;
1770
1771 fprintf(stderr, "s%d(%d) ", dp->space, (flags & SPACE_SET ? 1 : 0));
1772 fprintf(stderr, "b%d(%d) ", dp->border, (flags & BORDER_SET ? 1 : 0));
1773 fprintf(stderr, "p%d(%d) ", dp->pad, (flags & PAD_SET ? 1 : 0));
1774 switch (flags & HALIGN_MASK) {
1775 case HALIGN_RIGHT:
1776 c = 'r';
1777 break;
1778 case HALIGN_LEFT:
1779 c = 'l';
1780 break;
1781 default:
1782 c = 'n';
1783 break;
1784 }
1785 fprintf(stderr, "%c", c);
1786 switch (flags & VALIGN_MASK) {
1787 case VALIGN_TOP:
1788 c = 't';
1789 break;
1790 case VALIGN_BOTTOM:
1791 c = 'b';
1792 break;
1793 default:
1794 c = 'c';
1795 break;
1796 }
1797 fprintf(stderr, "%c ", c);
1798 printBox(dp->box);
1799}
1800
1801void printTbl(htmltbl_t * tbl, int ind)
1802{
1803 htmlcell_t **cells = tbl->cells;
1804 indent(ind);
1805 fprintf(stderr, "tbl (%p) %" PRISIZE_T " %" PRISIZE_T " ", tbl, tbl->column_count, tbl->row_count);
1806 printData(&tbl->data);
1807 fputs("\n", stderr);
1808 while (*cells)
1809 printCell(*cells++, ind + 1);
1810}
1811
1812static void printCell(htmlcell_t * cp, int ind)
1813{
1814 indent(ind);
1815 fprintf(stderr, "cell %" PRIu16 " %" PRIu16 " %" PRIu16 " %" PRIu16 " ", cp->colspan,
1816 cp->colspan, cp->rowspan, cp->col, cp->row);
1817 printData(&cp->data);
1818 fputs("\n", stderr);
1819 switch (cp->child.kind) {
1820 case HTML_TBL:
1821 printTbl(cp->child.u.tbl, ind + 1);
1822 break;
1823 case HTML_TEXT:
1824 printTxt(cp->child.u.txt, ind + 1);
1825 break;
1826 case HTML_IMAGE:
1827 printImage(cp->child.u.img, ind + 1);
1828 break;
1829 default:
1830 break;
1831 }
1832}
1833
1834void printLbl(htmllabel_t * lbl)
1835{
1836 if (lbl->kind == HTML_TBL)
1837 printTbl(lbl->u.tbl, 0);
1838 else
1839 printTxt(lbl->u.txt, 0);
1840}
1841#endif /* DEBUG */
1842
1843static char *getPenColor(void *obj)
1844{
1845 char *str;
1846
1847 if ((str = agget(obj, "pencolor")) != 0 && str[0])
1848 return str;
1849 else if ((str = agget(obj, "color")) != 0 && str[0])
1850 return str;
1851 else
1852 return NULL;
1853}
1854
1856int make_html_label(void *obj, textlabel_t * lp)
1857{
1858 int rv;
1859 double wd2, ht2;
1860 graph_t *g;
1861 htmllabel_t *lbl;
1862 htmlenv_t env;
1863 char *s;
1864
1865 env.obj = obj;
1866 switch (agobjkind(obj)) {
1867 case AGRAPH:
1868 env.g = ((Agraph_t *) obj)->root;
1869 break;
1870 case AGNODE:
1871 env.g = agraphof(obj);
1872 break;
1873 case AGEDGE:
1874 env.g = agraphof(aghead(((Agedge_t *) obj)));
1875 break;
1876 }
1877 g = env.g->root;
1878
1879 env.finfo.size = lp->fontsize;
1880 env.finfo.name = lp->fontname;
1881 env.finfo.color = lp->fontcolor;
1882 env.finfo.flags = 0;
1883 lbl = parseHTML(lp->text, &rv, &env);
1884 if (!lbl) {
1885 if (rv == 3) {
1886 // fatal error; `parseHTML` will have printed detail of it
1887 lp->html = false;
1888 lp->text = gv_strdup(lp->text);
1889 return rv;
1890 }
1891 /* Parse of label failed; revert to simple text label */
1892 agxbuf xb = {0};
1893 lp->html = false;
1894 lp->text = gv_strdup(nameOf(obj, &xb));
1895 switch (lp->charset) {
1896 case CHAR_LATIN1:
1897 s = latin1ToUTF8(lp->text);
1898 break;
1899 default: /* UTF8 */
1900 s = htmlEntityUTF8(lp->text, env.g);
1901 break;
1902 }
1903 free(lp->text);
1904 lp->text = s;
1905 make_simple_label(GD_gvc(g), lp);
1906 agxbfree(&xb);
1907 return rv;
1908 }
1909
1910 if (lbl->kind == HTML_TBL) {
1911 if (!lbl->u.tbl->data.pencolor && getPenColor(obj))
1912 lbl->u.tbl->data.pencolor = gv_strdup(getPenColor(obj));
1913 rv |= size_html_tbl(g, lbl->u.tbl, NULL, &env);
1914 wd2 = lbl->u.tbl->data.box.UR.x / 2;
1915 ht2 = lbl->u.tbl->data.box.UR.y / 2;
1916 boxf b = {{-wd2, -ht2}, {wd2, ht2}};
1917 pos_html_tbl(lbl->u.tbl, b, BOTTOM | RIGHT | TOP | LEFT);
1918 lp->dimen.x = b.UR.x - b.LL.x;
1919 lp->dimen.y = b.UR.y - b.LL.y;
1920 } else {
1921 rv |= size_html_txt(GD_gvc(g), lbl->u.txt, &env);
1922 wd2 = lbl->u.txt->box.UR.x / 2;
1923 ht2 = lbl->u.txt->box.UR.y / 2;
1924 boxf b = {{-wd2, -ht2}, {wd2, ht2}};
1925 lbl->u.txt->box = b;
1926 lp->dimen.x = b.UR.x - b.LL.x;
1927 lp->dimen.y = b.UR.y - b.LL.y;
1928 }
1929
1930 lp->u.html = lbl;
1931
1932 /* If the label is a table, replace label text because this may
1933 * be used for the title and alt fields in image maps.
1934 */
1935 if (lbl->kind == HTML_TBL) {
1936 free(lp->text);
1937 lp->text = gv_strdup("<TABLE>");
1938 }
1939
1940 return rv;
1941}
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:1260
char * htmlEntityUTF8(char *s, graph_t *g)
Definition utils.c:1183
#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:4330
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:198
char * agget(void *obj, char *name)
Definition attr.c:447
#define agtail(e)
Definition cgraph.h:977
#define aghead(e)
Definition cgraph.h:978
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:178
#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:822
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:1647
static void pos_html_cell(htmlcell_t *cp, boxf pos, unsigned char sides)
Definition htmltable.c:1401
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:1393
static void set_cell_widths(htmltbl_t *table)
Definition htmltable.c:1252
#define RESET(fld)
Definition htmltable.c:419
static char * nameOf(void *obj, agxbuf *xb)
Definition htmltable.c:1700
static void allocObj(GVJ_t *job)
Definition htmltable.c:682
boxf * html_port(node_t *n, char *pname, unsigned char *sides)
Definition htmltable.c:916
static void pos_html_tbl(htmltbl_t *, boxf, unsigned char)
Definition htmltable.c:1550
static double heightOfLbl(htmllabel_t *lp)
Definition htmltable.c:725
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:1856
static void emit_html_img(GVJ_t *job, htmlimg_t *cp, htmlenv_t *env)
Definition htmltable.c:597
static void pos_html_img(htmlimg_t *cp, boxf pos)
Definition htmltable.c:1387
#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:1101
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:1328
static pointf * mkPts(pointf *AF, boxf b, int border)
Definition htmltable.c:229
static void freeObj(GVJ_t *job)
Definition htmltable.c:713
static int processTbl(graph_t *g, htmltbl_t *tbl, htmlenv_t *env)
Definition htmltable.c:1189
static htmldata_t * portToTbl(htmltbl_t *, char *)
Definition htmltable.c:892
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:875
void free_html_text(htmltxt_t *t)
Definition htmltable.c:803
static void free_html_cell(htmlcell_t *cp)
Definition htmltable.c:828
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:934
void free_html_label(htmllabel_t *lp, int root)
Definition htmltable.c:861
static void emit_html_cell(GVJ_t *job, htmlcell_t *cp, htmlenv_t *env)
Definition htmltable.c:624
static uint16_t findCol(PointSet *ps, int row, int col, htmlcell_t *cellp)
Definition htmltable.c:1158
void emit_html_label(GVJ_t *job, htmllabel_t *lp, textlabel_t *tp)
Definition htmltable.c:745
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:792
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:840
static int size_html_img(htmlimg_t *img, htmlenv_t *env)
Definition htmltable.c:1080
static char * getPenColor(void *obj)
Definition htmltable.c:1843
#define PAD_SET
Definition htmltable.h:33
#define BORDER_RIGHT
Definition htmltable.h:40
#define BORDER_TOP
Definition htmltable.h:39
#define HALIGN_TEXT
Definition htmltable.h:28
#define UNSET_ALIGN
Definition htmltable.h:44
#define HALIGN_LEFT
Definition htmltable.h:26
#define VALIGN_BOTTOM
Definition htmltable.h:30
#define BALIGN_MASK
Definition htmltable.h:37
#define BALIGN_RIGHT
Definition htmltable.h:35
#define HALIGN_MASK
Definition htmltable.h:27
#define BALIGN_LEFT
Definition htmltable.h:36
#define BORDER_BOTTOM
Definition htmltable.h:41
@ HTML_TEXT
Definition htmltable.h:101
@ HTML_IMAGE
Definition htmltable.h:101
#define SPACE_SET
Definition htmltable.h:34
#define VALIGN_MASK
Definition htmltable.h:31
#define BORDER_SET
Definition htmltable.h:32
#define BORDER_LEFT
Definition htmltable.h:38
#define BORDER_MASK
Definition htmltable.h:42
#define HALIGN_RIGHT
Definition htmltable.h:25
#define VALIGN_TOP
Definition htmltable.h:29
#define FIXED_FLAG
Definition htmltable.h:24
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:80
#define LIST_FREE(list)
Definition list.h:370
#define LIST_GET(list, index)
Definition list.h:155
#define delta
Definition maze.c:136
static const int table[NTYPES][NTYPES]
Definition mincross.c:1713
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:709
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:57
size_t nitems
Definition htmltable.h:54
textspan_t * items
Definition htmltable.h:53
double size
Definition htmltable.h:56
uint16_t rowspan
Definition htmltable.h:158
htmllabel_t child
Definition htmltable.h:161
uint16_t colspan
Definition htmltable.h:157
htmltbl_t * parent
Definition htmltable.h:162
bool vruled
vertically ruled?
Definition htmltable.h:163
bool hruled
horizontally ruled?
Definition htmltable.h:164
uint16_t col
Definition htmltable.h:159
uint16_t row
Definition htmltable.h:160
htmldata_t data
Definition htmltable.h:156
char * bgcolor
Definition htmltable.h:87
unsigned char border
Definition htmltable.h:91
char * target
Definition htmltable.h:84
char * id
Definition htmltable.h:86
signed char space
Definition htmltable.h:90
unsigned short width
Definition htmltable.h:95
unsigned short height
Definition htmltable.h:96
int gradientangle
Definition htmltable.h:89
char * port
Definition htmltable.h:83
unsigned short flags
Definition htmltable.h:94
unsigned char sides
Definition htmltable.h:93
char * href
Definition htmltable.h:82
unsigned char pad
Definition htmltable.h:92
char * pencolor
Definition htmltable.h:88
htmlstyle_t style
Definition htmltable.h:97
char * title
Definition htmltable.h:85
graph_t * g
Definition htmltable.h:171
textfont_t finfo
Definition htmltable.h:169
pointf pos
Definition htmltable.h:168
bool objid_set
Definition htmltable.h:174
char * objid
Definition htmltable.h:173
char * imgscale
Definition htmltable.h:172
void * obj
Definition htmltable.h:170
char * scale
Definition htmltable.h:70
char * src
Definition htmltable.h:69
boxf box
Definition htmltable.h:68
htmltxt_t * txt
Definition htmltable.h:149
htmltbl_t * tbl
Definition htmltable.h:148
htmlimg_t * img
Definition htmltable.h:150
label_type_t kind
Definition htmltable.h:152
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:78
bool dotted
Definition htmltable.h:77
bool rounded
Definition htmltable.h:75
bool radial
Definition htmltable.h:74
bool invisible
Definition htmltable.h:76
textfont_t * font
Definition htmltable.h:141
size_t row_count
number of rows
Definition htmltable.h:139
double * widths
widths of the columns
Definition htmltable.h:138
htmlcell_t ** cells
Definition htmltable.h:129
htmldata_t data
Definition htmltable.h:125
rows_t rows
cells
Definition htmltable.h:133
htmlcell_t * parent
Definition htmltable.h:128
double * heights
heights of the rows
Definition htmltable.h:137
size_t column_count
number of columns
Definition htmltable.h:140
boxf box
Definition htmltable.h:64
size_t nspans
Definition htmltable.h:62
char simple
Definition htmltable.h:63
htextspan_t * spans
Definition htmltable.h:61
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
graph_t * sg
Definition gvcjob.h:187
union obj_state_s::@66 u
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:113
char * color
Definition textspan.h:55
char * name
Definition textspan.h:54
PostscriptAlias * postscript_alias
Definition textspan.h:56
unsigned int flags
Definition textspan.h:58
double size
Definition textspan.h:57
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:69
char * str
Definition textspan.h:65
char just
'l' 'n' 'r'
Definition textspan.h:71
void * layout
Definition textspan.h:67
pointf size
Definition textspan.h:70
textfont_t * font
Definition textspan.h:66
double yoffset_centerline
Definition textspan.h:69
void(* free_layout)(void *layout)
Definition textspan.h:68
Definition grammar.c:90
#define UNREACHABLE()
Definition unreachable.h:30