]> git.cworth.org Git - acre/commitdiff
Add SVG export.
authorCarl Worth <cworth@cworth.org>
Sat, 9 Nov 2013 00:18:58 +0000 (16:18 -0800)
committerCarl Worth <cworth@cworth.org>
Sat, 9 Nov 2013 21:06:02 +0000 (13:06 -0800)
This is cheesy for now, (using a hard-coded output filename).

acre-x.c

index 80b86dee2c234f9e49b0e52d8f65035927ba71c4..e62c5967601b44b246cd1ff8e1c505332b904c87 100644 (file)
--- a/acre-x.c
+++ b/acre-x.c
@@ -24,6 +24,8 @@
 #include <inttypes.h>
 
 #include <X11/Xlib.h>
+
+#include <cairo-svg.h>
 #include <cairo-xlib.h>
 
 #include "acre.h"
@@ -117,6 +119,24 @@ draw (Display *dpy, Window window, Visual *visual, acre_t *acre,
        cairo_surface_destroy (surface);
 }
 
+static void
+draw_svg (acre_t *acre, int width, int height, double x_min, double x_max)
+{
+       cairo_t *cr;
+       cairo_surface_t *surface;
+
+       surface = cairo_svg_surface_create ("acre-fips.svg", width, height);
+
+       cr = cairo_create (surface);
+
+       acre_set_x_axis_range (acre, x_min, x_max);
+       acre_draw (acre, cr, width, height);
+
+       cairo_destroy (cr);
+
+       cairo_surface_destroy (surface);
+}
+
 
 static void
 handle_events(Display *dpy, Window window, Visual *visual,
@@ -131,6 +151,7 @@ handle_events(Display *dpy, Window window, Visual *visual,
         KeyCode equal_code = XKeysymToKeycode (dpy, XStringToKeysym("equal"));
         KeyCode minus_code = XKeysymToKeycode (dpy, XStringToKeysym("minus"));
         KeyCode home_code = XKeysymToKeycode (dpy, XStringToKeysym("Home"));
+        KeyCode svg_code = XKeysymToKeycode (dpy, XStringToKeysym("S"));
        KeyCode keycode;
        bool need_redraw = false;
        double x_min, x_max, shift;
@@ -183,6 +204,11 @@ handle_events(Display *dpy, Window window, Visual *visual,
                        {
                                acre_get_x_axis_data_range (acre, &x_min, &x_max);
                        }
+                       else if (keycode == svg_code)
+                       {
+                               need_redraw = false;
+                               draw_svg (acre, width, height, x_min, x_max);
+                       }
                        else
                        {
                                need_redraw = false;