author | Francesco Abbate <francesco.bbt@gmail.com> | 2011年12月06日 22:26:34 +0100 |
---|---|---|
committer | Francesco Abbate <francesco.bbt@gmail.com> | 2011年12月06日 22:26:34 +0100 |
commit | 66988c8e83094758e55282c51f45a01933bcc0c9 (patch) | |
tree | 4a90ebd78fe31080e719c23c7f371bff9597d1f0 /agg-plot/lua-plot.cpp | |
parent | c9a356e30fcd55e51bdfc303ce47921b09fab2b4 (diff) | |
download | gsl-shell-66988c8e83094758e55282c51f45a01933bcc0c9.tar.gz |
-rw-r--r-- | agg-plot/lua-plot.cpp | 28 |
diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp index d953ac50..b1bf2a75 100644 --- a/agg-plot/lua-plot.cpp +++ b/agg-plot/lua-plot.cpp @@ -38,6 +38,7 @@ extern "C" { #include "drawable.h" #include "resource-manager.h" #include "agg-parse-trans.h" +#include "canvas_svg.h" __BEGIN_DECLS @@ -58,6 +59,7 @@ static int plot_set_limits (lua_State *L); static int plot_push_layer (lua_State *L); static int plot_pop_layer (lua_State *L); static int plot_clear (lua_State *L); +static int plot_save_svg (lua_State *L); static int plot_sync_mode_get (lua_State *L); static int plot_sync_mode_set (lua_State *L); @@ -95,6 +97,7 @@ static const struct luaL_Reg plot_methods[] = { {"poplayer", plot_pop_layer }, {"clear", plot_clear }, {"save", bitmap_save_image }, + {"save_svg", plot_save_svg }, {NULL, NULL} }; @@ -421,6 +424,31 @@ plot_clear (lua_State *L) return 0; } +int +plot_save_svg (lua_State *L) +{ + lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT); + const char *filename = lua_tostring(L, 2); + double w = luaL_optnumber(L, 3, 800.0); + double h = luaL_optnumber(L, 4, 600.0); + + if (!filename) + return gs_type_error(L, 2, "string"); + + FILE* f = fopen(filename, "w"); + if (!f) + return luaL_error(L, "cannot open filename: %s", filename); + + canvas_svg canvas(f); + agg::trans_affine m(w, 0.0, 0.0, -h, 0.0, h); + canvas.write_header(w, h); + p->draw(canvas, m); + canvas.write_end(); + fclose(f); + + return 0; +} + static int plot_pad_mode_set (lua_State *L) { lua_plot *p = object_check<lua_plot>(L, 1, GS_PLOT); |