]> mj.ucw.cz Git - leo.git/blobdiff - map.c
Inline styles can be specified in object tags
[leo.git] / map.c
diff --git a/map.c b/map.c
index d15b835c2761b3c4aee6b2665de0127ba3c28b53..3dbf7194b3b79468088bf8bb12eeaeb729999fa6 100644 (file)
--- a/map.c
+++ b/map.c
@@ -55,6 +55,7 @@ static struct cf_section map_source_cf = {
     CF_STRING("File", P(file)),
     CF_LOOKUP("Format", P(format), map_formats),
     CF_LIST("StyleSheet", P(styles), &map_style_cf),
+    CF_INT("InlineStyles", P(inline_styles)),
     CF_END
   }
 #undef P
@@ -280,6 +281,43 @@ void map_load_sources(void)
     map_load_source(ds);
 }
 
+static void map_apply_inline_styles(struct osm_object *o, struct style_results *r)
+{
+  char *name = NULL;
+
+  CLIST_FOR_EACH(struct osm_tag *, t, o->tags)
+    {
+      const char *key = osm_key_decode(t->key);
+      if (!strncmp(key, "style:", 6))
+       {
+         key += 6;
+         layer_t layer = STYLE_LAYER_DEFAULT;
+         char *sep = strstr(key, "::");
+         if (sep)
+           {
+             if (sep[2])
+               {
+                 // XXX: Only layers defined in the main stylesheet can be modified
+                 layer = style_layer_encode_if_exists(sep+2);
+                 if (!layer)
+                   goto skip;
+               }
+             int keylen = sep - key;
+             char *t = mp_alloc(r->pool, keylen+1);
+             memcpy(t, key, keylen);
+             t[keylen] = 0;
+             key = t;
+           }
+
+         if (!name)
+           name = mp_printf(r->pool, "Inline style in object #%ju", (uintmax_t) o->id);
+         struct style_prop *p= css_parse_prop(r->pool, name, key, osm_val_decode(t->val));
+         style_set_by_layer(r, layer, p);
+skip: ;
+       }
+    }
+}
+
 void map_apply_styles(struct svg *svg)
 {
   struct style_results r;
@@ -305,6 +343,8 @@ void map_apply_styles(struct svg *svg)
            style_begin(&r, o);
            CLIST_FOR_EACH(struct data_source_style *, ss, ds->styles)
              css_apply(ss->css, &r);
+           if (ds->inline_styles)
+             map_apply_inline_styles(o, &r);
            if (debug_dump_styling)
              style_dump(&r);
            sym_from_style(o, &r, svg);