From: Martin Mares Date: Thu, 16 Apr 2015 14:38:12 +0000 (+0200) Subject: Low-level parts of text rotation X-Git-Url: http://mj.ucw.cz/gitweb/?p=leo.git;a=commitdiff_plain;h=3d14be2fa32fe908dfef0f6ac3b76067c080a43a Low-level parts of text rotation There are currently no style properties to control that, but it will be used in Karry's labelling branch. Also made formatting of SVG dimensions slightly more systematic. --- diff --git a/leo.c b/leo.c index 5d02f68..b309965 100644 --- a/leo.c +++ b/leo.c @@ -55,7 +55,7 @@ static void draw_scale(struct svg *svg) svg_push_element(svg, "g"); svg_set_attr(svg, "id", "scale"); - svg_set_attr_format(svg, "transform", "translate(%.6g,%.6g)", x * svg->scale, y * svg->scale); + svg_set_attr_format(svg, "transform", "translate(%s,%s)", svg_format_dimen(svg, x), svg_format_dimen(svg, y)); for (int outline=1; outline>=0; outline--) { diff --git a/svg.c b/svg.c index 0aaa4d9..8190143 100644 --- a/svg.c +++ b/svg.c @@ -273,9 +273,14 @@ void svg_set_attr_float(struct svg *svg, const char *key, double val) svg_set_attr_ref(svg, key, mp_printf(svg->pool, "%.6g", val)); } +char *svg_format_dimen(struct svg *svg, double val) +{ + return mp_printf(svg->pool, "%.6g", val * svg->scale); +} + void svg_set_attr_dimen(struct svg *svg, const char *key, double val) { - svg_set_attr_ref(svg, key, mp_printf(svg->pool, "%.6g", val * svg->scale)); + svg_set_attr_ref(svg, key, svg_format_dimen(svg, val)); } void svg_set_attr_color(struct svg *svg, const char *key, color_t color) diff --git a/svg.h b/svg.h index c9520c4..b50a869 100644 --- a/svg.h +++ b/svg.h @@ -69,6 +69,8 @@ void svg_path_line_to(struct svg *svg, double x, double y); void svg_path_line_to_rel(struct svg *svg, double x, double y); void svg_path_close(struct svg *svg); +char *svg_format_dimen(struct svg *svg, double val); + /* svg-icon.c */ struct svg_icon { diff --git a/sym-text.c b/sym-text.c index 2666acd..ffcfc42 100644 --- a/sym-text.c +++ b/sym-text.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include FT_FREETYPE_H @@ -241,10 +242,16 @@ static void sym_text_draw(struct symbol *sym, struct svg *svg) t->y = sy / nn; } - if (t->opacity != 1) + bool use_group = 0; + bool want_rotate = (fabs(t->rotate) > 1e-5); + if (t->opacity != 1 || want_rotate) { + use_group = 1; svg_push_element(svg, "g"); - svg_set_attr_float(svg, "opacity", t->opacity); + if (t->opacity != 1) + svg_set_attr_float(svg, "opacity", t->opacity); + if (want_rotate) + svg_set_attr_format(svg, "transform", "rotate(%.2f %s %s)", -t->rotate, svg_format_dimen(svg, t->x), svg_format_dimen(svg, t->y)); } if (t->halo_radius) @@ -292,7 +299,7 @@ static void sym_text_draw(struct symbol *sym, struct svg *svg) svg_pop(svg); #endif - if (t->opacity != 1) + if (use_group) svg_pop(svg); } diff --git a/sym.h b/sym.h index e846a79..e53409e 100644 --- a/sym.h +++ b/sym.h @@ -132,6 +132,7 @@ struct sym_text { color_t text_color; double x; double y; + double rotate; // Rotation in degrees CCW struct text_font *font; double opacity; color_t halo_color;