gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot/text.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'agg-plot/text.cpp')
-rw-r--r--agg-plot/text.cpp 67
1 files changed, 62 insertions, 5 deletions
diff --git a/agg-plot/text.cpp b/agg-plot/text.cpp
index b1935d1b..1a382c37 100644
--- a/agg-plot/text.cpp
+++ b/agg-plot/text.cpp
@@ -1,4 +1,6 @@
+#include "agg_trans_affine.h"
+
#include "text.h"
namespace draw {
@@ -19,13 +21,17 @@ namespace draw {
void
text::apply_transform(const agg::trans_affine& m, double as)
{
- double& x = m_matrix.tx;
- double& y = m_matrix.ty;
+ m_user_matrix.tx = m_x;
+ m_user_matrix.ty = m_y;
+
+ m.transform(&m_user_matrix.tx, &m_user_matrix.ty);
- x = m_x;
- y = m_y;
+ m_matrix = m_user_matrix;
- m.transform(&x, &y);
+ if (m.sy < 0.0) {
+ m_matrix.shy *= -1.0;
+ m_matrix.sy *= -1.0;
+ }
m_stroke.approximation_scale(as);
}
@@ -36,4 +42,55 @@ namespace draw {
*x1 = *x2 = m_x;
*y1 = *y2 = m_y;
}
+
+ str
+ text::write_svg(int id, agg::rgba8 c)
+ {
+ const agg::trans_affine& m = m_user_matrix;
+ const double eps = 1.0e-6;
+ str s;
+
+ if (str_is_null(&m_text_buf))
+ return s;
+
+ str style;
+ int hjust = lrint(m_hjustif * 2.0);
+ if (hjust == 1)
+ style.append(";text-anchor:middle");
+ else if (hjust >= 2)
+ style.append(";text-anchor:end");
+
+ if (c.r != 0 || c.g != 0 || c.b != 0) {
+ char rgbstr[8];
+ format_rgb(rgbstr, c);
+ style.printf_add(";fill:%s", rgbstr);
+ }
+
+ bool need_rotate = (fabs(m.sx - 1.0) > eps || fabs(m.shx) > eps || \
+ fabs(m.shy) > eps || fabs(m.sy - 1.0) > eps);
+
+ int txt_size = (int)(m_text_height * 1.5);
+
+ double x = 0.0, y = m_vjustif * m_text_height * 1.2;
+ if (!need_rotate) {
+ x += m.tx;
+ y += m.ty;
+ }
+
+ 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);
+
+ if (need_rotate) {
+ s = str::print("<g transform=\"matrix(%g,%g,%g,%g,%g,%g)\">%s</g>",
+ m.sx, m.shx, m.shy, m.sy, m.tx, m.ty, txt.cstr());
+ } else {
+ s = txt;
+ }
+
+ return s;
+ }
}
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月16日 06:12:47 +0000

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