void svgtiny_parse_position_attributes(const xmlNode *node, const struct svgtiny_parse_state state, float *x, float *y, float *width, float *height) { xmlAttr *attr; *x = 0; *y = 0; *width = state.viewport_width; *height = state.viewport_height; 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, "x") == 0) *x = svgtiny_parse_length(content, state.viewport_width, state); else if (strcmp(name, "y") == 0) *y = svgtiny_parse_length(content, state.viewport_height, state); else if (strcmp(name, "width") == 0) *width = svgtiny_parse_length(content, state.viewport_width, state); else if (strcmp(name, "height") == 0) *height = svgtiny_parse_length(content, state.viewport_height, state); } }
svgtiny_code svgtiny_parse_line(Poco::XML::Element *line, struct svgtiny_parse_state state) { float x1 = 0, y1 = 0, x2 = 0, y2 = 0; float *p; //xmlAttr *attr; Poco::XML::Attr *attr; //for (attr = line->properties; attr; attr = attr->next) { //for( attr = line->FirstAttribute(); attr; attr = attr->Next() ) { Poco::XML::NamedNodeMap *map = line->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(); const char *name = (const char *) map->item(i)->localName().c_str(); const char *content = (const char *) map->item(i)->getNodeValue().c_str(); if (strcmp(name, "x1") == 0) x1 = svgtiny_parse_length(content, state.viewport_width, state); else if (strcmp(name, "y1") == 0) y1 = svgtiny_parse_length(content, state.viewport_height, state); else if (strcmp(name, "x2") == 0) x2 = svgtiny_parse_length(content, state.viewport_width, state); else if (strcmp(name, "y2") == 0) y2 = svgtiny_parse_length(content, state.viewport_height, state); } svgtiny_parse_paint_attributes(line, &state); svgtiny_parse_transform_attributes(line, &state); p = (float*) malloc(7 * sizeof p[0]); if (!p) return svgtiny_OUT_OF_MEMORY; p[0] = svgtiny_PATH_MOVE; p[1] = x1; p[2] = y1; p[3] = svgtiny_PATH_LINE; p[4] = x2; p[5] = y2; p[6] = svgtiny_PATH_CLOSE; return svgtiny_add_path(p, 7, &state); }
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(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); } }
svgtiny_code svgtiny_parse_line(xmlNode *line, struct svgtiny_parse_state state) { float x1 = 0, y1 = 0, x2 = 0, y2 = 0; float *p; xmlAttr *attr; for (attr = line->properties; attr; attr = attr->next) { const char *name = (const char *) attr->name; const char *content = (const char *) attr->children->content; if (strcmp(name, "x1") == 0) x1 = svgtiny_parse_length(content, state.viewport_width, state); else if (strcmp(name, "y1") == 0) y1 = svgtiny_parse_length(content, state.viewport_height, state); else if (strcmp(name, "x2") == 0) x2 = svgtiny_parse_length(content, state.viewport_width, state); else if (strcmp(name, "y2") == 0) y2 = svgtiny_parse_length(content, state.viewport_height, state); } svgtiny_parse_paint_attributes(line, &state); svgtiny_parse_transform_attributes(line, &state); p = malloc(7 * sizeof p[0]); if (!p) return svgtiny_OUT_OF_MEMORY; p[0] = svgtiny_PATH_MOVE; p[1] = x1; p[2] = y1; p[3] = svgtiny_PATH_LINE; p[4] = x2; p[5] = y2; p[6] = svgtiny_PATH_CLOSE; return svgtiny_add_path(p, 7, &state); }
void svgtiny_parse_position_attributes(const Poco::XML::Element *node, const struct svgtiny_parse_state state, float *x, float *y, float *width, float *height) { //xmlAttr *attr; const Poco::XML::Attr *attr; *x = 0; *y = 0; *width = state.viewport_width; *height = state.viewport_height; //for (attr = node->properties; attr; attr = attr->next) { //for( attr = node->FirstAttribute(); attr; attr = attr->Next() ) { Poco::XML::NamedNodeMap *map = node->attributes(); //for( attr = node->FirstAttribute(); attr; attr = attr->Next() ) { for( int i = 0; i < map->length(); i++ ) { //const char *name = (const char *) attr->name; //const char *content = (const char *) attr->children->content; // good god this is ugly const char *name = (const char *) map->item(i)->localName().c_str(); const char *content = (const char *) map->item(i)->getNodeValue().c_str(); if (strcmp(name, "x") == 0) *x = svgtiny_parse_length(content, state.viewport_width, state); else if (strcmp(name, "y") == 0) *y = svgtiny_parse_length(content, state.viewport_height, state); else if (strcmp(name, "width") == 0) *width = svgtiny_parse_length(content, state.viewport_width, state); else if (strcmp(name, "height") == 0) *height = svgtiny_parse_length(content, state.viewport_height, state); } }
void svgtiny_parse_position_attributes(dom_element *node, const struct svgtiny_parse_state state, float *x, float *y, float *width, float *height) { dom_string *attr; dom_exception exc; *x = 0; *y = 0; *width = state.viewport_width; *height = state.viewport_height; exc = dom_element_get_attribute(node, state.interned_x, &attr); if (exc == DOM_NO_ERR && attr != NULL) { *x = svgtiny_parse_length(attr, state.viewport_width, state); dom_string_unref(attr); } exc = dom_element_get_attribute(node, state.interned_y, &attr); if (exc == DOM_NO_ERR && attr != NULL) { *y = svgtiny_parse_length(attr, state.viewport_height, state); dom_string_unref(attr); } exc = dom_element_get_attribute(node, state.interned_width, &attr); if (exc == DOM_NO_ERR && attr != NULL) { *width = svgtiny_parse_length(attr, state.viewport_width, state); dom_string_unref(attr); } exc = dom_element_get_attribute(node, state.interned_height, &attr); if (exc == DOM_NO_ERR && attr != NULL) { *height = svgtiny_parse_length(attr, state.viewport_height, state); dom_string_unref(attr); } }
svgtiny_code svgtiny_parse_line(dom_element *line, struct svgtiny_parse_state state) { svgtiny_code err; float x1 = 0, y1 = 0, x2 = 0, y2 = 0; float *p; dom_string *attr; dom_exception exc; svgtiny_setup_state_local(&state); exc = dom_element_get_attribute(line, state.interned_x1, &attr); if (exc != DOM_NO_ERR) { svgtiny_cleanup_state_local(&state); return svgtiny_LIBDOM_ERROR; } if (attr != NULL) { x1 = svgtiny_parse_length(attr, state.viewport_width, state); } dom_string_unref(attr); exc = dom_element_get_attribute(line, state.interned_y1, &attr); if (exc != DOM_NO_ERR) { svgtiny_cleanup_state_local(&state); return svgtiny_LIBDOM_ERROR; } if (attr != NULL) { y1 = svgtiny_parse_length(attr, state.viewport_height, state); } dom_string_unref(attr); exc = dom_element_get_attribute(line, state.interned_x2, &attr); if (exc != DOM_NO_ERR) { svgtiny_cleanup_state_local(&state); return svgtiny_LIBDOM_ERROR; } if (attr != NULL) { x2 = svgtiny_parse_length(attr, state.viewport_width, state); } dom_string_unref(attr); exc = dom_element_get_attribute(line, state.interned_y2, &attr); if (exc != DOM_NO_ERR) { svgtiny_cleanup_state_local(&state); return svgtiny_LIBDOM_ERROR; } if (attr != NULL) { y2 = svgtiny_parse_length(attr, state.viewport_height, state); } dom_string_unref(attr); svgtiny_parse_paint_attributes(line, &state); svgtiny_parse_transform_attributes(line, &state); p = malloc(7 * sizeof p[0]); if (!p) { svgtiny_cleanup_state_local(&state); return svgtiny_OUT_OF_MEMORY; } p[0] = svgtiny_PATH_MOVE; p[1] = x1; p[2] = y1; p[3] = svgtiny_PATH_LINE; p[4] = x2; p[5] = y2; p[6] = svgtiny_PATH_CLOSE; err = svgtiny_add_path(p, 7, &state); svgtiny_cleanup_state_local(&state); return err; }
svgtiny_code svgtiny_parse_ellipse(dom_element *ellipse, struct svgtiny_parse_state state) { svgtiny_code err; float x = 0, y = 0, rx = -1, ry = -1; float *p; dom_string *attr; dom_exception exc; svgtiny_setup_state_local(&state); exc = dom_element_get_attribute(ellipse, state.interned_cx, &attr); if (exc != DOM_NO_ERR) { svgtiny_cleanup_state_local(&state); return svgtiny_LIBDOM_ERROR; } if (attr != NULL) { x = svgtiny_parse_length(attr, state.viewport_width, state); } dom_string_unref(attr); exc = dom_element_get_attribute(ellipse, state.interned_cy, &attr); if (exc != DOM_NO_ERR) { svgtiny_cleanup_state_local(&state); return svgtiny_LIBDOM_ERROR; } if (attr != NULL) { y = svgtiny_parse_length(attr, state.viewport_height, state); } dom_string_unref(attr); exc = dom_element_get_attribute(ellipse, state.interned_rx, &attr); if (exc != DOM_NO_ERR) { svgtiny_cleanup_state_local(&state); return svgtiny_LIBDOM_ERROR; } if (attr != NULL) { rx = svgtiny_parse_length(attr, state.viewport_width, state); } dom_string_unref(attr); exc = dom_element_get_attribute(ellipse, state.interned_ry, &attr); if (exc != DOM_NO_ERR) { svgtiny_cleanup_state_local(&state); return svgtiny_LIBDOM_ERROR; } if (attr != NULL) { ry = svgtiny_parse_length(attr, state.viewport_width, state); } dom_string_unref(attr); svgtiny_parse_paint_attributes(ellipse, &state); svgtiny_parse_transform_attributes(ellipse, &state); if (rx < 0 || ry < 0) { state.diagram->error_line = -1; /* ellipse->line; */ state.diagram->error_message = "ellipse: rx or ry missing " "or negative"; svgtiny_cleanup_state_local(&state); return svgtiny_SVG_ERROR; } if (rx == 0 || ry == 0) { svgtiny_cleanup_state_local(&state); return svgtiny_OK; } p = malloc(32 * sizeof p[0]); if (!p) { svgtiny_cleanup_state_local(&state); return svgtiny_OUT_OF_MEMORY; } p[0] = svgtiny_PATH_MOVE; p[1] = x + rx; p[2] = y; p[3] = svgtiny_PATH_BEZIER; p[4] = x + rx; p[5] = y + ry * KAPPA; p[6] = x + rx * KAPPA; p[7] = y + ry; p[8] = x; p[9] = y + ry; p[10] = svgtiny_PATH_BEZIER; p[11] = x - rx * KAPPA; p[12] = y + ry; p[13] = x - rx; p[14] = y + ry * KAPPA; p[15] = x - rx; p[16] = y; p[17] = svgtiny_PATH_BEZIER; p[18] = x - rx; p[19] = y - ry * KAPPA; p[20] = x - rx * KAPPA; p[21] = y - ry; p[22] = x; p[23] = y - ry; p[24] = svgtiny_PATH_BEZIER; p[25] = x + rx * KAPPA; p[26] = y - ry; p[27] = x + rx; p[28] = y - ry * KAPPA; p[29] = x + rx; p[30] = y; p[31] = svgtiny_PATH_CLOSE; err = svgtiny_add_path(p, 32, &state); svgtiny_cleanup_state_local(&state); return err; }
svgtiny_code svgtiny_parse_ellipse(xmlNode *ellipse, struct svgtiny_parse_state state) { float x = 0, y = 0, rx = -1, ry = -1; float *p; xmlAttr *attr; for (attr = ellipse->properties; attr; attr = attr->next) { const char *name = (const char *) attr->name; const char *content = (const char *) attr->children->content; if (strcmp(name, "cx") == 0) x = svgtiny_parse_length(content, state.viewport_width, state); else if (strcmp(name, "cy") == 0) y = svgtiny_parse_length(content, state.viewport_height, state); else if (strcmp(name, "rx") == 0) rx = svgtiny_parse_length(content, state.viewport_width, state); else if (strcmp(name, "ry") == 0) ry = svgtiny_parse_length(content, state.viewport_width, state); } svgtiny_parse_paint_attributes(ellipse, &state); svgtiny_parse_transform_attributes(ellipse, &state); if (rx < 0 || ry < 0) { state.diagram->error_line = ellipse->line; state.diagram->error_message = "ellipse: rx or ry missing " "or negative"; return svgtiny_SVG_ERROR; } if (rx == 0 || ry == 0) return svgtiny_OK; p = malloc(32 * sizeof p[0]); if (!p) return svgtiny_OUT_OF_MEMORY; p[0] = svgtiny_PATH_MOVE; p[1] = x + rx; p[2] = y; p[3] = svgtiny_PATH_BEZIER; p[4] = x + rx; p[5] = y + ry * KAPPA; p[6] = x + rx * KAPPA; p[7] = y + ry; p[8] = x; p[9] = y + ry; p[10] = svgtiny_PATH_BEZIER; p[11] = x - rx * KAPPA; p[12] = y + ry; p[13] = x - rx; p[14] = y + ry * KAPPA; p[15] = x - rx; p[16] = y; p[17] = svgtiny_PATH_BEZIER; p[18] = x - rx; p[19] = y - ry * KAPPA; p[20] = x - rx * KAPPA; p[21] = y - ry; p[22] = x; p[23] = y - ry; p[24] = svgtiny_PATH_BEZIER; p[25] = x + rx * KAPPA; p[26] = y - ry; p[27] = x + rx; p[28] = y - ry * KAPPA; p[29] = x + rx; p[30] = y; p[31] = svgtiny_PATH_CLOSE; return svgtiny_add_path(p, 32, &state); }
svgtiny_code svgtiny_parse_ellipse(Poco::XML::Element *ellipse, struct svgtiny_parse_state state) { float x = 0, y = 0, rx = -1, ry = -1; float *p; Poco::XML::Attr *attr; //for (attr = ellipse->properties; attr; attr = attr->next) { //for( attr = ellipse->FirstAttribute(); attr; attr = attr->Next() ) { Poco::XML::NamedNodeMap *map = ellipse->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(); const char *name = (const char *) map->item(i)->localName().c_str(); const char *content = (const char *) map->item(i)->getNodeValue().c_str(); if (strcmp(name, "cx") == 0) x = svgtiny_parse_length(content, state.viewport_width, state); else if (strcmp(name, "cy") == 0) y = svgtiny_parse_length(content, state.viewport_height, state); else if (strcmp(name, "rx") == 0) rx = svgtiny_parse_length(content, state.viewport_width, state); else if (strcmp(name, "ry") == 0) ry = svgtiny_parse_length(content, state.viewport_width, state); } svgtiny_parse_paint_attributes(ellipse, &state); svgtiny_parse_transform_attributes(ellipse, &state); if (rx < 0 || ry < 0) { //state.diagram->error_line = ellipse->line; state.diagram->error_message = "ellipse: rx or ry missing " "or negative"; return svgtiny_SVG_ERROR; } if (rx == 0 || ry == 0) return svgtiny_OK; p = (float*) malloc(32 * sizeof p[0]); if (!p) return svgtiny_OUT_OF_MEMORY; p[0] = svgtiny_PATH_MOVE; p[1] = x + rx; p[2] = y; p[3] = svgtiny_PATH_BEZIER; p[4] = x + rx; p[5] = y + ry * KAPPA; p[6] = x + rx * KAPPA; p[7] = y + ry; p[8] = x; p[9] = y + ry; p[10] = svgtiny_PATH_BEZIER; p[11] = x - rx * KAPPA; p[12] = y + ry; p[13] = x - rx; p[14] = y + ry * KAPPA; p[15] = x - rx; p[16] = y; p[17] = svgtiny_PATH_BEZIER; p[18] = x - rx; p[19] = y - ry * KAPPA; p[20] = x - rx * KAPPA; p[21] = y - ry; p[22] = x; p[23] = y - ry; p[24] = svgtiny_PATH_BEZIER; p[25] = x + rx * KAPPA; p[26] = y - ry; p[27] = x + rx; p[28] = y - ry * KAPPA; p[29] = x + rx; p[30] = y; p[31] = svgtiny_PATH_CLOSE; return svgtiny_add_path(p, 32, &state); }
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); } } } }