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.
11
/* mpgen.c 1999-Feb-23 Jim Hefferon jim@joshua.smcvt.edu
12
* Adapted from psgen.c. See 1st_read.mp.
31
/* static point Pages; */
33
static int onetime = TRUE;
35
/* static char **U_lib; */
37
typedef struct grcontext_t {
42
#define STACKSIZE 32 /* essentially infinite? */
43
static grcontext_t S[STACKSIZE];
53
mp_begin_job(FILE *ofp,graph_t *g, char **lib, char *user, char *info[],
57
/* pages and libraries not here (yet?) */
60
/* N_pages = pages.x * pages.y; */
63
fprintf(Outfile,"%%--- graphviz MetaPost input\n");
64
fprintf(Outfile,"%% Created by program: %s version %s (%s)\n",info[0],info[1], info[2]);
65
fprintf(Outfile,"%% For user: %s\n",user);
66
fprintf(Outfile,"%% Title: %s\n",g->name);
67
fprintf(Outfile,"%% Put this between beginfig and endfig. See 1st_read.mp.\n");
68
fprintf(Outfile,"%% \n");
74
fprintf(Outfile,"%% End of graphviz MetaPost input\n");
75
fprintf(Outfile,"%% \n");
79
mp_comment(void* obj, attrsym_t* sym)
82
str = late_string(obj,sym,"");
83
if (str[0]) fprintf(Outfile,"%% %s\n",str);
87
mp_begin_graph(graph_t* g, box bb, point pb)
91
fprintf(Outfile,"%% BoundingBox: %d %d %d %d\n",
92
bb.LL.x,bb.LL.y,bb.UR.x+1,bb.UR.y+1);
93
mp_comment(g,agfindattr(g,"comment"));
94
/* cat_libfile(Outfile,U_lib,mp_lib); */
105
mp_begin_page(point page, double scale, int rot, point offset)
109
S[SP].color = "black";
119
mp_begin_cluster(graph_t* g)
156
mp_begin_node(node_t* n)
159
fprintf(Outfile,"%% GV node: \n%% %s\n",n->name);
160
mp_comment(n,N_comment);
170
mp_begin_edge (edge_t* e)
173
fprintf(Outfile,"%% GV edge: \n%% %s -> %s\n",e->tail->name,e->head->name);
174
mp_comment(e,E_comment);
184
mp_begin_context(void)
186
if (SP == STACKSIZE - 1) fprintf(stderr,"warning: mpgen stack overflow\n");
187
else {SP++; S[SP] = S[SP-1];}
193
if (SP == 0) fprintf(stderr,"warning: mpgen stack underflow\n");
198
mp_set_font(char* name, double size)
200
if (strcmp(S[SP].font,name) || (size != S[SP].size)) {
201
fprintf(Outfile,"%% GV set font: %.2f /%s ignored\n",size,name);
208
mp_set_color(char* name)
210
static char *op[] = {"graph","node","edge","sethsb"};
213
if (strcmp(name,S[SP].color)) {
214
colorxlate(name,&color,HSV_DOUBLE);
215
fprintf(Outfile,"%% GV set color: %.3f %.3f %.3f %scolor\n",
216
color.u.HSV[0],color.u.HSV[1],color.u.HSV[2],op[Obj]);
222
mp_set_style(char** s)
226
while ((p = line = *s++)) {
229
fprintf(Outfile,"%% GV set style: %s \n",p);
232
fprintf(Outfile,"%% GV set style:: %s\n",line);
239
static char *buf = NULL;
240
static int bufsize = 0;
246
buf = malloc(bufsize);
251
if (pos > (bufsize-8)) {
253
buf = realloc(buf,bufsize);
256
if ((*s == LPAREN) || (*s == RPAREN)) {
268
mp_textline(point p, textline_t *line)
270
fprintf(Outfile,"label(btex %s etex,(%dbp,%dbp)) withcolor %s;\n",
271
mp_string(line->str),p.x,p.y,S[SP].color);
275
mp_bezier(point *A, int n, int arrow_at_start, int arrow_at_end)
278
if (arrow_at_start || arrow_at_end)
279
fprintf(stderr," mp_bezier illegal arrow args\n");
280
fprintf(Outfile,"draw (%dbp,%dbp) ",A[0].x,A[0].y);
281
for (j = 1; j < n; j += 3)
282
fprintf(Outfile,"\n ..controls (%dbp,%dbp) and (%dbp,%dbp).. (%dbp,%dbp)",
283
A[j].x,A[j].y,A[j+1].x,A[j+1].y,A[j+2].x,A[j+2].y);
284
fprintf(Outfile," withcolor %s;\n",S[SP].color);
288
mp_polygon(point *A, int n, int filled)
292
fprintf(Outfile," fill (%dbp,%dbp)",A[0].x,A[0].y);
293
for (j = 1; j < n; j++)
294
fprintf(Outfile,"\n --(%dbp,%dbp)",A[j].x,A[j].y);
295
fprintf(Outfile,"\n --cycle withcolor %s;\n",S[SP].color);
297
fprintf(Outfile,"draw (%dbp,%dbp) ",A[0].x,A[0].y);
298
for (j = 1; j < n; j++)
299
fprintf(Outfile,"\n --(%dbp,%dbp)",A[j].x,A[j].y);
300
fprintf(Outfile,"\n --cycle withcolor %s;\n",S[SP].color);
304
mp_ellipse(point p, int rx, int ry, int filled)
307
fprintf(Outfile," fill fullcircle xscaled %dbp yscaled %dbp shifted (%dbp,%dbp) withcolor %s;\n",
308
2*rx,2*ry,p.x,p.y,S[SP].color);
309
fprintf(Outfile,"draw fullcircle xscaled %dbp yscaled %dbp shifted (%dbp,%dbp);\n",
314
mp_polyline(point* A, int n)
318
fprintf(Outfile,"draw (%dbp,%dbp) ",A[0].x,A[0].y);
319
for (j = 1; j < n; j ++) fprintf(Outfile,"\n --(%dbp,%dbp)",A[j].x,A[j].y);
320
fprintf(Outfile," withcolor %s;\n",S[SP].color);
324
mp_user_shape(char *name, point *A, int sides, int filled)
327
fprintf(Outfile,"%%GV USER SHAPE [ ");
328
for (j = 0; j < sides; j++) fprintf(Outfile,"%d %d ",A[j].x,A[j].y);
329
fprintf(Outfile,"%d %d ",A[0].x,A[0].y);
330
fprintf(Outfile,"] %d %s %s ignored\n",sides,(filled?"true":"false"),name);
334
codegen_t MP_CodeGen = {
336
mp_begin_job, mp_end_job,
337
mp_begin_graph, mp_end_graph,
338
mp_begin_page, mp_end_page,
339
mp_begin_cluster, mp_end_cluster,
340
mp_begin_nodes, mp_end_nodes,
341
mp_begin_edges, mp_end_edges,
342
mp_begin_node, mp_end_node,
343
mp_begin_edge, mp_end_edge,
344
mp_begin_context, mp_end_context,
345
mp_set_font, mp_textline,
346
mp_set_color, mp_set_color, mp_set_style,
347
mp_ellipse, mp_polygon,
348
mp_bezier, mp_polyline,
349
0 /* mp_arrowhead */, mp_user_shape,
350
mp_comment, 0 /* mp_textsize */