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: */
4
/**********************************************************
5
* This software is part of the graphviz package *
6
* http://www.graphviz.org/ *
8
* Copyright (c) 1994-2004 AT&T Corp. *
9
* and is licensed under the *
10
* Common Public License, Version 1.0 *
13
* Information and Software Systems Research *
14
* AT&T Research, Florham Park NJ *
15
**********************************************************/
25
/* MIF font modifiers */
33
#define P_DOTTED 4 /* i wasn't sure about this */
34
#define P_DASHED 11 /* or this */
36
/* MIF bold line constant */
37
#define WIDTH_NORMAL 1
41
/* static point Pages; */
45
static int onetime = TRUE;
47
typedef struct context_t {
48
char color_ix, *fontfam, fontopt, font_was_set;
49
char pen, fill, penwidth, style_was_set;
54
static context_t cstk[MAXNEST];
57
static char *FillStr = "<Fill 3>";
58
static char *NoFillStr = "<Fill 15>";
60
static void mif_reset(void)
66
static void init_mif(void)
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;
77
static pointf mifpt(pointf p)
84
rv.y = PB.UR.y - PB.LL.y - tmp.y;
86
rv.x = PB.UR.x - PB.LL.x - tmp.y;
92
static void mifptarray(point * A, int n)
97
fprintf(Output_file, " <NumPoints %d>\n", n);
98
for (i = 0; i < n; i++) {
102
fprintf(Output_file, " <Point %.2f %.2f>\n", p.x, p.y);
106
static void mif_font(context_t * cp)
111
switch (cp->fontopt) {
120
"<Font <FFamily `%s'> <FSize %.1f pt> <FWeight %s> <FAngle %s>>\n",
121
cp->fontfam, Scale * cp->fontsz, fw, fa);
124
static void mif_color(int i)
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",
134
fprintf(Output_file, "<Separation %d>\n", i);
136
fprintf(Output_file, "<ObColor `%s'>\n", mifcolor[i]);
139
static void mif_style(context_t * cp)
141
fprintf(Output_file, "<Pen %d> <Fill %d> <PenWidth %d>\n",
142
cp->pen, cp->fill, cp->penwidth);
145
static void mif_comment(char *str)
147
fprintf(Output_file, "# %s\n", str);
151
mif_begin_job(FILE * ofp, graph_t * g, char **lib, char *user,
152
char *info[], point pages)
155
N_pages = pages.x * pages.y;
157
"<MIFFile 3.00> # Generated by %s version %s (%s)\n", info[0],
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");
309
static void mif_end_job(void)
311
fprintf(Output_file, "# end of MIFFile\n");
314
static void mif_begin_graph(GVC_t * gvc, graph_t * g, box bb, point pb)
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);
326
mif_begin_page(graph_t * g, point page, double scale, int rot,
329
/* int page_number; */
334
/* page_number = page.x + page.y * Pages.x + 1; */
335
/* sz = sub_points(PB.UR,PB.LL); */
337
" <ArrowStyle <TipAngle 15> <BaseAngle 90> <Length %.1f> <HeadType Filled>>\n",
341
static void mif_begin_context(void)
343
assert(SP + 1 < MAXNEST);
344
cstk[SP + 1] = cstk[SP];
348
static void mif_end_context(void)
352
if (cstk[SP].color_ix != (c = cstk[psp].color_ix))
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); */
362
static void mif_set_font(char *name, double size)
368
cp->font_was_set = TRUE;
371
if ((q = strchr(p, '-'))) {
373
if (strcasecmp(q, "italic") == 0)
374
cp->fontopt = ITALIC;
375
else if (strcasecmp(q, "bold") == 0)
382
static void mif_set_color(char *name)
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",
395
tok = canontoken(name);
396
for (i = 0; mifcolor[i]; i++) {
397
if (strcasecmp(mifcolor[i], tok) == 0) {
398
cstk[SP].color_ix = i;
403
agerr(AGERR, "color %s not supported in MIF\n", name);
406
static void mif_set_style(char **s)
412
while ((line = *s++)) {
413
if (streq(line, "solid"))
415
else if (streq(line, "dashed"))
417
else if (streq(line, "dotted"))
419
else if (streq(line, "invis"))
421
else if (streq(line, "bold"))
422
cp->penwidth = WIDTH_BOLD;
423
else if (streq(line, "filled"))
425
else if (streq(line, "unfilled"))
429
"mif_set_style: unsupported style %s - ignoring\n",
432
cp->style_was_set = TRUE;
434
if (cp->style_was_set)
438
static char *mif_string(char *s)
440
static char *buf = NULL;
441
static int bufsize = 0;
447
buf = N_GNEW(bufsize, char);
452
if (pos > (bufsize - 8)) {
454
buf = grealloc(buf, bufsize);
483
static void mif_textpara(point p, textpara_t * para)
489
mp.y = p.y - cstk[SP].fontsz / 2 + 2;
490
switch (para->just) {
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));
509
static void mif_bezier(point * A, int n, int arrow_at_start,
510
int arrow_at_end, int filled)
513
"<PolyLine <Fill 15> <Smoothed Yes> <HeadCap Square>\n");
515
fprintf(Output_file, ">\n");
518
static void mif_polygon(point * A, int n, int filled)
520
fprintf(Output_file, "<Polygon %s\n", (filled ? FillStr : NoFillStr));
522
fprintf(Output_file, ">\n");
525
static void mif_ellipse(point p, int rx, int ry, int filled)
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));
542
static void mif_polyline(point * A, int n)
544
fprintf(Output_file, "<PolyLine <HeadCap Square>\n");
546
fprintf(Output_file, ">\n");
549
static void mif_usershape(usershape_t *us, boxf b, point *A, int n, boolean filled)
551
static boolean onetime = TRUE;
553
agerr(AGERR, "custom shapes not available with this driver\n");
558
codegen_t MIF_CodeGen = {
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 */