~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to dotneato/common/postproc.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This software may only be used by you under license from AT&T Corp.
 
3
    ("AT&T").  A copy of AT&T's Source Code Agreement is available at
 
4
    AT&T's Internet website having the URL:
 
5
    <http://www.research.att.com/sw/tools/graphviz/license/source.html>
 
6
    If you received this software without first entering into a license
 
7
    with AT&T, you have an infringing copy of this software and cannot use
 
8
    it without violating AT&T's intellectual property rights.
 
9
*/
 
10
#pragma prototyped
 
11
 
 
12
#include        "render.h"
 
13
 
 
14
#ifdef DMALLOC
 
15
#include "dmalloc.h"
 
16
#endif
 
17
 
 
18
static boolean  Flip;
 
19
static point    Offset;
 
20
 
 
21
static void place_flip_graph_label(graph_t* g);
 
22
 
 
23
#define M1 \
 
24
        "/pathbox { /Y exch %d sub def /X exch %d sub def /y exch %d sub def /x exch %d sub def newpath x y moveto X y lineto X Y lineto x Y lineto closepath stroke } def\n"
 
25
#define M2 \
 
26
        "/pathbox { /X exch neg %d sub def /Y exch %d sub def /x exch neg %d sub def /y exch %d sub def newpath x y moveto X y lineto X Y lineto x Y lineto closepath stroke } def\n"
 
27
 
 
28
point
 
29
map_point(point p)
 
30
{
 
31
        int             x = p.x;
 
32
        int     y = p.y;
 
33
 
 
34
        if (Flip) { p.x = -y - Offset.x; p.y = x - Offset.y; }
 
35
        else { p.x = x - Offset.x; p.y = y - Offset.y; }
 
36
        return p;
 
37
}
 
38
 
 
39
void
 
40
map_edge(edge_t* e)
 
41
{
 
42
        int                     j,k;
 
43
        bezier          bz;
 
44
 
 
45
if (e->u.spl == NULL) {
 
46
        if ((Concentrate == FALSE) || (e->u.edge_type != IGNORED))
 
47
                fprintf(stderr,"lost %s %s edge\n",e->tail->name,e->head->name);
 
48
        return;
 
49
}
 
50
        for (j = 0; j < e->u.spl->size; j++) {
 
51
                bz = e->u.spl->list[j];
 
52
                for (k = 0; k < bz.size; k++)
 
53
                        bz.list[k] = map_point(bz.list[k]);
 
54
                if (bz.sflag)
 
55
                        e->u.spl->list[j].sp = map_point (e->u.spl->list[j].sp);
 
56
                if (bz.eflag)
 
57
                        e->u.spl->list[j].ep = map_point (e->u.spl->list[j].ep);
 
58
        }
 
59
        if (e->u.label) e->u.label->p = map_point(e->u.label->p);
 
60
    /* vladimir */
 
61
        if (e->u.head_label) e->u.head_label->p = map_point(e->u.head_label->p);
 
62
        if (e->u.tail_label) e->u.tail_label->p = map_point(e->u.tail_label->p);
 
63
}
 
64
 
 
65
void translate_bb(graph_t* g, int lr)
 
66
{
 
67
        int                     c;
 
68
        box                     bb,new_bb;
 
69
 
 
70
        bb = g->u.bb;
 
71
        if (lr) {
 
72
                new_bb.LL = map_point(pointof(bb.LL.x,bb.UR.y));
 
73
                new_bb.UR = map_point(pointof(bb.UR.x,bb.LL.y));
 
74
        }
 
75
        else {
 
76
                new_bb.LL = map_point(pointof(bb.LL.x,bb.LL.y));
 
77
                new_bb.UR = map_point(pointof(bb.UR.x,bb.UR.y));
 
78
        }
 
79
        g->u.bb = new_bb;
 
80
        if (g->u.label) {
 
81
                g->u.label->p = map_point(g->u.label->p);
 
82
    }
 
83
        for (c = 1; c <= g->u.n_cluster; c++) translate_bb(g->u.clust[c],lr);
 
84
}
 
85
 
 
86
static void translate_drawing(graph_t* g, nodesizefn_t ns)
 
87
{
 
88
        node_t          *v;
 
89
        edge_t          *e;
 
90
 
 
91
        for (v = agfstnode(g); v; v = agnxtnode(g,v)) {
 
92
                ns(v,FALSE);
 
93
                v->u.coord = map_point(v->u.coord);
 
94
                for (e = agfstout(g,v); e; e = agnxtout(g,e)) map_edge(e);
 
95
        }
 
96
        translate_bb(g,g->u.left_to_right);
 
97
}
 
98
 
 
99
static void
 
100
place_root_label (graph_t* g)
 
101
{
 
102
    point       p,d;
 
103
 
 
104
    d = cvt2pt(g->u.label->dimen);
 
105
    if (Flip) {
 
106
        p.y = (g->u.bb.LL.y + g->u.bb.UR.y)/2;
 
107
        p.x = g->u.bb.LL.x + d.y/2;
 
108
    }
 
109
    else {
 
110
        p.x = (g->u.bb.LL.x + g->u.bb.UR.x)/2;
 
111
        p.y = g->u.bb.LL.y + d.y/2;
 
112
    }
 
113
    g->u.label->p = p;
 
114
}
 
115
 
 
116
void dotneato_postprocess(Agraph_t *g, nodesizefn_t ns)
 
117
{
 
118
        Flip = g->u.left_to_right;
 
119
        if (Flip) place_flip_graph_label(g);
 
120
        else place_graph_label(g);
 
121
        if (Flip) {
 
122
                if (g->u.label) {
 
123
                        int             yd = POINTS(g->u.label->dimen.x);
 
124
                        g->u.bb.LL.x -= POINTS(g->u.label->dimen.y);
 
125
                                /* in case label is wide than the rest of the drawing */
 
126
                        if (yd > g->u.bb.UR.y - g->u.bb.LL.y) {
 
127
                                yd = yd/2;
 
128
                                g->u.bb.LL.y -= yd; g->u.bb.UR.y += yd;
 
129
                        }
 
130
                }
 
131
                Offset.x = -g->u.bb.UR.y;
 
132
                Offset.y = g->u.bb.LL.x;
 
133
        }
 
134
        else {
 
135
                if (g->u.label) {
 
136
                        int             xd = POINTS(g->u.label->dimen.x);
 
137
                        g->u.bb.LL.y -= POINTS(g->u.label->dimen.y);
 
138
                        if (xd > g->u.bb.UR.x - g->u.bb.LL.x) {
 
139
                                xd = xd/2;
 
140
                                g->u.bb.LL.x -= xd; g->u.bb.UR.x += xd;
 
141
                        }
 
142
                }
 
143
                Offset = g->u.bb.LL;
 
144
        }
 
145
        translate_drawing(g, ns);
 
146
        if (g->u.label) place_root_label (g);
 
147
 
 
148
        if (Show_boxes) {
 
149
                if (Flip)
 
150
                        fprintf (stderr, M2, Offset.x, Offset.y, Offset.x, Offset.y);
 
151
                else
 
152
                        fprintf (stderr, M1, Offset.y, Offset.x, Offset.y, Offset.x);
 
153
        }
 
154
}
 
155
 
 
156
void osize_label(textlabel_t *label, int *b, int* t ,int *l, int *r)
 
157
{
 
158
        point   pt,sz2;
 
159
        sz2.x = POINTS(label->dimen.x)/2;
 
160
        sz2.y = POINTS(label->dimen.y)/2;
 
161
        pt = add_points(label->p,sz2);
 
162
        if (*r < pt.x) *r = pt.x;
 
163
        if (*t < pt.y) *t = pt.y;
 
164
        pt = sub_points(label->p,sz2);
 
165
        if (*l > pt.x) *l = pt.x;
 
166
        if (*b > pt.y) *b = pt.y;
 
167
}
 
168
 
 
169
/* place_flip_graph_label:
 
170
 * Put cluster labels recursively in the flip case.
 
171
 */
 
172
static void place_flip_graph_label(graph_t* g)
 
173
{
 
174
        int                     c,maxx,minx;
 
175
        int                     maxy, miny;
 
176
        point           p,d;
 
177
    char*       pos;
 
178
 
 
179
    if ((g != g->root) && (g->u.label)) {
 
180
        d = cvt2pt(g->u.label->dimen);
 
181
        pos = agget(g,"labeljust");
 
182
        if (pos && (pos[0] == 'r')) {
 
183
          p.y = g->u.bb.LL.y + d.x/2;
 
184
          maxy = p.y + d.x/2;
 
185
          if (g->root->u.bb.UR.y < maxy) g->root->u.bb.UR.y = maxy;
 
186
        }
 
187
        else {
 
188
          p.y = g->u.bb.UR.y - d.x/2;
 
189
          miny = p.y - d.x/2;
 
190
          if (g->root->u.bb.LL.y > miny) g->root->u.bb.LL.y = miny;
 
191
        }
 
192
 
 
193
        pos = agget(g,"labelloc");
 
194
        if (pos && (pos[0] == 'b')) {
 
195
          p.x = g->u.bb.LL.x - d.y/2;
 
196
          minx = g->u.bb.LL.x - d.y;
 
197
          if (g->root->u.bb.LL.x > minx) g->root->u.bb.LL.x = minx;
 
198
        }
 
199
        else {
 
200
          p.x = g->u.bb.UR.x + d.y/2;
 
201
          maxx = g->u.bb.UR.x + d.y;
 
202
          if (g->root->u.bb.UR.x < maxx) g->root->u.bb.UR.x = maxx;
 
203
        }
 
204
        g->u.label->p = p;
 
205
    }
 
206
 
 
207
        for (c = 1; c <= g->u.n_cluster; c++)
 
208
                place_flip_graph_label(g->u.clust[c]);
 
209
}
 
210
 
 
211
/* place_graph_label:
 
212
 * Put cluster labels recursively in the non-flip case.
 
213
 */
 
214
void place_graph_label(graph_t* g)
 
215
{
 
216
        int                     c;
 
217
        /* int                  maxy,miny; */
 
218
    int         minx, maxx;
 
219
        point           p,d;
 
220
    char*       pos;
 
221
 
 
222
    if ((g != g->root) && (g->u.label)) {
 
223
        d = cvt2pt(g->u.label->dimen);
 
224
        pos = agget(g,"labeljust");
 
225
        if (pos && (pos[0] == 'r')) {
 
226
          p.x = g->u.bb.UR.x - d.x/2;
 
227
          minx = p.x - d.x/2;
 
228
          if (g->root->u.bb.LL.x > minx) g->root->u.bb.LL.x = minx;
 
229
        }
 
230
        else {
 
231
          p.x = g->u.bb.LL.x + d.x/2;
 
232
          maxx = p.x + d.x/2;
 
233
          if (g->root->u.bb.UR.x < maxx) g->root->u.bb.UR.x = maxx;
 
234
        }
 
235
        pos = agget(g,"labelloc");
 
236
        if (pos && (pos[0] == 'b')) {
 
237
          p.y = g->u.bb.LL.y + d.y/2;
 
238
#ifdef NOTDEF  
 
239
 /* remove this code - fixed the graph labeling nightmare. */
 
240
          miny = g->u.bb.LL.y - d.y;
 
241
          if (g->root->u.bb.LL.y > miny) g->root->u.bb.LL.y = miny;
 
242
#endif
 
243
        }
 
244
        else {
 
245
          p.y = g->u.bb.UR.y - d.y/2;
 
246
#ifdef NOTDEF
 
247
          maxy = g->u.bb.UR.y + d.y;
 
248
          if (g->root->u.bb.UR.y < maxy) g->root->u.bb.UR.y = maxy;
 
249
#endif
 
250
        }
 
251
        g->u.label->p = p;
 
252
    }
 
253
 
 
254
        for (c = 1; c <= g->u.n_cluster; c++)
 
255
                place_graph_label(g->u.clust[c]);
 
256
}