Clone in a terminal:
Commit 6449ea6
Johan Mattsson - 2016-01-12T00:34:22+00:00
6449ea6a0542eaa875b7cc622406f7c3e6237bccjohan.mattsson.m@gmail.com

Fix inheritance of style in SVG import

Changed files (5)

Diff

diff --git a/libsvgbird/AttributePattern.vala b/libsvgbird/AttributePattern.valaindex 72d1550..7e1aca6 100644--- a/libsvgbird/AttributePattern.vala+++ b/libsvgbird/AttributePattern.vala@@ -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.";+	} }  }diff --git a/libsvgbird/LineCap.vala b/libsvgbird/LineCap.valaindex ba027b9..45b673f 100644--- a/libsvgbird/LineCap.vala+++ b/libsvgbird/LineCap.vala@@ -12,9 +12,6 @@ 	Lesser General Public License for more details. */ -using B;-using Math;- namespace SvgBird {  public enum LineCap {diff --git a/libsvgbird/SelectorPattern.vala b/libsvgbird/SelectorPattern.valaindex 328802d..bae64c6 100644--- a/libsvgbird/SelectorPattern.vala+++ b/libsvgbird/SelectorPattern.vala@@ -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;diff --git a/libsvgbird/SelectorTag.vala b/libsvgbird/SelectorTag.valaindex 90bcbc9..cd2c7ee 100644--- a/libsvgbird/SelectorTag.vala+++ b/libsvgbird/SelectorTag.vala@@ -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;+	} }  }diff --git a/libsvgbird/SvgStyle.vala b/libsvgbird/SvgStyle.valaindex 377780b..116b79e 100644--- a/libsvgbird/SvgStyle.vala+++ b/libsvgbird/SvgStyle.vala@@ -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); 		} 	} }

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112