gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2012年01月24日 18:19:41 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2012年01月30日 21:26:02 +0100
commit336b7b2386f8021a3dc569addf2e2876b10d711b (patch)
tree9abffd4b383ce85c64352d2dd26c7df99fde8bb8
parent17a0c5fb5ebaed9a694b8f48e14eb085ffcb9ab1 (diff)
downloadgsl-shell-336b7b2386f8021a3dc569addf2e2876b10d711b.tar.gz
New method to manage the Y coordinate flip for SVG output
Diffstat
-rw-r--r--agg-plot/canvas_svg.cpp 4
-rw-r--r--agg-plot/canvas_svg.h 8
-rw-r--r--agg-plot/draw_svg.h 29
-rw-r--r--agg-plot/lua-plot.cpp 2
-rw-r--r--agg-plot/sg_object.h 16
-rw-r--r--agg-plot/text.cpp 7
-rw-r--r--agg-plot/text.h 2
-rw-r--r--agg-plot/trans.h 18
8 files changed, 53 insertions, 33 deletions
diff --git a/agg-plot/canvas_svg.cpp b/agg-plot/canvas_svg.cpp
index 9cb97e1b..fc5a859e 100644
--- a/agg-plot/canvas_svg.cpp
+++ b/agg-plot/canvas_svg.cpp
@@ -6,7 +6,7 @@ template <>
void canvas_svg::draw<sg_object>(sg_object& vs, agg::rgba8 c)
{
int id = m_current_id ++;
- str s = vs.write_svg(id, c);
+ str s = vs.write_svg(id, c, m_height);
canvas_svg::writeln(m_output, s, " ");
}
@@ -15,7 +15,7 @@ void canvas_svg::draw_outline<sg_object>(sg_object& vs, agg::rgba8 c)
{
int id = m_current_id ++;
str path;
- svg_property_list* ls = vs.svg_path(path);
+ svg_property_list* ls = vs.svg_path(path, m_height);
str s = svg_stroke_path(path, canvas_svg::default_stroke_width, id, c, ls);
list::free(ls);
canvas_svg::writeln(m_output, s, " ");
diff --git a/agg-plot/canvas_svg.h b/agg-plot/canvas_svg.h
index 96c07b31..23d669e1 100644
--- a/agg-plot/canvas_svg.h
+++ b/agg-plot/canvas_svg.h
@@ -25,7 +25,8 @@ static const char *svg_end = "</svg>\n";
class canvas_svg {
public:
- canvas_svg(FILE *f) : m_output(f), m_current_id(0) { }
+ canvas_svg(FILE *f, double height):
+ m_output(f), m_height(height), m_current_id(0) { }
void clip_box(const agg::rect_base<int>& clip) { }
@@ -35,7 +36,7 @@ public:
void draw(VertexSource& vs, agg::rgba8 c)
{
str path;
- svg_coords_from_vs(&vs, path);
+ svg_coords_from_vs(&vs, path, m_height);
str s = svg_fill_path(path, m_current_id++, c);
writeln(m_output, s, " ");
}
@@ -44,7 +45,7 @@ public:
void draw_outline(VertexSource& vs, agg::rgba8 c)
{
str path;
- svg_coords_from_vs(&vs, path);
+ svg_coords_from_vs(&vs, path, m_height);
str s = svg_stroke_path(path, default_stroke_width, m_current_id++, c);
writeln(m_output, s, " ");
}
@@ -64,6 +65,7 @@ public:
private:
FILE *m_output;
+ double m_height;
int m_current_id;
};
diff --git a/agg-plot/draw_svg.h b/agg-plot/draw_svg.h
index f7341a67..20d5a77c 100644
--- a/agg-plot/draw_svg.h
+++ b/agg-plot/draw_svg.h
@@ -22,10 +22,21 @@ struct svg_property_item {
svg_property_item(enum svg_path_property_e k, const char *v) : key(k), value(v) { }
};
+static inline double svg_y_coord(double y, double h) { return h - y; }
+
+template <class VertexSource>
+static inline unsigned
+vertex_flip(VertexSource* vs, double* x, double* y, double h)
+{
+ unsigned cmd = vs->vertex(x, y);
+ *y = svg_y_coord(*y, h);
+ return cmd;
+}
+
typedef pod_list<svg_property_item> svg_property_list;
template <typename VertexSource>
-void svg_coords_from_vs(VertexSource* vs, str& s)
+void svg_coords_from_vs(VertexSource* vs, str& s, double h)
{
unsigned cmd;
double x, y;
@@ -34,7 +45,7 @@ void svg_coords_from_vs(VertexSource* vs, str& s)
vs->rewind(0);
- while ((cmd = vs->vertex(&x, &y)))
+ while ((cmd = vertex_flip(vs, &x, &y, h)))
{
if (agg::is_move_to(cmd)) {
s.printf_add("%sM %g,%g", sep, x, y);
@@ -43,11 +54,11 @@ void svg_coords_from_vs(VertexSource* vs, str& s)
} else if (agg::is_close(cmd)) {
s.printf_add("%sz", sep);
} else if (agg::is_curve3(cmd)) {
- vs->vertex(&x, &y);
+ vertex_flip(vs, &x, &y, h);
s.printf_add("%s%g,%g", sep, x, y);
} else if (agg::is_curve4(cmd)) {
vs->vertex(&x, &y);
- vs->vertex(&x, &y);
+ vertex_flip(vs, &x, &y, h);
s.printf_add("%s%g,%g", sep, x, y);
}
sep = space;
@@ -55,7 +66,7 @@ void svg_coords_from_vs(VertexSource* vs, str& s)
}
template <typename VertexSource>
-void svg_curve_coords_from_vs(VertexSource* vs, str& s)
+void svg_curve_coords_from_vs(VertexSource* vs, str& s, double h)
{
unsigned cmd;
double x, y;
@@ -65,7 +76,7 @@ void svg_curve_coords_from_vs(VertexSource* vs, str& s)
vs->rewind(0);
- while ((cmd = vs->vertex(&x, &y)))
+ while ((cmd = vertex_flip(vs, &x, &y, h)))
{
if (agg::is_move_to(cmd)) {
s.printf_add("%sM %g,%g", sep, x, y);
@@ -75,13 +86,13 @@ void svg_curve_coords_from_vs(VertexSource* vs, str& s)
} else if (agg::is_curve4(cmd)) {
double x1 = x, y1 = y;
double x2, y2;
- vs->vertex(&x2, &y2);
- vs->vertex(&x, &y);
+ vertex_flip(vs, &x2, &y2, h);
+ vertex_flip(vs, &x, &y, h);
s.printf_add("%sC %g,%g %g,%g %g,%g", sep, x1, y1, x2, x2, x, y);
omit_line_to = false;
} else if (agg::is_curve3(cmd)) {
double x1 = x, y1 = y;
- vs->vertex(&x, &y);
+ vertex_flip(vs, &x, &y, h);
s.printf_add("%sQ %g,%g %g,%g", sep, x1, y1, x, y);
omit_line_to = false;
} else if (agg::is_close(cmd)) {
diff --git a/agg-plot/lua-plot.cpp b/agg-plot/lua-plot.cpp
index 2f34add2..1bf9e8ec 100644
--- a/agg-plot/lua-plot.cpp
+++ b/agg-plot/lua-plot.cpp
@@ -548,7 +548,7 @@ plot_save_svg (lua_State *L)
if (!f)
return luaL_error(L, "cannot open filename: %s", filename);
- canvas_svg canvas(f);
+ canvas_svg canvas(f, h);
agg::trans_affine m(w, 0.0, 0.0, -h, 0.0, h);
canvas.write_header(w, h);
p->draw(canvas, m);
diff --git a/agg-plot/sg_object.h b/agg-plot/sg_object.h
index f1d5ec7b..00dabda1 100644
--- a/agg-plot/sg_object.h
+++ b/agg-plot/sg_object.h
@@ -43,16 +43,16 @@ struct sg_object : public vertex_source {
virtual bool affine_compose(agg::trans_affine& m) { return false; }
- virtual str write_svg(int id, agg::rgba8 c) {
+ virtual str write_svg(int id, agg::rgba8 c, double h) {
str path;
- svg_property_list* ls = this->svg_path(path);
+ svg_property_list* ls = this->svg_path(path, h);
str s = svg_fill_path(path, id, c, ls);
list::free(ls);
return s;
}
- virtual svg_property_list* svg_path(str& s) {
- svg_coords_from_vs(this, s);
+ virtual svg_property_list* svg_path(str& s, double h) {
+ svg_coords_from_vs(this, s, h);
return 0;
}
@@ -188,9 +188,13 @@ public:
virtual void bounding_box(double *x1, double *y1, double *x2, double *y2) { this->m_source->bounding_box(x1, y1, x2, y2); }
- virtual str write_svg(int id, agg::rgba8 c) { return this->m_source->write_svg(id, c); }
+ virtual str write_svg(int id, agg::rgba8 c, double h) {
+ return this->m_source->write_svg(id, c, h);
+ }
- virtual svg_property_list* svg_path(str& s) { return this->m_source->svg_path(s); }
+ virtual svg_property_list* svg_path(str& s, double h) {
+ return this->m_source->svg_path(s, h);
+ }
virtual bool affine_compose(agg::trans_affine& m) { return this->m_source->affine_compose(m); }
diff --git a/agg-plot/text.cpp b/agg-plot/text.cpp
index 09a1fb0b..df04cd34 100644
--- a/agg-plot/text.cpp
+++ b/agg-plot/text.cpp
@@ -45,7 +45,7 @@ namespace draw {
}
str
- text::write_svg(int id, agg::rgba8 c)
+ text::write_svg(int id, agg::rgba8 c, double h)
{
const agg::trans_affine& m = m_user_matrix;
const double eps = 1.0e-6;
@@ -78,12 +78,15 @@ namespace draw {
y += m.ty;
}
+ double x_svg = x, y_svg = svg_y_coord(y, h);
+
const char* cont = m_text_buf.cstr();
str txt = str::print("<text x=\"%g\" y=\"%g\" id=\"text%i\"" \
" style=\"font-size:%i%s\">" \
" <tspan x=\"%g\" y=\"%g\" id=\"tspan%i\">%s</tspan>" \
"</text>",
- x, y, id, txt_size, style.cstr(), x, y, id, cont);
+ x_svg, y_svg, id, txt_size, style.cstr(),
+ x_svg, y_svg, id, cont);
if (need_rotate) {
s = str::print("<g transform=\"matrix(%g,%g,%g,%g,%g,%g)\">%s</g>",
diff --git a/agg-plot/text.h b/agg-plot/text.h
index da78c1cc..36844306 100644
--- a/agg-plot/text.h
+++ b/agg-plot/text.h
@@ -81,7 +81,7 @@ namespace draw {
virtual void apply_transform(const agg::trans_affine& m, double as);
virtual void bounding_box(double *x1, double *y1, double *x2, double *y2);
- virtual str write_svg(int id, agg::rgba8 c);
+ virtual str write_svg(int id, agg::rgba8 c, double h);
const vs_text& self() const { return m_text; };
vs_text& self() { return m_text; };
diff --git a/agg-plot/trans.h b/agg-plot/trans.h
index 5b004882..99498738 100644
--- a/agg-plot/trans.h
+++ b/agg-plot/trans.h
@@ -35,9 +35,9 @@ struct trans {
m_width = w;
}
- virtual str write_svg(int id, agg::rgba8 c) {
+ virtual str write_svg(int id, agg::rgba8 c, double h) {
str path;
- svg_property_list* ls = this->m_source->svg_path(path);
+ svg_property_list* ls = this->m_source->svg_path(path, h);
str s = svg_stroke_path(path, m_width, id, c, ls);
list::free(ls);
return s;
@@ -60,8 +60,8 @@ struct trans {
public:
curve_a(sg_object* src) : base_type(src) { }
- virtual svg_property_list* svg_path(str& s) {
- svg_curve_coords_from_vs(this->m_source, s);
+ virtual svg_property_list* svg_path(str& s, double h) {
+ svg_curve_coords_from_vs(this->m_source, s, h);
return 0;
}
};
@@ -79,8 +79,8 @@ struct trans {
public:
dash_a(sg_object* src) : base_type(src), m_dasharray(16) { }
- virtual svg_property_list* svg_path(str& s) {
- svg_property_list* ls = this->m_source->svg_path(s);
+ virtual svg_property_list* svg_path(str& s, double h) {
+ svg_property_list* ls = this->m_source->svg_path(s, h);
svg_property_item item(stroke_dasharray, m_dasharray.cstr());
ls = new svg_property_list(item, ls);
return ls;
@@ -162,12 +162,12 @@ struct trans {
m_symbol->apply_transform(m_scale, 1.0);
}
- virtual str write_svg(int id, agg::rgba8 c) {
+ virtual str write_svg(int id, agg::rgba8 c, double h) {
str marker_id;
str marker_def = gen_svg_marker_def(id, c, marker_id);
str path;
- svg_property_list* ls = m_source->svg_path(path);
+ svg_property_list* ls = m_source->svg_path(path, h);
str marker_url = gen_marker_url(marker_id);
const char* murl = marker_url.cstr();
@@ -213,7 +213,7 @@ struct trans {
const double S = m_size + 2*pad;
const double wf = S / m_size;
- str marker_svg = m_symbol->write_svg(-1, c);
+ str marker_svg = m_symbol->write_svg(-1, c, S);
str s = str::print("<defs><marker id=\"%s\" "
"refX=\"%g\" refY=\"%g\" "
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月13日 12:38:55 +0000

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