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.
23
/* MIF font modifiers */
31
#define P_DOTTED 4 /* i wasn't sure about this */
32
#define P_DASHED 11 /* or this */
34
/* MIF bold line constant */
35
#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;
81
tmp.x = p.x * Scale; tmp.y = Scale * p.y;
82
if (Rot == 0) { rv.x = tmp.x; rv.y = PB.UR.y - PB.LL.y - tmp.y; }
83
else {rv.x = PB.UR.x - PB.LL.x - tmp.y; rv.y = tmp.x; }
88
mifptarray(point* A, int n)
93
fprintf(Outfile," <NumPoints %d>\n",n);
94
for (i = 0; i < n; i++) {
95
p.x = A[i].x; p.y = A[i].y;
97
fprintf(Outfile," <Point %.2f %.2f>\n",p.x,p.y);
101
static void mif_font(context_t* cp)
106
switch (cp->fontopt) {
107
case BOLD: fw = "Bold"; break;
108
case ITALIC: fa = "Italic"; break;
110
fprintf(Outfile,"<Font <FFamily `%s'> <FSize %.1f pt> <FWeight %s> <FAngle %s>>\n",cp->fontfam,Scale*cp->fontsz,fw,fa);
113
static void mif_color(int i)
115
static char *mifcolor[]= {
116
"black","white","red","green","blue","cyan",
117
"magenta","yellow","comment",
118
"aquamarine","plum","peru","pink","mediumpurple","grey",
119
"lightgrey","lightskyblue","lightcoral","yellowgreen",
121
if (i <= 8) fprintf(Outfile,"<Separation %d>\n",i);
122
if (i > 8) fprintf(Outfile, "<ObColor `%s'>\n", mifcolor[i]);
125
static void mif_style(context_t* cp)
127
fprintf(Outfile,"<Pen %d> <Fill %d> <PenWidth %d>\n",
128
cp->pen,cp->fill,cp->penwidth);
131
static void mif_comment(void* obj, attrsym_t* sym)
134
str = late_string(obj,sym,"");
135
if (str[0]) fprintf(Outfile,"# %s\n",str);
139
mif_begin_job(FILE *ofp, graph_t *g, char **lib, char *user, char *info[], point pages)
143
N_pages = pages.x * pages.y;
144
fprintf(Outfile,"<MIFFile 3.00> # Generated by %s version %s (%s)\n",
145
info[0],info[1],info[2]);
146
fprintf(Outfile,"# For: %s\n",user);
147
fprintf(Outfile,"# Title: %s\n",g->name);
148
fprintf(Outfile,"# Pages: %d\n",N_pages);
149
fprintf(Outfile,"<Units Upt>\n");
150
fprintf(Outfile, "<ColorCatalog \n");
151
fprintf(Outfile, " <Color \n");
152
fprintf(Outfile, " <ColorTag `Black'>\n");
153
fprintf(Outfile, " <ColorCyan 0.000000>\n");
154
fprintf(Outfile, " <ColorMagenta 0.000000>\n");
155
fprintf(Outfile, " <ColorYellow 0.000000>\n");
156
fprintf(Outfile, " <ColorBlack 100.000000>\n");
157
fprintf(Outfile, " <ColorAttribute ColorIsBlack>\n");
158
fprintf(Outfile, " <ColorAttribute ColorIsReserved>\n");
159
fprintf(Outfile, " > # end of Color\n");
160
fprintf(Outfile, " <Color \n");
161
fprintf(Outfile, " <ColorTag `White'>\n");
162
fprintf(Outfile, " <ColorCyan 0.000000>\n");
163
fprintf(Outfile, " <ColorMagenta 0.000000>\n");
164
fprintf(Outfile, " <ColorYellow 0.000000>\n");
165
fprintf(Outfile, " <ColorBlack 0.000000>\n");
166
fprintf(Outfile, " <ColorAttribute ColorIsWhite>\n");
167
fprintf(Outfile, " <ColorAttribute ColorIsReserved>\n");
168
fprintf(Outfile, " > # end of Color\n");
169
fprintf(Outfile, " <Color \n");
170
fprintf(Outfile, " <ColorTag `Red'>\n");
171
fprintf(Outfile, " <ColorCyan 0.000000>\n");
172
fprintf(Outfile, " <ColorMagenta 100.000000>\n");
173
fprintf(Outfile, " <ColorYellow 100.000000>\n");
174
fprintf(Outfile, " <ColorBlack 0.000000>\n");
175
fprintf(Outfile, " <ColorAttribute ColorIsRed>\n");
176
fprintf(Outfile, " <ColorAttribute ColorIsReserved>\n");
177
fprintf(Outfile, " > # end of Color\n");
178
fprintf(Outfile, " <Color \n");
179
fprintf(Outfile, " <ColorTag `Green'>\n");
180
fprintf(Outfile, " <ColorCyan 100.000000>\n");
181
fprintf(Outfile, " <ColorMagenta 0.000000>\n");
182
fprintf(Outfile, " <ColorYellow 100.000000>\n");
183
fprintf(Outfile, " <ColorBlack 0.000000>\n");
184
fprintf(Outfile, " <ColorAttribute ColorIsGreen>\n");
185
fprintf(Outfile, " <ColorAttribute ColorIsReserved>\n");
186
fprintf(Outfile, " > # end of Color\n");
187
fprintf(Outfile, " <Color \n");
188
fprintf(Outfile, " <ColorTag `Blue'>\n");
189
fprintf(Outfile, " <ColorCyan 100.000000>\n");
190
fprintf(Outfile, " <ColorMagenta 100.000000>\n");
191
fprintf(Outfile, " <ColorYellow 0.000000>\n");
192
fprintf(Outfile, " <ColorBlack 0.000000>\n");
193
fprintf(Outfile, " <ColorAttribute ColorIsBlue>\n");
194
fprintf(Outfile, " <ColorAttribute ColorIsReserved>\n");
195
fprintf(Outfile, " > # end of Color\n");
196
fprintf(Outfile, " <Color \n");
197
fprintf(Outfile, " <ColorTag `Cyan'>\n");
198
fprintf(Outfile, " <ColorCyan 100.000000>\n");
199
fprintf(Outfile, " <ColorMagenta 0.000000>\n");
200
fprintf(Outfile, " <ColorYellow 0.000000>\n");
201
fprintf(Outfile, " <ColorBlack 0.000000>\n");
202
fprintf(Outfile, " <ColorAttribute ColorIsCyan>\n");
203
fprintf(Outfile, " <ColorAttribute ColorIsReserved>\n");
204
fprintf(Outfile, " > # end of Color\n");
205
fprintf(Outfile, " <Color \n");
206
fprintf(Outfile, " <ColorTag `Magenta'>\n");
207
fprintf(Outfile, " <ColorCyan 0.000000>\n");
208
fprintf(Outfile, " <ColorMagenta 100.000000>\n");
209
fprintf(Outfile, " <ColorYellow 0.000000>\n");
210
fprintf(Outfile, " <ColorBlack 0.000000>\n");
211
fprintf(Outfile, " <ColorAttribute ColorIsMagenta>\n");
212
fprintf(Outfile, " <ColorAttribute ColorIsReserved>\n");
213
fprintf(Outfile, " > # end of Color\n");
214
fprintf(Outfile, " <Color \n");
215
fprintf(Outfile, " <ColorTag `Yellow'>\n");
216
fprintf(Outfile, " <ColorCyan 0.000000>\n");
217
fprintf(Outfile, " <ColorMagenta 0.000000>\n");
218
fprintf(Outfile, " <ColorYellow 100.000000>\n");
219
fprintf(Outfile, " <ColorBlack 0.000000>\n");
220
fprintf(Outfile, " <ColorAttribute ColorIsYellow>\n");
221
fprintf(Outfile, " <ColorAttribute ColorIsReserved>\n");
222
fprintf(Outfile, " > # end of Color\n");
223
fprintf(Outfile, " <Color \n");
224
fprintf(Outfile, " <ColorTag `aquamarine'>\n");
225
fprintf(Outfile, " <ColorCyan 100.000000>\n");
226
fprintf(Outfile, " <ColorMagenta 0.000000>\n");
227
fprintf(Outfile, " <ColorYellow 18.000000>\n");
228
fprintf(Outfile, " <ColorBlack 0.000000>\n");
229
fprintf(Outfile, " > # end of Color\n");
230
fprintf(Outfile, " <Color \n");
231
fprintf(Outfile, " <ColorTag `plum'>\n");
232
fprintf(Outfile, " <ColorCyan 0.000000>\n");
233
fprintf(Outfile, " <ColorMagenta 100.000000>\n");
234
fprintf(Outfile, " <ColorYellow 0.000000>\n");
235
fprintf(Outfile, " <ColorBlack 33.000000>\n");
236
fprintf(Outfile, " > # end of Color\n");
237
fprintf(Outfile, " <Color \n");
238
fprintf(Outfile, " <ColorTag `peru'>\n");
239
fprintf(Outfile, " <ColorCyan 0.000000>\n");
240
fprintf(Outfile, " <ColorMagenta 24.000000>\n");
241
fprintf(Outfile, " <ColorYellow 100.000000>\n");
242
fprintf(Outfile, " <ColorBlack 32.000000>\n");
243
fprintf(Outfile, " > # end of Color\n");
244
fprintf(Outfile, " <Color \n");
245
fprintf(Outfile, " <ColorTag `pink'>\n");
246
fprintf(Outfile, " <ColorCyan 0.000000>\n");
247
fprintf(Outfile, " <ColorMagenta 50.000000>\n");
248
fprintf(Outfile, " <ColorYellow 0.000000>\n");
249
fprintf(Outfile, " <ColorBlack 0.000000>\n");
250
fprintf(Outfile, " > # end of Color\n");
251
fprintf(Outfile, " <Color \n");
252
fprintf(Outfile, " <ColorTag `mediumpurple'>\n");
253
fprintf(Outfile, " <ColorCyan 40.000000>\n");
254
fprintf(Outfile, " <ColorMagenta 100.000000>\n");
255
fprintf(Outfile, " <ColorYellow 0.000000>\n");
256
fprintf(Outfile, " <ColorBlack 0.000000>\n");
257
fprintf(Outfile, " > # end of Color\n");
258
fprintf(Outfile, " <Color \n");
259
fprintf(Outfile, " <ColorTag `grey'>\n");
260
fprintf(Outfile, " <ColorCyan 0.000000>\n");
261
fprintf(Outfile, " <ColorMagenta 0.000000>\n");
262
fprintf(Outfile, " <ColorYellow 0.000000>\n");
263
fprintf(Outfile, " <ColorBlack 50.000000>\n");
264
fprintf(Outfile, " > # end of Color\n");
265
fprintf(Outfile, " <Color \n");
266
fprintf(Outfile, " <ColorTag `lightgrey'>\n");
267
fprintf(Outfile, " <ColorCyan 0.000000>\n");
268
fprintf(Outfile, " <ColorMagenta 0.000000>\n");
269
fprintf(Outfile, " <ColorYellow 0.000000>\n");
270
fprintf(Outfile, " <ColorBlack 25.000000>\n");
271
fprintf(Outfile, " > # end of Color\n");
272
fprintf(Outfile, " <Color \n");
273
fprintf(Outfile, " <ColorTag `lightskyblue'>\n");
274
fprintf(Outfile, " <ColorCyan 38.000000>\n");
275
fprintf(Outfile, " <ColorMagenta 33.000000>\n");
276
fprintf(Outfile, " <ColorYellow 0.000000>\n");
277
fprintf(Outfile, " <ColorBlack 0.000000>\n");
278
fprintf(Outfile, " > # end of Color\n");
279
fprintf(Outfile, " <Color \n");
280
fprintf(Outfile, " <ColorTag `lightcoral'>\n");
281
fprintf(Outfile, " <ColorCyan 0.000000>\n");
282
fprintf(Outfile, " <ColorMagenta 50.000000>\n");
283
fprintf(Outfile, " <ColorYellow 60.000000>\n");
284
fprintf(Outfile, " <ColorBlack 0.000000>\n");
285
fprintf(Outfile, " > # end of Color\n");
286
fprintf(Outfile, " <Color \n");
287
fprintf(Outfile, " <ColorTag `yellowgreen'>\n");
288
fprintf(Outfile, " <ColorCyan 31.000000>\n");
289
fprintf(Outfile, " <ColorMagenta 0.000000>\n");
290
fprintf(Outfile, " <ColorYellow 100.000000>\n");
291
fprintf(Outfile, " <ColorBlack 0.000000>\n");
292
fprintf(Outfile, " > # end of Color\n");
293
fprintf(Outfile, "> # end of ColorCatalog\n");
300
fprintf(Outfile,"# end of MIFFile\n");
304
mif_begin_graph(graph_t* g, box bb, point pb)
309
fprintf(Outfile,"<BRect %d %d %d %d>\n",
310
PB.LL.x,PB.UR.y,PB.UR.x - PB.LL.x, PB.UR.y - PB.LL.y);
312
mif_comment(g,agfindattr(g,"comment"));
323
mif_begin_page(point page, double scale, int rot, point offset)
325
/* int page_number; */
330
/* page_number = page.x + page.y * Pages.x + 1; */
331
/* sz = sub_points(PB.UR,PB.LL); */
332
fprintf(Outfile," <ArrowStyle <TipAngle 15> <BaseAngle 90> <Length %.1f> <HeadType Filled>>\n",14*Scale);
341
mif_begin_cluster(graph_t* g)
347
mif_end_cluster (void)
353
mif_begin_nodes(void)
365
mif_begin_edges(void)
377
mif_begin_node(node_t* n)
380
fprintf(Outfile,"# %s\n",n->name);
381
mif_comment(n,N_comment);
391
mif_begin_edge (edge_t* e)
394
fprintf(Outfile,"# %s -> %s\n",e->tail->name,e->head->name);
395
mif_comment(e,E_comment);
405
mif_begin_context(void)
407
assert(SP + 1 < MAXNEST);
408
cstk[SP+1] = cstk[SP];
413
mif_end_context(void)
417
if (cstk[SP].color_ix != (c = cstk[psp].color_ix)) mif_color(c);
418
if (cstk[SP].font_was_set) mif_font(&(cstk[psp]));
419
if (cstk[SP].style_was_set) mif_style(&(cstk[psp]));
420
/*free(cstk[psp].fontfam);*/
425
mif_set_font(char* name, double size)
431
cp->font_was_set = TRUE;
434
if ((q = strchr(p,'-'))) {
436
if (strcasecmp(q,"italic") == 0)
437
cp->fontopt = ITALIC;
438
else if (strcasecmp(q,"bold") == 0)
446
mif_set_color(char* name)
451
static char *mifcolor[]= {
452
"black","white","red","green","blue","cyan",
453
"magenta","yellow","comment",
454
"aquamarine","plum","peru","pink","mediumpurple","grey",
455
"lightgrey", "lightskyblue","lightcoral","yellowgreen",
458
tok = canontoken(name);
459
for (i = 0; mifcolor[i]; i++) {
460
if (strcasecmp(mifcolor[i],tok) == 0) {
461
cstk[SP].color_ix = i;
466
fprintf(stderr,"color %s not supported in MIF\n",name);
470
mif_set_style(char** s)
476
while ((line = *s++)) {
477
if (streq(line,"solid")) { /* no-op */ }
478
else if (streq(line,"dashed")) cp->pen = P_DASHED;
479
else if (streq(line,"dotted")) cp->pen = P_DOTTED;
480
else if (streq(line,"invis")) cp->pen = P_NONE;
481
else if (streq(line,"bold")) cp->penwidth = WIDTH_BOLD;
482
else if (streq(line,"filled")) cp->fill = P_SOLID;
483
else if (streq(line,"unfilled")) { /* no-op */ }
485
fprintf(stderr, "mif_set_style: unsupported style %s - ignoring\n",
488
cp->style_was_set = TRUE;
490
if (cp->style_was_set) mif_style(cp);
496
static char *buf = NULL;
497
static int bufsize = 0;
503
buf = malloc(bufsize);
508
if (pos > (bufsize-8)) {
510
buf = realloc(buf,bufsize);
515
case '\t': esc = 't'; break;
516
case '>': case '\'': case '`': case '\\': esc = *s; break;
533
static void mif_textline(point p, textline_t *line)
536
char *str = line->str;
540
mp.y = p.y - cstk[SP].fontsz/2 + 2;
555
"<TextLine <Angle %d> <TLOrigin %.2f %.2f> <TLAlignment %s>",
556
Rot,mp.x,mp.y,anchor);
557
fprintf(Outfile," <String `%s'>>\n",mif_string(str));
560
static void mif_bezier(point* A, int n, int arrow_at_start, int arrow_at_end)
562
fprintf(Outfile,"<PolyLine <Fill 15> <Smoothed Yes> <HeadCap Square>\n");
564
fprintf(Outfile,">\n");
567
static void mif_polygon(point *A, int n, int filled)
569
fprintf(Outfile,"<Polygon %s\n",(filled? FillStr : NoFillStr));
571
fprintf(Outfile,">\n");
574
static void mif_ellipse(point p, int rx, int ry, int filled)
577
tl.x = p.x - rx; tl.y = p.y + ry;
578
if (Rot) {int t; t = rx; rx = ry; ry = t;}
580
fprintf(Outfile,"<Ellipse %s <BRect %.2f %.2f %.1f %.1f>>\n",
581
filled?FillStr:NoFillStr,
582
mp.x,mp.y,Scale*(rx + rx),Scale*(ry + ry));
585
static void mif_polyline(point* A, int n)
587
fprintf(Outfile,"<PolyLine <HeadCap Square>\n");
589
fprintf(Outfile,">\n");
592
static void mif_user_shape(char *name, point *A, int n, int filled)
594
static boolean onetime = TRUE;
595
if (onetime) {fprintf(stderr,"custom shapes not available with this driver\n"); onetime = FALSE;}
596
mif_polygon(A,n,filled);
599
codegen_t MIF_CodeGen = {
601
mif_begin_job, mif_end_job,
602
mif_begin_graph, mif_end_graph,
603
mif_begin_page, mif_end_page,
604
mif_begin_cluster, mif_end_cluster,
605
mif_begin_nodes, mif_end_nodes,
606
mif_begin_edges, mif_end_edges,
607
mif_begin_node, mif_end_node,
608
mif_begin_edge, mif_end_edge,
609
mif_begin_context, mif_end_context,
610
mif_set_font, mif_textline,
611
mif_set_color, mif_set_color, mif_set_style,
612
mif_ellipse, mif_polygon,
613
mif_bezier, mif_polyline,
614
0 /* mif_arrowhead */, mif_user_shape,
615
0 /* mif_comment */, 0 /* mif_textsize */