Add support for plot legends - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot/text-shape.h
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2012年01月11日 16:41:22 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2012年01月30日 21:26:02 +0100
commit3835be08da347dcaf854d61dc21f0cb52164ef8a (patch)
treec2a6772c5dc17fbfb551fbdb36e4d4617a82dd31 /agg-plot/text-shape.h
parent900c2a906c1a7ec8043b3f6eb9e74ec1c8f05063 (diff)
downloadgsl-shell-3835be08da347dcaf854d61dc21f0cb52164ef8a.tar.gz
Add support for plot legends
Introduce also the textshape graphical object required to create legends effectively.
Diffstat (limited to 'agg-plot/text-shape.h')
-rw-r--r--agg-plot/text-shape.h 100
1 files changed, 100 insertions, 0 deletions
diff --git a/agg-plot/text-shape.h b/agg-plot/text-shape.h
new file mode 100644
index 00000000..326ca9b8
--- /dev/null
+++ b/agg-plot/text-shape.h
@@ -0,0 +1,100 @@
+#ifndef AGGPLOT_TEXT_SHAPE_H
+#define AGGPLOT_TEXT_SHAPE_H
+
+#include "agg_gsv_text.h"
+
+#include "sg_object.h"
+
+typedef sg_object_gen<agg::gsv_text> sg_text_base;
+
+namespace draw {
+
+ class text_shape : public sg_object {
+ public:
+ text_shape(double x, double y, const char* text,
+ double _size = 10.0, double hjustif = 0.0, double vjustif = 0.0):
+ m_sg_text(), m_x(x), m_y(y), m_text(text), m_size(_size),
+ m_scaling(0), m_trans(m_sg_text, identity_matrix), m_stroke(m_trans)
+ {
+ agg::gsv_text& t = m_sg_text.self();
+ t.text(text);
+ t.size(_size);
+
+ const double text_width = t.text_width(), text_height = _size;
+ m_x -= hjustif * text_width;
+ m_y -= vjustif * text_height;
+
+ t.start_point(m_x, m_y);
+
+ m_stroke.line_cap(agg::round_cap);
+ m_stroke.line_join(agg::round_join);
+ }
+
+ virtual void rewind(unsigned path_id)
+ {
+ m_sg_text.self().start_point(m_x, m_y);
+ m_stroke.rewind(path_id);
+ }
+
+ virtual unsigned vertex(double* x, double* y)
+ {
+ return m_stroke.vertex(x, y);
+ }
+
+ virtual void bounding_box(double *x1, double *y1, double *x2, double *y2)
+ {
+ agg::bounding_rect_single(m_sg_text, 0, x1, y1, x2, y2);
+ }
+
+ virtual str write_svg(int id, agg::rgba8 c, double h)
+ {
+ const char* text = m_text.cstr();
+ int txt_size = (int)(m_size * 1.5);
+
+ const agg::trans_affine& m = *m_scaling;
+
+ double x = m_x, y = -m_y;
+ const double dx = m.tx, dy = svg_y_coord(m.ty, h);
+
+ if (is_unit_matrix(m))
+ {
+ x += dx;
+ y += dy;
+ }
+
+ str svgtext = str::print("<text x=\"%g\" y=\"%g\" id=\"text%i\"" \
+ " style=\"font-size:%i\">" \
+ " <tspan id=\"tspan%i\">%s</tspan>" \
+ "</text>",
+ x, y, id, txt_size, id, text);
+
+ str s;
+ if (is_unit_matrix(m))
+ s = svgtext;
+ else
+ s = str::print("<g transform=\"matrix(%g,%g,%g,%g,%g,%g)\">%s</g>",
+ m.sx, m.shx, m.shy, m.sy, dx, dy, svgtext.cstr());
+
+ return s;
+ }
+
+ virtual void apply_transform(const agg::trans_affine& m, double as)
+ {
+ m_stroke.width(1.5 * m.scale());
+ m_trans.transformer(m);
+ m_scaling = &m;
+ }
+
+ private:
+ sg_text_base m_sg_text;
+ double m_x, m_y;
+ str m_text;
+ double m_size;
+
+ const agg::trans_affine* m_scaling;
+ agg::conv_transform<sg_object> m_trans;
+ agg::conv_stroke<agg::conv_transform<sg_object> > m_stroke;
+ };
+}
+
+#endif
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月26日 14:13:20 +0000

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