private void RunTest(String src, IList <String> tokenValues, IList <CssDeclarationValueTokenizer.TokenType> tokenTypes) { CssDeclarationValueTokenizer tokenizer = new CssDeclarationValueTokenizer(src); CssDeclarationValueTokenizer.Token token = null; NUnit.Framework.Assert.IsTrue(tokenValues.Count == tokenTypes.Count, "Value and type arrays size should be equal" ); int index = 0; while ((token = tokenizer.GetNextValidToken()) != null) { NUnit.Framework.Assert.AreEqual(tokenValues[index], token.GetValue()); NUnit.Framework.Assert.AreEqual(tokenTypes[index], token.GetType()); ++index; } NUnit.Framework.Assert.IsTrue(index == tokenValues.Count); }
private TransparentColor GetColorFromAttributeValue(SvgDrawContext context, String rawColorValue, float objectBoundingBoxMargin , float parentOpacity) { if (rawColorValue == null) { return(null); } CssDeclarationValueTokenizer tokenizer = new CssDeclarationValueTokenizer(rawColorValue); CssDeclarationValueTokenizer.Token token = tokenizer.GetNextValidToken(); if (token == null) { return(null); } String tokenValue = token.GetValue(); if (tokenValue.StartsWith("url(#") && tokenValue.EndsWith(")")) { Color resolvedColor = null; float resolvedOpacity = 1; String normalizedName = tokenValue.JSubstring(5, tokenValue.Length - 1).Trim(); ISvgNodeRenderer colorRenderer = context.GetNamedObject(normalizedName); if (colorRenderer is AbstractGradientSvgNodeRenderer) { resolvedColor = ((AbstractGradientSvgNodeRenderer)colorRenderer).CreateColor(context, GetObjectBoundingBox (context), objectBoundingBoxMargin, parentOpacity); } if (resolvedColor != null) { return(new TransparentColor(resolvedColor, resolvedOpacity)); } token = tokenizer.GetNextValidToken(); } // may become null after function parsing and reading the 2nd token if (token != null) { String value = token.GetValue(); if (!SvgConstants.Values.NONE.EqualsIgnoreCase(value)) { return(new TransparentColor(WebColors.GetRGBColor(value), parentOpacity * GetAlphaFromRGBA(value))); } } return(null); }
/// <summary> /// Extracts shorthand properties as list of string lists from a string, where the top level /// list is shorthand property and the lower level list is properties included in shorthand property. /// </summary> /// <param name="str">the source string with shorthand properties</param> /// <returns>the list of string lists</returns> public static IList <IList <String> > ExtractShorthandProperties(String str) { IList <IList <String> > result = new List <IList <String> >(); IList <String> currentLayer = new List <String>(); CssDeclarationValueTokenizer tokenizer = new CssDeclarationValueTokenizer(str); CssDeclarationValueTokenizer.Token currentToken = tokenizer.GetNextValidToken(); while (currentToken != null) { if (currentToken.GetType() == CssDeclarationValueTokenizer.TokenType.COMMA) { result.Add(currentLayer); currentLayer = new List <String>(); } else { currentLayer.Add(currentToken.GetValue()); } currentToken = tokenizer.GetNextValidToken(); } result.Add(currentLayer); return(result); }