]> mj.ucw.cz Git - leo.git/blobdiff - sym-text.c
Labelling: Bugfixes in get_closure
[leo.git] / sym-text.c
index 66e834a05c42297f112792ae86708fc3d1ce538d..8acfe4b0a1565683b658173c6a49da8b413c61ec 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
@@ -16,7 +17,6 @@
 #include "osm.h"
 #include "sym.h"
 #include "map.h"
-
 #include "labeller.h"
 
 /*** Fonts ***/
@@ -224,6 +224,23 @@ static void prepare_text_element(struct sym_text *t, struct svg *svg)
     svg_set_attr(svg, "font-style", osm_val_decode(font->style));
 }
 
+static struct symbol * sym_text_copy(struct symbol *sym)
+{
+  struct sym_text *t = (struct sym_text *) sym;
+
+  struct sym_text *new = xmalloc(sizeof(struct sym_text));
+  *new = *t;   // FIXME: Is this OK? with respect to pointer fields...
+
+  return (struct symbol *) new;
+}
+
+static bool sym_text_look_same(struct symbol *s1, struct symbol *s2)
+{
+  struct sym_text *st1 = (struct sym_text *) s1;
+  struct sym_text *st2 = (struct sym_text *) s2;
+  return (st1->text == st2->text && st1->text_color == st2->text_color);
+}
+
 static void sym_text_draw(struct symbol *sym, struct svg *svg)
 {
   struct sym_text *t = (struct sym_text *) sym;
@@ -243,10 +260,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)
@@ -294,7 +317,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);
 }
 
@@ -441,8 +464,6 @@ static void sym_text_node(struct osm_object *o, struct style_info *si, osm_val_t
       msg(L_DEBUG, "Text <%s> dropped as duplicate", osm_val_decode(text));
       return;
     }
-
-  sym_plan(&st->s, sym_zindex(o, si, 5));
 }
 
 static void sym_text_center(struct osm_object *o, struct style_info *si, osm_val_t text, double x, double y)
@@ -457,15 +478,7 @@ static void sym_text_center(struct osm_object *o, struct style_info *si, osm_val
   st->x -= st->tw / 2;
   st->y += st->th - (st->th + st->td) / 2;
   text_fix_placement(st);
-  if (o->type == OSM_TYPE_WAY && !osm_way_cyclic_p((struct osm_way *) o))
-  {
-    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_arealabel(&st->s, o, sym_zindex(o, si, 4.9));
-  }
+  labeller_add_label(&st->s, o, sym_zindex(o, si, 4.9));
 }
 
 static void sym_text_way(struct osm_object *o, struct style_info *si, osm_val_t text)
@@ -538,6 +551,8 @@ struct symbolizer symbolizer_text = {
   .draw = sym_text_draw,
   .gen = sym_text_gen,
   .init = sym_text_init,
+  .copy = sym_text_copy,
+  .look_same = sym_text_look_same,
 };
 
 struct sym_text *sym_text_new(struct osm_object *o)