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/draw_svg.cpp | |
parent | c9a356e30fcd55e51bdfc303ce47921b09fab2b4 (diff) | |
download | gsl-shell-66988c8e83094758e55282c51f45a01933bcc0c9.tar.gz |
-rw-r--r-- | agg-plot/draw_svg.cpp | 63 |
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; +} |