37 #define BEZIERSUBDIVISION 6
43 static void figptarray(
GVJ_t *job,
pointf * A,
int n,
int close)
48 for (i = 0; i < n; i++) {
59 static char *fig_string(
char *
s)
61 static char *buf =
NULL;
62 static int bufsize = 0;
69 buf = malloc(bufsize *
sizeof(
char));
74 if (pos > (bufsize - 8)) {
76 buf = realloc(buf, bufsize *
sizeof(
char));
88 sprintf(p,
"%03o", c);
97 static int figColorResolve(
int *
new,
int r,
int g,
int b)
104 long rd, gd, bd,
dist;
105 long mindist = 3 * 255 * 255;
108 for (c = 0; c <
top; c++) {
109 rd = (long) (red[c] - r);
110 gd = (long) (green[c] - g);
111 bd = (long) (blue[c] - b);
112 dist = rd * rd + gd * gd + bd * bd;
113 if (dist < mindist) {
131 static char *figcolor[] = {
132 "black",
"blue",
"green",
"cyan",
"red",
"magenta",
"yellow",
"white", (
char *)
NULL
140 switch (color->
type) {
142 for (i = 0; figcolor[i]; i++) {
150 i = 32 + figColorResolve(&
new,
155 gvprintf(job,
"%d %d #%02x%02x%02x\n",
169 static void fig_line_style(
obj_state_t *obj,
int *line_style,
double *style_val)
188 static void fig_comment(
GVJ_t *job,
char *
str)
193 static void fig_begin_graph(
GVJ_t * job)
197 gvputs(job,
"#FIG 3.2\n");
198 gvprintf(job,
"# Generated by %s version %s (%s)\n",
202 gvputs(job,
"Portrait\n");
213 static void fig_end_graph(
GVJ_t * job)
215 gvputs(job,
"# end of FIG file\n");
218 static void fig_begin_page(
GVJ_t * job)
223 static void fig_begin_node(
GVJ_t * job)
228 static void fig_end_node(
GVJ_t * job)
233 static void fig_begin_edge(
GVJ_t * job)
238 static void fig_end_edge(
GVJ_t * job)
261 double height = font_size;
262 double length = 2.0*font_size/3.0 * (double)strlen(span->
str) / 2.0;
268 switch (span->
just) {
288 "%d %d %d %d %d %d %.1f %.4f %d %.1f %.1f %d %d %s\\001\n",
289 object_code, sub_type, color, depth, pen_style, font,
290 font_size, angle, font_flags, height, length,
ROUND(p.
x),
ROUND((p.
y-72.0)),
291 fig_string(span->
str));
294 static void fig_ellipse(
GVJ_t * job,
pointf * A,
int filled)
306 int area_fill = filled ? 20 : -1;
310 int center_x, center_y, radius_x, radius_y;
311 int start_x, start_y, end_x, end_y;
313 fig_line_style(obj, &line_style, &style_val);
315 start_x = center_x =
ROUND(A[0].x);
316 start_y = center_y =
ROUND(A[0].y);
317 radius_x =
ROUND(A[1].x - A[0].x);
318 radius_y =
ROUND(A[1].y - A[0].y);
319 end_x =
ROUND(A[1].x);
320 end_y =
ROUND(A[1].y);
323 "%d %d %d %d %d %d %d %d %d %.3f %d %.4f %d %d %d %d %d %d %d %d\n",
324 object_code, sub_type, line_style, thickness, pen_color,
325 fill_color, depth, pen_style, area_fill, style_val, direction,
326 angle, center_x, center_y, radius_x, radius_y, start_x,
327 start_y, end_x, end_y);
330 static void fig_bezier(
GVJ_t * job,
pointf * A,
int n,
int arrow_at_start,
331 int arrow_at_end,
int filled)
346 int forward_arrow = 0;
347 int backward_arrow = 0;
364 1) * 20 *
sizeof(
char));
367 fig_line_style(obj, &line_style, &style_val);
384 size = sprintf(buf,
" %d %d", p.
x, p.
y);
387 for (i = 0; i + 3 < n; i += 3) {
389 for (j = 1; j <= 3; j++) {
397 size = sprintf(buf,
" %d %d", p.
x, p.
y);
402 gvprintf(job,
"%d %d %d %d %d %d %d %d %d %.1f %d %d %d %d\n",
412 style_val, cap_style, forward_arrow, backward_arrow, count);
416 for (i = 0; i < count; i++) {
417 gvprintf(job,
" %d", i % (count - 1) ? 1 : 0);
422 static void fig_polygon(
GVJ_t * job,
pointf * A,
int n,
int filled)
434 int area_fill = filled ? 20 : -1;
439 int forward_arrow = 0;
440 int backward_arrow = 0;
443 fig_line_style(obj, &line_style, &style_val);
446 "%d %d %d %d %d %d %d %d %d %.1f %d %d %d %d %d %d\n",
447 object_code, sub_type, line_style, thickness, pen_color,
448 fill_color, depth, pen_style, area_fill, style_val, join_style,
449 cap_style, radius, forward_arrow, backward_arrow, npoints);
450 figptarray(job, A, n, 1);
453 static void fig_polyline(
GVJ_t * job,
pointf * A,
int n)
470 int forward_arrow = 0;
471 int backward_arrow = 0;
474 fig_line_style(obj, &line_style, &style_val);
477 "%d %d %d %d %d %d %d %d %d %.1f %d %d %d %d %d %d\n",
478 object_code, sub_type, line_style, thickness, pen_color,
479 fill_color, depth, pen_style, area_fill, style_val, join_style,
480 cap_style, radius, forward_arrow, backward_arrow, npoints);
481 figptarray(job, A, n, 0);
519 static char *fig_knowncolors[] = {
520 "black",
"blue",
"cyan",
"green",
"magenta",
"red",
"white",
"yellow",
529 sizeof(fig_knowncolors) /
sizeof(
char *),
gvdevice_features_t device_features_fig
gvrender_features_t render_features_fig
#define GVRENDER_Y_GOES_DOWN
int gvputs(GVJ_t *job, const char *s)
CGRAPH_API char * agnameof(void *)
gvrender_engine_t fig_engine
#define BEZIERSUBDIVISION
PostscriptAlias * postscript_alias
pointf Bezier(pointf *V, int degree, double t, pointf *Left, pointf *Right)
gvplugin_installed_t gvdevice_fig_types[]
gvplugin_installed_t gvrender_fig_types[]
void(* pf)(char *, void *)
double dist(Site *s, Site *t)
void gvprintf(GVJ_t *job, const char *format,...)