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 void DrawArrow() { editor.Position.Translate(ExampleDocumentSizes.ArrowStart.X, ExampleDocumentSizes.ArrowStart.Y); editor.GraphicProperties.IsStroked = true; editor.GraphicProperties.StrokeThickness = 1; editor.GraphicProperties.StrokeColor = new RgbColor(191, 191, 191); editor.GraphicProperties.IsFilled = true; editor.GraphicProperties.FillColor = editor.GraphicProperties.StrokeColor; var arrow = new G.PathGeometry(); var figure = arrow.Figures.AddPathFigure(); figure.StartPoint = new Point(); figure.Segments.AddLineSegment(new Point(2, 0)); figure.Segments.AddLineSegment(new Point(2, 13)); figure.Segments.AddLineSegment(new Point(7, 7)); figure.Segments.AddLineSegment(new Point(7, 13)); figure.Segments.AddLineSegment(new Point(0, ExampleDocumentSizes.ArrowLength)); figure.Segments.AddLineSegment(new Point(-7, 13)); figure.Segments.AddLineSegment(new Point(-7, 7)); figure.Segments.AddLineSegment(new Point(-2, 13)); figure.Segments.AddLineSegment(new Point(-2, 0)); figure.IsClosed = true; editor.DrawPath(arrow); }
private void DrawFunnelBlock(double startPercentHeight, double endPercentHeight) { Point[] contourPoints = ExampleDocumentSizes.GetSubFunnelBlockContourPoints(startPercentHeight, endPercentHeight); editor.GraphicProperties.IsStroked = false; var path = new G.PathGeometry(); var figure = path.Figures.AddPathFigure(); figure.StartPoint = contourPoints[0]; figure.IsClosed = true; string funnelBlockText; double textYOffset = 0; if (startPercentHeight == 0) { funnelBlockText = "IMAGES"; editor.GraphicProperties.FillColor = new RgbColor(37, 160, 219); var arc = figure.Segments.AddArcSegment(); arc.Point = contourPoints[1]; arc.IsLargeArc = false; arc.SweepDirection = G.SweepDirection.Counterclockwise; arc.RadiusX = ExampleDocumentSizes.EllipseRadiuses.Width; arc.RadiusY = ExampleDocumentSizes.EllipseRadiuses.Height; textYOffset = arc.RadiusY / 2; figure.Segments.AddLineSegment(contourPoints[2]); figure.Segments.AddLineSegment(contourPoints[3]); textYOffset = ExampleDocumentSizes.EllipseRadiuses.Height; } else if (endPercentHeight == 1) { funnelBlockText = "FONTS"; editor.GraphicProperties.FillColor = new RgbColor(42, 180, 0); figure.Segments.AddLineSegment(contourPoints[1]); figure.Segments.AddLineSegment(contourPoints[2]); var arc = figure.Segments.AddArcSegment(); arc.Point = contourPoints[3]; arc.IsLargeArc = false; arc.SweepDirection = G.SweepDirection.Clockwise; arc.RadiusX = ExampleDocumentSizes.EllipseRadiuses.Width; arc.RadiusY = ExampleDocumentSizes.EllipseRadiuses.Height + 100; } else { funnelBlockText = "SHAPES"; editor.GraphicProperties.FillColor = new RgbColor(255, 127, 0); figure.Segments.AddLineSegment(contourPoints[1]); figure.Segments.AddLineSegment(contourPoints[2]); figure.Segments.AddLineSegment(contourPoints[3]); } editor.DrawPath(path); using (editor.SavePosition()) { Size textSize = new Size(contourPoints[1].X - contourPoints[0].X, ExampleDocumentSizes.FunnelBlockHeight - textYOffset); editor.Position.Translate(contourPoints[0].X, contourPoints[0].Y + textYOffset); DrawCenteredText(editor, funnelBlockText, textSize); } }
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); } }