private void ParseStdDeviation() { if (!this.HasAttribute("stdDeviation")) { _stdDeviationX = new SvgAnimatedNumber(0.0); _stdDeviationY = new SvgAnimatedNumber(0.0); } var stdDeviation = this.GetAttribute("stdDeviation"); if (string.IsNullOrWhiteSpace(stdDeviation)) { _stdDeviationX = new SvgAnimatedNumber(0.0); _stdDeviationY = new SvgAnimatedNumber(0.0); } var stdDeviationParts = _reSeparators.Split(stdDeviation); if (stdDeviationParts == null || stdDeviationParts.Length == 0) { _stdDeviationX = new SvgAnimatedNumber(0.0); _stdDeviationY = new SvgAnimatedNumber(0.0); } if (stdDeviationParts.Length == 1) { var stdDeviationValue = SvgNumber.ParseNumber(stdDeviationParts[0]); _stdDeviationX = new SvgAnimatedNumber(stdDeviationValue); _stdDeviationY = new SvgAnimatedNumber(stdDeviationValue); } else if (stdDeviationParts.Length == 2) { _stdDeviationX = new SvgAnimatedNumber(SvgNumber.ParseNumber(stdDeviationParts[0])); _stdDeviationY = new SvgAnimatedNumber(SvgNumber.ParseNumber(stdDeviationParts[1])); } }
private void ParseRadius() { if (!this.HasAttribute("radius")) { _radiusX = new SvgAnimatedNumber(0); _radiusY = new SvgAnimatedNumber(0); } var radius = this.GetAttribute("radius"); if (string.IsNullOrWhiteSpace(radius)) { _radiusX = new SvgAnimatedNumber(0); _radiusY = new SvgAnimatedNumber(0); } var radiusParts = _reSeparators.Split(radius); if (radiusParts == null || radiusParts.Length == 0) { _radiusX = new SvgAnimatedNumber(0); _radiusY = new SvgAnimatedNumber(0); } if (radiusParts.Length == 1) { var radiusValue = SvgNumber.ParseNumber(radiusParts[0]); _radiusX = new SvgAnimatedNumber(radiusValue); _radiusY = new SvgAnimatedNumber(radiusValue); } else if (radiusParts.Length == 2) { _radiusX = new SvgAnimatedNumber(SvgNumber.ParseNumber(radiusParts[0])); _radiusY = new SvgAnimatedNumber(SvgNumber.ParseNumber(radiusParts[1])); } }
// <filter id = "edgeFilter" > // < feConvolveMatrix filterRes="100 100" style="color-interpolation-filters:sRGB" // order="3" kernelMatrix="0 -1 0 -1 4 -1 0 -1 0" preserveAlpha="true"/> // </filter> private void ParseFilterRes() { if (!this.HasAttribute("filterRes")) { return; } var filterRes = this.GetAttribute("filterRes"); if (string.IsNullOrWhiteSpace(filterRes)) { return; } var filterResParts = _reSeparators.Split(filterRes); if (filterResParts == null || filterResParts.Length == 0) { return; } if (filterResParts.Length == 1) { var filterResValue = SvgNumber.ParseNumber(filterResParts[0]); _filterResX = new SvgAnimatedInteger(filterResValue); _filterResY = new SvgAnimatedInteger(filterResValue); } else if (filterResParts.Length == 2) { _filterResX = new SvgAnimatedInteger(SvgNumber.ParseNumber(filterResParts[0])); _filterResY = new SvgAnimatedInteger(SvgNumber.ParseNumber(filterResParts[1])); } }
private void ParseBaseFrequency() { if (!this.HasAttribute("baseFrequency")) { _baseFrequencyX = new SvgAnimatedNumber(0.0); _baseFrequencyY = new SvgAnimatedNumber(0.0); } var baseFrequency = this.GetAttribute("baseFrequency"); if (string.IsNullOrWhiteSpace(baseFrequency)) { _baseFrequencyX = new SvgAnimatedNumber(0.0); _baseFrequencyY = new SvgAnimatedNumber(0.0); } var baseFrequencyParts = _reSeparators.Split(baseFrequency); if (baseFrequencyParts == null || baseFrequencyParts.Length == 0) { _baseFrequencyX = new SvgAnimatedNumber(0.0); _baseFrequencyY = new SvgAnimatedNumber(0.0); } if (baseFrequencyParts.Length == 1) { var baseFrequencyValue = SvgNumber.ParseNumber(baseFrequencyParts[0]); _baseFrequencyX = new SvgAnimatedNumber(baseFrequencyValue); _baseFrequencyY = new SvgAnimatedNumber(baseFrequencyValue); } else if (baseFrequencyParts.Length == 2) { _baseFrequencyX = new SvgAnimatedNumber(SvgNumber.ParseNumber(baseFrequencyParts[0])); _baseFrequencyY = new SvgAnimatedNumber(SvgNumber.ParseNumber(baseFrequencyParts[1])); } }
public SvgRect(string str) { string replacedStr = Regex.Replace(str, @"(\s|,)+", ","); string[] tokens = replacedStr.Split(new char[] { ',' }); if (tokens.Length == 2) { _x = 0; _y = 0; _width = SvgNumber.ParseNumber(tokens[0]); _height = SvgNumber.ParseNumber(tokens[1]); } else if (tokens.Length == 4) { _x = SvgNumber.ParseNumber(tokens[0]); _y = SvgNumber.ParseNumber(tokens[1]); _width = SvgNumber.ParseNumber(tokens[2]); _height = SvgNumber.ParseNumber(tokens[3]); } else { throw new SvgException(SvgExceptionType.SvgInvalidValueErr, "Invalid SvgRect value: " + str); } }
private void ParseOrder() { if (!this.HasAttribute("order")) { return; } var order = this.GetAttribute("order"); if (string.IsNullOrWhiteSpace(order)) { _orderX = new SvgAnimatedInteger(3.0); _orderY = new SvgAnimatedInteger(3.0); return; } var orderParts = _reSeparators.Split(order); if (orderParts == null || orderParts.Length == 0) { _orderX = new SvgAnimatedInteger(3.0); _orderY = new SvgAnimatedInteger(3.0); return; } if (orderParts.Length == 1) { var orderValue = SvgNumber.ParseNumber(orderParts[0]); _orderX = new SvgAnimatedInteger(orderValue); _orderY = new SvgAnimatedInteger(orderValue); } else if (orderParts.Length == 2) { _orderX = new SvgAnimatedInteger(SvgNumber.ParseNumber(orderParts[0])); _orderY = new SvgAnimatedInteger(SvgNumber.ParseNumber(orderParts[1])); } }
private double getViewportProp(string propertyName, string inValue, double calcParentVP, double defaultValue, SvgLengthDirection dir) { double ret; inValue = inValue.Trim(); if (inValue.Length > 0) { if (inValue.EndsWith("%", StringComparison.OrdinalIgnoreCase)) { double perc = SvgNumber.ParseNumber(inValue.Substring(0, inValue.Length - 1)) / 100; ret = calcParentVP * perc; } else { ret = new SvgLength(this, propertyName, dir, inValue, string.Empty).Value; } } else { ret = defaultValue; } return(ret); }
private void ParseKernelUnitLength() { if (!this.HasAttribute("kernelUnitLength")) { return; } var kernelUnitLength = this.GetAttribute("kernelUnitLength"); if (string.IsNullOrWhiteSpace(kernelUnitLength)) { return; } var kernelUnitLengthParts = _reSeparators.Split(kernelUnitLength); if (kernelUnitLengthParts == null || kernelUnitLengthParts.Length == 0) { return; } if (kernelUnitLengthParts.Length == 1) { var kernelUnitLengthValue = SvgNumber.ParseNumber(kernelUnitLengthParts[0]); _kernelUnitLengthX = new SvgAnimatedNumber(kernelUnitLengthValue); _kernelUnitLengthY = new SvgAnimatedNumber(kernelUnitLengthValue); } else if (kernelUnitLengthParts.Length == 2) { _kernelUnitLengthX = new SvgAnimatedNumber(SvgNumber.ParseNumber(kernelUnitLengthParts[0])); _kernelUnitLengthY = new SvgAnimatedNumber(SvgNumber.ParseNumber(kernelUnitLengthParts[1])); } }
public static string ScientificToDec(string sc) { if (sc.IndexOfAny(new char[] { 'e', 'E' }) > -1) { sc = sc.Trim(); // remove the unit Match match = reUnit.Match(sc); return(SvgNumber.ParseNumber(sc.Substring(0, sc.Length - match.Length)).ToString(Format) + match.Value); } else { return(sc); } }
public static string ScientificToDec(string sc) { if (sc.ToUpper().Contains("E")) { sc = sc.Trim(); // remove the unit Match match = reUnit.Match(sc); // Fix for scientific conversion // Idea is to convert the the decimal to "Number" format and remove the grouping and set proper decimal digits. return(SvgNumber.ParseNumber(sc.Substring(0, sc.Length - match.Length)).ToString("N", Format) + match.Value); //return SvgNumber.ParseNumber(sc.Substring(0, sc.Length - match.Length)).ToString(Format) + match.Value; } else { return(sc); } }
private static double[] ParseCoords(string segment) { double[] coords = new double[0]; segment = segment.Substring(1); segment = segment.Trim(); segment = segment.Trim(new char[] { ',' }); if (segment.Length > 0) { string[] sCoords = RegexCoordSplit.Split(segment); coords = new double[sCoords.Length]; for (int i = 0; i < sCoords.Length; i++) { coords[i] = SvgNumber.ParseNumber(sCoords[i]); } } return(coords); }
public SvgAnimatedNumber(string str) { _baseVal = SvgNumber.ParseNumber(str); _animVal = _baseVal; }
public SvgTransform(string str) { int start = str.IndexOf("("); string type = str.Substring(0, start); string valuesList = (str.Substring(start + 1, str.Length - start - 2)).Trim(); //JR added trim Regex re = new Regex("[\\s\\,]+"); valuesList = re.Replace(valuesList, ","); string[] valuesStr = valuesList.Split(new char[] { ',' }); int len = valuesStr.GetLength(0); double[] values = new double[len]; for (int i = 0; i < len; i++) { //values.SetValue(SvgNumber.ParseToFloat(valuesStr[i]), i); values[i] = SvgNumber.ParseNumber(valuesStr[i]); } switch (type) { case "translate": switch (len) { case 1: SetTranslate(values[0], 0); break; case 2: SetTranslate(values[0], values[1]); break; default: throw new ApplicationException("Wrong number of arguments in translate transform"); } break; case "rotate": switch (len) { case 1: SetRotate(values[0]); break; case 3: SetRotate(values[0], values[1], values[2]); break; default: throw new ApplicationException("Wrong number of arguments in rotate transform"); } break; case "scale": switch (len) { case 1: SetScale(values[0], values[0]); break; case 2: SetScale(values[0], values[1]); break; default: throw new ApplicationException("Wrong number of arguments in scale transform"); } break; case "skewX": if (len != 1) { throw new ApplicationException("Wrong number of arguments in skewX transform"); } SetSkewX(values[0]); break; case "skewY": if (len != 1) { throw new ApplicationException("Wrong number of arguments in skewY transform"); } SetSkewY(values[0]); break; case "matrix": if (len != 6) { throw new ApplicationException("Wrong number of arguments in matrix transform"); } SetMatrix( new SvgMatrix( values[0], values[1], values[2], values[3], values[4], values[5] )); break; default: this.type = (short)SvgTransformType.Unknown; break; } }
public SvgAnimatedInteger(string str) { _baseVal = Convert.ToInt64(SvgNumber.ParseNumber(str)); _animVal = _baseVal; }
public SvgNumber(string str) { _value = SvgNumber.ParseNumber(str); }
public void FromString(string listString) { // remove existing list items Clear(); if (string.IsNullOrWhiteSpace(listString)) { return; } int len = listString.Length; // temp int p = 0; // pos char c; // temp int sNum = -1; // start of the number int eNum = -1; // end of the number bool seenComma = false; // to handle 123,,123 int tempSNum = -1; // start of the number (held in temp until two numbers are found) int tempENum = -1; // end of the number (held in temp until two numbers are found) // This used to be a regex-- it is *much* faster this way while (p < len) { // Get the char in a temp c = listString[p]; // TODO: worry about NEL? if ((c == '\t') || (c == '\r') || (c == '\n') || (c == 0x20) || (c == ',')) { // Special handling for two commas if (c == ',') { if (seenComma && sNum < 0) { throw new SvgException(SvgExceptionType.SvgInvalidValueErr); } seenComma = true; } // Are we in a number? if (sNum >= 0) { // The end of the number is the previous char eNum = p - 1; // Is this the x or y? if (tempSNum == -1) { // must be the x, hang onto it for a second tempSNum = sNum; tempENum = eNum; } else { // must be the y, use temp as x and append the item AppendItem(new SvgPoint(SvgNumber.ParseNumber(listString.Substring(tempSNum, (tempENum - tempSNum) + 1)), SvgNumber.ParseNumber(listString.Substring(sNum, (eNum - sNum) + 1)))); tempSNum = -1; tempENum = -1; } // Reset sNum = -1; eNum = -1; seenComma = false; } } else if (sNum == -1) { sNum = p; } // OPTIMIZE: Right here we could check for [Ee] to save some time in IndexOfAny later // Move to next char p++; } // We need to handle the end of the buffer as a delimiter if (sNum >= 0) { if (tempSNum == -1) { throw new SvgException(SvgExceptionType.SvgInvalidValueErr); } // The end of the number is the previous char eNum = p - 1; // must be the y, use temp as x and append the item AppendItem(new SvgPoint(SvgNumber.ParseNumber(listString.Substring(tempSNum, (tempENum - tempSNum) + 1)), SvgNumber.ParseNumber(listString.Substring(sNum, (eNum - sNum) + 1)))); } else if (tempSNum != -1) { throw new SvgException(SvgExceptionType.SvgInvalidValueErr); } }
public SvgTransform(string str) { int start = str.IndexOf("(", StringComparison.OrdinalIgnoreCase); string type = str.Substring(0, start); string valuesList = (str.Substring(start + 1, str.Length - start - 2)).Trim(); //JR added trim Regex re = new Regex("[\\s\\,]+"); valuesList = re.Replace(valuesList, ","); string[] valuesStr = valuesList.Split(new char[] { ',' }); int len = valuesStr.GetLength(0); double[] values = new double[len]; try { for (int i = 0; i < len; i++) { values[i] = SvgNumber.ParseNumber(valuesStr[i]); } } catch { List <double> valueList = new List <double>(); foreach (Match m in SvgNumber.DoubleRegex.Matches(str)) { if (!string.IsNullOrEmpty(m.Value)) { valueList.Add(SvgNumber.ParseToFloat(m.Value)); } } values = valueList.ToArray(); len = values.Length; } _values = values; switch (type.Trim()) { case "translate": switch (len) { case 1: SetTranslate(values[0], 0); break; case 2: SetTranslate(values[0], values[1]); break; default: throw new ApplicationException("Wrong number of arguments in translate transform"); } break; case "rotate": switch (len) { case 1: SetRotate(values[0]); break; case 3: SetRotate(values[0], values[1], values[2]); break; default: throw new ApplicationException("Wrong number of arguments in rotate transform"); } break; case "scale": switch (len) { case 1: SetScale(values[0], values[0]); break; case 2: SetScale(values[0], values[1]); break; default: throw new ApplicationException("Wrong number of arguments in scale transform"); } break; case "skewX": if (len != 1) { throw new ApplicationException("Wrong number of arguments in skewX transform"); } SetSkewX(values[0]); break; case "skewY": if (len != 1) { throw new ApplicationException("Wrong number of arguments in skewY transform"); } SetSkewY(values[0]); break; case "matrix": if (len != 6) { throw new ApplicationException("Wrong number of arguments in matrix transform"); } SetMatrix(new SvgMatrix(values[0], values[1], values[2], values[3], values[4], values[5])); break; default: _type = SvgTransformType.Unknown; break; } }