From: Karryanna Date: Wed, 1 Jul 2015 16:07:02 +0000 (+0200) Subject: Symbolizers may return copy of symbol X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=3ee708f92e1d014b42a4eecb9cef0a96120152d1;p=leo.git Symbolizers may return copy of symbol --- diff --git a/lab-lines.c b/lab-lines.c index a0fc3c7..a329973 100644 --- a/lab-lines.c +++ b/lab-lines.c @@ -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; diff --git a/sym-text.c b/sym-text.c index 159f00e..9f61f7d 100644 --- a/sym-text.c +++ b/sym-text.c @@ -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 00d8941..752bea6 100644 --- 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 d2e294c..cb4ac12 100644 --- 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 {