Use freetype font rendering for text_shape objects - 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年07月08日 16:59:02 +0200
committerFrancesco Abbate <francesco.bbt@gmail.com>2012年07月08日 16:59:02 +0200
commit3115c6cf96e60f59b3c5d8cdc9d6edc3be2a410d (patch)
treeb1c167a4e8f24b9ef433aaa9d01263223dab7f3b /agg-plot/text-shape.h
parent47b9fe48be2408ebfeb4c2ad9d852cbd15530fc2 (diff)
downloadgsl-shell-3115c6cf96e60f59b3c5d8cdc9d6edc3be2a410d.tar.gz
Use freetype font rendering for text_shape objects
Diffstat (limited to 'agg-plot/text-shape.h')
-rw-r--r--agg-plot/text-shape.h 111
1 files changed, 46 insertions, 65 deletions
diff --git a/agg-plot/text-shape.h b/agg-plot/text-shape.h
index a1a55edf..77afb0af 100644
--- a/agg-plot/text-shape.h
+++ b/agg-plot/text-shape.h
@@ -1,104 +1,85 @@
#ifndef AGGPLOT_TEXT_SHAPE_H
#define AGGPLOT_TEXT_SHAPE_H
-#include "agg_gsv_text.h"
-
+#include "text_label.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)
+ m_text_label(text, _size), m_scaling(0), m_size(_size)
{
- 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);
+ m_matrix.tx = x;
+ m_matrix.ty = y;
+ m_text_label.model_mtx(m_matrix);
}
virtual void rewind(unsigned path_id)
{
- m_sg_text.self().start_point(m_x, m_y);
- m_stroke.rewind(path_id);
+ m_text_label.rewind(0.0, 0.0);
}
virtual unsigned vertex(double* x, double* y)
{
- return m_stroke.vertex(x, y);
+ unsigned cmd = m_text_label.vertex(x, y);
+ if (m_scaling && agg::is_vertex(cmd))
+ m_scaling->transform(x, y);
+ return cmd;
}
virtual void bounding_box(double *x1, double *y1, double *x2, double *y2)
{
- agg::bounding_rect_single(m_sg_text, 0, x1, y1, x2, y2);
- const double pad = 1.0;
- *x1 -= pad;
- *y1 -= pad;
- *x2 += pad;
- *y2 += pad;
+ const double pad = 1.0;
+ const double tx = m_matrix.tx, ty = m_matrix.ty;
+ *x1 = tx - pad;
+ *y1 = ty - pad;
+ *x2 = tx + m_text_label.get_text_width() + pad;
+ *y2 = ty + m_text_label.get_text_height() + pad;
}
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;
+ const str& text = m_text_label.text();
+ int txt_size = m_size;
+
+ const agg::trans_affine* m = m_scaling;
+
+ double x = m_matrix.tx, y = -m_matrix.ty;
+ const double dx = (m ? m->tx : 0.0), dy = svg_y_coord(m ? m->ty : 0.0, h);
+
+ 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.cstr());
+
+ str s;
+ if (!m || 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;
+ m_scaling = &m;
+ m_text_label.approximation_scale(m.scale());
}
private:
- sg_text_base m_sg_text;
- double m_x, m_y;
- str m_text;
- double m_size;
-
+ text_label m_text_label;
+ agg::trans_affine m_matrix;
const agg::trans_affine* m_scaling;
- agg::conv_transform<sg_object> m_trans;
- agg::conv_stroke<agg::conv_transform<sg_object> > m_stroke;
+ double m_size;
};
}
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月26日 18:50:20 +0000

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