]> mj.ucw.cz Git - leo.git/commitdiff
Low-level parts of text rotation
authorMartin Mares <mj@ucw.cz>
Thu, 16 Apr 2015 14:38:12 +0000 (16:38 +0200)
committerMartin Mares <mj@ucw.cz>
Thu, 16 Apr 2015 14:38:12 +0000 (16:38 +0200)
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.

leo.c
svg.c
svg.h
sym-text.c
sym.h

diff --git a/leo.c b/leo.c
index 5d02f680a90c6e84fe69954e5e32bbf73a2df4d7..b30996581f424d104a7775d91494fd0430810209 100644 (file)
--- 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 0aaa4d9410e0ca44dc4e3a25a3826e825bb8abbd..819014353509827840baea639d27500ed0c51f82 100644 (file)
--- 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 c9520c44bd5e7f326cb56da50584b68e0acb8c6f..b50a869f6ae20a1660e2122522fb29440520ce11 100644 (file)
--- 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 {
index 2666acd9f5d2e6f5984183750ad77b0a1ef2b7c8..ffcfc421d78a516ddd446644ac0a86a312368d41 100644 (file)
@@ -7,6 +7,7 @@
 #include <ucw/lib.h>
 #include <ucw/stkstring.h>
 
+#include <math.h>
 #include <stdio.h>
 #include <ft2build.h>
 #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 e846a790df44b6205416111feef6e691476fe5ed..e53409e7b8d9ecc9a35874bfae3ff72bdad4d1fa 100644 (file)
--- 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;