/* size_html_cell: */ static int size_html_cell(graph_t *g, htmlcell_t * cp, htmltbl_t * parent, htmlenv_t * env) { int rv; point sz, child_sz; int margin; cp->parent = parent; if (!(cp->data.flags & PAD_SET)) { if (parent->data.flags & PAD_SET) cp->data.pad = parent->data.pad; else cp->data.pad = DEFAULT_CELLPADDING; } if (!(cp->data.flags & BORDER_SET)) { if (parent->cb >= 0) cp->data.border = parent->cb; else if (parent->data.flags & BORDER_SET) cp->data.border = parent->data.border; else cp->data.border = DEFAULT_BORDER; } if (cp->child.kind == HTML_TBL) { rv = size_html_tbl(g, cp->child.u.tbl, cp, env); child_sz = cp->child.u.tbl->data.box.UR; } else if (cp->child.kind == HTML_IMAGE) { rv = size_html_img(cp->child.u.img, env); child_sz = cp->child.u.img->box.UR; } else { rv = size_html_txt(g, cp->child.u.txt, env); child_sz = cp->child.u.txt->box.UR; } margin = 2 * (cp->data.pad + cp->data.border); sz.x = child_sz.x + margin; sz.y = child_sz.y + margin; if (cp->data.flags & FIXED_FLAG) { if (cp->data.width && cp->data.height) { if ((cp->data.width < sz.x) || (cp->data.height < sz.y)) { agerr(AGWARN, "cell size too small for content\n"); rv = 1; } sz.x = sz.y = 0; } else { agerr(AGWARN, "fixed cell size with unspecified width or height\n"); rv = 1; } } cp->data.box.UR.x = MAX(sz.x, cp->data.width); cp->data.box.UR.y = MAX(sz.y, cp->data.height); return rv; }
/* make_html_label: * Return non-zero if problem parsing HTML. In this case, use object name. */ int make_html_label(graph_t *g, textlabel_t * lp, void *obj) { int rv; int wd2, ht2; box box; htmllabel_t *lbl; htmlenv_t env; env.obj = obj; switch (agobjkind(obj)) { case AGGRAPH: env.g = ((Agraph_t *) obj)->root; break; case AGNODE: env.g = ((Agnode_t *) obj)->graph; break; case AGEDGE: env.g = ((Agedge_t *) obj)->head->graph; break; } env.finfo.size = lp->fontsize; env.finfo.name = lp->fontname; env.finfo.color = lp->fontcolor; lbl = parseHTML(lp->text, &rv, GD_charset(env.g)); if (!lbl) { /* Parse of label failed; revert to simple text label */ agxbuf xb; unsigned char buf[SMALLBUF]; agxbinit(&xb, SMALLBUF, buf); lp->html = FALSE; lp->text = strdup(nameOf(obj, &xb)); size_label(env.g, lp); agxbfree(&xb); return rv; } if (lbl->kind == HTML_TBL) { lbl->u.tbl->data.pencolor = getPenColor(obj); rv |= size_html_tbl(g, lbl->u.tbl, NULL, &env); wd2 = (lbl->u.tbl->data.box.UR.x + 1) / 2; ht2 = (lbl->u.tbl->data.box.UR.y + 1) / 2; box = boxof(-wd2, -ht2, wd2, ht2); pos_html_tbl(lbl->u.tbl, box, BOTTOM | RIGHT | TOP | LEFT); lp->dimen.x = box.UR.x - box.LL.x; lp->dimen.y = box.UR.y - box.LL.y; } else { rv |= size_html_txt(g, lbl->u.txt, &env); wd2 = (lbl->u.txt->box.UR.x + 1) / 2; ht2 = (lbl->u.txt->box.UR.y + 1) / 2; box = boxof(-wd2, -ht2, wd2, ht2); lbl->u.txt->box = box; lp->dimen.x = box.UR.x - box.LL.x; lp->dimen.y = box.UR.y - box.LL.y; } lp->u.html = lbl; /* If the label is a table, replace label text because this may * be used for the title and alt fields in image maps. */ if (lbl->kind == HTML_TBL) { free (lp->text); lp->text = strdup ("<TABLE>"); } return rv; }
/* make_html_label: * Return non-zero if problem parsing HTML. In this case, use object name. */ int make_html_label(void *obj, textlabel_t * lp) { int rv; double wd2, ht2; boxf box; graph_t *g; htmllabel_t *lbl; htmlenv_t env; char *s; env.obj = obj; switch (agobjkind(obj)) { #ifdef WITH_CGRAPH case AGRAPH: #else case AGGRAPH: #endif env.g = ((Agraph_t *) obj)->root; break; case AGNODE: env.g = agraphof(((Agnode_t *) obj)); break; case AGEDGE: env.g = agraphof(aghead (((Agedge_t *) obj))); break; } g = env.g->root; env.finfo.size = lp->fontsize; env.finfo.name = lp->fontname; env.finfo.color = lp->fontcolor; lbl = parseHTML(lp->text, &rv, GD_charset(env.g)); if (!lbl) { /* Parse of label failed; revert to simple text label */ agxbuf xb; unsigned char buf[SMALLBUF]; agxbinit(&xb, SMALLBUF, buf); lp->html = FALSE; lp->text = strdup(nameOf(obj, &xb)); switch (lp->charset) { case CHAR_LATIN1: s = latin1ToUTF8(lp->text); break; default: /* UTF8 */ s = htmlEntityUTF8(lp->text, env.g); break; } free(lp->text); lp->text = s; make_simple_label(g, lp); agxbfree(&xb); return rv; } if (lbl->kind == HTML_TBL) { if (! lbl->u.tbl->data.pencolor && getPenColor(obj)) lbl->u.tbl->data.pencolor = strdup(getPenColor(obj)); rv |= size_html_tbl(g, lbl->u.tbl, NULL, &env); wd2 = (lbl->u.tbl->data.box.UR.x + 1) / 2; ht2 = (lbl->u.tbl->data.box.UR.y + 1) / 2; box = boxfof(-wd2, -ht2, wd2, ht2); pos_html_tbl(lbl->u.tbl, box, BOTTOM | RIGHT | TOP | LEFT); lp->dimen.x = box.UR.x - box.LL.x; lp->dimen.y = box.UR.y - box.LL.y; } else { rv |= size_html_txt(g, lbl->u.txt, &env); wd2 = (lbl->u.txt->box.UR.x + 1) / 2; ht2 = (lbl->u.txt->box.UR.y + 1) / 2; box = boxfof(-wd2, -ht2, wd2, ht2); lbl->u.txt->box = box; lp->dimen.x = box.UR.x - box.LL.x; lp->dimen.y = box.UR.y - box.LL.y; } lp->u.html = lbl; /* If the label is a table, replace label text because this may * be used for the title and alt fields in image maps. */ if (lbl->kind == HTML_TBL) { free (lp->text); lp->text = strdup ("<TABLE>"); } return rv; }