/*-- write_svg.c: routines for saving a display as an svg file --*/ /* This software may only be used by you under license from AT&T Corp. ("AT&T"). A copy of AT&T's Source Code Agreement is available at AT&T's Internet website having the URL: If you received this software without first entering into a license with AT&T, you have an infringing copy of this software and cannot use it without violating AT&T's intellectual property rights. */ #include #include "vars.h" #include "externs.h" gchar *hexcolor (GdkColor *color) { gulong val = 0; gchar buf[32]; val = ((gulong) ((256 * color->red) / 65536)) << 16; val |= ((gulong) ((256 * color->green) / 65536)) << 8; val |= (gulong) ((256 * color->blue) / 65536); sprintf (buf, "#%6lx", val & 0xffffff); return g_strdup (buf); } void svg_write_header (FILE *f) { fprintf (f, "\n"); fprintf (f, "\n"); fprintf (f, "\n"); } /*-- testing on xyplots only for the moment --*/ void splot_write_svg (splotd *sp, ggobid *gg) { gint k; gint i, m; gushort current_color; gint ncolors_used = 0; gushort colors_used[NCOLORS+2]; GtkWidget *da = sp->da; displayd *display = (displayd *) sp->displayptr; datad *d = display->d; gboolean draw_case; icoords minpix, maxpix; gchar *cx; FILE *f = fopen ("foo.svg", "w"); svg_write_header (f); fprintf (f, "\n", da->allocation.width, da->allocation.height); /* * I want to know the minimum and maximum horizontal and * vertical pixel position for the plotted data. */ maxpix.x = maxpix.y = 0; minpix.x = da->allocation.width; minpix.y = da->allocation.height; for (i=0; inrows_in_plot; i++) { m = d->rows_in_plot[i]; draw_case = splot_plot_case (m, d, sp, display, gg); if (draw_case) { if (sp->screen[m].x > 0 && sp->screen[m].x < da->allocation.width) { if (sp->screen[m].x < minpix.x) minpix.x = sp->screen[m].x; if (sp->screen[m].x > maxpix.x) maxpix.x = sp->screen[m].x; } if (sp->screen[m].y > 0 && sp->screen[m].y < da->allocation.height) { if (sp->screen[m].y < minpix.y) minpix.y = sp->screen[m].y; if (sp->screen[m].y > maxpix.y) maxpix.y = sp->screen[m].y; } } } /* * I'll shift enough to preserve about 20 pixels for * labelling on the left; and then scale enough to preserve * space on the bottom. This could be really elaborate, but * this will get us started. */ fprintf (f, "\n", MIN (20, minpix.x), 0, (gfloat) da->allocation.height / (gfloat) (da->allocation.height + 20)); /*-- x axis --*/ fprintf (f, "\n", minpix.x, maxpix.y, maxpix.x, maxpix.y); /* 122 242 */ /*-- y axis --*/ fprintf (f, "\n", minpix.x, minpix.y, minpix.x, maxpix.y); /* 107 146 */ /*-- draw points --*/ if (!gg->mono_p) { splot_point_colors_used_get (sp, &ncolors_used, colors_used, false, gg); /* * Now loop through colors_used[], plotting the points of each * color. This avoids the need to reset the foreground so often. * On the other hand, it requires more looping. */ for (k=0; kdefault_color_table[current_color]); #ifdef _WIN32 #else for (i=0; inrows_in_plot; i++) { m = d->rows_in_plot[i]; draw_case = splot_plot_case (m, d, sp, display, gg); if (draw_case && d->color_now.els[m] == current_color) { if (display->options.points_show_p) { fprintf (f, "screen values --*/ fprintf (f, " cx=\"%d\" cy=\"%d\" r=\"%d\"/>\n", sp->screen[m].x, sp->screen[m].y, 5); } } } #endif } /* deal with mono later */ } /*-- draw edges --*/ if (!gg->mono_p) { gint j, nl, to, from; gboolean doit; extern void splot_line_colors_used_get (splotd *sp, gint *ncolors_used, gushort *colors_used, datad *, ggobid *gg); splot_line_colors_used_get (sp, &ncolors_used, colors_used, d, gg); /* * Now loop through colors_used[], plotting the points of each * color. This avoids the need to reset the foreground so often. * On the other hand, it requires more looping. */ for (k=0; kdefault_color_table[current_color]); nl = 0; for (j=0; jnedges; j++) { if (d->line.hidden_now.els[j]) { doit = false; } else { from = d->edge_endpoints[j].a - 1; to = d->edge_endpoints[j].b - 1; doit = (!d->hidden_now.els[from] && !d->hidden_now.els[to]); } if (doit) { if (d->line.color_now.els[j] == current_color) { fprintf (f, "\n", cx, sp->screen[from].x, sp->screen[from].y, sp->screen[to].x, sp->screen[to].y); if (display->options.edges_directed_show_p) { } nl++; } } } } } fprintf (f, "\n"); fprintf (f, "\n"); fclose (f); return; } void display_write_svg (ggobid *gg) { /*-- for the moment, only deal with a single scatterplot --*/ splot_write_svg (gg->current_splot, gg); }