The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Fix inheritance of style in SVG import

These changes was commited to the Birdfont repository Tue, 12 Jan 2016 00:34:22 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Tue, 12 Jan 2016 00:34:22 +0000]

Updated Files

libsvgbird/AttributePattern.vala
libsvgbird/LineCap.vala
libsvgbird/SelectorPattern.vala
libsvgbird/SelectorTag.vala
libsvgbird/SvgStyle.vala
--- a/libsvgbird/AttributePattern.vala +++ b/libsvgbird/AttributePattern.vala @@ -58,7 +58,7 @@ 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 @@ 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; } } @@ -106,8 +106,31 @@ } 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."; } } }
--- a/libsvgbird/LineCap.vala +++ b/libsvgbird/LineCap.vala @@ -11,9 +11,6 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. */ - - using B; - using Math; namespace SvgBird {
--- a/libsvgbird/SelectorPattern.vala +++ b/libsvgbird/SelectorPattern.vala @@ -36,7 +36,7 @@ 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;
--- a/libsvgbird/SelectorTag.vala +++ b/libsvgbird/SelectorTag.vala @@ -29,17 +29,35 @@ 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 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 @@ return false; } - if (this.id != id) { + if (((!) this.id) != ((!) id)) { return false; } } @@ -118,7 +138,8 @@ return false; } - if (this.css_class != css_class) { + if (((!) this.css_class) != ((!) css_class)) { + print(@"class \"$((!)this.css_class)\"=\"$((!)css_class)\"\n"); return false; } } @@ -132,8 +153,31 @@ } 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; } } }
--- a/libsvgbird/SvgStyle.vala +++ b/libsvgbird/SvgStyle.vala @@ -70,6 +70,7 @@ 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,20 +159,22 @@ 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); } } } }