static elemstyle_t *parse_rule(xmlNode *a_node) { xmlNode *cur_node = NULL; elemstyle_t *elemstyle = g_new0(elemstyle_t, 1); elemstyle_condition_t **lastcond = &elemstyle->condition; for (cur_node = a_node->children; cur_node; cur_node = cur_node->next) { if (cur_node->type == XML_ELEMENT_NODE) { if(strcasecmp((char*)cur_node->name, "condition") == 0) { /* ------ parse condition ------ */ elemstyle_condition_t *newcond = g_new0(elemstyle_condition_t, 1); newcond->key = xmlGetProp(cur_node, BAD_CAST "k"); newcond->value = xmlGetProp(cur_node, BAD_CAST "v"); *lastcond = newcond; lastcond = &newcond->next; /* todo: add support for "b" (boolean) value */ } else if(strcasecmp((char*)cur_node->name, "line") == 0) { /* ------ parse line ------ */ g_assert(elemstyle->type == ES_TYPE_NONE); elemstyle->type = ES_TYPE_LINE; elemstyle->line = parse_line(cur_node); } else if(strcasecmp((char*)cur_node->name, "linemod") == 0) { /* ------ parse linemod ------ */ g_assert(elemstyle->type == ES_TYPE_NONE); elemstyle->type = ES_TYPE_LINE_MOD; elemstyle->line_mod = parse_line_mod(cur_node); } else if(strcasecmp((char*)cur_node->name, "area") == 0) { /* ------ parse area ------ */ g_assert(elemstyle->type == ES_TYPE_NONE); elemstyle->type = ES_TYPE_AREA; elemstyle->area = parse_area(cur_node); } else if(strcasecmp((char*)cur_node->name, "icon") == 0) { elemstyle->icon = parse_icon(cur_node); } else if(strcasecmp((char*)cur_node->name, "scale_min") == 0) { /* scale_min is currently ignored */ } else if(strcasecmp((char*)cur_node->name, "scale_max") == 0) { switch (elemstyle->type) { case ES_TYPE_LINE: parse_scale_max(cur_node, &elemstyle->line->zoom_max); break; case ES_TYPE_AREA: parse_scale_max(cur_node, &elemstyle->area->zoom_max); break; default: if (elemstyle->icon) { parse_scale_max(cur_node, &elemstyle->icon->zoom_max); } else { printf("scale_max for unhandled elemstyletype=0x02%x\n", elemstyle->type); } break; } } else { printf("found unhandled rules/rule/%s\n", cur_node->name); } } } return elemstyle; }
static void parse_style_node(xmlNode *a_node, xmlChar **fname, style_t *style) { xmlNode *cur_node = NULL, *sub_node = NULL; /* -------------- setup defaults -------------------- */ /* (the defaults are pretty much the potlatch style) */ style->background.color = 0xffffffff; // white style->area.border_width = 2.0; style->area.color = 0x00000060; // 37.5% style->area.zoom_max = 0.1111; // zoom factor above which an area is visible & selectable style->node.radius = 4.0; style->node.border_radius = 2.0; style->node.color = 0x000000ff; // black with filling ... style->node.fill_color = 0x008800ff; // ... in dark green style->node.show_untagged = FALSE; style->node.zoom_max = 0.4444; // zoom factor above which a node is visible & selectable style->track.width = 6.0; style->track.color = 0x0000ff40; // blue style->track.gps_color = 0x000080ff; style->way.width = 3.0; style->way.color = 0x606060ff; // grey style->way.zoom_max = 0.2222; // zoom above which it's visible & selectable style->highlight.width = 3.0; style->highlight.color = 0xffff0080; // normal highlights are yellow style->highlight.node_color = 0xff000080; // node highlights are red style->highlight.touch_color = 0x0000ff80; // touchnode and style->highlight.arrow_color = 0x0000ff80; // arrows are blue style->highlight.arrow_limit = 4.0; style->frisket.mult = 3.0; style->frisket.color = 0xffffffff; style->frisket.border.present = TRUE; style->frisket.border.width = 6.0; style->frisket.border.color = 0x00000099; style->icon.enable = FALSE; style->icon.scale = 1.0; // icon size (multiplier) for (cur_node = a_node->children; cur_node; cur_node = cur_node->next) { if (cur_node->type == XML_ELEMENT_NODE) { if(fname != NULL && strcasecmp((char*)cur_node->name, "elemstyles") == 0) { *fname = xmlGetProp(cur_node, BAD_CAST "filename"); /* ---------- node ------------------------------------- */ } else if(strcasecmp((char*)cur_node->name, "node") == 0) { parse_color(cur_node, "color", &style->node.color); parse_color(cur_node, "fill-color", &style->node.fill_color); style->node.radius = xml_get_prop_float(cur_node, "radius"); style->node.border_radius = xml_get_prop_float(cur_node, "border-radius"); style->node.zoom_max = parse_scale_max(cur_node); style->node.show_untagged = xml_get_prop_is(cur_node, "show-untagged", "true"); /* ---------- icon ------------------------------------- */ } else if(strcasecmp((char*)cur_node->name, "icon") == 0) { style->icon.scale = xml_get_prop_float(cur_node, "scale"); char *prefix = (char*)xmlGetProp(cur_node, BAD_CAST "path-prefix"); if(prefix) { g_free(style->icon.path_prefix); style->icon.path_prefix = prefix; } style->icon.enable = xml_get_prop_is(cur_node, "enable", "true"); /* ---------- way ------------------------------------- */ } else if(strcasecmp((char*)cur_node->name, "way") == 0) { parse_color(cur_node, "color", &style->way.color); style->way.width = xml_get_prop_float(cur_node, "width"); style->way.zoom_max = parse_scale_max(cur_node); /* ---------- frisket --------------------------------- */ } else if(strcasecmp((char*)cur_node->name, "frisket") == 0) { style->frisket.mult = xml_get_prop_float(cur_node, "mult"); parse_color(cur_node, "color", &style->frisket.color); style->frisket.border.present = FALSE; for(sub_node = cur_node->children; sub_node; sub_node=sub_node->next) { if(sub_node->type == XML_ELEMENT_NODE) { if(strcasecmp((char*)sub_node->name, "border") == 0) { style->frisket.border.present = TRUE; style->frisket.border.width = xml_get_prop_float(sub_node, "width"); parse_color(sub_node, "color", &style->frisket.border.color); } } } /* ---------- highlight ------------------------------- */ } else if(strcasecmp((char*)cur_node->name, "highlight") == 0) { parse_color(cur_node, "color", &style->highlight.color); parse_color(cur_node, "node-color", &style->highlight.node_color); parse_color(cur_node, "touch-color", &style->highlight.touch_color); parse_color(cur_node, "arrow-color", &style->highlight.arrow_color); style->highlight.width = xml_get_prop_float(cur_node, "width"); style->highlight.arrow_limit = xml_get_prop_float(cur_node, "arrow-limit"); /* ---------- track ------------------------------------ */ } else if(strcasecmp((char*)cur_node->name, "track") == 0) { parse_color(cur_node, "color", &style->track.color); parse_color(cur_node, "gps-color", &style->track.gps_color); style->track.width = xml_get_prop_float(cur_node, "width"); /* ---------- area ------------------------------------- */ } else if(strcasecmp((char*)cur_node->name, "area") == 0) { style->area.has_border_color = parse_color(cur_node, "border-color", &style->area.border_color); style->area.border_width = xml_get_prop_float(cur_node,"border-width"); style->area.zoom_max = parse_scale_max(cur_node); parse_color(cur_node, "color", &style->area.color); /* ---------- background ------------------------------- */ } else if(strcasecmp((char*)cur_node->name, "background") == 0) { parse_color(cur_node, "color", &style->background.color); } else printf(" found unhandled style/%s\n", cur_node->name); } } if(!style->icon.path_prefix) style->icon.path_prefix = g_strdup("standard"); }