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

« back to all changes in this revision

Viewing changes to dotneato/common/ismapgen.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
#include                "gd.h"
 
14
 
 
15
#ifdef DMALLOC
 
16
#include "dmalloc.h"
 
17
#endif
 
18
 
 
19
typedef struct context_t {
 
20
        char    color_ix, *fontfam, fontopt, font_was_set;
 
21
        char    pen, fill, penwidth;
 
22
        float   fontsz;
 
23
} context_t;
 
24
 
 
25
extern char *get_ttf_fontpath(char *fontreq, int warn);
 
26
extern pointf gdpt(pointf p);
 
27
extern void gd_font(context_t* cp);
 
28
 
 
29
#define         NONE            0
 
30
#define         NODE            1
 
31
#define         EDGE            2
 
32
#define         CLST            3
 
33
 
 
34
/* ISMAP font modifiers */
 
35
#define REGULAR 0
 
36
#define BOLD            1
 
37
#define ITALIC          2
 
38
 
 
39
/* ISMAP patterns */
 
40
#define P_SOLID         0
 
41
#define P_NONE  15
 
42
#define P_DOTTED 4                              /* i wasn't sure about this */
 
43
#define P_DASHED 11                             /* or this */
 
44
 
 
45
#define SCALE (GD_RESOLUTION/72.0)
 
46
 
 
47
/* ISMAP bold line constant */
 
48
#define WIDTH_NORMAL 1
 
49
#define WIDTH_BOLD 3
 
50
 
 
51
static FILE     *Outfile;
 
52
static int        Obj;
 
53
static edge_t   *Edge;
 
54
/* static int    N_pages; */
 
55
/* static point Pages; */
 
56
static double   Scale;
 
57
static pointf   Offset;
 
58
static int        Rot;
 
59
static box        PB;
 
60
static int        onetime = TRUE;
 
61
 
 
62
#define MAXNEST 4
 
63
static context_t cstk[MAXNEST];
 
64
static int        SP;
 
65
 
 
66
static  void
 
67
ismap_reset(void)
 
68
{
 
69
        onetime = TRUE;
 
70
}
 
71
 
 
72
static  void
 
73
init_ismap(void)
 
74
{
 
75
        SP = 0;
 
76
        cstk[0].color_ix = 0;           /* ISMAP color index 0-7 */
 
77
        cstk[0].fontfam = "Times";              /* font family name */
 
78
        cstk[0].fontopt = REGULAR;              /* modifier: REGULAR, BOLD or ITALIC */
 
79
        cstk[0].pen = P_SOLID;          /* pen pattern style, default is sold */
 
80
        cstk[0].fill = P_NONE;
 
81
        cstk[0].penwidth = WIDTH_NORMAL;
 
82
}
 
83
 
 
84
static            pointf
 
85
ismappt(pointf p)
 
86
{
 
87
        pointf            rv;
 
88
 
 
89
        if (Rot == 0) {
 
90
                rv.x = p.x * Scale + Offset.x;
 
91
                rv.y = PB.UR.y - PB.LL.y - p.y * Scale + Offset.y;
 
92
        } else {
 
93
                rv.x = PB.UR.x - PB.LL.x - p.y * Scale + Offset.x;
 
94
                rv.y = PB.UR.y - PB.LL.y - p.x * Scale + Offset.y;
 
95
        }
 
96
        return rv;
 
97
}
 
98
 
 
99
static void
 
100
ismap_begin_job(FILE *ofp, graph_t *g, char **lib, char *user, char *info[], point pages)
 
101
{
 
102
        Outfile = ofp;
 
103
        /* Pages = pages; */
 
104
        /* N_pages = pages.x * pages.y; */
 
105
}
 
106
 
 
107
static void
 
108
ismap_end_job(void)
 
109
{
 
110
}
 
111
 
 
112
static void
 
113
ismap_begin_graph(graph_t* g, box bb, point pb)
 
114
{
 
115
        char               *s;
 
116
 
 
117
        g = g;
 
118
        PB.LL.x = bb.LL.x * SCALE;
 
119
        PB.LL.y = bb.LL.y * SCALE;
 
120
        PB.UR.x = bb.UR.x * SCALE;
 
121
        PB.UR.y = bb.UR.y * SCALE;
 
122
        Offset.x = PB.LL.x + 1;
 
123
        Offset.y = PB.LL.y + 1;
 
124
        if (onetime) {
 
125
                init_ismap();
 
126
                onetime = FALSE;
 
127
        }
 
128
        if ((s = agget(g, "URL")) && strlen(s)) 
 
129
                fprintf(Outfile,"default %s %s\n",s, g->name);
 
130
}
 
131
 
 
132
static void
 
133
ismap_end_graph(void)
 
134
{
 
135
}
 
136
 
 
137
static  void
 
138
ismap_begin_page(point page, double scale, int rot, point offset)
 
139
{
 
140
        /* int                   page_number; */
 
141
        /* point                   sz; */
 
142
 
 
143
        Scale = scale * SCALE;
 
144
        Rot = rot;
 
145
        /* page_number = page.x + page.y * Pages.x + 1; */
 
146
        /* sz = sub_points(PB.UR, PB.LL); */
 
147
}
 
148
 
 
149
static  void
 
150
ismap_end_page(void)
 
151
{
 
152
}
 
153
 
 
154
static  void
 
155
ismap_begin_cluster(graph_t* g)
 
156
{
 
157
        Obj = CLST;
 
158
}
 
159
 
 
160
static  void
 
161
ismap_end_cluster(void)
 
162
{
 
163
        Obj = NONE;
 
164
}
 
165
 
 
166
static void
 
167
ismap_begin_nodes(void)        
 
168
{
 
169
        Obj = NONE;
 
170
}
 
171
    
 
172
static void
 
173
ismap_end_nodes(void)  
 
174
{
 
175
        Obj = NONE;
 
176
}
 
177
 
 
178
static void 
 
179
ismap_begin_edges(void)        
 
180
{
 
181
        Obj = NONE;
 
182
}            
 
183
 
 
184
static void
 
185
ismap_end_edges(void)  
 
186
{            
 
187
        Obj = NONE;
 
188
}            
 
189
 
 
190
static  void
 
191
ismap_begin_node(node_t* n)
 
192
{
 
193
        char               *s,*s1,*s2,*lab;
 
194
        pointf                  p,p1,p2;
 
195
 
 
196
        Obj = NODE;
 
197
        if ((s = agget(n, "URL")) && strlen(s)) {
 
198
                p.x = n->u.coord.x - n->u.lw;
 
199
                p.y = n->u.coord.y - (n->u.ht/2);
 
200
                p1 = ismappt(p);
 
201
                p.x = n->u.coord.x + n->u.rw;
 
202
                p.y = n->u.coord.y + (n->u.ht/2);
 
203
                p2 = ismappt(p);
 
204
 
 
205
                s = strdup(s);
 
206
                if ((s2 = strstr(s,NODENAME_ESC))) {
 
207
                        s1 = n->name;
 
208
                        *s2 = '\0';
 
209
                        s2 += 2;
 
210
                } else {
 
211
                        s1 = s2 = "";
 
212
                }
 
213
 
 
214
                lab = agget(n, "label");
 
215
                if ((strcmp(lab,NODENAME_ESC)) == 0) {
 
216
                        lab = n->name;
 
217
                }
 
218
                fprintf(Outfile,"rectangle (%d,%d) (%d,%d) %s%s%s %s\n",
 
219
                        ROUND(p1.x),ROUND(p1.y),ROUND(p2.x),ROUND(p2.y),
 
220
                        s,s1,s2,lab);
 
221
 
 
222
                free(s);
 
223
        }
 
224
}
 
225
 
 
226
static  void
 
227
ismap_end_node(void)
 
228
{
 
229
        Obj = NONE;
 
230
}
 
231
 
 
232
static  void
 
233
ismap_begin_edge(edge_t* e)
 
234
{
 
235
        Obj = EDGE;
 
236
        Edge = e;
 
237
}
 
238
 
 
239
static  void
 
240
ismap_end_edge(void)
 
241
{
 
242
        Obj = NONE;
 
243
}
 
244
 
 
245
static  void
 
246
ismap_begin_context(void)
 
247
{
 
248
        assert(SP + 1 < MAXNEST);
 
249
        cstk[SP + 1] = cstk[SP];
 
250
        SP++;
 
251
}
 
252
 
 
253
static  void
 
254
ismap_end_context(void)
 
255
{
 
256
        int                      psp = SP - 1;
 
257
        assert(SP > 0);
 
258
        if (cstk[SP].font_was_set)
 
259
                gd_font(&(cstk[psp]));
 
260
        SP = psp;
 
261
}
 
262
 
 
263
static  void
 
264
ismap_set_font(char* name, double size)
 
265
{
 
266
        char               *p, *q;
 
267
        context_t         *cp;
 
268
 
 
269
        cp = &(cstk[SP]);
 
270
        cp->font_was_set = TRUE;
 
271
        cp->fontsz = Scale * size;
 
272
        p = strdup(name);
 
273
        if ((q = strchr(p, '-'))) {
 
274
                *q++ = 0;
 
275
                if (strcasecmp(q, "italic") == 0)
 
276
                        cp->fontopt = ITALIC;
 
277
                else if (strcasecmp(q, "bold") == 0)
 
278
                        cp->fontopt = BOLD;
 
279
        }
 
280
        cp->fontfam = p;
 
281
        gd_font(&cstk[SP]);
 
282
 
 
283
}
 
284
 
 
285
static  void
 
286
ismap_set_color(char* name)
 
287
{
 
288
}
 
289
 
 
290
static  void
 
291
ismap_set_style(char** s)
 
292
{
 
293
}
 
294
 
 
295
static  void
 
296
ismap_textline(point p, textline_t *line)
 
297
{
 
298
        char            *fontlist, *err;
 
299
        char            *s,*s1,*s1h,*s1t,*s2;
 
300
        char            *str = line->str;
 
301
        pointf          mp;
 
302
        int             intfontsz, brect[8];
 
303
        extern          gdFontPtr       gdFontSmall;
 
304
 
 
305
 
 
306
        if (Obj != EDGE) 
 
307
                return;
 
308
        if (!((s = agget(Edge, "URL")) && strlen(s)))
 
309
                return;
 
310
        s = strdup(s);
 
311
        if ((s2 = strstr(s,NODENAME_ESC))) {
 
312
                s1t = Edge->tail->name;
 
313
                s1 = "->";
 
314
                s1h = Edge->head->name;
 
315
                *s2 = '\0';
 
316
                s2 += 2;
 
317
        } else {
 
318
                s1 = s1h = s1t = s2 = "";
 
319
        }
 
320
 
 
321
        intfontsz = cstk[SP].fontsz;
 
322
        fontlist = gd_alternate_fontlist(cstk[SP].fontfam);
 
323
 
 
324
        mp.x = p.x; mp.y = p.y;
 
325
        mp = gdpt(mp);
 
326
        err = gdImageStringFT(NULL, brect, 0, fontlist,
 
327
                (double)(intfontsz), (Rot? 90.0 : 0.0) * PI / 180.0,
 
328
                ROUND(mp.x), ROUND(mp.y), str);
 
329
        if (err)
 
330
                gdImageString(NULL, gdFontSmall, ROUND(mp.x), ROUND(mp.y),
 
331
                        (unsigned char *)str, 0);
 
332
 
 
333
        fprintf(Outfile,"rectangle (%d,%d) (%d,%d) %s%s%s%s%s %s\n",
 
334
                brect[0],brect[1],brect[4],brect[5],s,s1t,s1,s1h,s2,str);
 
335
        free(s);
 
336
}
 
337
 
 
338
static  void
 
339
ismap_bezier(point* A, int n, int arrow_at_start, int arrow_at_end)
 
340
{
 
341
}
 
342
 
 
343
static  void
 
344
ismap_polygon(point *A, int n, int filled)
 
345
{
 
346
        pointf            p, p0;
 
347
        int                      i;
 
348
 
 
349
        p0.x = A[0].x; p0.y = A[0].y;
 
350
        p0 = ismappt(p0);
 
351
        p.x = p0.x; p.y = p0.y;
 
352
        for (i = 1; i < n; i++) {
 
353
                /* p1.x = p.x; p1.y = p.y; */
 
354
                p.x = A[i].x; p.y = A[i].y;
 
355
                p = ismappt(p);
 
356
/*              gdImageLine(im, ROUND(p1.x), ROUND(p1.y), 
 
357
                        ROUND(p.x), ROUND(p.y), black); */
 
358
        }
 
359
/*      gdImageLine(im, ROUND(p.x), ROUND(p.y),
 
360
                ROUND(p0.x), ROUND(p0.y), black); */
 
361
}
 
362
 
 
363
static  void
 
364
ismap_ellipse(point p, int rx, int ry, int filled)
 
365
{
 
366
        pointf            mp;
 
367
 
 
368
        mp.x = p.x; mp.y = p.y;
 
369
        mp = ismappt(mp);
 
370
/*      gdImageArc(im, ROUND(mp.x), ROUND(mp.y),
 
371
                ROUND(Scale*(rx + rx)), ROUND(Scale*(ry + ry)), 0, 360, black); */
 
372
}
 
373
 
 
374
static  void
 
375
ismap_polyline(point* A, int n)
 
376
{
 
377
        pointf            p, p1;
 
378
        int                      i;
 
379
 
 
380
        p.x = A[0].x;
 
381
        p.y = A[0].y;
 
382
        p = ismappt(p);
 
383
        for (i = 1; i < n; i++) {
 
384
                p1.x = A[i].x;
 
385
                p1.y = A[i].y;
 
386
                p1 = ismappt(p1);
 
387
/*              gdImageLine(im, ROUND(p.x), ROUND(p.y), ROUND(p1.x), ROUND(p1.y), black); */
 
388
                p.x = p1.x;
 
389
                p.y = p1.y;
 
390
        }
 
391
}
 
392
 
 
393
static  void
 
394
ismap_user_shape(char *name, point *A,int  n, int filled)
 
395
{
 
396
        static boolean  onetime = TRUE;
 
397
        if (onetime) {
 
398
                fprintf(stderr, "custom shapes not available with this driver\n");
 
399
                onetime = FALSE;
 
400
        }
 
401
        ismap_polygon(A, n, filled);
 
402
}
 
403
 
 
404
codegen_t          ISMAP_CodeGen = {
 
405
        ismap_reset,
 
406
        ismap_begin_job, ismap_end_job,
 
407
        ismap_begin_graph, ismap_end_graph,
 
408
        ismap_begin_page, ismap_end_page,
 
409
        ismap_begin_cluster, ismap_end_cluster,
 
410
        ismap_begin_nodes, ismap_end_nodes,
 
411
        ismap_begin_edges, ismap_end_edges,
 
412
        ismap_begin_node, ismap_end_node,
 
413
        ismap_begin_edge, ismap_end_edge,
 
414
        ismap_begin_context, ismap_end_context,
 
415
        ismap_set_font, ismap_textline,
 
416
        ismap_set_color, ismap_set_color, ismap_set_style,
 
417
        ismap_ellipse, ismap_polygon,
 
418
        ismap_bezier, ismap_polyline,
 
419
        0 /* ismap_arrowhead */, ismap_user_shape,
 
420
        0 /* ismap_comment */, gd_textsize
 
421
};