39 #define BEZIERSUBDIVISION 6
45 static void mpptarray(
GVJ_t *job,
pointf * A,
int n,
int close)
50 for (i = 0; i < n; i++) {
61 static char *mp_string(
char *
s)
63 static char *buf =
NULL;
64 static int bufsize = 0;
71 buf = malloc(bufsize *
sizeof(
char));
76 if (pos > (bufsize - 8)) {
78 buf = realloc(buf, bufsize *
sizeof(
char));
90 sprintf(p,
"%03o", c);
99 static int mpColorResolve(
int *
new,
int r,
int g,
int b)
101 #define maxColors 256
106 long rd, gd, bd,
dist;
107 long mindist = 3 * 255 * 255;
110 for (c = 0; c <
top; c++) {
111 rd = (long) (red[c] - r);
112 gd = (long) (green[c] - g);
113 bd = (long) (blue[c] - b);
114 dist = rd * rd + gd * gd + bd * bd;
115 if (dist < mindist) {
133 static char *mpcolor[] = {
134 "black",
"blue",
"green",
"cyan",
"red",
"magenta",
"yellow",
"white", (
char *)
NULL
142 switch (color->
type) {
144 for (i = 0; mpcolor[i]; i++) {
152 i = 32 + mpColorResolve(&
new,
157 gvprintf(job,
"%d %d #%02x%02x%02x\n",
174 static void mp_line_style(
obj_state_t *obj,
int *line_style,
double *style_val)
193 static void mp_comment(
GVJ_t *job,
char *
str)
198 static void mp_begin_graph(
GVJ_t * job)
202 gvputs(job,
"#FIG 3.2\n");
203 gvprintf(job,
"# Generated by %s version %s (%s)\n",
207 gvputs(job,
"Portrait\n");
218 static void mp_end_graph(
GVJ_t * job)
220 gvputs(job,
"# end of FIG file\n");
223 static void mp_begin_page(
GVJ_t * job)
228 static void mp_begin_node(
GVJ_t * job)
233 static void mp_end_node(
GVJ_t * job)
238 static void mp_begin_edge(
GVJ_t * job)
243 static void mp_end_edge(
GVJ_t * job)
267 switch (span->
just) {
281 "%d %d %d %d %d %d %.1f %.4f %d %.1f %.1f %d %d %s\\001\n",
282 object_code, sub_type, color, depth, pen_style, font,
283 font_size, angle, font_flags, height, length,
ROUND(p.
x),
ROUND(p.
y),
284 mp_string(span->
str));
287 static void mp_ellipse(
GVJ_t * job,
pointf * A,
int filled)
299 int area_fill = filled ? 20 : -1;
303 int center_x, center_y, radius_x, radius_y;
304 int start_x, start_y, end_x, end_y;
306 mp_line_style(obj, &line_style, &style_val);
308 start_x = center_x =
ROUND(A[0].x);
309 start_y = center_y =
ROUND(A[0].y);
310 radius_x =
ROUND(A[1].x - A[0].x);
311 radius_y =
ROUND(A[1].y - A[0].y);
312 end_x =
ROUND(A[1].x);
313 end_y =
ROUND(A[1].y);
316 "%d %d %d %d %d %d %d %d %d %.3f %d %.4f %d %d %d %d %d %d %d %d\n",
317 object_code, sub_type, line_style, thickness, pen_color,
318 fill_color, depth, pen_style, area_fill, style_val, direction,
319 angle, center_x, center_y, radius_x, radius_y, start_x,
320 start_y, end_x, end_y);
323 static void mp_bezier(
GVJ_t * job,
pointf * A,
int n,
int arrow_at_start,
324 int arrow_at_end,
int filled)
339 int forward_arrow = 0;
340 int backward_arrow = 0;
354 1) * 20 *
sizeof(
char));
357 mp_line_style(obj, &line_style, &style_val);
374 size = sprintf(buf,
" %d %d", p.
x, p.
y);
377 for (i = 0; i + 3 < n; i += 3) {
379 for (j = 1; j <= 3; j++) {
387 size = sprintf(buf,
" %d %d", p.
x, p.
y);
392 gvprintf(job,
"%d %d %d %d %d %d %d %d %d %.1f %d %d %d %d\n",
402 style_val, cap_style, forward_arrow, backward_arrow, count);
406 for (i = 0; i < count; i++) {
407 gvprintf(job,
" %d", i % (count - 1) ? 1 : 0);
412 static void mp_polygon(
GVJ_t * job,
pointf * A,
int n,
int filled)
424 int area_fill = filled ? 20 : -1;
429 int forward_arrow = 0;
430 int backward_arrow = 0;
433 mp_line_style(obj, &line_style, &style_val);
436 "%d %d %d %d %d %d %d %d %d %.1f %d %d %d %d %d %d\n",
437 object_code, sub_type, line_style, thickness, pen_color,
438 fill_color, depth, pen_style, area_fill, style_val, join_style,
439 cap_style, radius, forward_arrow, backward_arrow, npoints);
440 mpptarray(job, A, n, 1);
443 static void mp_polyline(
GVJ_t * job,
pointf * A,
int n)
460 int forward_arrow = 0;
461 int backward_arrow = 0;
464 mp_line_style(obj, &line_style, &style_val);
467 "%d %d %d %d %d %d %d %d %d %.1f %d %d %d %d %d %d\n",
468 object_code, sub_type, line_style, thickness, pen_color,
469 fill_color, depth, pen_style, area_fill, style_val, join_style,
470 cap_style, radius, forward_arrow, backward_arrow, npoints);
471 mpptarray(job, A, n, 0);
gvplugin_installed_t gvdevice_mp_types[]
int gvputs(GVJ_t *job, const char *s)
gvplugin_installed_t gvrender_mp_types[]
CGRAPH_API char * agnameof(void *)
#define BEZIERSUBDIVISION
PostscriptAlias * postscript_alias
pointf Bezier(pointf *V, int degree, double t, pointf *Left, pointf *Right)
gvrender_engine_t mp_engine
void(* pf)(char *, void *)
double dist(Site *s, Site *t)
void gvprintf(GVJ_t *job, const char *format,...)