Commit 6449ea6
Fix inheritance of style in SVG import
Changed files (5)
modifiedlibsvgbird/AttributePattern.valamodifiedlibsvgbird/LineCap.valamodifiedlibsvgbird/SelectorPattern.valamodifiedlibsvgbird/SelectorTag.valamodifiedlibsvgbird/SvgStyle.vala
Diff
@@ -58,7 +58,7 @@ public class AttributePattern : GLib.Object { bool attribute_start_with (Attributes attributes) { foreach (Attribute attribute in attributes) { if (attribute.get_name () == name - && remove_hypen (attribute.get_content ()) == content) {+ && remove_hypen (attribute.get_content ()) == ((!) content)) { return true; } }@@ -69,7 +69,7 @@ public class AttributePattern : GLib.Object { bool attribute_equals (Attributes attributes) { foreach (Attribute attribute in attributes) { if (attribute.get_name () == name - && attribute.get_content () == content) {+ && attribute.get_content () == ((!) content)) { return true; } }@@ -107,6 +107,29 @@ public class AttributePattern : GLib.Object { return false; }++ public string to_string () {+ string c;+ + if (content == null) {+ c = "null";+ } else {+ c = (!) content;+ }+ + switch (type) {+ case AttributePatternType.ANYTHING:+ return "[" + name + "]";+ case AttributePatternType.LIST:+ return "[" + name + "~=" + c + "]";+ case AttributePatternType.EQUALS:+ return "[" + name + "=" + c + "]";+ case AttributePatternType.STARTS_WITH:+ return "[" + name + "|=" + c + "]";+ }+ + return "No attributes.";+ } } }@@ -12,9 +12,6 @@ Lesser General Public License for more details. */ -using B;-using Math;- namespace SvgBird { public enum LineCap {@@ -36,7 +36,7 @@ public class SelectorPattern : GLib.Object { public bool match (XmlElement tag, string? id, string? css_class) { for (int i = tags.size - 1; i >= 0; i--) { SelectorTag pattern = tags.get (i);- + if (pattern.name == ">") { if (i - 1 < 0) { return false;@@ -29,17 +29,35 @@ public class SelectorTag : GLib.Object { int id_separator = tag_pattern.index_of ("#"); int class_separator = tag_pattern.index_of ("."); int attribute_separator = tag_pattern.index_of ("[");- ++ if (attribute_separator != -1) {+ parse_attributes (tag_pattern.substring (attribute_separator));+ }+ if (id_separator != -1) { name = tag_pattern.substring (0, id_separator);- id = tag_pattern.substring (id_separator + "#".length);+ + id_separator += "#".length;+ if (attribute_separator == -1) {+ id = tag_pattern.substring (id_separator);+ } else {+ id = tag_pattern.substring (id_separator, attribute_separator - id_separator);+ } } else if (class_separator != -1) { name = tag_pattern.substring (0, class_separator);- css_class = tag_pattern.substring (class_separator + ".".length);- } else if (attribute_separator != -1) {- parse_attributes (tag_pattern.substring (attribute_separator));+ + class_separator += ".".length;+ if (attribute_separator == -1) {+ css_class = tag_pattern.substring (class_separator);+ } else {+ css_class = tag_pattern.substring (class_separator, attribute_separator - class_separator);+ } } else {- name = tag_pattern;+ if (attribute_separator == -1) {+ name = tag_pattern;+ } else {+ css_class = tag_pattern.substring (0, attribute_separator);+ } } } @@ -99,8 +117,10 @@ public class SelectorTag : GLib.Object { public bool match (XmlElement tag, string? id, string? css_class) { string tag_name = tag.get_name (); - if (this.name != "*" && this.name != "" && this.name != tag_name) {- return false;+ if (this.name != "*" && this.name != "" && tag_name != "") {+ if (this.name != tag_name) {+ return false;+ } } if (this.id != null) {@@ -108,7 +128,7 @@ public class SelectorTag : GLib.Object { return false; } - if (this.id != id) {+ if (((!) this.id) != ((!) id)) { return false; } }@@ -118,7 +138,8 @@ public class SelectorTag : GLib.Object { return false; } - if (this.css_class != css_class) {+ if (((!) this.css_class) != ((!) css_class)) {+ print(@"class \"$((!)this.css_class)\"=\"$((!)css_class)\"\n"); return false; } }@@ -133,6 +154,29 @@ public class SelectorTag : GLib.Object { return true; }++ public string to_string () {+ StringBuilder s = new StringBuilder ();+ s.append ((!) name);+ + if (id != null) {+ s.append ("#");+ s.append ((!) id);+ }++ if (css_class != null) {+ s.append (".");+ s.append ((!) css_class);+ }+ + if (attribute_patterns != null) {+ foreach (AttributePattern a in (!) attribute_patterns) {+ s.append (a.to_string ());+ }+ }+ + return s.str;+ } } }@@ -70,6 +70,7 @@ public class SvgStyle : GLib.Object { public void inherit (SvgStyle inherited) { foreach (string key in inherited.style.keys) {+ print (@"inherit $key: " + inherited.style.get (key) + "\n"); style.set (key, inherited.style.get (key)); } }@@ -158,17 +159,19 @@ public class SvgStyle : GLib.Object { string k, v; foreach (string kv in p) {- pair = kv.split (":");- - if (pair.length != 2) {- warning ("pair.length != 2 in " + svg_style);- continue;+ if (kv.index_of (":") != -1) {+ pair = kv.split (":");+ + if (pair.length != 2) {+ warning ("pair.length != 2 in " + svg_style);+ continue;+ }+ + k = pair[0].strip ();+ v = pair[1].strip ();+ + style.set (k, v); }- - k = pair[0];- v = pair[1];- - style.set (k, v); } } }