diff --git a/androidsvg/src/main/java/com/caverock/androidsvg/CSSParser.java b/androidsvg/src/main/java/com/caverock/androidsvg/CSSParser.java index 877319e2..9f0961b9 100644 --- a/androidsvg/src/main/java/com/caverock/androidsvg/CSSParser.java +++ b/androidsvg/src/main/java/com/caverock/androidsvg/CSSParser.java @@ -189,6 +189,11 @@ boolean isEmpty() return this.rules == null || this.rules.isEmpty(); } + int ruleCount() + { + return (this.rules != null) ? this.rules.size() : 0; + } + /* * Remove all rules that were addres from a give Source. */ @@ -218,7 +223,7 @@ public String toString() static enum Source { - Parser, + Document, RenderOptions } @@ -239,7 +244,7 @@ static class Rule @Override public String toString() { - return String.valueOf(selector) + " {}"; + return String.valueOf(selector) + " {...} (src="+this.source+")"; } } @@ -272,16 +277,19 @@ boolean isEmpty() } // Methods for accumulating a specificity value as SimpleSelector entries are added. + // Number of ID selectors in the selector void addedIdAttribute() { - specificity += 10000; + specificity += 1000000; } + // Number of class selectors, attributes selectors, and pseudo-classes void addedAttributeOrPseudo() { - specificity += 100; + specificity += 1000; } + // Number of type (element) selectors and pseudo-elements void addedElement() { specificity += 1; @@ -293,7 +301,7 @@ public String toString() StringBuilder sb = new StringBuilder(); for (SimpleSelector sel: selector) sb.append(sel).append(' '); - return sb.append('(').append(specificity).append(')').toString(); + return sb.append('[').append(specificity).append(']').toString(); } } @@ -304,7 +312,7 @@ public String toString() CSSParser() { - this(MediaType.screen, Source.Parser); + this(MediaType.screen, Source.Document); } @@ -470,14 +478,14 @@ boolean nextSimpleSelector(Selector selector) throws CSSParseException throw new CSSParseException("Invalid \"#id\" selector"); selectorPart.addAttrib(ID, AttribOp.EQUALS, value); selector.addedIdAttribute(); + continue; } - if (selectorPart == null) - break; - - // Now check for attribute selection and pseudo selectors + // Now check for attribute selection and pseudo selectors if (consume('[')) { + if (selectorPart == null) + selectorPart = new SimpleSelector(combinator, null); skipWhitespace(); String attrName = nextIdentifier(); String attrValue = null; @@ -507,6 +515,8 @@ else if (consume("|=")) if (consume(':')) { + if (selectorPart == null) + selectorPart = new SimpleSelector(combinator, null); // skip pseudo int pseudoStart = position; if (nextIdentifier() != null) { @@ -1072,8 +1082,8 @@ else if (sel.combinator == Combinator.CHILD) private static int getChildPosition(List ancestors, int ancestorsPos, SvgElementBase obj) { - if (ancestorsPos < 0) // Has no parent, so can't have a sibling - return -1; + if (ancestorsPos < 0) // Has no parent, so must be only child of document + return 0; if (ancestors.get(ancestorsPos) != obj.parent) // parent doesn't match, so obj must be an indirect reference (eg. from a ) return -1; int childPos = 0; diff --git a/androidsvg/src/main/java/com/caverock/androidsvg/SVGParser.java b/androidsvg/src/main/java/com/caverock/androidsvg/SVGParser.java index 61107826..687b0cb5 100644 --- a/androidsvg/src/main/java/com/caverock/androidsvg/SVGParser.java +++ b/androidsvg/src/main/java/com/caverock/androidsvg/SVGParser.java @@ -4483,7 +4483,7 @@ private void style(Attributes attributes) throws SVGParseException private void parseCSSStyleSheet(String sheet) { - CSSParser cssp = new CSSParser(MediaType.screen, CSSParser.Source.RenderOptions); + CSSParser cssp = new CSSParser(MediaType.screen, CSSParser.Source.Document); svgDocument.addCSSRules(cssp.parse(sheet)); }