2024-06-06 09:54:13 +02:00
|
|
|
function svg_parse(xmlStr) {
|
|
|
|
if(!is_struct(xmlStr)) return noone;
|
|
|
|
|
|
|
|
if(struct_try_get(xmlStr, "type") != "root") return noone;
|
|
|
|
if(array_empty(xmlStr.children)) return noone;
|
|
|
|
|
|
|
|
var svg_object = xmlStr.children[0];
|
|
|
|
|
|
|
|
if(struct_try_get(svg_object, "type") != "svg") return noone;
|
|
|
|
|
|
|
|
var attr = svg_object.attributes;
|
2024-06-23 04:53:47 +02:00
|
|
|
var svg = new SVG().setAttr(attr);
|
2024-06-06 09:54:13 +02:00
|
|
|
|
|
|
|
if(struct_has(attr, "viewBox")) {
|
|
|
|
var bbox = attr.viewBox;
|
|
|
|
bbox = string_splice(bbox);
|
|
|
|
for (var i = 0, n = array_length(bbox); i < n; i++)
|
2024-06-08 06:31:21 +02:00
|
|
|
bbox[i] = real(bbox[i])
|
2024-06-06 09:54:13 +02:00
|
|
|
svg.bbox = bbox;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(struct_has(svg_object, "children")) {
|
|
|
|
var _ind = 0;
|
|
|
|
|
|
|
|
for (var i = 0, n = array_length(svg_object.children); i < n; i++) {
|
|
|
|
var _ch = svg_object.children[i];
|
|
|
|
|
|
|
|
switch(_ch.type) {
|
2024-06-08 09:38:41 +02:00
|
|
|
case "path" : svg.contents[_ind++] = new SVG_path(svg).setAttr(_ch.attributes); break;
|
|
|
|
case "rect" : svg.contents[_ind++] = new SVG_rect(svg).setAttr(_ch.attributes); break;
|
|
|
|
case "circle" : svg.contents[_ind++] = new SVG_circle(svg).setAttr(_ch.attributes); break;
|
|
|
|
case "ellipse" : svg.contents[_ind++] = new SVG_ellipse(svg).setAttr(_ch.attributes); break;
|
|
|
|
case "line" : svg.contents[_ind++] = new SVG_line(svg).setAttr(_ch.attributes); break;
|
|
|
|
case "polyline" : svg.contents[_ind++] = new SVG_polyline(svg).setAttr(_ch.attributes); break;
|
|
|
|
case "polygon" : svg.contents[_ind++] = new SVG_polygon(svg).setAttr(_ch.attributes); break;
|
2024-06-06 09:54:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return svg;
|
|
|
|
}
|