Graphviz 13.0.0~dev.20241220.2304
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 <assert.h>
32#include <common/render.h>
33#include <common/htmltable.h>
34#include <common/pointset.h>
35#include <cdt/cdt.h>
36#include <float.h>
37#include <inttypes.h>
38#include <limits.h>
39#include <math.h>
40#include <stddef.h>
41#include <stdbool.h>
42#include <stdint.h>
43#include <stdio.h>
44#include <util/agxbuf.h>
45#include <util/alloc.h>
46#include <util/bitarray.h>
47#include <util/exit.h>
48#include <util/gv_math.h>
49#include <util/prisize_t.h>
50#include <util/strcasecmp.h>
51#include <util/streq.h>
52#include <util/unreachable.h>
53
54#define DEFAULT_BORDER 1
55#define DEFAULT_CELLPADDING 2
56#define DEFAULT_CELLSPACING 2
57
58typedef struct {
59 char *url;
60 char *tooltip;
61 char *target;
62 char *id;
67
68#ifdef DEBUG
69static void printCell(htmlcell_t * cp, int ind);
70#endif
71
72/* Replace current font attributes in env with ones from fp,
73 * storing old attributes in savp. We only deal with attributes
74 * set in env. The attributes are restored via popFontInfo.
75 */
76static void
78{
79 if (env->finfo.name) {
80 if (fp->name) {
81 savp->name = env->finfo.name;
82 env->finfo.name = fp->name;
83 } else
84 savp->name = NULL;
85 }
86 if (env->finfo.color) {
87 if (fp->color) {
88 savp->color = env->finfo.color;
89 env->finfo.color = fp->color;
90 } else
91 savp->color = NULL;
92 }
93 if (env->finfo.size >= 0) {
94 if (fp->size >= 0) {
95 savp->size = env->finfo.size;
96 env->finfo.size = fp->size;
97 } else
98 savp->size = -1.0;
99 }
100}
101
102/* Restore saved font attributes.
103 * Copy only set values.
104 */
105static void popFontInfo(htmlenv_t * env, textfont_t * savp)
106{
107 if (savp->name)
108 env->finfo.name = savp->name;
109 if (savp->color)
110 env->finfo.color = savp->color;
111 if (savp->size >= 0.0)
112 env->finfo.size = savp->size;
113}
114
115static void
116emit_htextspans(GVJ_t *job, size_t nspans, htextspan_t *spans, pointf p,
117 double halfwidth_x, textfont_t finfo, boxf b, int simple)
118{
119 double center_x, left_x, right_x;
120 textspan_t tl;
121 textfont_t tf;
122 pointf p_ = { 0.0, 0.0 };
123 textspan_t *ti;
124
125 center_x = p.x;
126 left_x = center_x - halfwidth_x;
127 right_x = center_x + halfwidth_x;
128
129 /* Initial p is in center of text block; set initial baseline
130 * to top of text block.
131 */
132 p_.y = p.y + (b.UR.y - b.LL.y) / 2.0;
133
135 for (size_t i = 0; i < nspans; i++) {
136 /* set p.x to leftmost point where the line of text begins */
137 switch (spans[i].just) {
138 case 'l':
139 p.x = left_x;
140 break;
141 case 'r':
142 p.x = right_x - spans[i].size;
143 break;
144 default:
145 case 'n':
146 p.x = center_x - spans[i].size / 2.0;
147 break;
148 }
149 p_.y -= spans[i].lfsize; /* move to current base line */
150
151 ti = spans[i].items;
152 for (size_t j = 0; j < spans[i].nitems; j++) {
153 if (ti->font && ti->font->size > 0)
154 tf.size = ti->font->size;
155 else
156 tf.size = finfo.size;
157 if (ti->font && ti->font->name)
158 tf.name = ti->font->name;
159 else
160 tf.name = finfo.name;
161 if (ti->font && ti->font->color)
162 tf.color = ti->font->color;
163 else
164 tf.color = finfo.color;
165 if (ti->font && ti->font->flags)
166 tf.flags = ti->font->flags;
167 else
168 tf.flags = 0;
169
171
172 tl.str = ti->str;
173 tl.font = &tf;
175 if (simple)
177 else
178 tl.yoffset_centerline = 1;
180 tl.layout = ti->layout;
181 tl.size.x = ti->size.x;
182 tl.size.y = spans[i].lfsize;
183 tl.just = 'l';
184
185 p_.x = p.x;
186 gvrender_textspan(job, p_, &tl);
187 p.x += ti->size.x;
188 ti++;
189 }
190 }
191
193}
194
195static void emit_html_txt(GVJ_t * job, htmltxt_t * tp, htmlenv_t * env)
196{
197 double halfwidth_x;
198 pointf p;
199
200 /* make sure that there is something to do */
201 if (tp->nspans < 1)
202 return;
203
204 halfwidth_x = (tp->box.UR.x - tp->box.LL.x) / 2.0;
205 p.x = env->pos.x + (tp->box.UR.x + tp->box.LL.x) / 2.0;
206 p.y = env->pos.y + (tp->box.UR.y + tp->box.LL.y) / 2.0;
207
208 emit_htextspans(job, tp->nspans, tp->spans, p, halfwidth_x, env->finfo,
209 tp->box, tp->simple);
210}
211
212static void doSide(GVJ_t * job, pointf p, double wd, double ht)
213{
214 boxf BF;
215
216 BF.LL = p;
217 BF.UR.x = p.x + wd;
218 BF.UR.y = p.y + ht;
219 gvrender_box(job, BF, 1);
220}
221
222/* Convert boxf into four corner points
223 * If border is > 1, inset the points by half the border.
224 * It is assumed AF is pointf[4], so the data is store there
225 * and AF is returned.
226 */
227static pointf *mkPts(pointf * AF, boxf b, int border)
228{
229 AF[0] = b.LL;
230 AF[2] = b.UR;
231 if (border > 1) {
232 const double delta = border / 2.0;
233 AF[0].x += delta;
234 AF[0].y += delta;
235 AF[2].x -= delta;
236 AF[2].y -= delta;
237 }
238 AF[1].x = AF[2].x;
239 AF[1].y = AF[0].y;
240 AF[3].x = AF[0].x;
241 AF[3].y = AF[2].y;
242
243 return AF;
244}
245
246/* Draw a rectangular border for the box b.
247 * Handles dashed and dotted styles, rounded corners.
248 * Also handles thick lines.
249 * Assume dp->border > 0
250 */
251static void doBorder(GVJ_t * job, htmldata_t * dp, boxf b)
252{
253 pointf AF[7];
254 char *sptr[2];
255 char *color = dp->pencolor ? dp->pencolor : DEFAULT_COLOR;
256 unsigned short sides;
257
259 if (dp->style.dashed || dp->style.dotted) {
260 sptr[0] = sptr[1] = NULL;
261 if (dp->style.dashed)
262 sptr[0] = "dashed";
263 else if (dp->style.dotted)
264 sptr[0] = "dotted";
265 gvrender_set_style(job, sptr);
266 } else
269
270 if (dp->style.rounded)
271 round_corners(job, mkPts(AF, b, dp->border), 4,
272 (graphviz_polygon_style_t){.rounded = true}, 0);
273 else if ((sides = (dp->flags & BORDER_MASK))) {
274 mkPts (AF+1, b, dp->border); /* AF[1-4] has LL=SW,SE,UR=NE,NW */
275 switch (sides) {
276 case BORDER_BOTTOM :
277 gvrender_polyline(job, AF+1, 2);
278 break;
279 case BORDER_RIGHT :
280 gvrender_polyline(job, AF+2, 2);
281 break;
282 case BORDER_TOP :
283 gvrender_polyline(job, AF+3, 2);
284 break;
285 case BORDER_LEFT :
286 AF[0] = AF[4];
287 gvrender_polyline(job, AF, 2);
288 break;
290 gvrender_polyline(job, AF+1, 3);
291 break;
293 gvrender_polyline(job, AF+2, 3);
294 break;
296 AF[5] = AF[1];
297 gvrender_polyline(job, AF+3, 3);
298 break;
300 AF[0] = AF[4];
301 gvrender_polyline(job, AF, 3);
302 break;
304 gvrender_polyline(job, AF+1, 4);
305 break;
307 AF[5] = AF[1];
308 gvrender_polyline(job, AF+2, 4);
309 break;
311 AF[5] = AF[1];
312 AF[6] = AF[2];
313 gvrender_polyline(job, AF+3, 4);
314 break;
316 AF[0] = AF[4];
317 gvrender_polyline(job, AF, 4);
318 break;
320 gvrender_polyline(job, AF+1, 2);
321 gvrender_polyline(job, AF+3, 2);
322 break;
324 AF[0] = AF[4];
325 gvrender_polyline(job, AF, 2);
326 gvrender_polyline(job, AF+2, 2);
327 break;
328 default:
329 break;
330 }
331 } else {
332 if (dp->border > 1) {
333 const double delta = dp->border / 2.0;
334 b.LL.x += delta;
335 b.LL.y += delta;
336 b.UR.x -= delta;
337 b.UR.y -= delta;
338 }
339 gvrender_box(job, b, 0);
340 }
341}
342
343/* Set up fill values from given color; make pen transparent.
344 * Return type of fill required.
345 */
346static int setFill(GVJ_t *job, char *color, int angle, htmlstyle_t style,
347 char *clrs[2]) {
348 int filled;
349 double frac;
350 if (findStopColor(color, clrs, &frac)) {
351 gvrender_set_fillcolor(job, clrs[0]);
352 if (clrs[1])
353 gvrender_set_gradient_vals(job, clrs[1], angle, frac);
354 else
355 gvrender_set_gradient_vals(job, DEFAULT_COLOR, angle, frac);
356 if (style.radial)
357 filled = RGRADIENT;
358 else
359 filled = GRADIENT;
360 } else {
362 filled = FILL;
363 }
364 gvrender_set_pencolor(job, "transparent");
365 return filled;
366}
367
368/* Save current map values.
369 * Initialize fields in job->obj pertaining to anchors.
370 * In particular, this also sets the output rectangle.
371 * If there is something to do,
372 * start the anchor and returns 1.
373 * Otherwise, it returns 0.
374 *
375 * FIX: Should we provide a tooltip if none is set, as is done
376 * for nodes, edges, etc. ?
377 */
378static int
380 htmlmap_data_t * save)
381{
382 obj_state_t *obj = job->obj;
383 int changed;
384 char *id;
385 static int anchorId;
386 agxbuf xb = {0};
387
388 save->url = obj->url;
389 save->tooltip = obj->tooltip;
390 save->target = obj->target;
391 save->id = obj->id;
392 save->explicit_tooltip = obj->explicit_tooltip != 0;
393 id = data->id;
394 if (!id || !*id) { /* no external id, so use the internal one */
395 if (!env->objid) {
396 env->objid = gv_strdup(getObjId(job, obj->u.n, &xb));
397 env->objid_set = true;
398 }
399 agxbprint(&xb, "%s_%d", env->objid, anchorId++);
400 id = agxbuse(&xb);
401 }
402 changed =
403 initMapData(job, NULL, data->href, data->title, data->target, id,
404 obj->u.g);
405 agxbfree(&xb);
406
407 if (changed) {
408 if (obj->url || obj->explicit_tooltip) {
409 emit_map_rect(job, b);
411 obj->url, obj->tooltip, obj->target,
412 obj->id);
413 }
414 }
415 return changed;
416}
417
418#define RESET(fld) \
419 if(obj->fld != save->fld) {free(obj->fld); obj->fld = save->fld;}
420
421/* Pop context pushed by initAnchor.
422 * This is done by ending current anchor, restoring old values and
423 * freeing new.
424 *
425 * NB: We don't save or restore geometric map info. This is because
426 * this preservation of map context is only necessary for SVG-like
427 * systems where graphical items are wrapped in an anchor, and we map
428 * top-down. For ordinary map anchors, this is all done bottom-up, so
429 * the geometric map info at the higher level hasn't been emitted yet.
430 */
431static void endAnchor(GVJ_t * job, htmlmap_data_t * save)
432{
433 obj_state_t *obj = job->obj;
434
435 if (obj->url || obj->explicit_tooltip)
437 RESET(url);
438 RESET(tooltip);
439 RESET(target);
440 RESET(id);
442}
443
444static void emit_html_cell(GVJ_t * job, htmlcell_t * cp, htmlenv_t * env);
445
446/* place vertical and horizontal lines between adjacent cells and
447 * extend the lines to intersect the rounded table boundary
448 */
449static void
450emit_html_rules(GVJ_t * job, htmlcell_t * cp, htmlenv_t * env, char *color, htmlcell_t* nextc)
451{
452 pointf rule_pt;
453 double rule_length;
454 double base;
455 boxf pts = cp->data.box;
456 pointf pos = env->pos;
457
458 if (!color)
462
463 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->u.n.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->u.n.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 htextspan_t *tl;
806 textspan_t *ti;
807
808 if (!t)
809 return;
810
811 tl = t->spans;
812 for (size_t i = 0; i < t->nspans; i++) {
813 ti = tl->items;
814 for (size_t j = 0; j < tl->nitems; j++) {
815 free(ti->str);
816 if (ti->layout && ti->free_layout)
817 ti->free_layout(ti->layout);
818 ti++;
819 }
820 tl++;
821 }
822 free(t->spans);
823 free(t);
824}
825
826static void free_html_img(htmlimg_t * ip)
827{
828 free(ip->src);
829 free(ip);
830}
831
832static void free_html_cell(htmlcell_t * cp)
833{
834 free_html_label(&cp->child, 0);
835 free_html_data(&cp->data);
836 free(cp);
837}
838
839/* If tbl->row_count is `SIZE_MAX`, table is in initial state from
840 * HTML parse, with data stored in u.p. Once run through processTbl,
841 * data is stored in u.n and tbl->row_count is < `SIZE_MAX`.
842 */
843static void free_html_tbl(htmltbl_t * tbl)
844{
845 htmlcell_t **cells;
846
847 if (tbl->row_count == SIZE_MAX) { // raw, parsed table
848 rows_free(&tbl->u.p.rows);
849 } else {
850 cells = tbl->u.n.cells;
851
852 free(tbl->heights);
853 free(tbl->widths);
854 while (*cells) {
855 free_html_cell(*cells);
856 cells++;
857 }
858 free(tbl->u.n.cells);
859 }
860 free_html_data(&tbl->data);
861 free(tbl);
862}
863
864void free_html_label(htmllabel_t * lp, int root)
865{
866 if (lp->kind == HTML_TBL)
867 free_html_tbl(lp->u.tbl);
868 else if (lp->kind == HTML_IMAGE)
869 free_html_img(lp->u.img);
870 else
871 free_html_text(lp->u.txt);
872 if (root)
873 free(lp);
874}
875
876static htmldata_t *portToTbl(htmltbl_t *, char *);
877
878static htmldata_t *portToCell(htmlcell_t * cp, char *id)
879{
880 htmldata_t *rv;
881
882 if (cp->data.port && strcasecmp(cp->data.port, id) == 0)
883 rv = &cp->data;
884 else if (cp->child.kind == HTML_TBL)
885 rv = portToTbl(cp->child.u.tbl, id);
886 else
887 rv = NULL;
888
889 return rv;
890}
891
892/* See if tp or any of its child cells has the given port id.
893 * If true, return corresponding box.
894 */
895static htmldata_t *portToTbl(htmltbl_t * tp, char *id)
896{
897 htmldata_t *rv;
898 htmlcell_t **cells;
899 htmlcell_t *cp;
900
901 if (tp->data.port && strcasecmp(tp->data.port, id) == 0)
902 rv = &tp->data;
903 else {
904 rv = NULL;
905 cells = tp->u.n.cells;
906 while ((cp = *cells++)) {
907 if ((rv = portToCell(cp, id)))
908 break;
909 }
910 }
911
912 return rv;
913}
914
915/* See if edge port corresponds to part of the html node.
916 * If successful, return pointer to port's box.
917 * Else return NULL.
918 */
919boxf *html_port(node_t *n, char *pname, unsigned char *sides){
920 assert(pname != NULL && !streq(pname, ""));
921 htmldata_t *tp;
922 htmllabel_t *lbl = ND_label(n)->u.html;
923 boxf *rv = NULL;
924
925 if (lbl->kind == HTML_TEXT)
926 return NULL;
927
928 tp = portToTbl(lbl->u.tbl, pname);
929 if (tp) {
930 rv = &tp->box;
931 *sides = tp->sides;
932 }
933 return rv;
934
935}
936
937static int size_html_txt(GVC_t *gvc, htmltxt_t * ftxt, htmlenv_t * env)
938{
939 double xsize = 0.0; /* width of text block */
940 double ysize = 0.0; /* height of text block */
941 double lsize; /* height of current line */
942 double mxfsize = 0.0; /* max. font size for the current line */
943 double curbline = 0.0; /* dist. of current base line from top */
944 pointf sz;
945 double width;
946 textspan_t lp;
947 textfont_t tf = {NULL,NULL,NULL,0.0,0,0};
948 double maxoffset, mxysize = 0.0;
949 bool simple = true; // one item per span, same font size/face, no flags
950 double prev_fsize = -1;
951 char* prev_fname = NULL;
952
953 for (size_t i = 0; i < ftxt->nspans; i++) {
954 if (ftxt->spans[i].nitems > 1) {
955 simple = false;
956 break;
957 }
958 if (ftxt->spans[i].items[0].font) {
959 if (ftxt->spans[i].items[0].font->flags) {
960 simple = false;
961 break;
962 }
963 if (ftxt->spans[i].items[0].font->size > 0)
964 tf.size = ftxt->spans[i].items[0].font->size;
965 else
966 tf.size = env->finfo.size;
967 if (ftxt->spans[i].items[0].font->name)
968 tf.name = ftxt->spans[i].items[0].font->name;
969 else
970 tf.name = env->finfo.name;
971 }
972 else {
973 tf.size = env->finfo.size;
974 tf.name = env->finfo.name;
975 }
976 if (i == 0)
977 prev_fsize = tf.size;
978 else if (tf.size != prev_fsize) {
979 simple = false;
980 break;
981 }
982 if (prev_fname == NULL)
983 prev_fname = tf.name;
984 else if (strcmp(tf.name,prev_fname)) {
985 simple = false;
986 break;
987 }
988 }
989 ftxt->simple = simple;
990
991 for (size_t i = 0; i < ftxt->nspans; i++) {
992 width = 0;
993 mxysize = maxoffset = mxfsize = 0;
994 for (size_t j = 0; j < ftxt->spans[i].nitems; j++) {
995 lp.str =
997 env->obj);
998 if (ftxt->spans[i].items[j].font) {
999 if (ftxt->spans[i].items[j].font->flags)
1000 tf.flags = ftxt->spans[i].items[j].font->flags;
1001 else if (env->finfo.flags > 0)
1002 tf.flags = env->finfo.flags;
1003 else
1004 tf.flags = 0;
1005 if (ftxt->spans[i].items[j].font->size > 0)
1006 tf.size = ftxt->spans[i].items[j].font->size;
1007 else
1008 tf.size = env->finfo.size;
1009 if (ftxt->spans[i].items[j].font->name)
1010 tf.name = ftxt->spans[i].items[j].font->name;
1011 else
1012 tf.name = env->finfo.name;
1013 if (ftxt->spans[i].items[j].font->color)
1014 tf.color = ftxt->spans[i].items[j].font->color;
1015 else
1016 tf.color = env->finfo.color;
1017 } else {
1018 tf.size = env->finfo.size;
1019 tf.name = env->finfo.name;
1020 tf.color = env->finfo.color;
1021 tf.flags = env->finfo.flags;
1022 }
1023 lp.font = dtinsert(gvc->textfont_dt, &tf);
1024 sz = textspan_size(gvc, &lp);
1025 free(ftxt->spans[i].items[j].str);
1026 ftxt->spans[i].items[j].str = lp.str;
1027 ftxt->spans[i].items[j].size.x = sz.x;
1028 ftxt->spans[i].items[j].yoffset_layout = lp.yoffset_layout;
1030 ftxt->spans[i].items[j].font = lp.font;
1031 ftxt->spans[i].items[j].layout = lp.layout;
1032 ftxt->spans[i].items[j].free_layout = lp.free_layout;
1033 width += sz.x;
1034 mxfsize = MAX(tf.size, mxfsize);
1035 mxysize = MAX(sz.y, mxysize);
1036 maxoffset = MAX(lp.yoffset_centerline, maxoffset);
1037 }
1038 /* lsize = mxfsize * LINESPACING; */
1039 ftxt->spans[i].size = width;
1040 /* ysize - curbline is the distance from the previous
1041 * baseline to the bottom of the previous line.
1042 * Then, in the current line, we set the baseline to
1043 * be 5/6 of the max. font size. Thus, lfsize gives the
1044 * distance from the previous baseline to the new one.
1045 */
1046 /* ftxt->spans[i].lfsize = 5*mxfsize/6 + ysize - curbline; */
1047 if (simple) {
1048 lsize = mxysize;
1049 if (i == 0)
1050 ftxt->spans[i].lfsize = mxfsize;
1051 else
1052 ftxt->spans[i].lfsize = mxysize;
1053 }
1054 else {
1055 lsize = mxfsize;
1056 if (i == 0)
1057 ftxt->spans[i].lfsize = mxfsize - maxoffset;
1058 else
1059 ftxt->spans[i].lfsize = mxfsize + ysize - curbline - maxoffset;
1060 }
1061 curbline += ftxt->spans[i].lfsize;
1062 xsize = MAX(width, xsize);
1063 ysize += lsize;
1064 }
1065 ftxt->box.UR.x = xsize;
1066 if (ftxt->nspans == 1)
1067 ftxt->box.UR.y = mxysize;
1068 else
1069 ftxt->box.UR.y = ysize;
1070 return 0;
1071}
1072
1073static int size_html_tbl(graph_t * g, htmltbl_t * tbl, htmlcell_t * parent,
1074 htmlenv_t * env);
1075
1076static int size_html_img(htmlimg_t * img, htmlenv_t * env)
1077{
1078 box b;
1079 int rv;
1080
1081 b.LL.x = b.LL.y = 0;
1082 b.UR = gvusershape_size(env->g, img->src);
1083 if (b.UR.x == -1 && b.UR.y == -1) {
1084 rv = 1;
1085 b.UR.x = b.UR.y = 0;
1086 agerrorf("No or improper image file=\"%s\"\n", img->src);
1087 } else {
1088 rv = 0;
1089 GD_has_images(env->g) = true;
1090 }
1091
1092 B2BF(b, img->box);
1093 return rv;
1094}
1095
1096static int
1098 htmlenv_t * env)
1099{
1100 int rv;
1101 pointf sz, child_sz;
1102 int margin;
1103
1104 cp->parent = parent;
1105 if (!(cp->data.flags & PAD_SET)) {
1106 if (parent->data.flags & PAD_SET)
1107 cp->data.pad = parent->data.pad;
1108 else
1110 }
1111 if (!(cp->data.flags & BORDER_SET)) {
1112 if (parent->cellborder >= 0)
1113 cp->data.border = (unsigned char)parent->cellborder;
1114 else if (parent->data.flags & BORDER_SET)
1115 cp->data.border = parent->data.border;
1116 else
1118 }
1119
1120 if (cp->child.kind == HTML_TBL) {
1121 rv = size_html_tbl(g, cp->child.u.tbl, cp, env);
1122 child_sz = cp->child.u.tbl->data.box.UR;
1123 } else if (cp->child.kind == HTML_IMAGE) {
1124 rv = size_html_img(cp->child.u.img, env);
1125 child_sz = cp->child.u.img->box.UR;
1126 } else {
1127 rv = size_html_txt(GD_gvc(g), cp->child.u.txt, env);
1128 child_sz = cp->child.u.txt->box.UR;
1129 }
1130
1131 margin = 2 * (cp->data.pad + cp->data.border);
1132 sz.x = child_sz.x + margin;
1133 sz.y = child_sz.y + margin;
1134
1135 if (cp->data.flags & FIXED_FLAG) {
1136 if (cp->data.width && cp->data.height) {
1137 if ((cp->data.width < sz.x || cp->data.height < sz.y) && cp->child.kind != HTML_IMAGE) {
1138 agwarningf("cell size too small for content\n");
1139 rv = 1;
1140 }
1141 sz.x = sz.y = 0;
1142
1143 } else {
1144 agwarningf(
1145 "fixed cell size with unspecified width or height\n");
1146 rv = 1;
1147 }
1148 }
1149 cp->data.box.UR.x = MAX(sz.x, cp->data.width);
1150 cp->data.box.UR.y = MAX(sz.y, cp->data.height);
1151 return rv;
1152}
1153
1154static uint16_t findCol(PointSet *ps, int row, int col, htmlcell_t *cellp) {
1155 int notFound = 1;
1156 int lastc;
1157 int i, j, c;
1158 int end = cellp->colspan - 1;
1159
1160 while (notFound) {
1161 lastc = col + end;
1162 for (c = lastc; c >= col; c--) {
1163 if (isInPS(ps, c, row))
1164 break;
1165 }
1166 if (c >= col) /* conflict : try column after */
1167 col = c + 1;
1168 else
1169 notFound = 0;
1170 }
1171 for (j = col; j < col + cellp->colspan; j++) {
1172 for (i = row; i < row + cellp->rowspan; i++) {
1173 addPS(ps, j, i);
1174 }
1175 }
1176 assert(col >= 0 && col <= UINT16_MAX);
1177 return (uint16_t)col;
1178}
1179
1180/* Convert parser representation of cells into final form.
1181 * Find column and row positions of cells.
1182 * Recursively size cells.
1183 * Return 1 if problem sizing a cell.
1184 */
1185static int processTbl(graph_t * g, htmltbl_t * tbl, htmlenv_t * env)
1186{
1187 htmlcell_t **cells;
1188 rows_t rows = tbl->u.p.rows;
1189 int rv = 0;
1190 size_t n_rows = 0;
1191 size_t n_cols = 0;
1192 PointSet *ps = newPS();
1193 bitarray_t is = bitarray_new((size_t)UINT16_MAX + 1);
1194
1195 size_t cnt = 0;
1196 for (uint16_t r = 0; r < rows_size(&rows); ++r) {
1197 row_t *rp = rows_get(&rows, r);
1198 cnt += cells_size(&rp->rp);
1199 if (rp->ruled) {
1200 bitarray_set(&is, r + 1, true);
1201 }
1202 }
1203
1204 cells = tbl->u.n.cells = gv_calloc(cnt + 1, sizeof(htmlcell_t *));
1205 for (uint16_t r = 0; r < rows_size(&rows); ++r) {
1206 row_t *rp = rows_get(&rows, r);
1207 uint16_t c = 0;
1208 for (size_t i = 0; i < cells_size(&rp->rp); ++i) {
1209 htmlcell_t *cellp = cells_get(&rp->rp, i);
1210 *cells++ = cellp;
1211 rv |= size_html_cell(g, cellp, tbl, env);
1212 c = findCol(ps, r, c, cellp);
1213 cellp->row = r;
1214 cellp->col = c;
1215 c += cellp->colspan;
1216 n_cols = MAX(c, n_cols);
1217 n_rows = MAX(r + cellp->rowspan, n_rows);
1218 if (bitarray_get(is, r + cellp->rowspan))
1219 cellp->hruled = true;
1220 }
1221 }
1222 tbl->row_count = n_rows;
1223 tbl->column_count = n_cols;
1224 rows_free(&rows);
1225 bitarray_reset(&is);
1226 freePS(ps);
1227 return rv;
1228}
1229
1249
1250 // `processTbl` has already done step 1, “1. Calculate the minimum content
1251 // width (MCW) of each cell”, and stored it in `.data.box.UR.x`.
1252
1253 // Allocate space for minimum column widths. Note that we add an extra entry
1254 // to allow later code to make references like `table->widths[col + colspan]`.
1255 assert(table->widths == NULL && "table widths computed twice");
1256 table->widths = gv_calloc(table->column_count + 1, sizeof(double));
1257
1258 // “2. For each column, determine a … minimum column width from the cells that
1259 // span only that column. The minimum is that required by the cell with the
1260 // largest minimum cell width …”. Note that this loop and the following one
1261 // could be fused, but this would make the implementation harder to relate
1262 // back to the specification.
1263 for (htmlcell_t **i = table->u.n.cells; *i != NULL; ++i) {
1264 const htmlcell_t cell = **i;
1265 if (cell.colspan > 1) {
1266 continue;
1267 }
1268 assert(cell.col < table->column_count && "out of range cell");
1269 table->widths[cell.col] = fmax(table->widths[cell.col], cell.data.box.UR.x);
1270 }
1271
1272 // “3. For each cell that spans more than one column, increase the minimum
1273 // widths of the columns it spans so that together, they are at least as wide
1274 // as the cell. … If possible, widen all spanned columns by approximately the
1275 // same amount.”
1276 for (htmlcell_t **i = table->u.n.cells; *i != NULL; ++i) {
1277 const htmlcell_t cell = **i;
1278 if (cell.colspan == 1) {
1279 continue;
1280 }
1281
1282 // what is the current width of this cell’s column(s)’ span?
1283 double span_width = 0;
1284 assert(cell.col + cell.colspan <= table->column_count &&
1285 "cell spans wider than containing table");
1286 for (size_t j = 0; j < cell.colspan; ++j) {
1287 span_width += table->widths[cell.col + j];
1288 }
1289
1290 // if it is wider than its span (including cell spacing), widen the span
1291 const double spacing = (cell.colspan - 1) * table->data.space;
1292 if (span_width + spacing < cell.data.box.UR.x) {
1293 const double widen_by =
1294 (cell.data.box.UR.x - spacing - span_width) / cell.colspan;
1295 for (size_t j = 0; j < cell.colspan; ++j) {
1296 table->widths[cell.col + j] += widen_by;
1297 }
1298 }
1299 }
1300
1301 // take the minimum width for each column and apply it to its contained cells
1302 for (htmlcell_t **i = table->u.n.cells; *i != NULL; ++i) {
1303 htmlcell_t *cell = *i;
1304
1305 // what is the current width of this cell’s column(s)’ span?
1306 double min_width = 0;
1307 assert(cell->col + cell->colspan <= table->column_count &&
1308 "cell spans wider than containing table");
1309 for (size_t j = 0; j < cell->colspan; ++j) {
1310 min_width += table->widths[cell->col + j];
1311 }
1312
1313 // widen the cell if necessary
1314 const double spacing = (cell->colspan - 1) * table->data.space;
1315 cell->data.box.UR.x = fmax(cell->data.box.UR.x, min_width + spacing);
1316 }
1317}
1318
1325
1326 assert(table->heights == NULL && "table heights computed twice");
1327 table->heights = gv_calloc(table->row_count + 1, sizeof(double));
1328
1329 for (htmlcell_t **i = table->u.n.cells; *i != NULL; ++i) {
1330 const htmlcell_t cell = **i;
1331 if (cell.rowspan > 1) {
1332 continue;
1333 }
1334 assert(cell.row < table->row_count && "out of range cell");
1335 table->heights[cell.row] =
1336 fmax(table->heights[cell.row], cell.data.box.UR.y);
1337 }
1338
1339 for (htmlcell_t **i = table->u.n.cells; *i != NULL; ++i) {
1340 const htmlcell_t cell = **i;
1341 if (cell.rowspan == 1) {
1342 continue;
1343 }
1344
1345 double span_height = 0;
1346 assert(cell.row + cell.rowspan <= table->row_count &&
1347 "cell spans higher than containing table");
1348 for (size_t j = 0; j < cell.rowspan; ++j) {
1349 span_height += table->heights[cell.row + j];
1350 }
1351
1352 const double spacing = (cell.rowspan - 1) * table->data.space;
1353 if (span_height + spacing < cell.data.box.UR.y) {
1354 const double heighten_by =
1355 (cell.data.box.UR.y - spacing - span_height) / cell.rowspan;
1356 for (size_t j = 0; j < cell.rowspan; ++j) {
1357 table->heights[cell.row + j] += heighten_by;
1358 }
1359 }
1360 }
1361
1362 for (htmlcell_t **i = table->u.n.cells; *i != NULL; ++i) {
1363 htmlcell_t *cell = *i;
1364
1365 double min_height = 0;
1366 assert(cell->row + cell->rowspan <= table->row_count &&
1367 "cell spans higher than containing table");
1368 for (size_t j = 0; j < cell->rowspan; ++j) {
1369 min_height += table->heights[cell->row + j];
1370 }
1371
1372 const double spacing = (cell->rowspan - 1) * table->data.space;
1373 cell->data.box.UR.y = fmax(cell->data.box.UR.y, min_height + spacing);
1374 }
1375}
1376
1377static void pos_html_tbl(htmltbl_t *, boxf, unsigned char);
1378
1379/* Place image in cell
1380 * storing allowed space handed by parent cell.
1381 * How this space is used is handled in emit_html_img.
1382 */
1383static void pos_html_img(htmlimg_t * cp, boxf pos)
1384{
1385 cp->box = pos;
1386}
1387
1389static void pos_html_txt(htmltxt_t * ftxt, char c)
1390{
1391 for (size_t i = 0; i < ftxt->nspans; i++) {
1392 if (ftxt->spans[i].just == UNSET_ALIGN) /* unset */
1393 ftxt->spans[i].just = c;
1394 }
1395}
1396
1397static void pos_html_cell(htmlcell_t *cp, boxf pos, unsigned char sides) {
1398 double delx, dely;
1399 pointf oldsz;
1400 boxf cbox;
1401
1402 if (!cp->data.pencolor && cp->parent->data.pencolor)
1404
1405 /* If fixed, align cell */
1406 if (cp->data.flags & FIXED_FLAG) {
1407 oldsz = cp->data.box.UR;
1408 delx = pos.UR.x - pos.LL.x - oldsz.x;
1409 if (delx > 0) {
1410 switch (cp->data.flags & HALIGN_MASK) {
1411 case HALIGN_LEFT:
1412 pos.UR.x = pos.LL.x + oldsz.x;
1413 break;
1414 case HALIGN_RIGHT:
1415 pos.UR.x += delx;
1416 pos.LL.x += delx;
1417 break;
1418 default:
1419 pos.LL.x += delx / 2;
1420 pos.UR.x -= delx / 2;
1421 break;
1422 }
1423 }
1424 dely = pos.UR.y - pos.LL.y - oldsz.y;
1425 if (dely > 0) {
1426 switch (cp->data.flags & VALIGN_MASK) {
1427 case VALIGN_BOTTOM:
1428 pos.UR.y = pos.LL.y + oldsz.y;
1429 break;
1430 case VALIGN_TOP:
1431 pos.UR.y += dely;
1432 pos.LL.y += dely;
1433 break;
1434 default:
1435 pos.LL.y += dely / 2;
1436 pos.UR.y -= dely / 2;
1437 break;
1438 }
1439 }
1440 }
1441 cp->data.box = pos;
1442 cp->data.sides = sides;
1443
1444 /* set up child's position */
1445 cbox.LL.x = pos.LL.x + cp->data.border + cp->data.pad;
1446 cbox.LL.y = pos.LL.y + cp->data.border + cp->data.pad;
1447 cbox.UR.x = pos.UR.x - cp->data.border - cp->data.pad;
1448 cbox.UR.y = pos.UR.y - cp->data.border - cp->data.pad;
1449
1450 if (cp->child.kind == HTML_TBL) {
1451 pos_html_tbl(cp->child.u.tbl, cbox, sides);
1452 } else if (cp->child.kind == HTML_IMAGE) {
1453 /* Note that alignment trumps scaling */
1454 oldsz = cp->child.u.img->box.UR;
1455 delx = cbox.UR.x - cbox.LL.x - oldsz.x;
1456 if (delx > 0) {
1457 switch (cp->data.flags & HALIGN_MASK) {
1458 case HALIGN_LEFT:
1459 cbox.UR.x -= delx;
1460 break;
1461 case HALIGN_RIGHT:
1462 cbox.LL.x += delx;
1463 break;
1464 default:
1465 break;
1466 }
1467 }
1468
1469 dely = cbox.UR.y - cbox.LL.y - oldsz.y;
1470 if (dely > 0) {
1471 switch (cp->data.flags & VALIGN_MASK) {
1472 case VALIGN_BOTTOM:
1473 cbox.UR.y -= dely;
1474 break;
1475 case VALIGN_TOP:
1476 cbox.LL.y += dely;
1477 break;
1478 default:
1479 break;
1480 }
1481 }
1482 pos_html_img(cp->child.u.img, cbox);
1483 } else {
1484 char dfltalign;
1485 int af;
1486
1487 oldsz = cp->child.u.txt->box.UR;
1488 delx = cbox.UR.x - cbox.LL.x - oldsz.x;
1489 /* If the cell is larger than the text block and alignment is
1490 * done at textblock level, the text box is shrunk accordingly.
1491 */
1492 if (delx > 0 && (af = (cp->data.flags & HALIGN_MASK)) != HALIGN_TEXT) {
1493 switch (af) {
1494 case HALIGN_LEFT:
1495 cbox.UR.x -= delx;
1496 break;
1497 case HALIGN_RIGHT:
1498 cbox.LL.x += delx;
1499 break;
1500 default:
1501 cbox.LL.x += delx / 2;
1502 cbox.UR.x -= delx / 2;
1503 break;
1504 }
1505 }
1506
1507 dely = cbox.UR.y - cbox.LL.y - oldsz.y;
1508 if (dely > 0) {
1509 switch (cp->data.flags & VALIGN_MASK) {
1510 case VALIGN_BOTTOM:
1511 cbox.UR.y -= dely;
1512 break;
1513 case VALIGN_TOP:
1514 cbox.LL.y += dely;
1515 break;
1516 default:
1517 cbox.LL.y += dely / 2;
1518 cbox.UR.y -= dely / 2;
1519 break;
1520 }
1521 }
1522 cp->child.u.txt->box = cbox;
1523
1524 /* Set default text alignment
1525 */
1526 switch (cp->data.flags & BALIGN_MASK) {
1527 case BALIGN_LEFT:
1528 dfltalign = 'l';
1529 break;
1530 case BALIGN_RIGHT:
1531 dfltalign = 'r';
1532 break;
1533 default:
1534 dfltalign = 'n';
1535 break;
1536 }
1537 pos_html_txt(cp->child.u.txt, dfltalign);
1538 }
1539}
1540
1541/* Position table given its box, then calculate
1542 * the position of each cell. In addition, set the sides
1543 * attribute indicating which external sides of the node
1544 * are accessible to the table.
1545 */
1546static void pos_html_tbl(htmltbl_t *tbl, boxf pos, unsigned char sides) {
1547 int plus;
1548 htmlcell_t **cells = tbl->u.n.cells;
1549 htmlcell_t *cp;
1550 boxf cbox;
1551
1552 if (tbl->u.n.parent && tbl->u.n.parent->data.pencolor
1553 && !tbl->data.pencolor)
1554 tbl->data.pencolor = gv_strdup(tbl->u.n.parent->data.pencolor);
1555
1556 double oldsz = tbl->data.box.UR.x;
1557 double delx = fmax(pos.UR.x - pos.LL.x - oldsz, 0);
1558 oldsz = tbl->data.box.UR.y;
1559 double dely = fmax(pos.UR.y - pos.LL.y - oldsz, 0);
1560
1561 /* If fixed, align box */
1562 if (tbl->data.flags & FIXED_FLAG) {
1563 if (delx > 0) {
1564 switch (tbl->data.flags & HALIGN_MASK) {
1565 case HALIGN_LEFT:
1566 pos.UR.x = pos.LL.x + oldsz;
1567 break;
1568 case HALIGN_RIGHT:
1569 pos.UR.x += delx;
1570 pos.LL.x += delx;
1571 break;
1572 default:
1573 pos.LL.x += delx / 2;
1574 pos.UR.x -= delx / 2;
1575 break;
1576 }
1577 delx = 0;
1578 }
1579 if (dely > 0) {
1580 switch (tbl->data.flags & VALIGN_MASK) {
1581 case VALIGN_BOTTOM:
1582 pos.UR.y = pos.LL.y + oldsz;
1583 break;
1584 case VALIGN_TOP:
1585 pos.LL.y += dely;
1586 pos.UR.y = pos.LL.y + oldsz;
1587 break;
1588 default:
1589 pos.LL.y += dely / 2;
1590 pos.UR.y -= dely / 2;
1591 break;
1592 }
1593 dely = 0;
1594 }
1595 }
1596
1597 /* change sizes to start positions and distribute extra space */
1598 double x = pos.LL.x + tbl->data.border + tbl->data.space;
1599 assert(tbl->column_count <= DBL_MAX);
1600 double extra = delx / (double)tbl->column_count;
1601 plus = ROUND(delx - extra * (double)tbl->column_count);
1602 for (size_t i = 0; i <= tbl->column_count; i++) {
1603 delx = tbl->widths[i] + extra + ((i <= INT_MAX && (int)i < plus) ? 1 : 0);
1604 tbl->widths[i] = x;
1605 x += delx + tbl->data.space;
1606 }
1607 double y = pos.UR.y - tbl->data.border - tbl->data.space;
1608 assert(tbl->row_count <= DBL_MAX);
1609 extra = dely / (double)tbl->row_count;
1610 plus = ROUND(dely - extra * (double)tbl->row_count);
1611 for (size_t i = 0; i <= tbl->row_count; i++) {
1612 dely = tbl->heights[i] + extra + ((i <= INT_MAX && (int)i < plus) ? 1 : 0);
1613 tbl->heights[i] = y;
1614 y -= dely + tbl->data.space;
1615 }
1616
1617 while ((cp = *cells++)) {
1618 unsigned char mask = 0;
1619 if (sides) {
1620 if (cp->col == 0)
1621 mask |= LEFT;
1622 if (cp->row == 0)
1623 mask |= TOP;
1624 if (cp->col + cp->colspan == tbl->column_count)
1625 mask |= RIGHT;
1626 if (cp->row + cp->rowspan == tbl->row_count)
1627 mask |= BOTTOM;
1628 }
1629 cbox.LL.x = tbl->widths[cp->col];
1630 cbox.UR.x = tbl->widths[cp->col + cp->colspan] - tbl->data.space;
1631 cbox.UR.y = tbl->heights[cp->row];
1632 cbox.LL.y = tbl->heights[cp->row + cp->rowspan] + tbl->data.space;
1633 pos_html_cell(cp, cbox, sides & mask);
1634 }
1635
1636 tbl->data.sides = sides;
1637 tbl->data.box = pos;
1638}
1639
1640/* Determine the size of a table by first determining the
1641 * size of each cell.
1642 */
1643static int
1645 htmlenv_t * env)
1646{
1647 int rv = 0;
1648 static textfont_t savef;
1649
1650 if (tbl->font)
1651 pushFontInfo(env, tbl->font, &savef);
1652 tbl->u.n.parent = parent;
1653 rv = processTbl(g, tbl, env);
1654
1655 /* Set up border and spacing */
1656 if (!(tbl->data.flags & SPACE_SET)) {
1658 }
1659 if (!(tbl->data.flags & BORDER_SET)) {
1660 tbl->data.border = DEFAULT_BORDER;
1661 }
1662
1663 set_cell_widths(tbl);
1664 set_cell_heights(tbl);
1665
1666 assert(tbl->column_count <= DBL_MAX);
1667 double wd = ((double)tbl->column_count + 1) * tbl->data.space + 2 * tbl->data.border;
1668 assert(tbl->row_count <= DBL_MAX);
1669 double ht = ((double)tbl->row_count + 1) * tbl->data.space + 2 * tbl->data.border;
1670 for (size_t i = 0; i < tbl->column_count; i++)
1671 wd += tbl->widths[i];
1672 for (size_t i = 0; i < tbl->row_count; i++)
1673 ht += tbl->heights[i];
1674
1675 if (tbl->data.flags & FIXED_FLAG) {
1676 if (tbl->data.width && tbl->data.height) {
1677 if (tbl->data.width < wd || tbl->data.height < ht) {
1678 agwarningf("table size too small for content\n");
1679 rv = 1;
1680 }
1681 wd = 0;
1682 ht = 0;
1683 } else {
1684 agwarningf(
1685 "fixed table size with unspecified width or height\n");
1686 rv = 1;
1687 }
1688 }
1689 tbl->data.box.UR.x = fmax(wd, tbl->data.width);
1690 tbl->data.box.UR.y = fmax(ht, tbl->data.height);
1691
1692 if (tbl->font)
1693 popFontInfo(env, &savef);
1694 return rv;
1695}
1696
1697static char *nameOf(void *obj, agxbuf * xb)
1698{
1699 Agedge_t *ep;
1700 switch (agobjkind(obj)) {
1701 case AGRAPH:
1702 agxbput(xb, agnameof(obj));
1703 break;
1704 case AGNODE:
1705 agxbput(xb, agnameof(obj));
1706 break;
1707 case AGEDGE:
1708 ep = obj;
1709 agxbput(xb, agnameof(agtail(ep)));
1710 agxbput(xb, agnameof(aghead(ep)));
1711 if (agisdirected(agraphof(aghead(ep))))
1712 agxbput(xb, "->");
1713 else
1714 agxbput(xb, "--");
1715 break;
1716 }
1717 return agxbuse(xb);
1718}
1719
1720#ifdef DEBUG
1721void indent(int i)
1722{
1723 while (i--)
1724 fprintf(stderr, " ");
1725}
1726
1727void printBox(boxf b)
1728{
1729 fprintf(stderr, "(%f,%f)(%f,%f)", b.LL.x, b.LL.y, b.UR.x, b.UR.y);
1730}
1731
1732void printImage(htmlimg_t * ip, int ind)
1733{
1734 indent(ind);
1735 fprintf(stderr, "img: %s\n", ip->src);
1736}
1737
1738void printTxt(htmltxt_t * txt, int ind)
1739{
1740 indent(ind);
1741 fprintf(stderr, "txt spans = %" PRISIZE_T " \n", txt->nspans);
1742 for (size_t i = 0; i < txt->nspans; i++) {
1743 indent(ind + 1);
1744 fprintf(stderr, "[%" PRISIZE_T "] %" PRISIZE_T " items\n", i,
1745 txt->spans[i].nitems);
1746 for (size_t j = 0; j < txt->spans[i].nitems; j++) {
1747 indent(ind + 2);
1748 fprintf(stderr, "[%" PRISIZE_T "] (%f,%f) \"%s\" ",
1749 j, txt->spans[i].items[j].size.x,
1750 txt->spans[i].items[j].size.y,
1751 txt->spans[i].items[j].str);
1752 if (txt->spans[i].items[j].font)
1753 fprintf(stderr, "font %s color %s size %f\n",
1754 txt->spans[i].items[j].font->name,
1755 txt->spans[i].items[j].font->color,
1756 txt->spans[i].items[j].font->size);
1757 else
1758 fprintf(stderr, "\n");
1759 }
1760 }
1761}
1762
1763void printData(htmldata_t * dp)
1764{
1765 unsigned char flags = dp->flags;
1766 char c;
1767
1768 fprintf(stderr, "s%d(%d) ", dp->space, (flags & SPACE_SET ? 1 : 0));
1769 fprintf(stderr, "b%d(%d) ", dp->border, (flags & BORDER_SET ? 1 : 0));
1770 fprintf(stderr, "p%d(%d) ", dp->pad, (flags & PAD_SET ? 1 : 0));
1771 switch (flags & HALIGN_MASK) {
1772 case HALIGN_RIGHT:
1773 c = 'r';
1774 break;
1775 case HALIGN_LEFT:
1776 c = 'l';
1777 break;
1778 default:
1779 c = 'n';
1780 break;
1781 }
1782 fprintf(stderr, "%c", c);
1783 switch (flags & VALIGN_MASK) {
1784 case VALIGN_TOP:
1785 c = 't';
1786 break;
1787 case VALIGN_BOTTOM:
1788 c = 'b';
1789 break;
1790 default:
1791 c = 'c';
1792 break;
1793 }
1794 fprintf(stderr, "%c ", c);
1795 printBox(dp->box);
1796}
1797
1798void printTbl(htmltbl_t * tbl, int ind)
1799{
1800 htmlcell_t **cells = tbl->u.n.cells;
1801 indent(ind);
1802 fprintf(stderr, "tbl (%p) %" PRISIZE_T " %" PRISIZE_T " ", tbl, tbl->column_count, tbl->row_count);
1803 printData(&tbl->data);
1804 fputs("\n", stderr);
1805 while (*cells)
1806 printCell(*cells++, ind + 1);
1807}
1808
1809static void printCell(htmlcell_t * cp, int ind)
1810{
1811 indent(ind);
1812 fprintf(stderr, "cell %" PRIu16 " %" PRIu16 " %" PRIu16 " %" PRIu16 " ", cp->colspan,
1813 cp->colspan, cp->rowspan, cp->col, cp->row);
1814 printData(&cp->data);
1815 fputs("\n", stderr);
1816 switch (cp->child.kind) {
1817 case HTML_TBL:
1818 printTbl(cp->child.u.tbl, ind + 1);
1819 break;
1820 case HTML_TEXT:
1821 printTxt(cp->child.u.txt, ind + 1);
1822 break;
1823 case HTML_IMAGE:
1824 printImage(cp->child.u.img, ind + 1);
1825 break;
1826 default:
1827 break;
1828 }
1829}
1830
1831void printLbl(htmllabel_t * lbl)
1832{
1833 if (lbl->kind == HTML_TBL)
1834 printTbl(lbl->u.tbl, 0);
1835 else
1836 printTxt(lbl->u.txt, 0);
1837}
1838#endif /* DEBUG */
1839
1840static char *getPenColor(void *obj)
1841{
1842 char *str;
1843
1844 if ((str = agget(obj, "pencolor")) != 0 && str[0])
1845 return str;
1846 else if ((str = agget(obj, "color")) != 0 && str[0])
1847 return str;
1848 else
1849 return NULL;
1850}
1851
1853int make_html_label(void *obj, textlabel_t * lp)
1854{
1855 int rv;
1856 double wd2, ht2;
1857 graph_t *g;
1858 htmllabel_t *lbl;
1859 htmlenv_t env;
1860 char *s;
1861
1862 env.obj = obj;
1863 switch (agobjkind(obj)) {
1864 case AGRAPH:
1865 env.g = ((Agraph_t *) obj)->root;
1866 break;
1867 case AGNODE:
1868 env.g = agraphof(obj);
1869 break;
1870 case AGEDGE:
1871 env.g = agraphof(aghead(((Agedge_t *) obj)));
1872 break;
1873 }
1874 g = env.g->root;
1875
1876 env.finfo.size = lp->fontsize;
1877 env.finfo.name = lp->fontname;
1878 env.finfo.color = lp->fontcolor;
1879 env.finfo.flags = 0;
1880 lbl = parseHTML(lp->text, &rv, &env);
1881 if (!lbl) {
1882 if (rv == 3) {
1883 // fatal error; `parseHTML` will have printed detail of it
1884 lp->html = false;
1885 lp->text = gv_strdup(lp->text);
1886 return rv;
1887 }
1888 /* Parse of label failed; revert to simple text label */
1889 agxbuf xb = {0};
1890 lp->html = false;
1891 lp->text = gv_strdup(nameOf(obj, &xb));
1892 switch (lp->charset) {
1893 case CHAR_LATIN1:
1894 s = latin1ToUTF8(lp->text);
1895 break;
1896 default: /* UTF8 */
1897 s = htmlEntityUTF8(lp->text, env.g);
1898 break;
1899 }
1900 free(lp->text);
1901 lp->text = s;
1902 make_simple_label(GD_gvc(g), lp);
1903 agxbfree(&xb);
1904 return rv;
1905 }
1906
1907 if (lbl->kind == HTML_TBL) {
1908 if (!lbl->u.tbl->data.pencolor && getPenColor(obj))
1909 lbl->u.tbl->data.pencolor = gv_strdup(getPenColor(obj));
1910 rv |= size_html_tbl(g, lbl->u.tbl, NULL, &env);
1911 wd2 = lbl->u.tbl->data.box.UR.x / 2;
1912 ht2 = lbl->u.tbl->data.box.UR.y / 2;
1913 boxf b = {{-wd2, -ht2}, {wd2, ht2}};
1914 pos_html_tbl(lbl->u.tbl, b, BOTTOM | RIGHT | TOP | LEFT);
1915 lp->dimen.x = b.UR.x - b.LL.x;
1916 lp->dimen.y = b.UR.y - b.LL.y;
1917 } else {
1918 rv |= size_html_txt(GD_gvc(g), lbl->u.txt, &env);
1919 wd2 = lbl->u.txt->box.UR.x / 2;
1920 ht2 = lbl->u.txt->box.UR.y / 2;
1921 boxf b = {{-wd2, -ht2}, {wd2, ht2}};
1922 lbl->u.txt->box = b;
1923 lp->dimen.x = b.UR.x - b.LL.x;
1924 lp->dimen.y = b.UR.y - b.LL.y;
1925 }
1926
1927 lp->u.html = lbl;
1928
1929 /* If the label is a table, replace label text because this may
1930 * be used for the title and alt fields in image maps.
1931 */
1932 if (lbl->kind == HTML_TBL) {
1933 free(lp->text);
1934 lp->text = gv_strdup("<TABLE>");
1935 }
1936
1937 return rv;
1938}
static void agxbfree(agxbuf *xb)
free any malloced resources
Definition agxbuf.h:78
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
Definition agxbuf.h:234
static WUR char * agxbuse(agxbuf *xb)
Definition agxbuf.h:307
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
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:46
static bool bitarray_get(bitarray_t self, size_t index)
get the value of the given element
Definition bitarray.h:64
static void bitarray_set(bitarray_t *self, size_t index, bool value)
set or clear the value of the given element
Definition bitarray.h:79
static void bitarray_reset(bitarray_t *self)
free underlying resources and leave a bit array empty
Definition bitarray.h:98
container data types API
#define dtinsert(d, o)
Definition cdt.h:185
#define parent(i)
Definition closest.c:80
char * latin1ToUTF8(char *s)
Converts string from Latin1 encoding to utf8. Also translates HTML entities.
Definition utils.c:1271
char * htmlEntityUTF8(char *s, graph_t *g)
Definition utils.c:1192
#define CHAR_LATIN1
Definition const.h:197
#define LEFT
Definition const.h:120
#define DEFAULT_COLOR
Definition const.h:48
#define RIGHT
Definition const.h:118
#define GRADIENT
Definition const.h:232
#define BOTTOM
Definition const.h:117
#define RGRADIENT
Definition const.h:233
#define TOP
Definition const.h:119
int initMapData(GVJ_t *job, char *lbl, char *url, char *tooltip, char *target, char *id, void *gobj)
Definition emit.c:154
bool findStopColor(const char *colorlist, char *clrs[2], double *frac)
Definition emit.c:4019
obj_state_t * push_obj_state(GVJ_t *job)
Definition emit.c:98
void emit_map_rect(GVJ_t *job, boxf b)
Definition emit.c:634
void pop_obj_state(GVJ_t *job)
Definition emit.c:122
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:201
#define A(n, t)
Definition expr.h:76
static int flags
Definition gc.c:61
#define B2BF(b, bf)
Definition geom.h:75
static pointf scale(double c, pointf p)
Definition geomprocs.h:130
#define FILL
Definition gmlparse.c:361
void free(void *)
#define SIZE_MAX
Definition gmlscan.c:347
#define UINT16_MAX
Definition gmlscan.c:340
node NULL
Definition grammar.y:163
simple
Definition grammar.y:156
static int cnt(Dict_t *d, Dtlink_t **set)
Definition graph.c:210
char * agget(void *obj, char *name)
Definition attr.c:439
#define agtail(e)
Definition cgraph.h:880
#define aghead(e)
Definition cgraph.h:881
void agwarningf(const char *fmt,...)
Definition agerror.c:173
void agerrorf(const char *fmt,...)
Definition agerror.c:165
int agisdirected(Agraph_t *g)
Definition graph.c:190
#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:185
char * agnameof(void *)
returns a string descriptor for the object.
Definition id.c:158
int agobjkind(void *obj)
Definition obj.c:252
@ 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:23
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:129
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:2379
textitem scanner parser str
Definition htmlparse.y:224
$2 u p rows
Definition htmlparse.y:298
rows row
Definition htmlparse.y:326
cell HTML_TBL
Definition htmlparse.y:338
static void free_html_img(htmlimg_t *ip)
Definition htmltable.c:826
static void endAnchor(GVJ_t *job, htmlmap_data_t *save)
Definition htmltable.c:431
static int size_html_tbl(graph_t *g, htmltbl_t *tbl, htmlcell_t *parent, htmlenv_t *env)
Definition htmltable.c:1644
static void pos_html_cell(htmlcell_t *cp, boxf pos, unsigned char sides)
Definition htmltable.c:1397
static void pushFontInfo(htmlenv_t *env, textfont_t *fp, textfont_t *savp)
Definition htmltable.c:77
static void pos_html_txt(htmltxt_t *ftxt, char c)
Set default alignment.
Definition htmltable.c:1389
static void set_cell_widths(htmltbl_t *table)
Definition htmltable.c:1248
#define RESET(fld)
Definition htmltable.c:418
static char * nameOf(void *obj, agxbuf *xb)
Definition htmltable.c:1697
static void allocObj(GVJ_t *job)
Definition htmltable.c:682
boxf * html_port(node_t *n, char *pname, unsigned char *sides)
Definition htmltable.c:919
static void pos_html_tbl(htmltbl_t *, boxf, unsigned char)
Definition htmltable.c:1546
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:1853
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:1383
#define DEFAULT_CELLSPACING
Definition htmltable.c:56
#define DEFAULT_CELLPADDING
Definition htmltable.c:55
static int size_html_cell(graph_t *g, htmlcell_t *cp, htmltbl_t *parent, htmlenv_t *env)
Definition htmltable.c:1097
static void doBorder(GVJ_t *job, htmldata_t *dp, boxf b)
Definition htmltable.c:251
static void set_cell_heights(htmltbl_t *table)
Definition htmltable.c:1324
static pointf * mkPts(pointf *AF, boxf b, int border)
Definition htmltable.c:227
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:1185
static htmldata_t * portToTbl(htmltbl_t *, char *)
Definition htmltable.c:895
static void emit_html_txt(GVJ_t *job, htmltxt_t *tp, htmlenv_t *env)
Definition htmltable.c:195
static htmldata_t * portToCell(htmlcell_t *cp, char *id)
Definition htmltable.c:878
void free_html_text(htmltxt_t *t)
Definition htmltable.c:803
static void free_html_cell(htmlcell_t *cp)
Definition htmltable.c:832
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:105
static int size_html_txt(GVC_t *gvc, htmltxt_t *ftxt, htmlenv_t *env)
Definition htmltable.c:937
void free_html_label(htmllabel_t *lp, int root)
Definition htmltable.c:864
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:1154
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:116
static int initAnchor(GVJ_t *job, htmlenv_t *env, htmldata_t *data, boxf b, htmlmap_data_t *save)
Definition htmltable.c:379
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:346
static void doSide(GVJ_t *job, pointf p, double wd, double ht)
Definition htmltable.c:212
#define DEFAULT_BORDER
Definition htmltable.c:54
static void emit_html_rules(GVJ_t *job, htmlcell_t *cp, htmlenv_t *env, char *color, htmlcell_t *nextc)
Definition htmltable.c:450
static void free_html_tbl(htmltbl_t *tbl)
Definition htmltable.c:843
static int size_html_img(htmlimg_t *img, htmlenv_t *env)
Definition htmltable.c:1076
static char * getPenColor(void *obj)
Definition htmltable.c:1840
#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)
Definition labels.c:385
void make_simple_label(GVC_t *gvc, textlabel_t *lp)
Definition labels.c:54
static int * ps
Definition lu.c:51
#define delta
Definition maze.c:133
static int table[NTYPES][NTYPES]
Definition mincross.c:1755
void addPS(PointSet *ps, double x, double y)
Definition pointset.c:71
PointSet * newPS(void)
Definition pointset.c:53
void freePS(PointSet *ps)
Definition pointset.c:58
int isInPS(PointSet *ps, double x, double y)
Definition pointset.c:84
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:213
#define PRISIZE_T
PRIu64 alike for printing size_t
Definition prisize_t.h:27
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:707
pointf textspan_size(GVC_t *gvc, textspan_t *span)
Estimates size of a textspan, in points.
Definition textspan.c:79
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:425
Agraph_t * root
subgraphs - ancestors
Definition cgraph.h:434
Definition gvcint.h:80
char ** defaultlinestyle
Definition gvcint.h:148
Dt_t * textfont_dt
Definition gvcint.h:107
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 legal.c:50
Definition cdt.h:100
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: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: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: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:70
char * src
Definition htmltable.h:69
boxf box
Definition htmltable.h:68
htmltxt_t * txt
Definition htmltable.h:151
union htmllabel_t::@76 u
htmltbl_t * tbl
Definition htmltable.h:150
htmlimg_t * img
Definition htmltable.h:152
label_type_t kind
Definition htmltable.h:154
bool explicit_tooltip
Definition htmltable.c:63
char * tooltip
Definition htmltable.c:60
char * target
Definition htmltable.c:61
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
union htmltbl_t::@73 u
textfont_t * font
Definition htmltable.h:143
size_t row_count
number of rows
Definition htmltable.h:141
struct htmltbl_t::@73::@75 p
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
struct htmltbl_t::@73::@74 n
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
union obj_state_s::@89 u
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
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
cells_t rp
Definition htmltable.h:114
bool ruled
Definition htmltable.h:115
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
union textlabel_t::@78 u
int charset
Definition types.h:108
char valign
Definition types.h:122
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:93
#define UNREACHABLE()
Definition unreachable.h:30
#define MAX(a, b)
Definition write.c:31