From fb633b44c26d41913fd24a3e01d62aa4c90e744a Mon Sep 17 00:00:00 2001 From: ellson Date: Tue, 19 Aug 2008 04:11:35 +0000 Subject: [PATCH] migrate towards more sharing of label code some floating point conversion --- lib/common/emit.c | 13 ++-- lib/common/htmlparse.y | 138 ---------------------------------- lib/common/htmltable.c | 23 +++++- lib/common/htmltable.h | 10 +-- lib/common/input.c | 36 +++------ lib/common/labels.c | 95 +++++++++++++++-------- lib/common/postproc.c | 24 ------ lib/common/render.h | 6 +- lib/common/shapes.c | 9 +-- lib/common/types.h | 7 +- lib/common/utils.c | 101 ++++++------------------- lib/dotgen/position.c | 14 ++-- lib/neatogen/poly.c | 2 + plugin/pango/gvrender_pango.c | 7 +- 14 files changed, 138 insertions(+), 347 deletions(-) diff --git a/lib/common/emit.c b/lib/common/emit.c index 6e753741e..08a3efd5c 100644 --- a/lib/common/emit.c +++ b/lib/common/emit.c @@ -716,6 +716,7 @@ static void init_job_pagination(GVJ_t * job, graph_t *g) } /* initial window size */ +//fprintf(stderr,"page=%g,%g dpi=%g,%g zoom=%g\n", pageSize.x, pageSize.y, job->dpi.x, job->dpi.y, job->zoom); job->width = ROUND((pageSize.x + 2*margin.x) * job->dpi.x / POINTS_PER_INCH); job->height = ROUND((pageSize.y + 2*margin.y) * job->dpi.y / POINTS_PER_INCH); @@ -1969,8 +1970,8 @@ static void init_gvc(GVC_t * gvc, graph_t * g) /* pagesize */ gvc->graph_sets_pageSize = FALSE; - P2PF(GD_drawing(g)->page, gvc->pageSize); - if ((GD_drawing(g)->page.x > 0) && (GD_drawing(g)->page.y > 0)) + gvc->pageSize = GD_drawing(g)->page; + if ((GD_drawing(g)->page.x > 0.001) && (GD_drawing(g)->page.y > 0.001)) gvc->graph_sets_pageSize = TRUE; /* rotation */ @@ -2079,9 +2080,7 @@ static void init_job_viewport(GVJ_t * job, graph_t * g) Agnode_t *n; char *str, *nodename = NULL, *junk = NULL; -// assert((gvc->bb.LL.x == 0) && (gvc->bb.LL.y == 0)); - P2PF(gvc->bb.UR, UR); - + UR = gvc->bb.UR; job->bb.LL.x = -job->pad.x; /* job->bb is bb of graph and padding - graph units */ job->bb.LL.y = -job->pad.y; job->bb.UR.x = UR.x + job->pad.x; @@ -2094,8 +2093,8 @@ static void init_job_viewport(GVJ_t * job, graph_t * g) /* start with "natural" size of layout */ Z = 1.0; - if (GD_drawing(g)->size.x > 0) { /* graph size was given by user... */ - P2PF(GD_drawing(g)->size, size); + if (GD_drawing(g)->size.x > 0.001 && GD_drawing(g)->size.y > 0.001) { /* graph size was given by user... */ + size = GD_drawing(g)->size; if ((size.x < sz.x) || (size.y < sz.y) /* drawing is too big (in either axi) ... */ || ((GD_drawing(g)->filled) /* or ratio=filled requested and ... */ && (size.x > sz.x) && (size.y > sz.y))) /* drawing is too small (in both axis) ... */ diff --git a/lib/common/htmlparse.y b/lib/common/htmlparse.y index 851b8a69e..43719fad6 100644 --- a/lib/common/htmlparse.y +++ b/lib/common/htmlparse.y @@ -30,9 +30,6 @@ typedef struct sfont_t { static struct { htmllabel_t* lbl; /* Generated label */ htmltbl_t* tblstack; /* Stack of tables maintained during parsing */ -#ifdef OLD - Dt_t* paras; /* Dictionary for paras of text */ -#endif Dt_t* fitemList; /* Dictionary for font text items */ Dt_t* fparaList; agxbuf* str; /* Buffer for text */ @@ -116,14 +113,6 @@ static Dtdisc_t cellDisc = { NIL(Dtevent_f) }; -#ifdef OLD -typedef struct { - Dtlink_t link; - const char* s; /* para of text */ - char c; /* alignment of text */ -} sitem; -#endif - typedef struct { Dtlink_t link; textitem_t ti; @@ -134,14 +123,6 @@ typedef struct { htextpara_t lp; } fpara; -#ifdef OLD -static void -free_sitem(Dt_t* d, sitem* p,Dtdisc_t* ds) -{ - free (p); -} -#endif - static void free_fitem(Dt_t* d, fitem* p, Dtdisc_t* ds) { @@ -170,20 +151,6 @@ free_fpara(Dt_t* d, fpara* p, Dtdisc_t* ds) free (p); } -#ifdef OLD -static Dtdisc_t strDisc = { - offsetof(sitem,s), - sizeof(char*), - offsetof(sitem,link), - NIL(Dtmake_f), - (Dtfree_f)free_sitem, - NIL(Dtcompar_f), - NIL(Dthash_f), - NIL(Dtmemory_f), - NIL(Dtevent_f) -}; -#endif - static Dtdisc_t fstrDisc = { 0, 0, @@ -209,17 +176,6 @@ static Dtdisc_t fparaDisc = { NIL(Dtevent_f) }; -#ifdef OLD -static void -appendStrList(const char* p,int v) -{ - sitem* sp = NEW(sitem); - sp->s = strdup(p); - sp->c = v; - dtinsert (HTMLstate.paras, sp); -} -#endif - /* dupFont: */ static htmlfont_t * @@ -271,50 +227,6 @@ appendFLineList (int v) dtinsert(HTMLstate.fparaList, ln); } -#ifdef OLD -/* mkText: - * Construct htmltxt_t from list of paras in HTMLstate.paras. - * lastl is a last, odd para with no
, so we use n by default. - */ -static htmltxt_t* -mkText (const char* lastl) -{ - int cnt; - textpara_t* lp; - sitem* sp; - Dt_t* paras = HTMLstate.paras; - htmltxt_t* tp = NEW(htmltxt_t); - - if (paras) - cnt = dtsize (paras); - else - cnt = 0; - if (lastl) cnt++; - - tp->nparas = cnt; - tp->para = N_NEW(cnt+1,textpara_t); - - lp = tp->para; - if (paras) { - sp = (sitem*)dtflatten(paras); - for (; sp; sp = (sitem*)dtlink(paras,(Dtlink_t*)sp)) { - lp->str = (char*)(sp->s); - lp->xshow = NULL; - lp->just = sp->c; - lp++; - } - } - if (lastl) { - lp->str = strdup(lastl); - lp->just = '\0'; - } - - if (paras) dtclear (paras); - - return tp; -} -#endif - static htmltxt_t* mkText(void) { @@ -376,46 +288,6 @@ static void setCell (htmlcell_t* cp, void* obj, int kind) cp->child.u.tbl = (htmltbl_t*)obj; } -#ifdef OLD -/* setFont: - * Copy in font attributes. fp has the new attributes. - * curf corresponds to the current font info of the object. - * From the parser, we are moving out from the object. Since - * the inmost value is the one used, we only use a new value - * if the attribute has not already been assigned. - */ -static htmlfont_t* setFont (htmlfont_t* fp, htmlfont_t* curf) -{ - if (curf) { - if (curf->size < 0.0) curf->size = fp->size; - if (!curf->color) curf->color = fp->color; - else if (fp->color) free (fp->color); - if (!curf->name) curf->name = fp->name; - else if (fp->name) free (fp->name); - free (fp); - return curf; - } - else - return fp; -} - -/* fontText: - * Attach font information to text. - */ -static void fontText (htmlfont_t* fp, htmltxt_t* cp) -{ - cp->font = setFont (fp, cp->font); -} - -/* fontTable: - * Attach font information to table. - */ -static void fontTable (htmlfont_t* fp, htmltbl_t* cp) -{ - cp->font = setFont (fp, cp->font); -} -#endif - /* mkLabel: * Create label, given body and type. */ @@ -641,16 +513,6 @@ image : T_img T_end_img { $$ = $1; } %% -#ifdef OLD -htmllabel_t* -simpleHTML (char* txt) -{ - htmltxt_t* tobj = mkText (txt); - htmllabel_t* l = mkLabel(tobj,HTML_TEXT); - return l; -} -#endif - /* parseHTML: * Return parsed label or NULL if failure. * Set warn to 0 on success; 1 for warning message; 2 if no expat. diff --git a/lib/common/htmltable.c b/lib/common/htmltable.c index e7b0ea094..c3c542404 100644 --- a/lib/common/htmltable.c +++ b/lib/common/htmltable.c @@ -33,11 +33,12 @@ * e.g., CELLGRID=n, which sets CELLBORDER=0 and has the border drawing * handled correctly by the table. */ + +#include #include "render.h" #include "htmltable.h" #include "agxbuf.h" #include "pointset.h" -#include #define DEFAULT_BORDER 1 #define DEFAULT_CELLPADDING 2 @@ -532,7 +533,7 @@ emit_html_label(GVJ_t * job, htmllabel_t * lp, textlabel_t * tp) env.finfo.size = tp->fontsize; env.finfo.size = tp->fontsize; env.imgscale = agget (job->obj->u.n, "imagescale"); - if ((env.imgscale == NULL) || (*env.imgscale == '\0')) + if ((env.imgscale == NULL) || (env.imgscale[0] == '\0')) env.imgscale = "false"; if (lp->kind == HTML_TBL) { htmltbl_t *tbl = lp->u.tbl; @@ -1721,13 +1722,15 @@ static char *getPenColor(void *obj) /* 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 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)) { @@ -1741,6 +1744,8 @@ int make_html_label(graph_t *g, textlabel_t * lp, void *obj) env.g = ((Agedge_t *) obj)->head->graph; break; } + g = env.g->root; + env.finfo.size = lp->fontsize; env.finfo.name = lp->fontname; env.finfo.color = lp->fontcolor; @@ -1752,7 +1757,17 @@ int make_html_label(graph_t *g, textlabel_t * lp, void *obj) agxbinit(&xb, SMALLBUF, buf); lp->html = FALSE; lp->text = strdup(nameOf(obj, &xb)); - size_label(env.g, lp); + switch (lp->charset) { + case CHAR_LATIN1: + s = latin1ToUTF8(lp->text); + break; + default: /* UTF8 */ + s = htmlEntityUTF8(lp->text); + break; + } + free(lp->text); + lp->text = s; + make_simple_label(g, lp); agxbfree(&xb); return rv; } diff --git a/lib/common/htmltable.h b/lib/common/htmltable.h index d90380048..43e20469c 100644 --- a/lib/common/htmltable.h +++ b/lib/common/htmltable.h @@ -53,14 +53,6 @@ extern "C" { * NOTE: As required, the str field in para is utf-8. * This translation is done when libexpat scans the input. */ -#ifdef OLD - typedef struct { - textpara_t *para; - short nparas; - box box; - htmlfont_t *font; /* font info */ - } htmltxt_t; -#endif /* atomic unit of text emitted using a single htmlfont_t */ typedef struct { @@ -172,7 +164,7 @@ extern "C" { extern htmllabel_t *parseHTML(char *, int *, int); - extern int make_html_label(graph_t *g, textlabel_t * lp, void *obj); + extern int make_html_label(void *obj, textlabel_t * lp); extern void emit_html_label(GVJ_t * job, htmllabel_t * lp, textlabel_t *); extern void free_html_label(htmllabel_t *, int); diff --git a/lib/common/input.c b/lib/common/input.c index fd6fe82af..3199786e7 100644 --- a/lib/common/input.c +++ b/lib/common/input.c @@ -348,11 +348,11 @@ void global_def(char *dcl, sym->fixed = 1; } -/* getdoubles2pt: - * converts a graph attribute to a point. +/* getdoubles2ptf: + * converts a graph attribute to floating graph units (POINTS). * Returns true if the attribute ends in '!'. */ -static boolean getdoubles2pt(graph_t * g, char *name, point * result) +static boolean getdoubles2ptf(graph_t * g, char *name, pointf * result) { char *p; int i; @@ -633,8 +633,8 @@ void graph_init(graph_t * g, boolean use_rankdir) setRatio(g); GD_drawing(g)->filled = - getdoubles2pt(g, "size", &(GD_drawing(g)->size)); - getdoubles2pt(g, "page", &(GD_drawing(g)->page)); + getdoubles2ptf(g, "size", &(GD_drawing(g)->size)); + getdoubles2ptf(g, "page", &(GD_drawing(g)->page)); GD_drawing(g)->centered = mapbool(agget(g, "center")); @@ -762,34 +762,20 @@ charsetToStr (int c) */ void do_graph_label(graph_t * sg) { - char *p, *pos, *just; + char *str, *pos, *just; int pos_ix; /* it would be nice to allow multiple graph labels in the future */ - if ((p = agget(sg, "label"))) { + if ((str = agget(sg, "label"))) { char pos_flag; - int lbl_kind = LT_NONE; point dpt; pointf dimen; - if (aghtmlstr(p)) lbl_kind = LT_HTML; GD_has_labels(sg->root) |= GRAPH_LABEL; - if (lbl_kind) p = strdup (p); - else p = strdup_and_subst_obj(p, (void*)sg); - GD_label(sg) = make_label(sg->root, lbl_kind, p, - late_double(sg, - agfindattr(sg, "fontsize"), - DEFAULT_FONTSIZE, MIN_FONTSIZE), - late_nnstring(sg, - agfindattr(sg, "fontname"), - DEFAULT_FONTNAME), - late_nnstring(sg, - agfindattr(sg, "fontcolor"), - DEFAULT_COLOR)); - if (lbl_kind) { - if (make_html_label(sg->root, GD_label(sg), sg) == 1) - agerr(AGPREV, "in label of graph %s\n", sg->name); - } + GD_label(sg) = make_label((void*)sg, str, (aghtmlstr(str) ? LT_HTML : LT_NONE), + late_double(sg, agfindattr(sg, "fontsize"), DEFAULT_FONTSIZE, MIN_FONTSIZE), + late_nnstring(sg, agfindattr(sg, "fontname"), DEFAULT_FONTNAME), + late_nnstring(sg, agfindattr(sg, "fontcolor"), DEFAULT_COLOR)); /* set label position */ pos = agget(sg, "labelloc"); diff --git a/lib/common/labels.c b/lib/common/labels.c index 039a8ba4a..0548411f7 100644 --- a/lib/common/labels.c +++ b/lib/common/labels.c @@ -43,16 +43,15 @@ static void storeline(graph_t *g, textlabel_t *lp, char *line, char terminator) lp->dimen.y += size.y; } -/* compiles into a label and returns its bounding box size. */ -static pointf label_size(graph_t * g, textlabel_t * lp) +/* compiles into a label */ +void make_simple_label(graph_t * g, textlabel_t * lp) { char c, *p, *line, *lineptr, *str = lp->text; unsigned char byte = 0x00; - int charset = GD_charset(g); lp->dimen.x = lp->dimen.y = 0.0; if (*str == '\0') - return lp->dimen; + return; line = lineptr = NULL; p = str; @@ -65,7 +64,7 @@ static pointf label_size(graph_t * g, textlabel_t * lp) * the second in 0x40-0x7e or 0xa1-0xfe. We assume that the input * is well-formed, but check that we don't go past the ending '\0'. */ - if ((charset == CHAR_BIG5) && 0xA1 <= byte && byte <= 0xFE) { + if ((lp->charset == CHAR_BIG5) && 0xA1 <= byte && byte <= 0xFE) { *lineptr++ = c; c = *p++; *lineptr++ = c; @@ -103,47 +102,77 @@ static pointf label_size(graph_t * g, textlabel_t * lp) } lp->space = lp->dimen; - return lp->dimen; -} - -/* size_label: - * Process label text for size and line breaks. - */ -void -size_label (graph_t* g, textlabel_t* rv) -{ - char *s; - - switch (GD_charset(g->root)) { - case CHAR_LATIN1: - s = latin1ToUTF8(rv->text); - break; - default: /* UTF8 */ - s = htmlEntityUTF8(rv->text); - break; - } - free(rv->text); - rv->text = s; - label_size(g, rv); } /* make_label: * Assume str is freshly allocated for this instance, so it * can be freed in free_label. */ -textlabel_t *make_label(graph_t *g, int kind, char *str, double fontsize, - char *fontname, char *fontcolor) +textlabel_t *make_label(void *obj, char *str, int kind, double fontsize, char *fontname, char *fontcolor) { textlabel_t *rv = NEW(textlabel_t); + graph_t *g = NULL, *sg = NULL; + node_t *n = NULL; + edge_t *e = NULL; + char *s; - rv->text = str; + switch (agobjkind(obj)) { + case AGGRAPH: + sg = (graph_t*)obj; + g = sg->root; + break; + case AGNODE: + n = (node_t*)obj; + g = n->graph->root; + break; + case AGEDGE: + e = (edge_t*)obj; + g = e->head->graph->root; + break; + } rv->fontname = fontname; rv->fontcolor = fontcolor; rv->fontsize = fontsize; - if (kind & LT_HTML) + rv->charset = GD_charset(g); + if (kind & LT_RECD) { + rv->text = strdup(str); + if (kind & LT_HTML) { + rv->html = TRUE; + } + } + else if (kind == LT_HTML) { + rv->text = strdup(str); rv->html = TRUE; - if (kind == LT_NONE) - size_label(g, rv); + if (make_html_label(obj, rv)) { + switch (agobjkind(obj)) { + case AGGRAPH: + agerr(AGPREV, "in label of graph %s\n",sg->name); + break; + case AGNODE: + agerr(AGPREV, "in label of node %s\n", n->name); + break; + case AGEDGE: + agerr(AGPREV, "in label of edge %s %s %s\n", + e->tail->name, AG_IS_DIRECTED(g)?"->":"--", e->head->name); + break; + } + } + } + else { + assert(kind == LT_NONE); + rv->text = strdup_and_subst_obj(str, obj); + switch (rv->charset) { + case CHAR_LATIN1: + s = latin1ToUTF8(rv->text); + break; + default: /* UTF8 */ + s = htmlEntityUTF8(rv->text); + break; + } + free(rv->text); + rv->text = s; + make_simple_label(g, rv); + } return rv; } diff --git a/lib/common/postproc.c b/lib/common/postproc.c index f53d8861e..cfefa6baa 100644 --- a/lib/common/postproc.c +++ b/lib/common/postproc.c @@ -317,30 +317,6 @@ void dotneato_postprocess(Agraph_t * g) } } -#if 0 -void osize_label(textlabel_t * label, int *b, int *t, int *l, int *r) -{ - point pt, sz2; - pointf dimen; - - dimen = label->dimen; - PAD(dimen); - sz2 = cvt2pt(label->dimen); - sz2.x /= 2; - sz2.y /= 2; - pt = add_points(label->p, sz2); - if (*r < pt.x) - *r = pt.x; - if (*t < pt.y) - *t = pt.y; - pt = sub_points(label->p, sz2); - if (*l > pt.x) - *l = pt.x; - if (*b > pt.y) - *b = pt.y; -} -#endif - /* place_flip_graph_label: * Put cluster labels recursively in the flip case. */ diff --git a/lib/common/render.h b/lib/common/render.h index 7383b1b66..c8f31b360 100644 --- a/lib/common/render.h +++ b/lib/common/render.h @@ -124,10 +124,8 @@ extern "C" { extern char *xml_url_string(char *s); extern void makeSelfEdge(path *, edge_t **, int, int, int, int, splineInfo *); - extern textlabel_t *make_label(graph_t *g, int html, char *str, - double fontsize, char *fontname, char *fontcolor); + extern textlabel_t *make_label(void *obj, char *str, int kind, double fontsize, char *fontname, char *fontcolor); extern bezier *new_spline(edge_t * e, int sz); - extern void osize_label(textlabel_t *, int *, int *, int *, int *); extern char **parse_style(char *s); extern void place_graph_label(Agraph_t *); extern void place_portlabel(edge_t * e, boolean head_p); @@ -145,7 +143,7 @@ extern "C" { extern void setup_graph(GVC_t * gvc, graph_t * g); extern shape_kind shapeOf(node_t *); extern void shape_clip(node_t * n, point curve[4]); - extern void size_label (graph_t* g, textlabel_t* rv); + extern void make_simple_label (graph_t* g, textlabel_t* rv); extern void start_timer(void); extern pointf textsize(graph_t *g, textpara_t * para, char *fontname, double fontsize); extern void translate_bb(Agraph_t *, int); diff --git a/lib/common/shapes.c b/lib/common/shapes.c index 05d427e7d..80168d3c3 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -1820,7 +1820,6 @@ parse_reclbl(node_t * n, int LR, int flag, char *text) char *tsp, *psp, *hstsp, *hspsp, *sp; char port[SMALLBUF]; int maxf, cnt, mode, wflag, ishardspace, fi; - graph_t *sg = n->graph; textlabel_t *lbl = ND_label(n); fp = NULL; @@ -1892,16 +1891,10 @@ parse_reclbl(node_t * n, int LR, int flag, char *text) tsp - 1 != hstsp && *(tsp - 1) == ' ') tsp--; *tsp = '\000'; - fp->lp = - make_label(sg->root, (lbl->html ? LT_HTML : LT_NONE), - strdup(text), + fp->lp = make_label((void *)n, strdup(text), (lbl->html ? LT_HTML : LT_NONE), lbl->fontsize, lbl->fontname, lbl->fontcolor); - if (lbl->html) { - if (make_html_label(sg->root, fp->lp, n)) - agerr(AGPREV, "in label of node %s\n", n->name); - } fp->LR = TRUE; hstsp = tsp = text; } diff --git a/lib/common/types.h b/lib/common/types.h index db6347162..ca10d2376 100644 --- a/lib/common/types.h +++ b/lib/common/types.h @@ -132,6 +132,7 @@ extern "C" { typedef struct textlabel_t { char *text, *fontname, *fontcolor; + int charset; double fontsize; pointf dimen; /* the diagonal size of the label (estimated by layout) */ pointf space; /* the diagonal size of the space for the label */ @@ -284,9 +285,9 @@ extern "C" { double scale; double ratio; /* set only if ratio_kind == R_VALUE */ double dpi; - point margin; - point page; - point size; + pointf margin; + pointf page; + pointf size; boolean filled; boolean landscape; boolean centered; diff --git a/lib/common/utils.c b/lib/common/utils.c index 46b39d9cf..c1dd003d1 100644 --- a/lib/common/utils.c +++ b/lib/common/utils.c @@ -610,51 +610,26 @@ int test_toggle() void common_init_node(node_t * n) { char *str; - int lbl_kind = LT_NONE; - graph_t *sg = n->graph; ND_width(n) = late_double(n, N_width, DEFAULT_NODEWIDTH, MIN_NODEWIDTH); ND_height(n) = late_double(n, N_height, DEFAULT_NODEHEIGHT, MIN_NODEHEIGHT); + ND_shape(n) = + bind_shape(late_nnstring(n, N_shape, DEFAULT_NODESHAPE), n); if (N_label == NULL) str = NODENAME_ESC; - else { + else str = agxget(n, N_label->index); - if (aghtmlstr(str)) lbl_kind = LT_HTML; - } - if (lbl_kind) - str = strdup(str); - else - str = strdup_and_subst_obj(str, (void*)n); - ND_shape(n) = - bind_shape(late_nnstring(n, N_shape, DEFAULT_NODESHAPE), n); - if (shapeOf(n) == SH_RECORD) - lbl_kind |= LT_RECD; - ND_label(n) = make_label(sg->root, lbl_kind, str, + ND_label(n) = make_label((void*)n, str, + ((aghtmlstr(str) ? LT_HTML : LT_NONE) | ( (shapeOf(n) == SH_RECORD) ? LT_RECD : LT_NONE)), late_double(n, N_fontsize, DEFAULT_FONTSIZE, MIN_FONTSIZE), late_nnstring(n, N_fontname, DEFAULT_FONTNAME), late_nnstring(n, N_fontcolor, DEFAULT_COLOR)); - if (lbl_kind == LT_HTML) { - if (make_html_label(sg->root, ND_label(n), n)) - agerr(AGPREV, "in label of node %s\n", n->name); - } ND_showboxes(n) = late_int(n, N_showboxes, 0, 0); ND_shape(n)->fns->initfn(n); } -static void edgeError(edge_t * e, char *msg) -{ - char *edgeop; - - if (AG_IS_DIRECTED(e->tail->graph)) - edgeop = "->"; - else - edgeop = "--"; - agerr(AGPREV, "for %s of edge %s %s %s\n", - msg, e->tail->name, edgeop, e->head->name); -} - struct fontinfo { double fontsize; char *fontname; @@ -663,8 +638,7 @@ struct fontinfo { static void initFontEdgeAttr(edge_t * e, struct fontinfo *fi) { - fi->fontsize = - late_double(e, E_fontsize, DEFAULT_FONTSIZE, MIN_FONTSIZE); + fi->fontsize = late_double(e, E_fontsize, DEFAULT_FONTSIZE, MIN_FONTSIZE); fi->fontname = late_nnstring(e, E_fontname, DEFAULT_FONTNAME); fi->fontcolor = late_nnstring(e, E_fontcolor, DEFAULT_COLOR); } @@ -673,10 +647,8 @@ static void initFontLabelEdgeAttr(edge_t * e, struct fontinfo *fi, struct fontinfo *lfi) { - if (!fi->fontname) - initFontEdgeAttr(e, fi); - lfi->fontsize = - late_double(e, E_labelfontsize, fi->fontsize, MIN_FONTSIZE); + if (!fi->fontname) initFontEdgeAttr(e, fi); + lfi->fontsize = late_double(e, E_labelfontsize, fi->fontsize, MIN_FONTSIZE); lfi->fontname = late_nnstring(e, E_labelfontname, fi->fontname); lfi->fontcolor = late_nnstring(e, E_labelfontcolor, fi->fontcolor); } @@ -720,30 +692,19 @@ chkPort (port (*pf)(node_t*, char*, char*), node_t* n, char* s) /* return true if edge has label */ int common_init_edge(edge_t * e) { - char *s; + char *str; int r = 0; struct fontinfo fi; struct fontinfo lfi; graph_t *sg = e->tail->graph; - int lbl_kind; fi.fontname = NULL; lfi.fontname = NULL; - if (E_label && (s = agxget(e, E_label->index)) && (s[0])) { + if (E_label && (str = agxget(e, E_label->index)) && (str[0])) { r = 1; - if (aghtmlstr(s)) lbl_kind = LT_HTML; - else lbl_kind = LT_NONE; - if (lbl_kind) - s = strdup(s); - else - s = strdup_and_subst_obj(s, (void*)e); initFontEdgeAttr(e, &fi); - ED_label(e) = make_label(sg->root, lbl_kind, s, + ED_label(e) = make_label((void*)e, str, (aghtmlstr(str) ? LT_HTML : LT_NONE), fi.fontsize, fi.fontname, fi.fontcolor); - if (lbl_kind == LT_HTML) { - if (make_html_label(sg->root, ED_label(e), e) == 1) - edgeError(e, "label"); - } GD_has_labels(sg) |= EDGE_LABEL; ED_label_ontop(e) = mapbool(late_string(e, E_label_float, "false")); @@ -751,52 +712,32 @@ int common_init_edge(edge_t * e) /* vladimir */ - if (E_headlabel && (s = agxget(e, E_headlabel->index)) && (s[0])) { - if (aghtmlstr(s)) lbl_kind = LT_HTML; - else lbl_kind = LT_NONE; - if (lbl_kind) - s = strdup(s); - else - s = strdup_and_subst_obj(s, (void*)e); + if (E_headlabel && (str = agxget(e, E_headlabel->index)) && (str[0])) { initFontLabelEdgeAttr(e, &fi, &lfi); - ED_head_label(e) = make_label(sg->root, lbl_kind, s, + ED_head_label(e) = make_label((void*)e, str, (aghtmlstr(str) ? LT_HTML : LT_NONE), lfi.fontsize, lfi.fontname, lfi.fontcolor); - if (lbl_kind) { - if (make_html_label(sg->root, ED_head_label(e), e) == 1) - edgeError(e, "head label"); - } GD_has_labels(sg) |= HEAD_LABEL; } - if (E_taillabel && (s = agxget(e, E_taillabel->index)) && (s[0])) { - if (aghtmlstr(s)) lbl_kind = LT_HTML; - else lbl_kind = LT_NONE; - if (lbl_kind) - s = strdup(s); - else - s = strdup_and_subst_obj(s, (void*)e); + if (E_taillabel && (str = agxget(e, E_taillabel->index)) && (str[0])) { if (!lfi.fontname) initFontLabelEdgeAttr(e, &fi, &lfi); - ED_tail_label(e) = make_label(sg->root, lbl_kind, s, + ED_tail_label(e) = make_label((void*)e, str, (aghtmlstr(str) ? LT_HTML : LT_NONE), lfi.fontsize, lfi.fontname, lfi.fontcolor); - if (lbl_kind) { - if (make_html_label(sg->root, ED_tail_label(e), e) == 1) - edgeError(e, "tail label"); - } GD_has_labels(sg) |= TAIL_LABEL; } /* end vladimir */ /* We still accept ports beginning with colons but this is deprecated */ - s = agget(e, TAIL_ID); - if (s[0]) + str = agget(e, TAIL_ID); + if (str[0]) ND_has_port(e->tail) = TRUE; - ED_tail_port(e) = chkPort (ND_shape(e->tail)->fns->portfn,e->tail, s); + ED_tail_port(e) = chkPort (ND_shape(e->tail)->fns->portfn,e->tail, str); if (noClip(e, E_tailclip)) ED_tail_port(e).clip = FALSE; - s = agget(e, HEAD_ID); - if (s[0]) + str = agget(e, HEAD_ID); + if (str[0]) ND_has_port(e->head) = TRUE; - ED_head_port(e) = chkPort(ND_shape(e->head)->fns->portfn,e->head, s); + ED_head_port(e) = chkPort(ND_shape(e->head)->fns->portfn,e->head, str); if (noClip(e, E_headclip)) ED_head_port(e).clip = FALSE; diff --git a/lib/dotgen/position.c b/lib/dotgen/position.c index 7ae2abc7b..56bdf8122 100644 --- a/lib/dotgen/position.c +++ b/lib/dotgen/position.c @@ -507,7 +507,7 @@ static void pos_clusters(graph_t * g) static void compress_graph(graph_t * g) { double x; - point p; + pointf p; if (GD_drawing(g)->ratio_kind != R_COMPRESS) return; @@ -1220,19 +1220,19 @@ static void contain_nodes(graph_t * g) static boolean idealsize(graph_t * g, double minallowed) { double xf, yf, f, R; - point b, relpage, margin; + pointf b, relpage, margin; /* try for one page */ relpage = GD_drawing(g)->page; - if (relpage.x == 0) + if (relpage.x < 0.001 || relpage.y < 0.001) return FALSE; /* no page was specified */ margin = GD_drawing(g)->margin; - relpage = sub_points(relpage, margin); - relpage = sub_points(relpage, margin); + relpage = sub_pointfs(relpage, margin); + relpage = sub_pointfs(relpage, margin); b.x = GD_bb(g).UR.x; b.y = GD_bb(g).UR.y; - xf = (double) relpage.x / b.x; - yf = (double) relpage.y / b.y; + xf = relpage.x / b.x; + yf = relpage.y / b.y; if ((xf >= 1.0) && (yf >= 1.0)) return FALSE; /* fits on one page */ diff --git a/lib/neatogen/poly.c b/lib/neatogen/poly.c index a237ac8f9..481376373 100644 --- a/lib/neatogen/poly.c +++ b/lib/neatogen/poly.c @@ -220,6 +220,7 @@ void makeAddPoly(Poly * pp, Agnode_t * n, float xmargin, float ymargin) pp->kind = 0; if (sides >= 3) { /* real polygon */ + verts = N_GNEW(sides, Point); if (pp->kind == BOX) { /* To do an additive margin, we rely on knowing that * the vertices are CCW starting from the UR @@ -237,6 +238,7 @@ void makeAddPoly(Poly * pp, Agnode_t * n, float xmargin, float ymargin) else { for (i = 0; i < sides; i++) { double h = LEN(poly->vertices[i].x,poly->vertices[i].y); +fprintf(stderr,"v=%g,%g h=%g\n", poly->vertices[i].x, poly->vertices[i].y, h); verts[i].x = poly->vertices[i].x * (1.0 + xmargin/h); verts[i].y = poly->vertices[i].y * (1.0 + ymargin/h); verts[i].x = PS2INCH(verts[i].x); diff --git a/plugin/pango/gvrender_pango.c b/plugin/pango/gvrender_pango.c index 0ea8156b4..7cbad8d26 100644 --- a/plugin/pango/gvrender_pango.c +++ b/plugin/pango/gvrender_pango.c @@ -149,11 +149,8 @@ static void cairogen_begin_page(GVJ_t * job) cairo_rotate(cr, -job->rotation * M_PI / 180.); cairo_translate(cr, job->translation.x, -job->translation.y); - cairo_rectangle(cr, - job->clip.LL.x, - - job->clip.LL.y, - job->clip.UR.x - job->clip.LL.x, - - (job->clip.UR.y - job->clip.LL.y)); + cairo_rectangle(cr, job->clip.LL.x, - job->clip.LL.y, + job->clip.UR.x - job->clip.LL.x, - (job->clip.UR.y - job->clip.LL.y)); cairo_clip(cr); } -- 2.40.0