~ubuntu-branches/ubuntu/precise/graphviz/precise-security

« back to all changes in this revision

Viewing changes to lib/common/mifgen.c

  • Committer: Bazaar Package Importer
  • Author(s): David Claughton
  • Date: 2010-03-24 22:45:18 UTC
  • mfrom: (1.2.7 upstream) (6.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100324224518-do441tthbqjaqjzd
Tags: 2.26.3-4
Add patch to fix segfault in circo. Backported from upstream snapshot
release.  Thanks to Francis Russell for his work on this.
(Closes: #575255)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: mifgen.c,v 1.12 2006/12/07 22:49:36 erg Exp $ $Revision: 1.12 $ */
2
 
/* vim:set shiftwidth=4 ts=8: */
3
 
 
4
 
/**********************************************************
5
 
*      This software is part of the graphviz package      *
6
 
*                http://www.graphviz.org/                 *
7
 
*                                                         *
8
 
*            Copyright (c) 1994-2004 AT&T Corp.           *
9
 
*                and is licensed under the                *
10
 
*            Common Public License, Version 1.0           *
11
 
*                      by AT&T Corp.                      *
12
 
*                                                         *
13
 
*        Information and Software Systems Research        *
14
 
*              AT&T Research, Florham Park NJ             *
15
 
**********************************************************/
16
 
 
17
 
 
18
 
#include "render.h"
19
 
 
20
 
#define NONE    0
21
 
#define NODE    1
22
 
#define EDGE    2
23
 
#define CLST    3
24
 
 
25
 
/* MIF font modifiers */
26
 
#define REGULAR 0
27
 
#define BOLD    1
28
 
#define ITALIC  2
29
 
 
30
 
/* MIF patterns */
31
 
#define P_SOLID 0
32
 
#define P_NONE  15
33
 
#define P_DOTTED 4              /* i wasn't sure about this */
34
 
#define P_DASHED 11             /* or this */
35
 
 
36
 
/* MIF bold line constant */
37
 
#define WIDTH_NORMAL 1
38
 
#define WIDTH_BOLD 3
39
 
 
40
 
static int N_pages;
41
 
/* static       point   Pages; */
42
 
static double Scale;
43
 
static int Rot;
44
 
static box PB;
45
 
static int onetime = TRUE;
46
 
 
47
 
typedef struct context_t {
48
 
    char color_ix, *fontfam, fontopt, font_was_set;
49
 
    char pen, fill, penwidth, style_was_set;
50
 
    double fontsz;
51
 
} context_t;
52
 
 
53
 
#define MAXNEST 4
54
 
static context_t cstk[MAXNEST];
55
 
static int SP;
56
 
 
57
 
static char *FillStr = "<Fill 3>";
58
 
static char *NoFillStr = "<Fill 15>";
59
 
 
60
 
static void mif_reset(void)
61
 
{
62
 
    onetime = TRUE;
63
 
}
64
 
 
65
 
 
66
 
static void init_mif(void)
67
 
{
68
 
    SP = 0;
69
 
    cstk[0].color_ix = 0;       /* MIF color index 0-7 */
70
 
    cstk[0].fontfam = "Times";  /* font family name */
71
 
    cstk[0].fontopt = REGULAR;  /* modifier: REGULAR, BOLD or ITALIC */
72
 
    cstk[0].pen = P_SOLID;      /* pen pattern style, default is solid */
73
 
    cstk[0].fill = P_NONE;
74
 
    cstk[0].penwidth = WIDTH_NORMAL;
75
 
}
76
 
 
77
 
static pointf mifpt(pointf p)
78
 
{
79
 
    pointf tmp, rv;
80
 
    tmp.x = p.x * Scale;
81
 
    tmp.y = Scale * p.y;
82
 
    if (Rot == 0) {
83
 
        rv.x = tmp.x;
84
 
        rv.y = PB.UR.y - PB.LL.y - tmp.y;
85
 
    } else {
86
 
        rv.x = PB.UR.x - PB.LL.x - tmp.y;
87
 
        rv.y = tmp.x;
88
 
    }
89
 
    return rv;
90
 
}
91
 
 
92
 
static void mifptarray(point * A, int n)
93
 
{
94
 
    int i;
95
 
    pointf p;
96
 
 
97
 
    fprintf(Output_file, " <NumPoints %d>\n", n);
98
 
    for (i = 0; i < n; i++) {
99
 
        p.x = A[i].x;
100
 
        p.y = A[i].y;
101
 
        p = mifpt(p);
102
 
        fprintf(Output_file, " <Point %.2f %.2f>\n", p.x, p.y);
103
 
    }
104
 
}
105
 
 
106
 
static void mif_font(context_t * cp)
107
 
{
108
 
    char *fw, *fa;
109
 
 
110
 
    fw = fa = "Regular";
111
 
    switch (cp->fontopt) {
112
 
    case BOLD:
113
 
        fw = "Bold";
114
 
        break;
115
 
    case ITALIC:
116
 
        fa = "Italic";
117
 
        break;
118
 
    }
119
 
    fprintf(Output_file,
120
 
            "<Font <FFamily `%s'> <FSize %.1f pt> <FWeight %s> <FAngle %s>>\n",
121
 
            cp->fontfam, Scale * cp->fontsz, fw, fa);
122
 
}
123
 
 
124
 
static void mif_color(int i)
125
 
{
126
 
    static char *mifcolor[] = {
127
 
        "black", "white", "red", "green", "blue", "cyan",
128
 
        "magenta", "yellow", "comment",
129
 
        "aquamarine", "plum", "peru", "pink", "mediumpurple", "grey",
130
 
        "lightgrey", "lightskyblue", "lightcoral", "yellowgreen",
131
 
        (char *) 0
132
 
    };
133
 
    if (i <= 8)
134
 
        fprintf(Output_file, "<Separation %d>\n", i);
135
 
    if (i > 8)
136
 
        fprintf(Output_file, "<ObColor `%s'>\n", mifcolor[i]);
137
 
}
138
 
 
139
 
static void mif_style(context_t * cp)
140
 
{
141
 
    fprintf(Output_file, "<Pen %d> <Fill %d> <PenWidth %d>\n",
142
 
            cp->pen, cp->fill, cp->penwidth);
143
 
}
144
 
 
145
 
static void mif_comment(char *str)
146
 
{
147
 
    fprintf(Output_file, "# %s\n", str);
148
 
}
149
 
 
150
 
static void
151
 
mif_begin_job(FILE * ofp, graph_t * g, char **lib, char *user,
152
 
              char *info[], point pages)
153
 
{
154
 
    /* Pages = pages; */
155
 
    N_pages = pages.x * pages.y;
156
 
    fprintf(Output_file,
157
 
            "<MIFFile 3.00> # Generated by %s version %s (%s)\n", info[0],
158
 
            info[1], info[2]);
159
 
    fprintf(Output_file, "# For: %s\n", user);
160
 
    fprintf(Output_file, "# Title: %s\n", g->name);
161
 
    fprintf(Output_file, "# Pages: %d\n", N_pages);
162
 
    fprintf(Output_file, "<Units Upt>\n");
163
 
    fprintf(Output_file, "<ColorCatalog \n");
164
 
    fprintf(Output_file, " <Color \n");
165
 
    fprintf(Output_file, "  <ColorTag `Black'>\n");
166
 
    fprintf(Output_file, "  <ColorCyan  0.000000>\n");
167
 
    fprintf(Output_file, "  <ColorMagenta  0.000000>\n");
168
 
    fprintf(Output_file, "  <ColorYellow  0.000000>\n");
169
 
    fprintf(Output_file, "  <ColorBlack  100.000000>\n");
170
 
    fprintf(Output_file, "  <ColorAttribute ColorIsBlack>\n");
171
 
    fprintf(Output_file, "  <ColorAttribute ColorIsReserved>\n");
172
 
    fprintf(Output_file, " > # end of Color\n");
173
 
    fprintf(Output_file, " <Color \n");
174
 
    fprintf(Output_file, "  <ColorTag `White'>\n");
175
 
    fprintf(Output_file, "  <ColorCyan  0.000000>\n");
176
 
    fprintf(Output_file, "  <ColorMagenta  0.000000>\n");
177
 
    fprintf(Output_file, "  <ColorYellow  0.000000>\n");
178
 
    fprintf(Output_file, "  <ColorBlack  0.000000>\n");
179
 
    fprintf(Output_file, "  <ColorAttribute ColorIsWhite>\n");
180
 
    fprintf(Output_file, "  <ColorAttribute ColorIsReserved>\n");
181
 
    fprintf(Output_file, " > # end of Color\n");
182
 
    fprintf(Output_file, " <Color \n");
183
 
    fprintf(Output_file, "  <ColorTag `Red'>\n");
184
 
    fprintf(Output_file, "  <ColorCyan  0.000000>\n");
185
 
    fprintf(Output_file, "  <ColorMagenta  100.000000>\n");
186
 
    fprintf(Output_file, "  <ColorYellow  100.000000>\n");
187
 
    fprintf(Output_file, "  <ColorBlack  0.000000>\n");
188
 
    fprintf(Output_file, "  <ColorAttribute ColorIsRed>\n");
189
 
    fprintf(Output_file, "  <ColorAttribute ColorIsReserved>\n");
190
 
    fprintf(Output_file, " > # end of Color\n");
191
 
    fprintf(Output_file, " <Color \n");
192
 
    fprintf(Output_file, "  <ColorTag `Green'>\n");
193
 
    fprintf(Output_file, "  <ColorCyan  100.000000>\n");
194
 
    fprintf(Output_file, "  <ColorMagenta  0.000000>\n");
195
 
    fprintf(Output_file, "  <ColorYellow  100.000000>\n");
196
 
    fprintf(Output_file, "  <ColorBlack  0.000000>\n");
197
 
    fprintf(Output_file, "  <ColorAttribute ColorIsGreen>\n");
198
 
    fprintf(Output_file, "  <ColorAttribute ColorIsReserved>\n");
199
 
    fprintf(Output_file, " > # end of Color\n");
200
 
    fprintf(Output_file, " <Color \n");
201
 
    fprintf(Output_file, "  <ColorTag `Blue'>\n");
202
 
    fprintf(Output_file, "  <ColorCyan  100.000000>\n");
203
 
    fprintf(Output_file, "  <ColorMagenta  100.000000>\n");
204
 
    fprintf(Output_file, "  <ColorYellow  0.000000>\n");
205
 
    fprintf(Output_file, "  <ColorBlack  0.000000>\n");
206
 
    fprintf(Output_file, "  <ColorAttribute ColorIsBlue>\n");
207
 
    fprintf(Output_file, "  <ColorAttribute ColorIsReserved>\n");
208
 
    fprintf(Output_file, " > # end of Color\n");
209
 
    fprintf(Output_file, " <Color \n");
210
 
    fprintf(Output_file, "  <ColorTag `Cyan'>\n");
211
 
    fprintf(Output_file, "  <ColorCyan  100.000000>\n");
212
 
    fprintf(Output_file, "  <ColorMagenta  0.000000>\n");
213
 
    fprintf(Output_file, "  <ColorYellow  0.000000>\n");
214
 
    fprintf(Output_file, "  <ColorBlack  0.000000>\n");
215
 
    fprintf(Output_file, "  <ColorAttribute ColorIsCyan>\n");
216
 
    fprintf(Output_file, "  <ColorAttribute ColorIsReserved>\n");
217
 
    fprintf(Output_file, " > # end of Color\n");
218
 
    fprintf(Output_file, " <Color \n");
219
 
    fprintf(Output_file, "  <ColorTag `Magenta'>\n");
220
 
    fprintf(Output_file, "  <ColorCyan  0.000000>\n");
221
 
    fprintf(Output_file, "  <ColorMagenta  100.000000>\n");
222
 
    fprintf(Output_file, "  <ColorYellow  0.000000>\n");
223
 
    fprintf(Output_file, "  <ColorBlack  0.000000>\n");
224
 
    fprintf(Output_file, "  <ColorAttribute ColorIsMagenta>\n");
225
 
    fprintf(Output_file, "  <ColorAttribute ColorIsReserved>\n");
226
 
    fprintf(Output_file, " > # end of Color\n");
227
 
    fprintf(Output_file, " <Color \n");
228
 
    fprintf(Output_file, "  <ColorTag `Yellow'>\n");
229
 
    fprintf(Output_file, "  <ColorCyan  0.000000>\n");
230
 
    fprintf(Output_file, "  <ColorMagenta  0.000000>\n");
231
 
    fprintf(Output_file, "  <ColorYellow  100.000000>\n");
232
 
    fprintf(Output_file, "  <ColorBlack  0.000000>\n");
233
 
    fprintf(Output_file, "  <ColorAttribute ColorIsYellow>\n");
234
 
    fprintf(Output_file, "  <ColorAttribute ColorIsReserved>\n");
235
 
    fprintf(Output_file, " > # end of Color\n");
236
 
    fprintf(Output_file, " <Color \n");
237
 
    fprintf(Output_file, "  <ColorTag `aquamarine'>\n");
238
 
    fprintf(Output_file, "  <ColorCyan  100.000000>\n");
239
 
    fprintf(Output_file, "  <ColorMagenta  0.000000>\n");
240
 
    fprintf(Output_file, "  <ColorYellow  18.000000>\n");
241
 
    fprintf(Output_file, "  <ColorBlack  0.000000>\n");
242
 
    fprintf(Output_file, " > # end of Color\n");
243
 
    fprintf(Output_file, " <Color \n");
244
 
    fprintf(Output_file, "  <ColorTag `plum'>\n");
245
 
    fprintf(Output_file, "  <ColorCyan  0.000000>\n");
246
 
    fprintf(Output_file, "  <ColorMagenta  100.000000>\n");
247
 
    fprintf(Output_file, "  <ColorYellow  0.000000>\n");
248
 
    fprintf(Output_file, "  <ColorBlack  33.000000>\n");
249
 
    fprintf(Output_file, " > # end of Color\n");
250
 
    fprintf(Output_file, " <Color \n");
251
 
    fprintf(Output_file, "  <ColorTag `peru'>\n");
252
 
    fprintf(Output_file, "  <ColorCyan  0.000000>\n");
253
 
    fprintf(Output_file, "  <ColorMagenta  24.000000>\n");
254
 
    fprintf(Output_file, "  <ColorYellow  100.000000>\n");
255
 
    fprintf(Output_file, "  <ColorBlack  32.000000>\n");
256
 
    fprintf(Output_file, " > # end of Color\n");
257
 
    fprintf(Output_file, " <Color \n");
258
 
    fprintf(Output_file, "  <ColorTag `pink'>\n");
259
 
    fprintf(Output_file, "  <ColorCyan  0.000000>\n");
260
 
    fprintf(Output_file, "  <ColorMagenta  50.000000>\n");
261
 
    fprintf(Output_file, "  <ColorYellow  0.000000>\n");
262
 
    fprintf(Output_file, "  <ColorBlack  0.000000>\n");
263
 
    fprintf(Output_file, " > # end of Color\n");
264
 
    fprintf(Output_file, " <Color \n");
265
 
    fprintf(Output_file, "  <ColorTag `mediumpurple'>\n");
266
 
    fprintf(Output_file, "  <ColorCyan  40.000000>\n");
267
 
    fprintf(Output_file, "  <ColorMagenta  100.000000>\n");
268
 
    fprintf(Output_file, "  <ColorYellow  0.000000>\n");
269
 
    fprintf(Output_file, "  <ColorBlack  0.000000>\n");
270
 
    fprintf(Output_file, " > # end of Color\n");
271
 
    fprintf(Output_file, " <Color \n");
272
 
    fprintf(Output_file, "  <ColorTag `grey'>\n");
273
 
    fprintf(Output_file, "  <ColorCyan  0.000000>\n");
274
 
    fprintf(Output_file, "  <ColorMagenta  0.000000>\n");
275
 
    fprintf(Output_file, "  <ColorYellow  0.000000>\n");
276
 
    fprintf(Output_file, "  <ColorBlack  50.000000>\n");
277
 
    fprintf(Output_file, " > # end of Color\n");
278
 
    fprintf(Output_file, " <Color \n");
279
 
    fprintf(Output_file, "  <ColorTag `lightgrey'>\n");
280
 
    fprintf(Output_file, "  <ColorCyan  0.000000>\n");
281
 
    fprintf(Output_file, "  <ColorMagenta  0.000000>\n");
282
 
    fprintf(Output_file, "  <ColorYellow  0.000000>\n");
283
 
    fprintf(Output_file, "  <ColorBlack  25.000000>\n");
284
 
    fprintf(Output_file, " > # end of Color\n");
285
 
    fprintf(Output_file, " <Color \n");
286
 
    fprintf(Output_file, "  <ColorTag `lightskyblue'>\n");
287
 
    fprintf(Output_file, "  <ColorCyan  38.000000>\n");
288
 
    fprintf(Output_file, "  <ColorMagenta  33.000000>\n");
289
 
    fprintf(Output_file, "  <ColorYellow  0.000000>\n");
290
 
    fprintf(Output_file, "  <ColorBlack  0.000000>\n");
291
 
    fprintf(Output_file, " > # end of Color\n");
292
 
    fprintf(Output_file, " <Color \n");
293
 
    fprintf(Output_file, "  <ColorTag `lightcoral'>\n");
294
 
    fprintf(Output_file, "  <ColorCyan  0.000000>\n");
295
 
    fprintf(Output_file, "  <ColorMagenta  50.000000>\n");
296
 
    fprintf(Output_file, "  <ColorYellow  60.000000>\n");
297
 
    fprintf(Output_file, "  <ColorBlack  0.000000>\n");
298
 
    fprintf(Output_file, " > # end of Color\n");
299
 
    fprintf(Output_file, " <Color \n");
300
 
    fprintf(Output_file, "  <ColorTag `yellowgreen'>\n");
301
 
    fprintf(Output_file, "  <ColorCyan  31.000000>\n");
302
 
    fprintf(Output_file, "  <ColorMagenta  0.000000>\n");
303
 
    fprintf(Output_file, "  <ColorYellow  100.000000>\n");
304
 
    fprintf(Output_file, "  <ColorBlack  0.000000>\n");
305
 
    fprintf(Output_file, " > # end of Color\n");
306
 
    fprintf(Output_file, "> # end of ColorCatalog\n");
307
 
}
308
 
 
309
 
static void mif_end_job(void)
310
 
{
311
 
    fprintf(Output_file, "# end of MIFFile\n");
312
 
}
313
 
 
314
 
static void mif_begin_graph(GVC_t * gvc, graph_t * g, box bb, point pb)
315
 
{
316
 
    PB = bb;
317
 
    if (onetime) {
318
 
        fprintf(Output_file, "<BRect %d %d %d %d>\n",
319
 
                PB.LL.x, PB.UR.y, PB.UR.x - PB.LL.x, PB.UR.y - PB.LL.y);
320
 
        init_mif();
321
 
        onetime = FALSE;
322
 
    }
323
 
}
324
 
 
325
 
static void
326
 
mif_begin_page(graph_t * g, point page, double scale, int rot,
327
 
               point offset)
328
 
{
329
 
    /* int          page_number; */
330
 
    /* point        sz; */
331
 
 
332
 
    Scale = scale;
333
 
    Rot = rot;
334
 
    /* page_number =  page.x + page.y * Pages.x + 1; */
335
 
    /* sz = sub_points(PB.UR,PB.LL); */
336
 
    fprintf(Output_file,
337
 
            " <ArrowStyle <TipAngle 15> <BaseAngle 90> <Length %.1f> <HeadType Filled>>\n",
338
 
            14 * Scale);
339
 
}
340
 
 
341
 
static void mif_begin_context(void)
342
 
{
343
 
    assert(SP + 1 < MAXNEST);
344
 
    cstk[SP + 1] = cstk[SP];
345
 
    SP++;
346
 
}
347
 
 
348
 
static void mif_end_context(void)
349
 
{
350
 
    int c, psp = SP - 1;
351
 
    assert(SP > 0);
352
 
    if (cstk[SP].color_ix != (c = cstk[psp].color_ix))
353
 
        mif_color(c);
354
 
    if (cstk[SP].font_was_set)
355
 
        mif_font(&(cstk[psp]));
356
 
    if (cstk[SP].style_was_set)
357
 
        mif_style(&(cstk[psp]));
358
 
    /*free(cstk[psp].fontfam); */
359
 
    SP = psp;
360
 
}
361
 
 
362
 
static void mif_set_font(char *name, double size)
363
 
{
364
 
    char *p, *q;
365
 
    context_t *cp;
366
 
 
367
 
    cp = &(cstk[SP]);
368
 
    cp->font_was_set = TRUE;
369
 
    cp->fontsz = size;
370
 
    p = strdup(name);
371
 
    if ((q = strchr(p, '-'))) {
372
 
        *q++ = 0;
373
 
        if (strcasecmp(q, "italic") == 0)
374
 
            cp->fontopt = ITALIC;
375
 
        else if (strcasecmp(q, "bold") == 0)
376
 
            cp->fontopt = BOLD;
377
 
    }
378
 
    cp->fontfam = p;
379
 
    mif_font(&cstk[SP]);
380
 
}
381
 
 
382
 
static void mif_set_color(char *name)
383
 
{
384
 
    int i;
385
 
    char *tok;
386
 
 
387
 
    static char *mifcolor[] = {
388
 
        "black", "white", "red", "green", "blue", "cyan",
389
 
        "magenta", "yellow", "comment",
390
 
        "aquamarine", "plum", "peru", "pink", "mediumpurple", "grey",
391
 
        "lightgrey", "lightskyblue", "lightcoral", "yellowgreen",
392
 
        (char *) 0
393
 
    };
394
 
 
395
 
    tok = canontoken(name);
396
 
    for (i = 0; mifcolor[i]; i++) {
397
 
        if (strcasecmp(mifcolor[i], tok) == 0) {
398
 
            cstk[SP].color_ix = i;
399
 
            mif_color(i);
400
 
            return;
401
 
        }
402
 
    }
403
 
    agerr(AGERR, "color %s not supported in MIF\n", name);
404
 
}
405
 
 
406
 
static void mif_set_style(char **s)
407
 
{
408
 
    char *line;
409
 
    context_t *cp;
410
 
 
411
 
    cp = &(cstk[SP]);
412
 
    while ((line = *s++)) {
413
 
        if (streq(line, "solid"))
414
 
            cp->pen = P_SOLID;
415
 
        else if (streq(line, "dashed"))
416
 
            cp->pen = P_DASHED;
417
 
        else if (streq(line, "dotted"))
418
 
            cp->pen = P_DOTTED;
419
 
        else if (streq(line, "invis"))
420
 
            cp->pen = P_NONE;
421
 
        else if (streq(line, "bold"))
422
 
            cp->penwidth = WIDTH_BOLD;
423
 
        else if (streq(line, "filled"))
424
 
            cp->fill = P_SOLID;
425
 
        else if (streq(line, "unfilled"))
426
 
            cp->fill = P_NONE;
427
 
        else {
428
 
            agerr(AGERR,
429
 
                  "mif_set_style: unsupported style %s - ignoring\n",
430
 
                  line);
431
 
        }
432
 
        cp->style_was_set = TRUE;
433
 
    }
434
 
    if (cp->style_was_set)
435
 
        mif_style(cp);
436
 
}
437
 
 
438
 
static char *mif_string(char *s)
439
 
{
440
 
    static char *buf = NULL;
441
 
    static int bufsize = 0;
442
 
    int pos = 0;
443
 
    char *p, esc;
444
 
 
445
 
    if (!buf) {
446
 
        bufsize = 64;
447
 
        buf = N_GNEW(bufsize, char);
448
 
    }
449
 
 
450
 
    p = buf;
451
 
    while (*s) {
452
 
        if (pos > (bufsize - 8)) {
453
 
            bufsize *= 2;
454
 
            buf = grealloc(buf, bufsize);
455
 
            p = buf + pos;
456
 
        }
457
 
        esc = 0;
458
 
        switch (*s) {
459
 
        case '\t':
460
 
            esc = 't';
461
 
            break;
462
 
        case '>':
463
 
        case '\'':
464
 
        case '`':
465
 
        case '\\':
466
 
            esc = *s;
467
 
            break;
468
 
        }
469
 
        if (esc) {
470
 
            *p++ = '\\';
471
 
            *p++ = esc;
472
 
            pos += 2;
473
 
        } else {
474
 
            *p++ = *s;
475
 
            pos++;
476
 
        }
477
 
        s++;
478
 
    }
479
 
    *p = '\0';
480
 
    return buf;
481
 
}
482
 
 
483
 
static void mif_textpara(point p, textpara_t * para)
484
 
{
485
 
    pointf mp;
486
 
    char *anchor;
487
 
 
488
 
    mp.x = p.x;
489
 
    mp.y = p.y - cstk[SP].fontsz / 2 + 2;
490
 
    switch (para->just) {
491
 
    case 'l':
492
 
        anchor = "Left";
493
 
        break;
494
 
    case 'r':
495
 
        anchor = "Right";
496
 
        break;
497
 
    default:
498
 
    case 'n':
499
 
        anchor = "Center";
500
 
        break;
501
 
    }
502
 
    mp = mifpt(mp);
503
 
    fprintf(Output_file,
504
 
            "<TextLine <Angle %d> <TLOrigin %.2f %.2f> <TLAlignment %s>",
505
 
            Rot, mp.x, mp.y, anchor);
506
 
    fprintf(Output_file, " <String `%s'>>\n", mif_string(para->str));
507
 
}
508
 
 
509
 
static void mif_bezier(point * A, int n, int arrow_at_start,
510
 
                       int arrow_at_end, int filled)
511
 
{
512
 
    fprintf(Output_file,
513
 
            "<PolyLine <Fill 15> <Smoothed Yes> <HeadCap Square>\n");
514
 
    mifptarray(A, n);
515
 
    fprintf(Output_file, ">\n");
516
 
}
517
 
 
518
 
static void mif_polygon(point * A, int n, int filled)
519
 
{
520
 
    fprintf(Output_file, "<Polygon %s\n", (filled ? FillStr : NoFillStr));
521
 
    mifptarray(A, n);
522
 
    fprintf(Output_file, ">\n");
523
 
}
524
 
 
525
 
static void mif_ellipse(point p, int rx, int ry, int filled)
526
 
{
527
 
    pointf tl, mp;
528
 
    tl.x = p.x - rx;
529
 
    tl.y = p.y + ry;
530
 
    if (Rot) {
531
 
        int t;
532
 
        t = rx;
533
 
        rx = ry;
534
 
        ry = t;
535
 
    }
536
 
    mp = mifpt(tl);
537
 
    fprintf(Output_file, "<Ellipse %s <BRect %.2f %.2f %.1f %.1f>>\n",
538
 
            filled ? FillStr : NoFillStr,
539
 
            mp.x, mp.y, Scale * (rx + rx), Scale * (ry + ry));
540
 
}
541
 
 
542
 
static void mif_polyline(point * A, int n)
543
 
{
544
 
    fprintf(Output_file, "<PolyLine <HeadCap Square>\n");
545
 
    mifptarray(A, n);
546
 
    fprintf(Output_file, ">\n");
547
 
}
548
 
 
549
 
static void mif_usershape(usershape_t *us, boxf b, point *A, int n, boolean filled)
550
 
{
551
 
    static boolean onetime = TRUE;
552
 
    if (onetime) {
553
 
        agerr(AGERR, "custom shapes not available with this driver\n");
554
 
        onetime = FALSE;
555
 
    }
556
 
}
557
 
 
558
 
codegen_t MIF_CodeGen = {
559
 
    mif_reset,
560
 
    mif_begin_job, mif_end_job,
561
 
    mif_begin_graph, 0,         /* mif_end_graph */
562
 
    mif_begin_page, 0,          /* mif_end_page */
563
 
    0, /* mif_begin_layer */ 0, /* mif_end_layer */
564
 
    0, /* mif_begin_cluster */ 0, /* mif_end_cluster */
565
 
    0, /* mif_begin_nodes */ 0, /* mif_end_nodes */
566
 
    0, /* mif_begin_edges */ 0, /* mif_end_edges */
567
 
    0, /* mif_begin_node */  0, /* mif_end_node */
568
 
    0, /* mif_begin_edge */  0, /* mif_end_edge */
569
 
    mif_begin_context, mif_end_context,
570
 
    0, /* mif_begin_anchor */ 0,        /* mif_end_anchor */
571
 
    mif_set_font, mif_textpara,
572
 
    mif_set_color, mif_set_color, mif_set_style,
573
 
    mif_ellipse, mif_polygon,
574
 
    mif_bezier, mif_polyline,
575
 
    0,                          /* bezier_has_arrows */
576
 
    mif_comment,
577
 
    mif_usershape
578
 
};