Add support to scale font directly inside text_label - 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年08月07日 17:19:04 +0200
committerFrancesco Abbate <francesco.bbt@gmail.com>2012年08月07日 17:19:04 +0200
commit5d5237a6688d733c645a1df04471545036f94c7a (patch)
tree1f2621c970ec63ef14d0d845c609d75f4d2818a4
parent78086498f6df8d08b540608dbf91337611864dc9 (diff)
downloadgsl-shell-5d5237a6688d733c645a1df04471545036f94c7a.tar.gz
Add support to scale font directly inside text_label
Useful to have scaled text with accurately hinted glyphs.
Diffstat
-rw-r--r--agg-plot/text-shape.h 18
-rw-r--r--agg-plot/text.h 2
-rw-r--r--agg-plot/text_label.h 14
3 files changed, 25 insertions, 9 deletions
diff --git a/agg-plot/text-shape.h b/agg-plot/text-shape.h
index 38abf892..aadbe147 100644
--- a/agg-plot/text-shape.h
+++ b/agg-plot/text-shape.h
@@ -15,6 +15,7 @@ namespace draw {
m_matrix.tx = x;
m_matrix.ty = y;
m_text_label.model_mtx(m_matrix);
+ compute_bounding_box();
}
virtual void rewind(unsigned path_id)
@@ -32,12 +33,20 @@ namespace draw {
virtual void bounding_box(double *x1, double *y1, double *x2, double *y2)
{
+ *x1 = m_bbox.x1;
+ *y1 = m_bbox.y1;
+ *x2 = m_bbox.x2;
+ *y2 = m_bbox.y2;
+ }
+
+ void compute_bounding_box()
+ {
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;
+ m_bbox.x1 = tx - pad;
+ m_bbox.y1 = ty - pad;
+ m_bbox.x2 = tx + m_text_label.get_text_width() + pad;
+ m_bbox.y2 = ty + m_text_label.get_text_height() + pad;
}
virtual str write_svg(int id, agg::rgba8 c, double h)
@@ -74,6 +83,7 @@ namespace draw {
agg::trans_affine m_matrix;
const agg::trans_affine* m_scaling;
double m_size;
+ agg::rect_base<double> m_bbox;
};
}
diff --git a/agg-plot/text.h b/agg-plot/text.h
index e38fa0ba..c6c62e6e 100644
--- a/agg-plot/text.h
+++ b/agg-plot/text.h
@@ -54,7 +54,7 @@ class text : public sg_object
const char * get_text() const { return m_text_label.text().cstr(); }
- double text_height() const { return m_text_label.text_height(); }
+ double text_height() const { return m_text_label.get_text_height(); }
void set_point(double x, double y)
{
diff --git a/agg-plot/text_label.h b/agg-plot/text_label.h
index 349a1d66..209876ba 100644
--- a/agg-plot/text_label.h
+++ b/agg-plot/text_label.h
@@ -22,6 +22,8 @@ class text_label
double m_width;
double m_height;
+ double m_scale_x, m_scale_y;
+
unsigned m_pos;
double m_x, m_y;
double m_advance_x, m_advance_y;
@@ -36,7 +38,7 @@ class text_label
public:
text_label(const char* text, double size):
- m_text_buf(text), m_height(size), m_pos(0),
+ m_text_buf(text), m_height(size), m_scale_x(1), m_scale_y(1), m_pos(0),
m_font_eng(gslshell::font_engine()), m_font_man(gslshell::font_manager()),
m_model_mtx(&identity_matrix),
m_text_curve(m_font_man.path_adaptor()), m_text_trans(m_text_curve, m_text_mtx)
@@ -49,11 +51,15 @@ class text_label
void set_font_size()
{
- m_font_eng.height(m_height);
- m_font_eng.width(m_height * scale_x);
+ m_font_eng.height(m_scale_y * m_height);
+ m_font_eng.width(m_scale_x * m_height * scale_x);
}
- double text_height() const { return m_height; }
+ void scale_font(double f_scale_x, double f_scale_y)
+ {
+ m_scale_x = f_scale_x;
+ m_scale_y = f_scale_y;
+ }
const str& text() const { return m_text_buf; }
generated by cgit v1.2.3 (git 2.39.1) at 2025年10月04日 00:53:16 +0000

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