31 static int onetime =
TRUE;
33 static const char **U_lib;
44 static void mp_reset(
void)
59 static void mp_cat_libfile(FILE * ofp,
const char **arglib,
const char **stdlib)
62 const char **
s, *bp, *p, *
path;
64 boolean use_stdlib =
TRUE;
68 for (i = 0; use_stdlib && ((p = arglib[i])); i++) {
74 for (s = stdlib; *s; s++) {
79 for (i = 0; (p = arglib[i]) != 0; i++) {
86 else if ((fp = fopen(path,
"r"))) {
87 while ((bp =
Fgets(fp)))
92 agerr(
AGWARN,
"can't open library file %s\n", path);
98 mp_begin_job(FILE * ofp,
graph_t * g,
const char **lib,
char *
info[],
point pages)
106 fprintf(Output_file,
"%%--- graphviz MetaPost input\n");
107 fprintf(Output_file,
"%% Created by program: %s version %s (%s)\n",
108 info[0], info[1], info[2]);
109 fprintf(Output_file,
"%% Title: %s\n",
agnameof(g));
111 "%% Put this between beginfig and endfig. See 1st_read.mp.\n");
112 fprintf(Output_file,
"%% \n");
115 static void mp_end_job(
void)
117 fprintf(Output_file,
"%% End of graphviz MetaPost input\n");
118 fprintf(Output_file,
"%% \n");
121 static void mp_comment(
char *
str)
123 fprintf(Output_file,
"%% %s\n", str);
129 static const char *mp_lib[] = {0};
131 fprintf(Output_file,
"%% BoundingBox: %d %d %d %d\n",
133 mp_cat_libfile(Output_file,U_lib,mp_lib);
143 S[SP].
color =
"black";
147 static void mp_begin_context(
void)
157 static void mp_end_context(
void)
165 static void mp_set_font(
char *name,
double size)
167 if (strcmp(S[SP].font, name) || (size != S[SP].size)) {
168 fprintf(Output_file,
"%% GV set font: %.2f /%s ignored\n", size,
175 static void mp_set_color(
char *name)
177 static char *op[] = {
"graph",
"node",
"edge",
"sethsb" };
180 if (strcmp(name, S[SP].color)) {
182 fprintf(Output_file,
"%% GV set color: %.3f %.3f %.3f %scolor\n",
183 color.u.HSVA[0], color.u.HSVA[1], color.u.HSVA[2], op[Obj]);
188 static void mp_set_style(
char **s)
192 while ((p = line = *s++)) {
197 fprintf(Output_file,
"%% GV set style: %s \n", p);
202 fprintf(Output_file,
"%% GV set style:: %s\n", line);
206 static char *mp_string(
char *s)
208 static char *buf =
NULL;
209 static int bufsize = 0;
215 buf =
N_GNEW(bufsize,
char);
220 if (pos > (bufsize - 8)) {
236 static void mp_textpara(
point p, textpara_t * para)
238 fprintf(Output_file,
"label(btex %s etex,(%dbp,%dbp)) withcolor %s;\n",
239 mp_string(para->str), p.
x, p.
y, S[SP].
color);
243 mp_bezier(
point * A,
int n,
int arrow_at_start,
int arrow_at_end,
int filled)
246 if (arrow_at_start || arrow_at_end)
247 agerr(
AGERR,
"mp_bezier illegal arrow args\n");
248 fprintf(Output_file,
"draw (%dbp,%dbp) ", A[0].x, A[0].y);
249 for (j = 1; j < n; j += 3)
251 "\n ..controls (%dbp,%dbp) and (%dbp,%dbp).. (%dbp,%dbp)",
252 A[j].x, A[j].y, A[j + 1].x, A[j + 1].y, A[j + 2].x,
254 fprintf(Output_file,
" withcolor %s;\n", S[SP].color);
257 static void mp_polygon(
point * A,
int n,
int filled)
261 fprintf(Output_file,
" fill (%dbp,%dbp)", A[0].x, A[0].y);
262 for (j = 1; j < n; j++)
263 fprintf(Output_file,
"\n --(%dbp,%dbp)", A[j].x, A[j].y);
264 fprintf(Output_file,
"\n --cycle withcolor %s;\n", S[SP].color);
266 fprintf(Output_file,
"draw (%dbp,%dbp) ", A[0].x, A[0].y);
267 for (j = 1; j < n; j++)
268 fprintf(Output_file,
"\n --(%dbp,%dbp)", A[j].x, A[j].y);
269 fprintf(Output_file,
"\n --cycle withcolor %s;\n", S[SP].color);
272 static void mp_ellipse(
point p,
int rx,
int ry,
int filled)
276 " fill fullcircle xscaled %dbp yscaled %dbp shifted (%dbp,%dbp) withcolor %s;\n",
277 2 * rx, 2 * ry, p.
x, p.
y, S[SP].
color);
279 "draw fullcircle xscaled %dbp yscaled %dbp shifted (%dbp,%dbp);\n",
280 2 * rx, 2 * ry, p.
x, p.
y);
283 static void mp_polyline(
point * A,
int n)
287 fprintf(Output_file,
"draw (%dbp,%dbp) ", A[0].x, A[0].y);
288 for (j = 1; j < n; j++)
289 fprintf(Output_file,
"\n --(%dbp,%dbp)", A[j].x, A[j].y);
290 fprintf(Output_file,
" withcolor %s;\n", S[SP].color);
296 fprintf(Output_file,
"%%GV USER SHAPE [ ");
297 for (j = 0; j < n; j++)
298 fprintf(Output_file,
"%d %d ", A[j].x, A[j].y);
299 fprintf(Output_file,
"%d %d ", A[0].x, A[0].y);
300 fprintf(Output_file,
"] %d %s %s ignored\n", n,
301 (filled ?
"true" :
"false"), us->
name);
306 mp_begin_job, mp_end_job,
315 mp_begin_context, mp_end_context,
317 mp_set_font, mp_textpara,
318 mp_set_color, mp_set_color, mp_set_style,
319 mp_ellipse, mp_polygon,
320 mp_bezier, mp_polyline,
void * grealloc(void *ptr, size_t size)
int agerr(agerrlevel_t level, const char *fmt,...)
CGRAPH_API char * agnameof(void *)
int colorxlate(char *str, gvcolor_t *color, color_type_t target_type)
const char * safefile(const char *filename)
struct grcontext_t grcontext_t