Add support to write plot objects in SVG format - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot/lua-plot.cpp
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2011年12月06日 22:26:34 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2011年12月06日 22:26:34 +0100
commit66988c8e83094758e55282c51f45a01933bcc0c9 (patch)
tree4a90ebd78fe31080e719c23c7f371bff9597d1f0 /agg-plot/lua-plot.cpp
parentc9a356e30fcd55e51bdfc303ce47921b09fab2b4 (diff)
downloadgsl-shell-66988c8e83094758e55282c51f45a01933bcc0c9.tar.gz
Add support to write plot objects in SVG format
Diffstat (limited to 'agg-plot/lua-plot.cpp')
-rw-r--r--agg-plot/lua-plot.cpp 28
1 files changed, 28 insertions, 0 deletions
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);
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月13日 12:09:09 +0000

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