/// <summary> /// Parse - returns an instance converted from the provided string using /// the culture "en-US" /// <param name="source"> string with Rect data </param> /// </summary> public static Rect Parse(string source) { IFormatProvider formatProvider = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS; TokenizerHelper th = new TokenizerHelper(source, formatProvider); Rect value; String firstToken = th.NextTokenRequired(); // The token will already have had whitespace trimmed so we can do a // simple string compare. if (firstToken == "Empty") { value = Empty; } else { value = new Rect( Convert.ToDouble(firstToken, formatProvider), Convert.ToDouble(th.NextTokenRequired(), formatProvider), Convert.ToDouble(th.NextTokenRequired(), formatProvider), Convert.ToDouble(th.NextTokenRequired(), formatProvider)); } // There should be no more tokens in this string. th.LastTokenRequired(); return(value); }
/// <summary> /// Parses the specified value. /// </summary> public static Point Parse(string value) { Point point = new Point(); TokenizerHelper tokenizer = new TokenizerHelper(value, CultureInfo.InvariantCulture); point.X = ParserHelper.ParseDouble(tokenizer.NextTokenRequired()); point.Y = ParserHelper.ParseDouble(tokenizer.NextTokenRequired()); return(point); }
/// <summary> /// Parses the specified value. /// </summary> public static Size Parse(string value) { Size size = new Size(); TokenizerHelper tokenizer = new TokenizerHelper(value); size.Width = ParserHelper.ParseDouble(tokenizer.NextTokenRequired()); size.Height = ParserHelper.ParseDouble(tokenizer.NextTokenRequired()); return(size); }
/// <summary> /// Parses the specified value. /// </summary> public static Rect Parse(string value) { Rect rect = new Rect(); IFormatProvider formatProvider = CultureInfo.InvariantCulture; TokenizerHelper helper = new TokenizerHelper(value, formatProvider); rect.X = Convert.ToDouble(helper.NextTokenRequired(), formatProvider); rect.Y = Convert.ToDouble(helper.NextTokenRequired(), formatProvider); rect.Width = Convert.ToDouble(helper.NextTokenRequired(), formatProvider); rect.Height = Convert.ToDouble(helper.NextTokenRequired(), formatProvider); return(rect); }
/// <summary> /// Parses the rectangle from a string. /// </summary> public static XRect Parse(string source) { XRect empty; CultureInfo cultureInfo = CultureInfo.InvariantCulture; TokenizerHelper helper = new TokenizerHelper(source, cultureInfo); string str = helper.NextTokenRequired(); empty = str == "Empty" ? Empty : new XRect(Convert.ToDouble(str, cultureInfo), Convert.ToDouble(helper.NextTokenRequired(), cultureInfo), Convert.ToDouble(helper.NextTokenRequired(), cultureInfo), Convert.ToDouble(helper.NextTokenRequired(), cultureInfo)); helper.LastTokenRequired(); return(empty); }
public static XVector Parse(string source) { TokenizerHelper helper = new TokenizerHelper(source, CultureInfo.InvariantCulture); string str = helper.NextTokenRequired(); XVector vector = new XVector(Convert.ToDouble(str, CultureInfo.InvariantCulture), Convert.ToDouble(helper.NextTokenRequired(), CultureInfo.InvariantCulture)); helper.LastTokenRequired(); return(vector); }
/// <summary> /// Parse - returns an instance converted from the provided string using /// the culture "en-US" /// <param name="source"> string with Vector data </param> /// </summary> public static Vector Parse(string source) { IFormatProvider formatProvider = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS; TokenizerHelper th = new TokenizerHelper(source, formatProvider); Vector value; String firstToken = th.NextTokenRequired(); value = new Vector( Convert.ToDouble(firstToken, formatProvider), Convert.ToDouble(th.NextTokenRequired(), formatProvider)); // There should be no more tokens in this string. th.LastTokenRequired(); return(value); }
/// <summary>Creates an <see cref="T:System.Windows.Int32Rect" /> structure from the specified <see cref="T:System.String" /> representation.</summary> /// <returns>The equivalent <see cref="T:System.Windows.Int32Rect" /> structure.</returns> /// <param name="source">A string representation of an <see cref="T:System.Windows.Int32Rect" />.</param> public static Int32Rect Parse(string source) { IFormatProvider invariantEnglishUS = TypeConverterHelper.InvariantEnglishUS; TokenizerHelper tokenizerHelper = new TokenizerHelper(source, invariantEnglishUS); string text = tokenizerHelper.NextTokenRequired(); Int32Rect result = (text == "Empty") ? Empty : new Int32Rect(Convert.ToInt32(text, invariantEnglishUS), Convert.ToInt32(tokenizerHelper.NextTokenRequired(), invariantEnglishUS), Convert.ToInt32(tokenizerHelper.NextTokenRequired(), invariantEnglishUS), Convert.ToInt32(tokenizerHelper.NextTokenRequired(), invariantEnglishUS)); tokenizerHelper.LastTokenRequired(); return(result); }
public static Point4D Parse(string source) { IFormatProvider cultureInfo = CultureInfo.InvariantCulture; TokenizerHelper helper = new TokenizerHelper(source, cultureInfo); string str = helper.NextTokenRequired(); Point4D pointd = new Point4D(Convert.ToSingle(str, cultureInfo), Convert.ToSingle(helper.NextTokenRequired(), cultureInfo), Convert.ToSingle(helper.NextTokenRequired(), cultureInfo), Convert.ToSingle(helper.NextTokenRequired(), cultureInfo)); helper.LastTokenRequired(); return(pointd); }
/// <summary> /// Parses the point from a string. /// </summary> public static XPoint Parse(string source) { CultureInfo cultureInfo = CultureInfo.InvariantCulture; TokenizerHelper helper = new TokenizerHelper(source, cultureInfo); string str = helper.NextTokenRequired(); XPoint point = new XPoint(Convert.ToDouble(str, cultureInfo), Convert.ToDouble(helper.NextTokenRequired(), cultureInfo)); helper.LastTokenRequired(); return(point); }
public static Vector3D Parse(string source) { IFormatProvider cultureInfo = CultureInfo.InvariantCulture; TokenizerHelper helper = new TokenizerHelper(source, cultureInfo); string str = helper.NextTokenRequired(); Vector3D vectord = new Vector3D(Convert.ToSingle(str, cultureInfo), Convert.ToSingle(helper.NextTokenRequired(), cultureInfo), Convert.ToSingle(helper.NextTokenRequired(), cultureInfo)); helper.LastTokenRequired(); return(vectord); }
/// <summary> /// ConvertFrom /// </summary> public override object ConvertFrom( ITypeDescriptorContext context, CultureInfo cultureInfo, object value) { string stringValue = value as string; if (value == null) { throw new NotSupportedException(SR.Get(SRID.Converter_ConvertFromNotSupported)); } TokenizerHelper th = new TokenizerHelper(stringValue, cultureInfo); return(new KeySpline( Convert.ToDouble(th.NextTokenRequired(), cultureInfo), Convert.ToDouble(th.NextTokenRequired(), cultureInfo), Convert.ToDouble(th.NextTokenRequired(), cultureInfo), Convert.ToDouble(th.NextTokenRequired(), cultureInfo))); }
/// <summary> /// Parse - returns an instance converted from the provided string. /// <param name="source"> string with Point3DCollection data </param> /// <param name="formatProvider">IFormatprovider for processing string</param> /// </summary> private static List <ThreeDoublesMarkup> ParseThreeDoublesCollection(string source, IFormatProvider formatProvider) { TokenizerHelper th = new TokenizerHelper(source, formatProvider); List <ThreeDoublesMarkup> resource = new List <ThreeDoublesMarkup>(source.Length / 8); // SWAG the length of the collection. ThreeDoublesMarkup value; while (th.NextToken()) { value = new ThreeDoublesMarkup( Convert.ToDouble(th.GetCurrentToken(), formatProvider), Convert.ToDouble(th.NextTokenRequired(), formatProvider), Convert.ToDouble(th.NextTokenRequired(), formatProvider)); resource.Add(value); } return(resource); }
/// <summary> /// Parse - returns an instance converted from the provided string /// using the current culture /// <param name="source"> string with Vector3DCollection data </param> /// </summary> public static Vector3DCollection Parse(string source) { IFormatProvider formatProvider = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS; TokenizerHelper th = new TokenizerHelper(source, formatProvider); Vector3DCollection resource = new Vector3DCollection(); Vector3D value; while (th.NextToken()) { value = new Vector3D( Convert.ToDouble(th.GetCurrentToken(), formatProvider), Convert.ToDouble(th.NextTokenRequired(), formatProvider), Convert.ToDouble(th.NextTokenRequired(), formatProvider)); resource.Add(value); } return(resource); }
public static Vector3Collection Parse(string source) { IFormatProvider formatProvider = CultureInfo.InvariantCulture; var th = new TokenizerHelper(source, formatProvider); var resource = new Vector3Collection(); Vector3 value; while (th.NextToken()) { value = new Vector3( Convert.ToSingle(th.GetCurrentToken(), formatProvider), Convert.ToSingle(th.NextTokenRequired(), formatProvider), Convert.ToSingle(th.NextTokenRequired(), formatProvider)); resource.Add(value); } return(resource); }
/// <summary> /// Parses the size from a string. /// </summary> public static XSize Parse(string source) { XSize empty; CultureInfo cultureInfo = CultureInfo.InvariantCulture; TokenizerHelper helper = new TokenizerHelper(source, cultureInfo); string str = helper.NextTokenRequired(); if (str == "Empty") { empty = Empty; } else { empty = new XSize(Convert.ToDouble(str, cultureInfo), Convert.ToDouble(helper.NextTokenRequired(), cultureInfo)); } helper.LastTokenRequired(); return(empty); }
/// <summary> /// Parses the specified value. /// </summary> public static Matrix Parse(string value) { Matrix matrix = new Matrix(); IFormatProvider formatProvider = CultureInfo.InvariantCulture; TokenizerHelper helper = new TokenizerHelper(value, formatProvider); matrix.m11 = Convert.ToDouble(helper.NextTokenRequired(), formatProvider); matrix.m12 = Convert.ToDouble(helper.NextTokenRequired(), formatProvider); matrix.m21 = Convert.ToDouble(helper.NextTokenRequired(), formatProvider); matrix.m22 = Convert.ToDouble(helper.NextTokenRequired(), formatProvider); matrix.offsetX = Convert.ToDouble(helper.NextTokenRequired(), formatProvider); matrix.offsetY = Convert.ToDouble(helper.NextTokenRequired(), formatProvider); return(matrix); }
/// <summary> /// Parses a PathGeometry from a data string element. /// </summary> PathGeometry ParsePathGeometry(string data) { #if DEBUG_ // XPS = M 20,100 C 45,50 70,150 95,100 S 145,150 170,100 220,150 245,100 C 220,50 195,150 170,100 S 120,150 95,100 45,150 20,100 // XXX = M20,100C45,50 70,150 95,100 120,50 145,150 170,100 195,50 220,150 245,100 220,50 195,150 170,100 145,50 120,150 95,100 70,50 45,150 20,100 if (data.StartsWith("M 20,100 C 45,50 70,150 95,100 S 145,")) { Debugger.Break(); } #endif PathGeometry geo = TryParseStaticResource <PathGeometry>(data); if (geo != null) { return(geo); } data = FixHack(data); // From the algorithm on page 365 in XPS 1.0 specs // See Petzold page 813 geo = new PathGeometry(); Point point = new Point(); PathFigure figure = null; TokenizerHelper helper = new TokenizerHelper(data); helper.NextTokenRequired(); do { string token = helper.GetCurrentToken(); switch (token[0]) { // FillRule case 'F': geo.FillRule = helper.NextTokenRequired() == "1" ? FillRule.NonZero : FillRule.EvenOdd; break; // Move case 'M': { figure = new PathFigure(); geo.Figures.Add(figure); point = new Point(ParseDouble(helper.NextTokenRequired()), ParseDouble(helper.NextTokenRequired())); figure.StartPoint = point; } break; // Move case 'm': { figure = new PathFigure(); geo.Figures.Add(figure); point = new Point(point.X + ParseDouble(helper.NextTokenRequired()), point.Y + ParseDouble(helper.NextTokenRequired())); figure.StartPoint = point; } break; // Line case 'L': { PolyLineSegment seg; int segCount = figure.Segments.Count; if (segCount > 0 && (seg = figure.Segments[segCount - 1] as PolyLineSegment) != null) { } else { seg = new PolyLineSegment(); figure.Segments.Add(seg); } do { point = new Point(ParseDouble(helper.NextTokenRequired()), ParseDouble(helper.NextTokenRequired())); seg.Points.Add(point); } while (!Char.IsLetter(helper.PeekNextCharacter())); } break; // Line case 'l': { PolyLineSegment seg; int segCount = figure.Segments.Count; if (segCount > 0 && (seg = figure.Segments[segCount - 1] as PolyLineSegment) != null) { } else { seg = new PolyLineSegment(); figure.Segments.Add(seg); } do { point = new Point(ParseDouble(helper.NextTokenRequired()), ParseDouble(helper.NextTokenRequired())); seg.Points.Add(point); } while (!Char.IsLetter(helper.PeekNextCharacter())); } break; // Horizontal Line case 'H': { PolyLineSegment seg; int segCount = figure.Segments.Count; if (segCount > 0 && (seg = figure.Segments[segCount - 1] as PolyLineSegment) != null) { } else { seg = new PolyLineSegment(); figure.Segments.Add(seg); } do { point.X = ParseDouble(helper.NextTokenRequired()); seg.Points.Add(point); } while (!Char.IsLetter(helper.PeekNextCharacter())); } break; // Horizontal Line case 'h': { PolyLineSegment seg; int segCount = figure.Segments.Count; if (segCount > 0 && (seg = figure.Segments[segCount - 1] as PolyLineSegment) != null) { } else { seg = new PolyLineSegment(); figure.Segments.Add(seg); } do { point.X += ParseDouble(helper.NextTokenRequired()); seg.Points.Add(point); } while (!Char.IsLetter(helper.PeekNextCharacter())); } break; // Vertical Line case 'V': { PolyLineSegment seg; int segCount = figure.Segments.Count; if (segCount > 0 && (seg = figure.Segments[segCount - 1] as PolyLineSegment) != null) { } else { seg = new PolyLineSegment(); figure.Segments.Add(seg); } do { point.Y = ParseDouble(helper.NextTokenRequired()); seg.Points.Add(point); } while (!Char.IsLetter(helper.PeekNextCharacter())); } break; // Vertical Line case 'v': { PolyLineSegment seg; int segCount = figure.Segments.Count; if (segCount > 0 && (seg = figure.Segments[segCount - 1] as PolyLineSegment) != null) { } else { seg = new PolyLineSegment(); figure.Segments.Add(seg); } do { point.Y += ParseDouble(helper.NextTokenRequired()); seg.Points.Add(point); } while (!Char.IsLetter(helper.PeekNextCharacter())); } break; // Elliptical Arc case 'A': do { // I cannot believe it: "A70.1,50.1 1,34 0 0 170.1,30.1" // The rotation angle "1,34" uses a ',' instead of a '.' in my German Windows Vista! //A70.1,50.1 1,34 0 0 170.1,30.1 ArcSegment seg = new ArcSegment(); figure.Segments.Add(seg); seg.Size = new Size(ParseDouble(helper.NextTokenRequired()), ParseDouble(helper.NextTokenRequired())); seg.RotationAngle = ParseDouble(helper.NextTokenRequired()); seg.IsLargeArc = helper.NextTokenRequired() == "1"; seg.SweepDirection = helper.NextTokenRequired() == "1" ? SweepDirection.Clockwise : SweepDirection.Counterclockwise; point = new Point(ParseDouble(helper.NextTokenRequired()), ParseDouble(helper.NextTokenRequired())); seg.Point = point; } while (!Char.IsLetter(helper.PeekNextCharacter())); break; // Elliptical Arc case 'a': do { ArcSegment seg = new ArcSegment(); figure.Segments.Add(seg); seg.Size = new Size(ParseDouble(helper.NextTokenRequired()), ParseDouble(helper.NextTokenRequired())); seg.RotationAngle = ParseDouble(helper.NextTokenRequired()); seg.IsLargeArc = helper.NextTokenRequired() == "1"; seg.SweepDirection = helper.NextTokenRequired() == "1" ? SweepDirection.Clockwise : SweepDirection.Counterclockwise; point = new Point(point.X + ParseDouble(helper.NextTokenRequired()), point.Y + ParseDouble(helper.NextTokenRequired())); seg.Point = point; } while (!Char.IsLetter(helper.PeekNextCharacter())); break; // Cubic Bézier Curve case 'C': { PolyBezierSegment seg; int segCount = figure.Segments.Count; if (segCount > 0 && (seg = figure.Segments[segCount - 1] as PolyBezierSegment) != null) { } else { seg = new PolyBezierSegment(); figure.Segments.Add(seg); } do { seg.Points.Add(new Point(ParseDouble(helper.NextTokenRequired()), ParseDouble(helper.NextTokenRequired()))); seg.Points.Add(new Point(ParseDouble(helper.NextTokenRequired()), ParseDouble(helper.NextTokenRequired()))); point = new Point(ParseDouble(helper.NextTokenRequired()), ParseDouble(helper.NextTokenRequired())); seg.Points.Add(point); } while (!Char.IsLetter(helper.PeekNextCharacter())); } break; // Cubic Bézier Curve case 'c': { PolyBezierSegment seg; int segCount = figure.Segments.Count; if (segCount > 0 && (seg = figure.Segments[segCount - 1] as PolyBezierSegment) != null) { } else { seg = new PolyBezierSegment(); figure.Segments.Add(seg); } do { seg.Points.Add(new Point(point.X + ParseDouble(helper.NextTokenRequired()), point.Y + ParseDouble(helper.NextTokenRequired()))); seg.Points.Add(new Point(point.X + ParseDouble(helper.NextTokenRequired()), point.Y + ParseDouble(helper.NextTokenRequired()))); point = new Point(point.X + ParseDouble(helper.NextTokenRequired()), point.Y + ParseDouble(helper.NextTokenRequired())); seg.Points.Add(point); } while (!Char.IsLetter(helper.PeekNextCharacter())); } break; // Smooth Cubic Bézier Curve case 'S': { PolyBezierSegment seg; int segCount = figure.Segments.Count; if (segCount > 0 && (seg = figure.Segments[segCount - 1] as PolyBezierSegment) != null) { } else { seg = new PolyBezierSegment(); figure.Segments.Add(seg); } do { Point pt = new Point(); int count = seg.Points.Count; segCount = figure.Segments.Count; if (count > 0) { Point lastCtrlPoint = seg.Points[count - 2]; pt.X = 2 * point.X - lastCtrlPoint.X; pt.Y = 2 * point.Y - lastCtrlPoint.Y; } else if (segCount > 1 && figure.Segments[count - 2] is PolyBezierSegment) { PolyBezierSegment lastSeg = (PolyBezierSegment)figure.Segments[count - 2]; count = lastSeg.Points.Count; Point lastCtrlPoint = lastSeg.Points[count - 2]; pt.X = 2 * point.X - lastCtrlPoint.X; pt.Y = 2 * point.Y - lastCtrlPoint.Y; } else { pt = point; } seg.Points.Add(pt); seg.Points.Add(new Point(ParseDouble(helper.NextTokenRequired()), ParseDouble(helper.NextTokenRequired()))); point = new Point(ParseDouble(helper.NextTokenRequired()), ParseDouble(helper.NextTokenRequired())); seg.Points.Add(point); } while (!Char.IsLetter(helper.PeekNextCharacter())); } break; // Smooth Cubic Bézier Curve case 's': { PolyBezierSegment seg; int segCount = figure.Segments.Count; if (segCount > 0 && (seg = figure.Segments[segCount - 1] as PolyBezierSegment) != null) { } else { seg = new PolyBezierSegment(); figure.Segments.Add(seg); } do { Point pt = new Point(); int count = seg.Points.Count; segCount = figure.Segments.Count; if (count > 0) { Point lastCtrlPoint = seg.Points[count - 2]; pt.X = 2 * point.X - lastCtrlPoint.X; pt.Y = 2 * point.Y - lastCtrlPoint.Y; } else if (segCount > 1 && figure.Segments[count - 2] is PolyBezierSegment) { PolyBezierSegment lastSeg = (PolyBezierSegment)figure.Segments[count - 2]; count = lastSeg.Points.Count; Point lastCtrlPoint = lastSeg.Points[count - 2]; pt.X = 2 * point.X - lastCtrlPoint.X; pt.Y = 2 * point.Y - lastCtrlPoint.Y; } else { pt = point; } seg.Points.Add(pt); seg.Points.Add(new Point(point.X + ParseDouble(helper.NextTokenRequired()), point.Y + ParseDouble(helper.NextTokenRequired()))); point = new Point(point.X + ParseDouble(helper.NextTokenRequired()), point.Y + ParseDouble(helper.NextTokenRequired())); seg.Points.Add(point); } while (!Char.IsLetter(helper.PeekNextCharacter())); } break; // Quadratic Bézier Curve case 'Q': { PolyQuadraticBezierSegment seg = new PolyQuadraticBezierSegment(); figure.Segments.Add(seg); do { seg.Points.Add(new Point(ParseDouble(helper.NextTokenRequired()), ParseDouble(helper.NextTokenRequired()))); point = new Point(ParseDouble(helper.NextTokenRequired()), ParseDouble(helper.NextTokenRequired())); seg.Points.Add(point); } while (!Char.IsLetter(helper.PeekNextCharacter())); } break; // Quadratic Bézier Curve case 'q': { PolyQuadraticBezierSegment seg = new PolyQuadraticBezierSegment(); figure.Segments.Add(seg); do { seg.Points.Add(new Point(point.X + ParseDouble(helper.NextTokenRequired()), point.Y + ParseDouble(helper.NextTokenRequired()))); point = new Point(point.X + ParseDouble(helper.NextTokenRequired()), point.Y + ParseDouble(helper.NextTokenRequired())); seg.Points.Add(point); } while (!Char.IsLetter(helper.PeekNextCharacter())); } break; // Close case 'Z': case 'z': { figure.IsClosed = true; if (figure.Segments.Count > 0) { PathSegment seg = figure.Segments[0]; } point = figure.StartPoint; figure = null; } break; default: Debug.Assert(false); break; } } while (helper.NextToken()); return(geo); }
/// <summary> /// Parse - returns an instance converted from the provided string. /// <param name="source"> string with Point3DCollection data </param> /// <param name="formatProvider">IFormatprovider for processing string</param> /// </summary> private static List<Point> ParsePointCollection(string source, IFormatProvider formatProvider) { TokenizerHelper th = new TokenizerHelper(source, formatProvider); List<Point> resource = new List<Point>(source.Length/ 8 ); // SWAG the length of the collection. Point value; while (th.NextToken()) { value = new Point( Convert.ToDouble(th.GetCurrentToken(), formatProvider), Convert.ToDouble(th.NextTokenRequired(), formatProvider) ); resource.Add(value); } return resource; }
/// <summary> /// Parses a series of points. /// </summary> internal static PointStopCollection ParsePoints(string value) { PointStopCollection points = new PointStopCollection(); TokenizerHelper tokenizer = new TokenizerHelper(value, CultureInfo.InvariantCulture); while (tokenizer.NextToken()) { Point point = new Point(ParserHelper.ParseDouble(tokenizer.GetCurrentToken()), ParserHelper.ParseDouble(tokenizer.NextTokenRequired())); points.Add(point); } return(points); }
public static Point3DCollection Parse(string source) { IFormatProvider cultureInfo = CultureInfo.InvariantCulture; TokenizerHelper helper = new TokenizerHelper(source, cultureInfo); Point3DCollection pointds = new Point3DCollection(); while (helper.NextToken()) { Point3D pointd = new Point3D(Convert.ToSingle(helper.GetCurrentToken(), cultureInfo), Convert.ToSingle(helper.NextTokenRequired(), cultureInfo), Convert.ToSingle(helper.NextTokenRequired(), cultureInfo)); pointds.Add(pointd); } return(pointds); }
public static Vector3DCollection Parse(string source) { IFormatProvider cultureInfo = CultureInfo.InvariantCulture; TokenizerHelper helper = new TokenizerHelper(source, cultureInfo); Vector3DCollection vectords = new Vector3DCollection(); while (helper.NextToken()) { Vector3D vectord = new Vector3D(Convert.ToSingle(helper.GetCurrentToken(), cultureInfo), Convert.ToSingle(helper.NextTokenRequired(), cultureInfo), Convert.ToSingle(helper.NextTokenRequired(), cultureInfo)); vectords.Add(vectord); } return(vectords); }