]> mj.ucw.cz Git - leo.git/blobdiff - sym-text.c
Labelling: Let's evolve!
[leo.git] / sym-text.c
index f2f901e978270a7e364569750020842a0f483891..6622fd61fbd2b56b9c769b6be16484a7d2f10a07 100644 (file)
@@ -7,6 +7,7 @@
 #include <ucw/lib.h>
 #include <ucw/stkstring.h>
 
 #include <ucw/lib.h>
 #include <ucw/stkstring.h>
 
+#include <math.h>
 #include <stdio.h>
 #include <ft2build.h>
 #include FT_FREETYPE_H
 #include <stdio.h>
 #include <ft2build.h>
 #include FT_FREETYPE_H
@@ -227,6 +228,7 @@ static void prepare_text_element(struct sym_text *t, struct svg *svg)
 static void sym_text_draw(struct symbol *sym, struct svg *svg)
 {
   struct sym_text *t = (struct sym_text *) sym;
 static void sym_text_draw(struct symbol *sym, struct svg *svg)
 {
   struct sym_text *t = (struct sym_text *) sym;
+printf("Drawing %s at [%.2f; %.2f]\n", osm_val_decode(t->text), t->x, t->y);
 
   if (t->next_duplicate)
     {
 
   if (t->next_duplicate)
     {
@@ -243,10 +245,16 @@ static void sym_text_draw(struct symbol *sym, struct svg *svg)
       t->y = sy / nn;
     }
 
       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_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)
     }
 
   if (t->halo_radius)
@@ -294,7 +302,7 @@ static void sym_text_draw(struct symbol *sym, struct svg *svg)
   svg_pop(svg);
 #endif
 
   svg_pop(svg);
 #endif
 
-  if (t->opacity != 1)
+  if (use_group)
     svg_pop(svg);
 }
 
     svg_pop(svg);
 }
 
@@ -460,11 +468,13 @@ static void sym_text_center(struct osm_object *o, struct style_info *si, osm_val
   if (o->type == OSM_TYPE_WAY && !osm_way_cyclic_p((struct osm_way *) o))
   {
     //sym_plan(&st->s, sym_zindex(o, si, 4.9));
   if (o->type == OSM_TYPE_WAY && !osm_way_cyclic_p((struct osm_way *) o))
   {
     //sym_plan(&st->s, sym_zindex(o, si, 4.9));
+    printf("[Sym] Labelling way %ju with %s\n", o->id, osm_val_decode(st->text));
     labeller_add_linelabel(&st->s, o, sym_zindex(o, si, 4.9));
   }
   else
   {
     //sym_plan(&st->s, sym_zindex(o, si, 4.9));
     labeller_add_linelabel(&st->s, o, sym_zindex(o, si, 4.9));
   }
   else
   {
     //sym_plan(&st->s, sym_zindex(o, si, 4.9));
+    printf("[Sym] Labelling area %ju with %s\n", o->id, osm_val_decode(st->text));
     labeller_add_arealabel(&st->s, o, sym_zindex(o, si, 4.9));
   }
 }
     labeller_add_arealabel(&st->s, o, sym_zindex(o, si, 4.9));
   }
 }