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/draw_svg.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/draw_svg.cpp
parentc9a356e30fcd55e51bdfc303ce47921b09fab2b4 (diff)
downloadgsl-shell-66988c8e83094758e55282c51f45a01933bcc0c9.tar.gz
Add support to write plot objects in SVG format
Diffstat (limited to 'agg-plot/draw_svg.cpp')
-rw-r--r--agg-plot/draw_svg.cpp 63
1 files changed, 63 insertions, 0 deletions
diff --git a/agg-plot/draw_svg.cpp b/agg-plot/draw_svg.cpp
new file mode 100644
index 00000000..a86da5b1
--- /dev/null
+++ b/agg-plot/draw_svg.cpp
@@ -0,0 +1,63 @@
+#include "agg_color_rgba.h"
+
+#include "draw_svg.h"
+
+const char *svg_path_property_name[] = {"stroke-dasharray"};
+
+void format_rgb(char rgbstr[], agg::rgba8 c)
+{
+ sprintf(rgbstr, "#%02X%02X%02X", (int)c.r, (int)c.g, (int)c.b);
+}
+
+static void append_properties(str& s, svg_property_list* properties)
+{
+ for (svg_property_list* p = properties; p; p = p->next())
+ {
+ svg_property_item& item = p->content();
+ const char* name = svg_path_property_name[item.key];
+ s.printf_add(";%s:%s", name, item.value);
+ }
+}
+
+str svg_stroke_path(str& path_coords, double width, int id, agg::rgba8 c,
+ svg_property_list* properties)
+{
+ char rgbstr[8];
+ format_rgb(rgbstr, c);
+
+ str s = str::print("<path d=\"%s\" "
+ "id=\"path%i\" "
+ "style=\"fill:none;stroke:%s;"
+ "stroke-width:%gpx;stroke-linecap:butt;"
+ "stroke-linejoin:miter",
+ path_coords.cstr(), id, rgbstr, width);
+
+ if (c.a < 255) {
+ double alpha = (double)c.a / 255;
+ s.printf_add(";stroke-opacity:%g", alpha);
+ }
+
+ append_properties(s, properties);
+ s.append("\" />");
+
+ return s;
+}
+
+str svg_fill_path(str& path_coords, int id, agg::rgba8 c,
+ svg_property_list* properties)
+{
+ char rgbstr[8];
+ format_rgb(rgbstr, c);
+
+ double alpha = (double)c.a / 255;
+
+ str s = str::print("<path d=\"%s\" "
+ "id=\"path%i\" "
+ "style=\"fill:%s;fill-opacity:%g;stroke:none\" />",
+ path_coords.cstr(), id, rgbstr, alpha);
+
+ append_properties(s, properties);
+ s.append("\" />");
+
+ return s;
+}
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月13日 21:40:39 +0000

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