public static WMedia.Geometry ToWindows(this Geometry geometry) { WMedia.Geometry wGeometry = null; if (geometry is LineGeometry) { LineGeometry lineGeometry = geometry as LineGeometry; wGeometry = new WMedia.LineGeometry { StartPoint = lineGeometry.StartPoint.ToWindows(), EndPoint = lineGeometry.EndPoint.ToWindows() }; } else if (geometry is RectangleGeometry) { var rect = (geometry as RectangleGeometry).Rect; wGeometry = new WMedia.RectangleGeometry { Rect = new WFoundation.Rect(rect.X, rect.Y, rect.Width, rect.Height) }; } else if (geometry is EllipseGeometry) { EllipseGeometry ellipseGeometry = geometry as EllipseGeometry; wGeometry = new WMedia.EllipseGeometry { Center = ellipseGeometry.Center.ToWindows(), RadiusX = ellipseGeometry.RadiusX, RadiusY = ellipseGeometry.RadiusY }; } else if (geometry is GeometryGroup) { GeometryGroup geometryGroup = geometry as GeometryGroup; wGeometry = new WMedia.GeometryGroup { FillRule = ConvertFillRule(geometryGroup.FillRule) }; foreach (Geometry children in geometryGroup.Children) { WMedia.Geometry winChild = children.ToWindows(); (wGeometry as WMedia.GeometryGroup).Children.Add(winChild); } } else if (geometry is PathGeometry) { PathGeometry pathGeometry = geometry as PathGeometry; WMedia.PathGeometry wPathGeometry = new WMedia.PathGeometry { FillRule = ConvertFillRule(pathGeometry.FillRule) }; foreach (PathFigure xamPathFigure in pathGeometry.Figures) { WMedia.PathFigure wPathFigure = new WMedia.PathFigure { StartPoint = xamPathFigure.StartPoint.ToWindows(), IsFilled = xamPathFigure.IsFilled, IsClosed = xamPathFigure.IsClosed }; wPathGeometry.Figures.Add(wPathFigure); foreach (PathSegment pathSegment in xamPathFigure.Segments) { // LineSegment if (pathSegment is LineSegment) { LineSegment lineSegment = pathSegment as LineSegment; WMedia.LineSegment winSegment = new WMedia.LineSegment { Point = lineSegment.Point.ToWindows() }; wPathFigure.Segments.Add(winSegment); } // PolylineSegment if (pathSegment is PolyLineSegment) { PolyLineSegment polyLineSegment = pathSegment as PolyLineSegment; WMedia.PolyLineSegment wSegment = new WMedia.PolyLineSegment(); foreach (var point in polyLineSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // BezierSegment if (pathSegment is BezierSegment) { BezierSegment bezierSegment = pathSegment as BezierSegment; WMedia.BezierSegment wSegment = new WMedia.BezierSegment { Point1 = bezierSegment.Point1.ToWindows(), Point2 = bezierSegment.Point2.ToWindows(), Point3 = bezierSegment.Point3.ToWindows() }; wPathFigure.Segments.Add(wSegment); } // PolyBezierSegment else if (pathSegment is PolyBezierSegment) { PolyBezierSegment polyBezierSegment = pathSegment as PolyBezierSegment; WMedia.PolyBezierSegment wSegment = new WMedia.PolyBezierSegment(); foreach (var point in polyBezierSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // QuadraticBezierSegment if (pathSegment is QuadraticBezierSegment) { QuadraticBezierSegment quadraticBezierSegment = pathSegment as QuadraticBezierSegment; WMedia.QuadraticBezierSegment wSegment = new WMedia.QuadraticBezierSegment { Point1 = quadraticBezierSegment.Point1.ToWindows(), Point2 = quadraticBezierSegment.Point2.ToWindows() }; wPathFigure.Segments.Add(wSegment); } // PolyQuadraticBezierSegment else if (pathSegment is PolyQuadraticBezierSegment) { PolyQuadraticBezierSegment polyQuadraticBezierSegment = pathSegment as PolyQuadraticBezierSegment; WMedia.PolyQuadraticBezierSegment wSegment = new WMedia.PolyQuadraticBezierSegment(); foreach (var point in polyQuadraticBezierSegment.Points) { wSegment.Points.Add(point.ToWindows()); } wPathFigure.Segments.Add(wSegment); } // ArcSegment else if (pathSegment is ArcSegment) { ArcSegment arcSegment = pathSegment as ArcSegment; WMedia.ArcSegment wSegment = new WMedia.ArcSegment { Size = new WFoundation.Size(arcSegment.Size.Width, arcSegment.Size.Height), RotationAngle = arcSegment.RotationAngle, IsLargeArc = arcSegment.IsLargeArc, SweepDirection = arcSegment.SweepDirection == SweepDirection.Clockwise ? WMedia.SweepDirection.Clockwise : WMedia.SweepDirection.Counterclockwise, Point = arcSegment.Point.ToWindows() }; wPathFigure.Segments.Add(wSegment); } } } wGeometry = wPathGeometry; } return(wGeometry); }
public object ConvertToNative(Geometry geometry) { winMedia.Geometry winGeometry = null; // Determine what type of geometry we're dealing with. if (geometry is LineGeometry) { LineGeometry xamGeometry = geometry as LineGeometry; winGeometry = new winMedia.LineGeometry { StartPoint = ConvertPoint(xamGeometry.StartPoint), EndPoint = ConvertPoint(xamGeometry.EndPoint) }; } else if (geometry is RectangleGeometry) { Rect rect = (geometry as RectangleGeometry).Rect; winGeometry = new winMedia.RectangleGeometry { Rect = new winFound.Rect(rect.X, rect.Y, rect.Width, rect.Height) }; } else if (geometry is EllipseGeometry) { EllipseGeometry xamGeometry = geometry as EllipseGeometry; winGeometry = new winMedia.EllipseGeometry { Center = ConvertPoint(xamGeometry.Center), RadiusX = xamGeometry.RadiusX, RadiusY = xamGeometry.RadiusY }; } else if (geometry is GeometryGroup) { GeometryGroup xamGeometry = geometry as GeometryGroup; winGeometry = new winMedia.GeometryGroup { FillRule = ConvertFillRule(xamGeometry.FillRule) }; foreach (Geometry xamChild in xamGeometry.Children) { winMedia.Geometry winChild = ConvertToNative(xamChild) as winMedia.Geometry; (winGeometry as winMedia.GeometryGroup).Children.Add(winChild); } } else if (geometry is PathGeometry) { PathGeometry xamPathGeometry = geometry as PathGeometry; winMedia.PathGeometry winPathGeometry = new winMedia.PathGeometry { FillRule = ConvertFillRule(xamPathGeometry.FillRule) }; foreach (PathFigure xamPathFigure in xamPathGeometry.Figures) { winMedia.PathFigure winPathFigure = new winMedia.PathFigure { StartPoint = ConvertPoint(xamPathFigure.StartPoint), IsFilled = xamPathFigure.IsFilled, IsClosed = xamPathFigure.IsClosed }; winPathGeometry.Figures.Add(winPathFigure); foreach (PathSegment xamPathSegment in xamPathFigure.Segments) { // LineSegment if (xamPathSegment is LineSegment) { LineSegment xamSegment = xamPathSegment as LineSegment; winMedia.LineSegment winSegment = new winMedia.LineSegment { Point = ConvertPoint(xamSegment.Point) }; winPathFigure.Segments.Add(winSegment); } // PolylineSegment if (xamPathSegment is PolyLineSegment) { PolyLineSegment xamSegment = xamPathSegment as PolyLineSegment; winMedia.PolyLineSegment winSegment = new winMedia.PolyLineSegment(); foreach (Point point in xamSegment.Points) { winSegment.Points.Add(ConvertPoint(point)); } winPathFigure.Segments.Add(winSegment); } // BezierSegment if (xamPathSegment is BezierSegment) { BezierSegment xamSegment = xamPathSegment as BezierSegment; winMedia.BezierSegment winSegment = new winMedia.BezierSegment { Point1 = ConvertPoint(xamSegment.Point1), Point2 = ConvertPoint(xamSegment.Point2), Point3 = ConvertPoint(xamSegment.Point3) }; winPathFigure.Segments.Add(winSegment); } // PolyBezierSegment else if (xamPathSegment is PolyBezierSegment) { PolyBezierSegment xamSegment = xamPathSegment as PolyBezierSegment; winMedia.PolyBezierSegment winSegment = new winMedia.PolyBezierSegment(); foreach (Point point in xamSegment.Points) { winSegment.Points.Add(ConvertPoint(point)); } winPathFigure.Segments.Add(winSegment); } // QuadraticBezierSegment if (xamPathSegment is QuadraticBezierSegment) { QuadraticBezierSegment xamSegment = xamPathSegment as QuadraticBezierSegment; winMedia.QuadraticBezierSegment winSegment = new winMedia.QuadraticBezierSegment { Point1 = ConvertPoint(xamSegment.Point1), Point2 = ConvertPoint(xamSegment.Point2), }; winPathFigure.Segments.Add(winSegment); } // PolyQuadraticBezierSegment else if (xamPathSegment is PolyQuadraticBezierSegment) { PolyQuadraticBezierSegment xamSegment = xamPathSegment as PolyQuadraticBezierSegment; winMedia.PolyQuadraticBezierSegment winSegment = new winMedia.PolyQuadraticBezierSegment(); foreach (Point point in xamSegment.Points) { winSegment.Points.Add(ConvertPoint(point)); } winPathFigure.Segments.Add(winSegment); } // ArcSegment else if (xamPathSegment is ArcSegment) { ArcSegment xamSegment = xamPathSegment as ArcSegment; winMedia.ArcSegment winSegment = new winMedia.ArcSegment(); winSegment.Size = new winFound.Size(xamSegment.Size.Width, xamSegment.Size.Height); winSegment.RotationAngle = xamSegment.RotationAngle; winSegment.IsLargeArc = xamSegment.IsLargeArc; winSegment.SweepDirection = xamSegment.SweepDirection == SweepDirection.Clockwise ? winMedia.SweepDirection.Clockwise : winMedia.SweepDirection.Counterclockwise; winSegment.Point = ConvertPoint(xamSegment.Point); winPathFigure.Segments.Add(winSegment); } } } winGeometry = winPathGeometry; } // Set transform. if (geometry.Transform != null) { winGeometry.Transform = (winMedia.Transform)geometry.Transform.GetNativeObject(); } return(winGeometry); }
private Geometry GetFlattenedPathGeometry(Geometry geometry) { return geometry; }
private double GetGeometryLendth(Geometry geometry) { double result = 0; var pathGeometry = geometry as PathGeometry; if (pathGeometry != null) { foreach (var figure in pathGeometry.Figures) { var currentPoint = figure.StartPoint; foreach (var segment in figure.Segments) { var bezier = segment as BezierSegment; var line = segment as LineSegment; if (bezier != null) { result += GetBezierLength(currentPoint, bezier.Point1, bezier.Point2, bezier.Point3); currentPoint = bezier.Point3; } else if (line != null) { result += GetLineLength(currentPoint, line.Point); currentPoint = line.Point; } } } } return result; }
private void GetPointAtFractionLength(Geometry data, int i, out Point point, out Point tangent) { //throw new NotImplementedException(); }