private static void ExportGeometry(FixedContentEditor editor, FixedContentEditor filledEditor, Geometry geometry, bool isConnection = false) { // We need two editors because there might be filled and not filled figures. #if WPF var pathGeometry = geometry as PathGeometry; #else var pathGeometry = GeometryParser.GetGeometry(geometry.ToString()) as PathGeometry; #endif if (pathGeometry != null) { var path = new G.PathGeometry(); var filledPath = new G.PathGeometry(); for (int i = 0; i < pathGeometry.Figures.Count; i++) { var figure = pathGeometry.Figures[i]; var newFigure = new G.PathFigure(); newFigure.StartPoint = figure.StartPoint; newFigure.IsClosed = figure.IsClosed; foreach (var segment in figure.Segments) { var arc = segment as ArcSegment; if (arc != null) { var newS = new G.ArcSegment(); newS.Point = arc.Point; newS.RadiusX = arc.Size.Width; newS.RadiusY = arc.Size.Height; newS.RotationAngle = arc.RotationAngle; // why new enum ? if (arc.SweepDirection == SweepDirection.Clockwise) { newS.SweepDirection = G.SweepDirection.Clockwise; } else { newS.SweepDirection = G.SweepDirection.Counterclockwise; } newS.IsLargeArc = arc.IsLargeArc; newFigure.Segments.Add(newS); continue; } var bezier = segment as BezierSegment; if (bezier != null) { var newS = new G.BezierSegment(); newS.Point1 = bezier.Point1; newS.Point2 = bezier.Point2; newS.Point3 = bezier.Point3; newFigure.StartPoint = newFigure.StartPoint; newFigure.Segments.Add(newS); continue; } var polyLine = segment as PolyLineSegment; if (polyLine != null) { foreach (var point in polyLine.Points) { var newS = new G.LineSegment(); newS.Point = point; newFigure.Segments.Add(newS); } continue; } var line = segment as LineSegment; if (line != null) { var newS = new G.LineSegment(); newS.Point = line.Point; newFigure.Segments.Add(newS); continue; } var quadraticBezier = segment as QuadraticBezierSegment; if (quadraticBezier != null) { var newS = new G.QuadraticBezierSegment(); newS.Point1 = quadraticBezier.Point1; newS.Point2 = quadraticBezier.Point2; newFigure.Segments.Add(newS); continue; } } #if SILVERLIGHT if (isConnection) { var realGeometry = geometry as PathGeometry; if (realGeometry != null && realGeometry.Figures.Count > i) { if (realGeometry.Figures[i].IsFilled) { filledPath.Figures.Add(newFigure); } else { path.Figures.Add(newFigure); } continue; } } #endif if (figure.IsFilled) { filledPath.Figures.Add(newFigure); } else { path.Figures.Add(newFigure); } } // why new enum ? if (pathGeometry.FillRule == FillRule.EvenOdd) { path.FillRule = G.FillRule.EvenOdd; filledPath.FillRule = G.FillRule.EvenOdd; } else { path.FillRule = G.FillRule.Nonzero; filledPath.FillRule = G.FillRule.Nonzero; } if (filledPath.Figures.Count > 0) { filledEditor.DrawPath(filledPath); } if (path.Figures.Count > 0) { editor.DrawPath(path); } } }
private static void ExportGeometry(FixedContentEditor editor, FixedContentEditor filledEditor, Geometry geometry, bool isConnection = false) { // We need two editors because there might be filled and not filled figures. #if WPF var pathGeometry = geometry as PathGeometry; #else var pathGeometry = GeometryParser.GetGeometry(geometry.ToString()) as PathGeometry; #endif if (pathGeometry != null) { var path = new G.PathGeometry(); var filledPath = new G.PathGeometry(); for (int i = 0; i < pathGeometry.Figures.Count; i++) { var figure = pathGeometry.Figures[i]; var newFigure = new G.PathFigure(); newFigure.StartPoint = figure.StartPoint; newFigure.IsClosed = figure.IsClosed; foreach (var segment in figure.Segments) { var arc = segment as ArcSegment; if (arc != null) { var newS = new G.ArcSegment(); newS.Point = arc.Point; newS.RadiusX = arc.Size.Width; newS.RadiusY = arc.Size.Height; newS.RotationAngle = arc.RotationAngle; // why new enum ? if (arc.SweepDirection == SweepDirection.Clockwise) newS.SweepDirection = G.SweepDirection.Clockwise; else newS.SweepDirection = G.SweepDirection.Counterclockwise; newS.IsLargeArc = arc.IsLargeArc; newFigure.Segments.Add(newS); continue; } var bezier = segment as BezierSegment; if (bezier != null) { var newS = new G.BezierSegment(); newS.Point1 = bezier.Point1; newS.Point2 = bezier.Point2; newS.Point3 = bezier.Point3; newFigure.StartPoint = newFigure.StartPoint; newFigure.Segments.Add(newS); continue; } var polyLine = segment as PolyLineSegment; if (polyLine != null) { foreach (var point in polyLine.Points) { var newS = new G.LineSegment(); newS.Point = point; newFigure.Segments.Add(newS); } continue; } var line = segment as LineSegment; if (line != null) { var newS = new G.LineSegment(); newS.Point = line.Point; newFigure.Segments.Add(newS); continue; } var quadraticBezier = segment as QuadraticBezierSegment; if (quadraticBezier != null) { var newS = new G.QuadraticBezierSegment(); newS.Point1 = quadraticBezier.Point1; newS.Point2 = quadraticBezier.Point2; newFigure.Segments.Add(newS); continue; } } #if SILVERLIGHT if (isConnection) { var realGeometry = geometry as PathGeometry; if (realGeometry != null && realGeometry.Figures.Count > i) { if (realGeometry.Figures[i].IsFilled) filledPath.Figures.Add(newFigure); else path.Figures.Add(newFigure); continue; } } #endif if (figure.IsFilled) filledPath.Figures.Add(newFigure); else path.Figures.Add(newFigure); } // why new enum ? if (pathGeometry.FillRule == FillRule.EvenOdd) { path.FillRule = G.FillRule.EvenOdd; filledPath.FillRule = G.FillRule.EvenOdd; } else { path.FillRule = G.FillRule.Nonzero; filledPath.FillRule = G.FillRule.Nonzero; } if (filledPath.Figures.Count > 0) filledEditor.DrawPath(filledPath); if (path.Figures.Count > 0) editor.DrawPath(path); } }