Commit f5139a9
Parse more style attributes in SVG files
Changed files (2)
Diff
@@ -479,15 +479,13 @@ public class SvgParser { r = parse_double (attr.get_content ()); } - if (attr.get_name () == "style") {- style = SvgStyle.parse (attr.get_content ());- }- if (attr.get_name () == "display" && attr.get_content () == "none") { hidden = true; } } + style = SvgStyle.parse (tag.get_attributes ());+ if (hidden) { return; }@@ -549,15 +547,13 @@ public class SvgParser { ry = parse_double (attr.get_content ()); } - if (attr.get_name () == "style") {- style = SvgStyle.parse (attr.get_content ());- }- if (attr.get_name () == "display" && attr.get_content () == "none") { hidden = true; } } + style = SvgStyle.parse (tag.get_attributes ());+ if (hidden) { return; }@@ -616,16 +612,14 @@ public class SvgParser { if (attr.get_name () == "xy") { y2 = -parse_double (attr.get_content ()); }-- if (attr.get_name () == "style") {- style = SvgStyle.parse (attr.get_content ());- } if (attr.get_name () == "display" && attr.get_content () == "none") { hidden = true; } } + style = SvgStyle.parse (tag.get_attributes ());+ if (hidden) { return; }@@ -695,16 +689,14 @@ public class SvgParser { if (attr.get_name () == "height") { y2 = -parse_double (attr.get_content ()); }-- if (attr.get_name () == "style") {- style = SvgStyle.parse (attr.get_content ());- } if (attr.get_name () == "display" && attr.get_content () == "none") { hidden = true; } } + style = SvgStyle.parse (tag.get_attributes ());+ if (hidden) { return; }@@ -785,22 +777,21 @@ public class SvgParser { if (attr.get_name () == "points") { p = parse_poly_data (attr.get_content ()); }- - if (attr.get_name () == "style") {- style = SvgStyle.parse (attr.get_content ());- } if (attr.get_name () == "display" && attr.get_content () == "none") { hidden = true; } }++ style = SvgStyle.parse (tag.get_attributes ()); if (hidden) { return path_list; } path_list.add (p);- + style.apply (path_list);+ foreach (Attribute attr in tag.get_attributes ()) { if (attr.get_name () == "transform") { transform_paths (attr.get_content (), path_list);@@ -820,10 +811,6 @@ public class SvgParser { if (attr.get_name () == "d") { path_list = parse_svg_data (attr.get_content (), glyph); }-- if (attr.get_name () == "style") {- style = SvgStyle.parse (attr.get_content ());- } if (attr.get_name () == "display" && attr.get_content () == "none") { hidden = true;@@ -836,6 +823,8 @@ public class SvgParser { } } + style = SvgStyle.parse (tag.get_attributes ());+ if (hidden) { return; }@@ -57,15 +57,39 @@ public class SvgStyle { if (!style.has_key ("stroke-width")) { return 0; }- + return double.parse (style.get ("stroke-width")); } - public static SvgStyle parse (string svg_style) {+ + public static SvgStyle parse (Attributes attributes) {+ SvgStyle s = new SvgStyle ();+ + foreach (Attribute a in attributes) {+ if (a.get_name () == "style") {+ s.parse_key_value_pairs (a.get_content ());+ }+ + if (a.get_name () == "stroke-width") {+ s.style.set ("stroke-width", a.get_content ());+ }++ if (a.get_name () == "stroke") {+ s.style.set ("stroke", a.get_content ());+ }++ if (a.get_name () == "fill") {+ s.style.set ("fill", a.get_content ());+ }+ }+ + return s;+ }+ + void parse_key_value_pairs (string svg_style) { string[] p = svg_style.split (";"); string[] pair; string k, v;- SvgStyle s = new SvgStyle (); foreach (string kv in p) { pair = kv.split (":");@@ -78,10 +102,8 @@ public class SvgStyle { k = pair[0]; v = pair[1]; - s.style.set (k, v);+ style.set (k, v); }- - return s; } public void apply (PathList path_list) {