void svgtiny_parse_paint_attributes(dom_element *node, struct svgtiny_parse_state *state) { dom_string *attr; dom_exception exc; exc = dom_element_get_attribute(node, state->interned_fill, &attr); if (exc == DOM_NO_ERR && attr != NULL) { svgtiny_parse_color(attr, &state->fill, state); dom_string_unref(attr); } exc = dom_element_get_attribute(node, state->interned_stroke, &attr); if (exc == DOM_NO_ERR && attr != NULL) { svgtiny_parse_color(attr, &state->stroke, state); dom_string_unref(attr); } exc = dom_element_get_attribute(node, state->interned_stroke_width, &attr); if (exc == DOM_NO_ERR && attr != NULL) { state->stroke_width = svgtiny_parse_length(attr, state->viewport_width, *state); dom_string_unref(attr); } exc = dom_element_get_attribute(node, state->interned_style, &attr); if (exc == DOM_NO_ERR && attr != NULL) { char *style = strndup(dom_string_data(attr), dom_string_byte_length(attr)); const char *s; char *value; if ((s = strstr(style, "fill:"))) { s += 5; while (*s == ' ') s++; value = strndup(s, strcspn(s, "; ")); _svgtiny_parse_color(value, &state->fill, state); free(value); } if ((s = strstr(style, "stroke:"))) { s += 7; while (*s == ' ') s++; value = strndup(s, strcspn(s, "; ")); _svgtiny_parse_color(value, &state->stroke, state); free(value); } if ((s = strstr(style, "stroke-width:"))) { s += 13; while (*s == ' ') s++; value = strndup(s, strcspn(s, "; ")); state->stroke_width = _svgtiny_parse_length(value, state->viewport_width, *state); free(value); } free(style); dom_string_unref(attr); } }
void svgtiny_parse_paint_attributes(const xmlNode *node, struct svgtiny_parse_state *state) { const xmlAttr *attr; for (attr = node->properties; attr; attr = attr->next) { const char *name = (const char *) attr->name; const char *content = (const char *) attr->children->content; if (strcmp(name, "fill") == 0) svgtiny_parse_color(content, &state->fill, state); else if (strcmp(name, "stroke") == 0) svgtiny_parse_color(content, &state->stroke, state); else if (strcmp(name, "stroke-width") == 0) state->stroke_width = svgtiny_parse_length(content, state->viewport_width, *state); else if (strcmp(name, "style") == 0) { const char *style = (const char *) attr->children->content; const char *s; char *value; if ((s = strstr(style, "fill:"))) { s += 5; while (*s == ' ') s++; value = strndup(s, strcspn(s, "; ")); svgtiny_parse_color(value, &state->fill, state); free(value); } if ((s = strstr(style, "stroke:"))) { s += 7; while (*s == ' ') s++; value = strndup(s, strcspn(s, "; ")); svgtiny_parse_color(value, &state->stroke, state); free(value); } if ((s = strstr(style, "stroke-width:"))) { s += 13; while (*s == ' ') s++; value = strndup(s, strcspn(s, "; ")); state->stroke_width = svgtiny_parse_length(value, state->viewport_width, *state); free(value); } } } }
void svgtiny_parse_paint_attributes(const Poco::XML::Element *node, struct svgtiny_parse_state *state) { //const xmlAttr *attr; const Poco::XML::Attr *attr; //for (attr = node->properties; attr; attr = attr->next) { //for( attr = node->FirstAttribute(); attr; attr = attr->Next() ) { Poco::XML::NamedNodeMap *map = node->attributes(); for( int i = 0; i < map->length(); i++ ) { //const char *name = (const char *) attr->name; //const char *content = (const char *) attr->children->content; //const char *name = (const char *) attr->Name(); //const char *content = (const char *) attr->Value(); attr = (Poco::XML::Attr*) map->item(i); const char *name = (const char *) attr->localName().c_str(); const char *content = (const char *) attr->getNodeValue().c_str(); if (strcmp(name, "fill") == 0) svgtiny_parse_color(content, &state->fill, state); else if (strcmp(name, "stroke") == 0) svgtiny_parse_color(content, &state->stroke, state); else if (strcmp(name, "stroke-width") == 0) state->stroke_width = svgtiny_parse_length(content, state->viewport_width, *state); else if (strcmp(name, "style") == 0) { //const char *style = (const char *) attr->children->content; const char *style = attr->getValue().c_str(); const char *s; char *value; if ((s = strstr(style, "fill:"))) { s += 5; while (*s == ' ') s++; value = strndup(s, strcspn(s, "; ")); svgtiny_parse_color(value, &state->fill, state); free(value); } if ((s = strstr(style, "stroke:"))) { s += 7; while (*s == ' ') s++; value = strndup(s, strcspn(s, "; ")); svgtiny_parse_color(value, &state->stroke, state); free(value); } if ((s = strstr(style, "stroke-width:"))) { s += 13; while (*s == ' ') s++; value = strndup(s, strcspn(s, "; ")); state->stroke_width = svgtiny_parse_length(value, state->viewport_width, *state); free(value); } } } }