]> mj.ucw.cz Git - leo.git/commitdiff
Symbolizers may return copy of symbol
authorKarryanna <karry@karryanna.cz>
Wed, 1 Jul 2015 16:07:02 +0000 (18:07 +0200)
committerKarryanna <karry@karryanna.cz>
Wed, 1 Jul 2015 16:07:02 +0000 (18:07 +0200)
lab-lines.c
sym-text.c
sym.c
sym.h

index a0fc3c79a48141d09ded41e608db0dd0c9832c0b..a32997317a57485c3d25e39a6fba45bb0bab3d31 100644 (file)
@@ -406,15 +406,7 @@ static void cut_edge(struct graph_edge *e, double dist)
   *new = *e;
   e->next = new;
 
-  switch (e->label->type)
-  {
-    case SYMBOLIZER_TEXT:
-      new->label = xmalloc(sizeof(struct sym_text));
-      *((struct sym_text *) new->label) = *((struct sym_text *) e->label);
-      break;
-    default:
-      ;
-  }
+  new->label = sym_copy(e->label);
 
   struct osm_node *n1 = e->n1->o;
   struct osm_node *n2 = e->n2->o;
index 159f00ebe911a8a0ae5d828bfc92ea7374ddcab4..9f61f7d376443a1d0e3fee0f910e13f40520ca21 100644 (file)
@@ -224,6 +224,16 @@ 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 void sym_text_draw(struct symbol *sym, struct svg *svg)
 {
   struct sym_text *t = (struct sym_text *) sym;
@@ -534,6 +544,7 @@ struct symbolizer symbolizer_text = {
   .draw = sym_text_draw,
   .gen = sym_text_gen,
   .init = sym_text_init,
+  .copy = sym_text_copy,
 };
 
 struct sym_text *sym_text_new(struct osm_object *o)
diff --git a/sym.c b/sym.c
index 00d89416b3e798d4ce3f16405e2d420847771aaa..752bea609cf6bf2d128301a8616d033b2ebd3beb 100644 (file)
--- a/sym.c
+++ b/sym.c
@@ -146,3 +146,12 @@ void sym_draw_all(struct svg *svg)
   for (uns i = 0; i < GARY_SIZE(sym_planned); i++)
     sym_draw(sym_planned[i].sym, sym_planned[i].zindex, svg);
 }
+
+struct symbol * sym_copy(struct symbol *sym)
+{
+  ASSERT(sym->type && sym->type < SYMBOLIZER_MAX);
+  if (symbolizers[sym->type]->copy)
+    return symbolizers[sym->type]->copy(sym);
+  else
+    return NULL;
+}
diff --git a/sym.h b/sym.h
index d2e294c893c7afc541c99984b19039da35075c84..cb4ac122713abf0c393d7c63bbcbcd4863f4ca5f 100644 (file)
--- a/sym.h
+++ b/sym.h
@@ -33,6 +33,7 @@ struct symbolizer {
   void (*draw)(struct symbol *sym, struct svg *svg);
   void (*gen)(struct osm_object *o, struct style_info *si, struct svg *svg);
   void (*init)(void);
+  struct symbol* (*copy)(struct symbol *sym);
 };
 
 extern struct mempool *sym_mp;
@@ -58,6 +59,8 @@ void sym_draw_all(struct svg *svg);
 void sym_from_style(struct osm_object *o, struct style_results *sr, struct svg *svg);
 z_index_t sym_zindex(struct osm_object *o, struct style_info *si, double default_mzi);
 
+struct symbol * sym_copy(struct symbol *sym);
+
 /* sym-point.c handles point symbols and icons */
 
 struct sym_point {