39 #define BEZIERSUBDIVISION 6
45 static void vtxptarray(
GVJ_t *job,
pointf * A,
int n,
int close)
50 for (i = 0; i < n; i++) {
61 static char *vtx_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 vtxColorResolve(
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 *vtxcolor[] = {
134 "black",
"blue",
"green",
"cyan",
"red",
"magenta",
"yellow",
"white", (
char *)
NULL
142 switch (color->
type) {
144 for (i = 0; vtxcolor[i]; i++) {
152 i = 32 + vtxColorResolve(&
new,
157 gvprintf(job,
"%d %d #%02x%02x%02x\n",
171 static void vtx_line_style(
obj_state_t *obj,
int *line_style,
double *style_val)
190 static void vtx_comment(
GVJ_t *job,
char *
str)
195 static void vtx_begin_graph(
GVJ_t * job)
199 gvputs(job,
"#FIG 3.2\n");
200 gvprintf(job,
"# Generated by %s version %s (%s)\n",
202 gvprintf(job,
"# Title: %s\n", obj->
u.
g->name);
204 gvputs(job,
"Portrait\n");
215 static void vtx_end_graph(
GVJ_t * job)
217 gvputs(job,
"# end of FIG file\n");
220 static void vtx_begin_page(
GVJ_t * job)
225 static void vtx_begin_node(
GVJ_t * job)
230 static void vtx_end_node(
GVJ_t * job)
235 static void vtx_begin_edge(
GVJ_t * job)
240 static void vtx_end_edge(
GVJ_t * job)
245 static void vtx_textpara(
GVJ_t * job,
pointf p, textpara_t * para)
255 double font_size = para->fontsize * job->
zoom;
261 if (para->postscript_alias)
262 font = para->postscript_alias->xfig_code;
264 switch (para->just) {
278 "%d %d %d %d %d %d %.1f %.4f %d %.1f %.1f %d %d %s\\001\n",
279 object_code, sub_type, color, depth, pen_style, font,
280 font_size, angle, font_flags, height, length,
ROUND(p.
x),
ROUND(p.
y),
281 vtx_string(para->str));
284 static void vtx_ellipse(
GVJ_t * job,
pointf * A,
int filled)
296 int area_fill = filled ? 20 : -1;
300 int center_x, center_y, radius_x, radius_y;
301 int start_x, start_y, end_x, end_y;
303 vtx_line_style(obj, &line_style, &style_val);
305 start_x = center_x =
ROUND(A[0].x);
306 start_y = center_y =
ROUND(A[0].y);
307 radius_x =
ROUND(A[1].x - A[0].x);
308 radius_y =
ROUND(A[1].y - A[0].y);
309 end_x =
ROUND(A[1].x);
310 end_y =
ROUND(A[1].y);
313 "%d %d %d %d %d %d %d %d %d %.3f %d %.4f %d %d %d %d %d %d %d %d\n",
314 object_code, sub_type, line_style, thickness, pen_color,
315 fill_color, depth, pen_style, area_fill, style_val, direction,
316 angle, center_x, center_y, radius_x, radius_y, start_x,
317 start_y, end_x, end_y);
320 static void vtx_bezier(
GVJ_t * job,
pointf * A,
int n,
int arrow_at_start,
321 int arrow_at_end,
int filled)
336 int forward_arrow = 0;
337 int backward_arrow = 0;
351 1) * 20 *
sizeof(
char));
354 vtx_line_style(obj, &line_style, &style_val);
371 size = sprintf(buf,
" %d %d", p.
x, p.
y);
374 for (i = 0; i + 3 < n; i += 3) {
376 for (j = 1; j <= 3; j++) {
384 size = sprintf(buf,
" %d %d", p.
x, p.
y);
389 gvprintf(job,
"%d %d %d %d %d %d %d %d %d %.1f %d %d %d %d\n",
399 style_val, cap_style, forward_arrow, backward_arrow, count);
403 for (i = 0; i < count; i++) {
404 gvprintf(job,
" %d", i % (count - 1) ? 1 : 0);
409 static void vtx_polygon(
GVJ_t * job,
pointf * A,
int n,
int filled)
421 int area_fill = filled ? 20 : -1;
426 int forward_arrow = 0;
427 int backward_arrow = 0;
430 vtx_line_style(obj, &line_style, &style_val);
433 "%d %d %d %d %d %d %d %d %d %.1f %d %d %d %d %d %d\n",
434 object_code, sub_type, line_style, thickness, pen_color,
435 fill_color, depth, pen_style, area_fill, style_val, join_style,
436 cap_style, radius, forward_arrow, backward_arrow, npoints);
437 vtxptarray(job, A, n, 1);
440 static void vtx_polyline(
GVJ_t * job,
pointf * A,
int n)
457 int forward_arrow = 0;
458 int backward_arrow = 0;
461 vtx_line_style(obj, &line_style, &style_val);
464 "%d %d %d %d %d %d %d %d %d %.1f %d %d %d %d %d %d\n",
465 object_code, sub_type, line_style, thickness, pen_color,
466 fill_color, depth, pen_style, area_fill, style_val, join_style,
467 cap_style, radius, forward_arrow, backward_arrow, npoints);
468 vtxptarray(job, A, n, 0);
gvplugin_installed_t gvdevice_vtx_types[]
gvplugin_installed_t gvrender_vtx_types[]
int gvputs(GVJ_t *job, const char *s)
gvrender_engine_t vtx_engine
pointf Bezier(pointf *V, int degree, double t, pointf *Left, pointf *Right)
void(* pf)(char *, void *)
#define BEZIERSUBDIVISION
double dist(Site *s, Site *t)
void gvprintf(GVJ_t *job, const char *format,...)