From 66988c8e83094758e55282c51f45a01933bcc0c9 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 6 Dec 2011 22:26:34 +0100 Subject: Add support to write plot objects in SVG format --- agg-plot/lua-plot.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'agg-plot/lua-plot.cpp') 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(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(L, 1, GS_PLOT); -- cgit v1.2.3

AltStyle によって変換されたページ (->オリジナル) /