示例#1
0
        //Size newArrangeOverride(Size finalSize)
        protected override Size ArrangeOverride(Size finalSize)
        {
            var bezier = new QuadraticBezierSegment(InnerPoint, new Point(finalSize.Width, finalSize.Height), true);
            var pathFigure = new PathFigure(new Point(10, 10), new[] { bezier }, false);

            var pathLength = TextOnPathBase.GetPathFigureLength(pathFigure);
            var neededSpace = 0.0; // finalSize.Width;


            foreach (UIElement child in Children)
            {
                //child.Measure(new Size(Double.PositiveInfinity,
                //                       Double.PositiveInfinity));
                neededSpace += child.DesiredSize.Width;
            }

            if (!pathLength.Equals(0.0) && !neededSpace.Equals(0.0) && !finalSize.Width.Equals(0.0))
            {
                var spaceAvail = pathLength - neededSpace;
                var spaceStep = spaceAvail / Children.Count;
                var stepPerc = spaceStep / spaceAvail;

                var scalingFactor = pathLength / neededSpace;
                var pathGeometry = new PathGeometry(new[] {pathFigure});
                var baseline = scalingFactor;

                var progress = 0.0; // stepPerc / 2;

                foreach (UIElement element in Children)
                {
                    var width = /*scalingFactor**/element.DesiredSize.Width;
                    progress += stepPerc / 2;

                    Point point, tangent;
                    pathGeometry.GetPointAtFractionLength(progress,
                                                          out point, out tangent);

                    var transformGroup = new TransformGroup();

                    //transformGroup.Children.Add(
                    //    new ScaleTransform(scalingFactor, scalingFactor));
                    transformGroup.Children.Add(
                        new RotateTransform(Math.Atan2(tangent.Y, tangent.X)
                                                *180/Math.PI, width/2, baseline));
                    //transformGroup.Children.Add(
                    //    new TranslateTransform(point.X - width / 2,
                    //                           point.Y - baseline));

                    element.RenderTransform = transformGroup;

                    element.Arrange(new Rect(point.X, point.Y, element.DesiredSize.Width, element.DesiredSize.Height));

                    progress += stepPerc / 2;
                }
            }
            return base.ArrangeOverride(finalSize);
        }
示例#2
0
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
 {
     switch (connectionId)
     {
     case 1:
         this.seg = ((System.Windows.Media.QuadraticBezierSegment)(target));
         return;
     }
     this._contentLoaded = true;
 }
示例#3
0
        public static PathGeometry GenerateBezierCurve(Point[] points)
        {
            PathFigure pathFigure = new PathFigure();
            PointCollection pointCollection = new PointCollection(points.Length);
            pathFigure.StartPoint = new Point(points[0].X, points[0].Y);

            PathGeometry myPathGeometry = new PathGeometry();
            PathSegment pathSegment;

            if (points.Length == 2)
            {
                pathSegment = new LineSegment();
                ((LineSegment)pathSegment).Point = new Point(points[1].X, points[1].Y);
            }
            else if (points.Length == 3)
            {
                pathSegment = new QuadraticBezierSegment();
                ((QuadraticBezierSegment)pathSegment).Point1 = new Point(points[1].X, points[1].Y);
                ((QuadraticBezierSegment)pathSegment).Point2 = new Point(points[2].X, points[2].Y);
            }
            else if (points.Length == 4)
            {
                for (int i = 1; i < points.Length; i++)
                {
                    pointCollection.Add(points[i]);
                }

                pathSegment = new PolyBezierSegment();
                ((PolyBezierSegment)pathSegment).Points = pointCollection;
            }
            else
            {
                return null;
            }

            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();
            pathSegmentCollection.Add(pathSegment);

            pathFigure.Segments = pathSegmentCollection;

            PathFigureCollection pathFigureCollection = new PathFigureCollection();
            pathFigureCollection.Add(pathFigure);

            myPathGeometry.Figures = pathFigureCollection;

            return myPathGeometry;
        }
        public void SetMouth()
        {
            int index = _laugh ? 0 : 1;

            var figure = new PathFigure() { StartPoint = _mouthPoints[index, 0] };
            figure.Segments = new PathSegmentCollection();
            var segment1 = new QuadraticBezierSegment();
            segment1.Point1 = _mouthPoints[index, 1];
            segment1.Point2 = _mouthPoints[index, 2];
            figure.Segments.Add(segment1);
            var geometry = new PathGeometry();
            geometry.Figures = new PathFigureCollection();
            geometry.Figures.Add(figure);

            mouth.Data = geometry;
            _laugh = !_laugh;
        }
示例#5
0
文件: z10.g.i.cs 项目: MrRobotUA/WPF
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.path = ((System.Windows.Shapes.Path)(target));
                return;

            case 2:
                this.path1 = ((System.Windows.Shapes.Path)(target));
                return;

            case 3:
                this.mySegment = ((System.Windows.Media.QuadraticBezierSegment)(target));
                return;
            }
            this._contentLoaded = true;
        }
示例#6
0
        public void DrawCurve(int x1, int y1, int ctrlx, int ctrly, int x2, int y2)
        {
            Path path = new Path() { Stroke = new SolidColorBrush(_color), StrokeThickness = 1 };

            QuadraticBezierSegment bezier = new QuadraticBezierSegment() { Point1 = new Point(ctrlx, ctrly), Point2 = new Point(x2, y2) };

            PathFigure figure = new PathFigure() { StartPoint = new Point(x1, y1) };
            figure.Segments.Add(bezier);

            PathGeometry geometry = new PathGeometry();
            geometry.Figures.Add(figure);

            path.Data = geometry;

            Canvas.Children.Add(path);
            //Debug.WriteLine("Curve Start Point: ( " + x1 + ", " + y1 + ")");
            //Debug.WriteLine("Curve End Point: ( " + x2 + ", " + y2 + ")");
        }
示例#7
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            var pgFill = new PathGeometry();
            var pfFill = new PathFigure {IsFilled = true, IsClosed = true};
            pfFill.StartPoint = new Point(0.0, 0.0);

            var q1Fill = new QuadraticBezierSegment
            {
                Point1 = new Point(RenderSize.Width/3, RenderSize.Height/10.0),
                Point2 = new Point(RenderSize.Width, RenderSize.Height),
                IsStroked = false
            };
            pfFill.Segments.Add(q1Fill);

            pfFill.Segments.Add(new LineSegment {Point = new Point(0, RenderSize.Height), IsStroked = false});

            pgFill.Figures.Add(pfFill);

            drawingContext.DrawGeometry(Fill, null, pgFill);

            var pgBorder = new PathGeometry();
            var pfBorder = new PathFigure {IsFilled = false, IsClosed = false};
            pfBorder.StartPoint = new Point(0.0, Thickness/2);

            var q1Border = new QuadraticBezierSegment
            {
                Point1 = new Point(RenderSize.Width/3, RenderSize.Height/10.0),
                Point2 = new Point(RenderSize.Width, RenderSize.Height)
            };
            pfBorder.Segments.Add(q1Border);

            pfFill.Segments.Add(new LineSegment {Point = new Point(0, RenderSize.Height), IsStroked = false});

            pgBorder.Figures.Add(pfBorder);

            drawingContext.DrawGeometry(null, new Pen(Stroke, Thickness), pgBorder);

            base.OnRender(drawingContext);
        }
示例#8
0
文件: WpfUtils.cs 项目: alexiej/YATE
 /// <summary>
 /// Converts a PolyQuadraticBezierSegment into a PolyLineSegment because I currently have no muse to calculate
 /// the correct Bézier curves.
 /// </summary>
 public static PdfSharp.Xps.XpsModel.PolyLineSegment FlattenSegment(PdfSharp.Xps.XpsModel.Point startPoint,
   PdfSharp.Xps.XpsModel.PolyQuadraticBezierSegment seg)
 {
   PathGeometry geo = new PathGeometry();
   PathFigure fig = new PathFigure();
   geo.Figures.Add(fig);
   fig.StartPoint = new Point(startPoint.X, startPoint.Y);
   int count = seg.Points.Count;
   Point[] points = new Point[count];
   for (int idx = 0; idx < count - 1; idx += 2)
   {
     QuadraticBezierSegment qbseg = new QuadraticBezierSegment(
       new Point(seg.Points[idx].X, seg.Points[idx].Y), new Point(seg.Points[idx + 1].X, seg.Points[idx + 1].Y), seg.IsStroked);
     fig.Segments.Add(qbseg);
   }
   geo = geo.GetFlattenedPathGeometry();
   fig = geo.Figures[0];
   PolyLineSegment lineSeg = (PolyLineSegment)fig.Segments[0];
   PdfSharp.Xps.XpsModel.PolyLineSegment resultSeg = new PdfSharp.Xps.XpsModel.PolyLineSegment();
   foreach (Point point in lineSeg.Points)
     resultSeg.Points.Add(new PdfSharp.Xps.XpsModel.Point(point.X, point.Y));
   return resultSeg;
 }
示例#9
0
		/// <summary>
		/// Transforms the specified path segment and returns the result.
		/// </summary>
		/// <param name="pathSegment">The path segment.</param>
		/// <param name="transform">The transform.</param>
		/// <returns></returns>
        public static PathSegment Transform(this PathSegment pathSegment, TransformGroup transform)
		{
			PathSegment ret;
			if (pathSegment is LineSegment)
				ret = new LineSegment { Point = ((LineSegment)pathSegment).Point.Transform(transform) };
			else if (pathSegment is ArcSegment)
			{
				var arcSegment = (ArcSegment) pathSegment;
			    var scaleTransform = transform.Children.OfType<ScaleTransform>().FirstOrDefault();
                var rotateTransform = transform.Children.OfType<RotateTransform>().FirstOrDefault();
                var size = new Size { Height = arcSegment.Size.Height * scaleTransform.ScaleY, Width = arcSegment.Size.Width * scaleTransform.ScaleX };
                ret = new ArcSegment { Point = arcSegment.Point.Transform(transform), Size = size, IsLargeArc = arcSegment.IsLargeArc, RotationAngle = rotateTransform.Angle };
			}
			else if (pathSegment is BezierSegment)
			{
				var bezierSegment = (BezierSegment)pathSegment;
				ret = new BezierSegment
				{
					Point1 = bezierSegment.Point1.Transform(transform),
					Point2 = bezierSegment.Point2.Transform(transform),
					Point3 = bezierSegment.Point3.Transform(transform),
				};
			}
			else if (pathSegment is QuadraticBezierSegment)
			{
				var bezierSegment = (QuadraticBezierSegment)pathSegment;
				ret = new QuadraticBezierSegment
				{
					Point1 = bezierSegment.Point1.Transform(transform),
					Point2 = bezierSegment.Point2.Transform(transform),
				};
			}
			else
				throw new Exception("Transform To implement");
			return ret;
		}
示例#10
0
        private static Shape Worm(double dSize)
        {
            Path path = new Path();
            path.StrokeThickness = iStrokeThickness;
            path.StrokeLineJoin = PenLineJoin.Round;

            /*
            string[] arrStrPoints = new string[10];
            double dBringToStartX = -(dSize / 8);
            double dBringToStartY = -(dSize / 5);
            arrStrPoints[0] = (dBringToStartX + 2 * (dSize / 5)).ToString() + "," + (dBringToStartY + dSize / 4).ToString() + " ";
            arrStrPoints[1] = (dBringToStartX + 3 * (dSize / 5)).ToString() + "," + (dBringToStartY + (dSize / 4) - (dSize / 10)).ToString() + " ";
            arrStrPoints[2] = (dBringToStartX + dSize / 5).ToString() + "," + (dBringToStartY + dSize / 4).ToString() + " ";
            arrStrPoints[3] = dBringToStartX.ToString() + "," + (dBringToStartY + dSize / 4).ToString() + " ";
            arrStrPoints[4] = (dBringToStartX + 2 * (dSize / 5)).ToString() + "," + (dBringToStartY + dSize).ToString() + " ";
            arrStrPoints[5] = (dBringToStartX + dSize / 5).ToString() + "," + (dBringToStartY + dSize).ToString() + " ";
            arrStrPoints[6] = (dBringToStartX + dSize / 5).ToString() + "," + (dBringToStartY + dSize / 4).ToString() + " ";
            arrStrPoints[7] = (dBringToStartX + 3 * (dSize / 5)).ToString() + "," + (dBringToStartY + dSize).ToString() + " ";
            arrStrPoints[8] = (dBringToStartX + 2 * (dSize / 5)).ToString() + "," + (dBringToStartY + dSize).ToString() + " ";
            arrStrPoints[9] = dBringToStartX.ToString() + "," + (dBringToStartY + dSize + (dSize / 10)).ToString() + " ";

            string sGeometry = "M " + arrStrPoints[0];
            sGeometry += "C " + arrStrPoints[0] + arrStrPoints[1] + arrStrPoints[2];
            sGeometry += "C " + arrStrPoints[3] + arrStrPoints[4] + arrStrPoints[5];
            sGeometry += "M " + arrStrPoints[0];
            sGeometry += "C " + arrStrPoints[6] + arrStrPoints[7] + arrStrPoints[8];
            sGeometry += "C " + arrStrPoints[8] + arrStrPoints[9] + arrStrPoints[5];
            path.Data = Geometry.Parse(sGeometry);
            */

            QuadraticBezierSegment pBezierSegment = new QuadraticBezierSegment();
            PointCollection pointsCollection = new PointCollection();
            pointsCollection.Add(new Point(0, 20));
            pointsCollection.Add(new Point(-10, 10));
            pointsCollection.Add(new Point(0, 0));
            pointsCollection.Add(new Point(10, 0));
            pointsCollection.Add(new Point(20, 40));
            pointsCollection.Add(new Point(30, 50));
            pointsCollection.Add(new Point(20, 60));
            pointsCollection.Add(new Point(10, 60));

            PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();
            pathSegmentCollection.Add(new QuadraticBezierSegment(bez3pts1(pointsCollection[0], pointsCollection[1], pointsCollection[2]), pointsCollection[2], true));
            pathSegmentCollection.Add(new QuadraticBezierSegment(bez3pts1(pointsCollection[2], pointsCollection[3], pointsCollection[4]), pointsCollection[4], true));
            pathSegmentCollection.Add(new QuadraticBezierSegment(bez3pts1(pointsCollection[4], pointsCollection[5], pointsCollection[6]), pointsCollection[6], true));
            pathSegmentCollection.Add(new QuadraticBezierSegment(bez3pts1(pointsCollection[6], pointsCollection[7], pointsCollection[0]), pointsCollection[0], true));

            PathFigure pathFigure = new PathFigure();
            pathFigure.StartPoint = pointsCollection[0];
            pathFigure.IsClosed = true;
            pathFigure.Segments = pathSegmentCollection;

            PathFigureCollection pathFigureCollection = new PathFigureCollection();
            pathFigureCollection.Add(pathFigure);

            PathGeometry pathGeometry = new PathGeometry();
            pathGeometry.Figures = pathFigureCollection;

            path.Data = pathGeometry;

            /*
            GraphicsPath p = new GraphicsPath();
            System.Drawing.Point[] wormArray = new System.Drawing.Point[6];
            wormArray[0] = new System.Drawing.Point(0, 0);
            wormArray[1] = new System.Drawing.Point(iSize / 10, 2 * (iSize / 5));
            wormArray[2] = new System.Drawing.Point(iSize / 10, 9 * (iSize / 10));
            wormArray[3] = new System.Drawing.Point(3 * (iSize / 5), iSize);
            wormArray[4] = new System.Drawing.Point((iSize / 2), 3 * (iSize / 5));
            wormArray[5] = new System.Drawing.Point((iSize / 2), (iSize / 10));

            for (int i = 0; i < 6; i++)
            {
                wormArray[i].X += x;
                wormArray[i].Y += y;
            }
            p.AddClosedCurve(wormArray);
            */
            return path;
        }
        public static Telerik.Windows.Documents.Fixed.Model.Graphics.QuadraticBezierSegment ConvertQuadraticBezierSegment(QuadraticBezierSegment quadraticBezierSegment)
        {
            var pdfQuadraticBezierSegment = new Telerik.Windows.Documents.Fixed.Model.Graphics.QuadraticBezierSegment();
            pdfQuadraticBezierSegment.Point1 = quadraticBezierSegment.Point1;
            pdfQuadraticBezierSegment.Point2 = quadraticBezierSegment.Point2;

            return pdfQuadraticBezierSegment;
        }
        protected override void OnRender(DrawingContext drawingContext)
        {
            var pgFill = new PathGeometry();
            var pfFill = new PathFigure() { IsFilled = true, IsClosed = true };
            pfFill.StartPoint = new Point(ActualWidth, 0.0);

            var q1Fill = new QuadraticBezierSegment() { Point1 = new Point(ActualWidth * 2 / 3, 0.0), Point2 = new Point(ActualWidth / 2.0, ActualHeight / 2.0), IsStroked = false };
            pfFill.Segments.Add(q1Fill);
            var q2Fill = new QuadraticBezierSegment() { Point1 = new Point(ActualWidth / 3, ActualHeight), Point2 = new Point(0, ActualHeight), IsStroked = false };
            pfFill.Segments.Add(q2Fill);

            pfFill.Segments.Add(new LineSegment() { Point = new Point(ActualWidth, ActualHeight), IsStroked = false });

            pgFill.Figures.Add(pfFill);

            drawingContext.DrawGeometry(Fill, null, pgFill);

            var pgBorder = new PathGeometry();
            var pfBorder = new PathFigure() { IsFilled = false, IsClosed = false };
            pfBorder.StartPoint = new Point(ActualWidth, Thickness / 2);

            var q1Border = new QuadraticBezierSegment() { Point1 = new Point(ActualWidth * 2 / 3, 0.0), Point2 = new Point(ActualWidth / 2.0, ActualHeight / 2.0) };
            pfBorder.Segments.Add(q1Border);
            var q2Border = new QuadraticBezierSegment() { Point1 = new Point(ActualWidth / 3, ActualHeight), Point2 = new Point(0.0, ActualHeight - BottomBorderMargin) };
            pfBorder.Segments.Add(q2Border);

            pgBorder.Figures.Add(pfBorder);

            drawingContext.DrawGeometry(null, new Pen(Stroke, Thickness), pgBorder);

            base.OnRender(drawingContext);
        }
 /// <summary>
 /// Adds the segments necessary to close the shape
 /// </summary>
 /// <param name="pathFigure"></param>
 private void CloseFigure(PathFigure pathFigure)
 {
     //No need to visually close the figure if we don't have at least 3 points.
     if (Points.Count < 3)
         return;
     Point backPoint, nextPoint;
     if (UseRoundnessPercentage)
     {
         backPoint = GetPointAtDistancePercent(Points[Points.Count - 1], Points[0], ArcRoundness, false);
         nextPoint = GetPointAtDistancePercent(Points[0], Points[1], ArcRoundness, true);
     }
     else
     {
         backPoint = GetPointAtDistance(Points[Points.Count - 1], Points[0], ArcRoundness, false);
         nextPoint = GetPointAtDistance(Points[0], Points[1], ArcRoundness, true);
     }
     ConnectLinePoints(pathFigure, Points[Points.Count - 2], Points[Points.Count - 1], backPoint, ArcRoundness, UseRoundnessPercentage);
     var line2 = new QuadraticBezierSegment { Point1 = Points[0], Point2 = nextPoint };
     pathFigure.Segments.Add(line2);
     pathFigure.StartPoint = nextPoint;
 }
 private static IEnumerable<Telerik.Windows.Documents.Fixed.Model.Graphics.QuadraticBezierSegment> ToQuadraticBezierSegments(QuadraticBezierSegment quadraticBezierSegment)
 {
     yield return ConvertQuadraticBezierSegment(quadraticBezierSegment);
 }
示例#15
0
 public void QuadraticCurveTo(double cpx, double cpy, double x, double y)
 {
     //transform initial coordinates according to the latest transformation
     Point[] points = TransformPoints(new Point(cpx, cpy), new Point(x, y));
     var segment = new QuadraticBezierSegment {Point1 = points[0], Point2 = points[1]};
     _figure.Segments.Add(segment);
     _isEmpty = false;
 }
        /// <summary>
        /// FinishSegment - called to completed any outstanding Segment which may be present.
        /// </summary> 
        private void FinishSegment()
        { 
            if (_currentSegmentPoints != null) 
            {
                Debug.Assert(_currentFigure != null); 

                int count = _currentSegmentPoints.Count;

                Debug.Assert(count > 0); 

                // Is this the first segment? 
                if (_segments == null) 
                {
                    // While we could always just retrieve _currentFigure.Segments (which would auto-promote) 
                    // it's more efficient to create the collection ourselves and set it explicitly.

                    _segments = new PathSegmentCollection();
                    _currentFigure.Segments = _segments; 
                }
 
                PathSegment segment; 

                switch (_currentSegmentType) 
                {
                    case MIL_SEGMENT_TYPE.MilSegmentPolyLine:
                        if (count == 1)
                        { 
                            LineSegment lSegment = new LineSegment();
                            lSegment.Point = _currentSegmentPoints[0]; 
                            segment = lSegment; 
                        }
                        else 
                        {
                            PolyLineSegment pSegment = new PolyLineSegment();
                            pSegment.Points = _currentSegmentPoints;
                            segment = pSegment; 
                        }
                        break; 
                    case MIL_SEGMENT_TYPE.MilSegmentPolyBezier: 
                        if (count == 3)
                        { 
                            BezierSegment bSegment = new BezierSegment();
                            bSegment.Point1 = _currentSegmentPoints[0];
                            bSegment.Point2 = _currentSegmentPoints[1];
                            bSegment.Point3 = _currentSegmentPoints[2]; 
                            segment = bSegment;
                        } 
                        else 
                        {
                            Debug.Assert(count % 3 == 0); 

                            PolyBezierSegment pSegment = new PolyBezierSegment();
                            pSegment.Points = _currentSegmentPoints;
                            segment = pSegment; 
                        }
                        break; 
                    case MIL_SEGMENT_TYPE.MilSegmentPolyQuadraticBezier: 
                        if (count == 2)
                        { 
                            QuadraticBezierSegment qSegment = new QuadraticBezierSegment();
                            qSegment.Point1 = _currentSegmentPoints[0];
                            qSegment.Point2 = _currentSegmentPoints[1];
                            segment = qSegment; 
                        }
                        else 
                        { 
                            Debug.Assert(count % 2 == 0);
 
                            PolyQuadraticBezierSegment pSegment = new PolyQuadraticBezierSegment();
                            pSegment.Points = _currentSegmentPoints;
                            segment = pSegment;
                        } 
                        break;
                    default: 
                        segment = null; 
                        Debug.Assert(false);
                        break; 
                }

                // Handle common PathSegment properties.
                if (_currentSegmentIsStroked != s_defaultValueForPathSegmentIsStroked) 
                {
                    segment.IsStroked  = _currentSegmentIsStroked; 
                } 

                if (_currentSegmentIsSmoothJoin != s_defaultValueForPathSegmentIsSmoothJoin) 
                {
                    segment.IsSmoothJoin  = _currentSegmentIsSmoothJoin;
                }
 
                _segments.Add(segment);
 
                _currentSegmentPoints = null; 
                _currentSegmentType = MIL_SEGMENT_TYPE.MilSegmentNone;
            } 
        }
示例#17
0
        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);
        }
示例#18
0
        /// <summary>
        /// FinishSegment - called to completed any outstanding Segment which may be present.
        /// </summary>
        private void FinishSegment()
        {
            if (_currentSegmentPoints != null)
            {
                Debug.Assert(_currentFigure != null);

                int count = _currentSegmentPoints.Count;

                Debug.Assert(count > 0);

                // Is this the first segment?
                if (_segments == null)
                {
                    // While we could always just retrieve _currentFigure.Segments (which would auto-promote)
                    // it's more efficient to create the collection ourselves and set it explicitly.

                    _segments = new PathSegmentCollection();
                    _currentFigure.Segments = _segments;
                }

                PathSegment segment;

                switch (_currentSegmentType)
                {
                case MIL_SEGMENT_TYPE.MilSegmentPolyLine:
                    if (count == 1)
                    {
                        LineSegment lSegment = new LineSegment();
                        lSegment.Point = _currentSegmentPoints[0];
                        segment        = lSegment;
                    }
                    else
                    {
                        PolyLineSegment pSegment = new PolyLineSegment();
                        pSegment.Points = _currentSegmentPoints;
                        segment         = pSegment;
                    }
                    break;

                case MIL_SEGMENT_TYPE.MilSegmentPolyBezier:
                    if (count == 3)
                    {
                        BezierSegment bSegment = new BezierSegment();
                        bSegment.Point1 = _currentSegmentPoints[0];
                        bSegment.Point2 = _currentSegmentPoints[1];
                        bSegment.Point3 = _currentSegmentPoints[2];
                        segment         = bSegment;
                    }
                    else
                    {
                        Debug.Assert(count % 3 == 0);

                        PolyBezierSegment pSegment = new PolyBezierSegment();
                        pSegment.Points = _currentSegmentPoints;
                        segment         = pSegment;
                    }
                    break;

                case MIL_SEGMENT_TYPE.MilSegmentPolyQuadraticBezier:
                    if (count == 2)
                    {
                        QuadraticBezierSegment qSegment = new QuadraticBezierSegment();
                        qSegment.Point1 = _currentSegmentPoints[0];
                        qSegment.Point2 = _currentSegmentPoints[1];
                        segment         = qSegment;
                    }
                    else
                    {
                        Debug.Assert(count % 2 == 0);

                        PolyQuadraticBezierSegment pSegment = new PolyQuadraticBezierSegment();
                        pSegment.Points = _currentSegmentPoints;
                        segment         = pSegment;
                    }
                    break;

                default:
                    segment = null;
                    Debug.Assert(false);
                    break;
                }

                // Handle common PathSegment properties.
                if (_currentSegmentIsStroked != s_defaultValueForPathSegmentIsStroked)
                {
                    segment.IsStroked = _currentSegmentIsStroked;
                }

                if (_currentSegmentIsSmoothJoin != s_defaultValueForPathSegmentIsSmoothJoin)
                {
                    segment.IsSmoothJoin = _currentSegmentIsSmoothJoin;
                }

                _segments.Add(segment);

                _currentSegmentPoints = null;
                _currentSegmentType   = MIL_SEGMENT_TYPE.MilSegmentNone;
            }
        }
示例#19
0
        /// <inheritdoc/>
        public override void Draw(object dc, XQuadraticBezier quadraticBezier, double dx, double dy, ImmutableArray<XProperty> db, XRecord r)
        {
            var _dc = dc as DrawingContext;

            var style = quadraticBezier.Style;
            if (style == null)
                return;

            double thickness = style.Thickness / _state.ZoomX;
            double half = thickness / 2.0;

            Tuple<Brush, Pen> styleCached = _styleCache.Get(style);
            Brush fill;
            Pen stroke;
            if (styleCached != null)
            {
                fill = styleCached.Item1;
                stroke = styleCached.Item2;
            }
            else
            {
                fill = CreateBrush(style.Fill);
                stroke = CreatePen(style, thickness);
                _styleCache.Set(style, Tuple.Create(fill, stroke));
            }

            PathGeometry pg = _quadraticBezierCache.Get(quadraticBezier);
            if (pg != null)
            {
                var pf = pg.Figures[0];
                pf.StartPoint = new Point(quadraticBezier.Point1.X + dx, quadraticBezier.Point1.Y + dy);
                pf.IsFilled = quadraticBezier.IsFilled;
                var qbs = pf.Segments[0] as QuadraticBezierSegment;
                qbs.Point1 = new Point(quadraticBezier.Point2.X + dx, quadraticBezier.Point2.Y + dy);
                qbs.Point2 = new Point(quadraticBezier.Point3.X + dx, quadraticBezier.Point3.Y + dy);
                qbs.IsStroked = quadraticBezier.IsStroked;
            }
            else
            {
                var pf = new PathFigure()
                {
                    StartPoint = new Point(quadraticBezier.Point1.X + dx, quadraticBezier.Point1.Y + dy),
                    IsFilled = quadraticBezier.IsFilled
                };

                var qbs = new QuadraticBezierSegment(
                        new Point(quadraticBezier.Point2.X + dx, quadraticBezier.Point2.Y + dy),
                        new Point(quadraticBezier.Point3.X + dx, quadraticBezier.Point3.Y + dy),
                        quadraticBezier.IsStroked);
                //bs.Freeze();
                pf.Segments.Add(qbs);
                //pf.Freeze();
                pg = new PathGeometry();
                pg.Figures.Add(pf);
                //pg.Freeze();

                _quadraticBezierCache.Set(quadraticBezier, pg);
            }

            DrawPathGeometryInternal(_dc, half, fill, stroke, quadraticBezier.IsStroked, quadraticBezier.IsFilled, pg);
        }
示例#20
0
        private PathGeometry parse(string path)
        {
            PathGeometry _pathGeometry = null;


            _formatProvider = CultureInfo.InvariantCulture;
            _pathString = path;
            _pathLength = path.Length;
            _curIndex = 0;

            _secondLastPoint = new Point(0, 0);
            _lastPoint = new Point(0, 0);
            _lastStart = new Point(0, 0);

            _figureStarted = false;

            bool first = true;

            char last_cmd = ' ';

            while (ReadToken())
            {
                char cmd = _token;

                if (first)
                {
                    if ((cmd != 'M') && (cmd != 'm')) 
                    {
                        ThrowBadToken();
                    }

                    first = false;
                }

                switch (cmd)
                {
                    case 'm':
                    case 'M':
                        _lastPoint = ReadPoint(cmd, !AllowComma);

                        _figure = new PathFigure();
                        _figure.StartPoint = _lastPoint;
                        _figure.IsFilled = IsFilled;
                        _figure.IsClosed = !IsClosed;
       
                        _figureStarted = true;
                        _lastStart = _lastPoint;
                        last_cmd = 'M';

                        while (IsNumber(AllowComma))
                        {
                            _lastPoint = ReadPoint(cmd, !AllowComma);

                            LineSegment _lineSegment = new LineSegment();
                            _lineSegment.Point = _lastPoint;
                            _figure.Segments.Add(_lineSegment);
                            last_cmd = 'L';
                        }
                        break;

                    case 'l':
                    case 'L':
                    case 'h':
                    case 'H':
                    case 'v':
                    case 'V':
                        EnsureFigure();

                        do
                        {
                            switch (cmd)
                            {
                                case 'l': _lastPoint = ReadPoint(cmd, !AllowComma); break;
                                case 'L': _lastPoint = ReadPoint(cmd, !AllowComma); break;
                                case 'h': _lastPoint.X += ReadNumber(!AllowComma); break;
                                case 'H': _lastPoint.X = ReadNumber(!AllowComma); break;
                                case 'v': _lastPoint.Y += ReadNumber(!AllowComma); break;
                                case 'V': _lastPoint.Y = ReadNumber(!AllowComma); break;
                            }

                            LineSegment _lineSegment = new LineSegment();
                            _lineSegment.Point = _lastPoint;
                            _figure.Segments.Add(_lineSegment);

                        }
                        while (IsNumber(AllowComma));

                        last_cmd = 'L';
                        break;

                    case 'c':
                    case 'C': 
                    case 's':
                    case 'S': 
                        EnsureFigure();

                        do
                        {
                            Point p;

                            if ((cmd == 's') || (cmd == 'S'))
                            {
                                if (last_cmd == 'C')
                                {
                                    p = Reflect();
                                }
                                else
                                {
                                    p = _lastPoint;
                                }

                                _secondLastPoint = ReadPoint(cmd, !AllowComma);
                            }
                            else
                            {
                                p = ReadPoint(cmd, !AllowComma);

                                _secondLastPoint = ReadPoint(cmd, AllowComma);
                            }

                            _lastPoint = ReadPoint(cmd, AllowComma);

                            BezierSegment _bizierSegment = new BezierSegment();
                            _bizierSegment.Point1 = p;
                            _bizierSegment.Point2 = _secondLastPoint;
                            _bizierSegment.Point3 = _lastPoint;
                            _figure.Segments.Add(_bizierSegment);
                         
                            last_cmd = 'C';
                        }
                        while (IsNumber(AllowComma));

                        break;

                    case 'q':
                    case 'Q': 
                    case 't':
                    case 'T': 
                        EnsureFigure();

                        do
                        {
                            if ((cmd == 't') || (cmd == 'T'))
                            {
                                if (last_cmd == 'Q')
                                {
                                    _secondLastPoint = Reflect();
                                }
                                else
                                {
                                    _secondLastPoint = _lastPoint;
                                }

                                _lastPoint = ReadPoint(cmd, !AllowComma);
                            }
                            else
                            {
                                _secondLastPoint = ReadPoint(cmd, !AllowComma);
                                _lastPoint = ReadPoint(cmd, AllowComma);
                            }

                            QuadraticBezierSegment _quadraticBezierSegment = new QuadraticBezierSegment();
                            _quadraticBezierSegment.Point1 = _secondLastPoint;
                            _quadraticBezierSegment.Point2 = _lastPoint;
                            _figure.Segments.Add(_quadraticBezierSegment);
                         
                            last_cmd = 'Q';
                        }
                        while (IsNumber(AllowComma));

                        break;

                    case 'a':
                    case 'A':
                        EnsureFigure();

                        do
                        {
                            double w = ReadNumber(!AllowComma);
                            double h = ReadNumber(AllowComma);
                            double rotation = ReadNumber(AllowComma);
                            bool large = ReadBool();
                            bool sweep = ReadBool();

                            _lastPoint = ReadPoint(cmd, AllowComma);

                            ArcSegment _arcSegment = new ArcSegment();
                            _arcSegment.Point = _lastPoint;
                            _arcSegment.Size = new Size(w, h);
                            _arcSegment.RotationAngle = rotation;
                            _arcSegment.IsLargeArc = large;
                            _arcSegment.SweepDirection = sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise;
                            _figure.Segments.Add(_arcSegment);

                        }
                        while (IsNumber(AllowComma));

                        last_cmd = 'A';
                        break;

                    case 'z':
                    case 'Z':
                        EnsureFigure();
                        _figure.IsClosed = IsClosed;

                        _figureStarted = false;
                        last_cmd = 'Z';

                        _lastPoint = _lastStart; 
                        break;

                    default:
                        ThrowBadToken();
                        break;
                }
            }

            if (null != _figure)
            {
                _pathGeometry = new PathGeometry();
                _pathGeometry.Figures.Add(_figure);

            }
            return _pathGeometry;
        }
示例#21
0
        /// <summary>
        ///     Main parser routine, which loops over each char in received string, and performs actions according to command/parameter being passed
        /// </summary>
        /// <param name="path">String with path data definition</param>
        /// <returns>PathGeometry object created from string definition</returns>
        private PathGeometry parse(string path)
        {
            PathGeometry _pathGeometry = null;

            _formatProvider = CultureInfo.InvariantCulture;
            _pathString = path;
            _pathLength = path.Length;
            _curIndex = 0;

            _secondLastPoint = new Point(0, 0);
            _lastPoint = new Point(0, 0);
            _lastStart = new Point(0, 0);

            _figureStarted = false;

            bool first = true;

            char last_cmd = ' ';

            while (ReadToken()) // Empty path is allowed in XAML
            {
                char cmd = _token;

                if (first)
                {
                    if ((cmd != 'M') && (cmd != 'm')) // Path starts with M|m
                    {
                        ThrowBadToken();
                    }

                    first = false;
                }

                switch (cmd)
                {
                    case 'm':
                    case 'M':
                        // XAML allows multiple points after M/m
                        _lastPoint = ReadPoint(cmd, !AllowComma);

                        _figure = new PathFigure();
                        _figure.StartPoint = _lastPoint;
                        _figure.IsFilled = IsFilled;
                        _figure.IsClosed = !IsClosed;
                        //context.BeginFigure(_lastPoint, IsFilled, !IsClosed);
                        _figureStarted = true;
                        _lastStart = _lastPoint;
                        last_cmd = 'M';

                        while (IsNumber(AllowComma))
                        {
                            _lastPoint = ReadPoint(cmd, !AllowComma);

                            var _lineSegment = new LineSegment();
                            _lineSegment.Point = _lastPoint;
                            _figure.Segments.Add(_lineSegment);
                            //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin);
                            last_cmd = 'L';
                        }
                        break;

                    case 'l':
                    case 'L':
                    case 'h':
                    case 'H':
                    case 'v':
                    case 'V':
                        EnsureFigure();

                        do
                        {
                            switch (cmd)
                            {
                                case 'l':
                                    _lastPoint = ReadPoint(cmd, !AllowComma);
                                    break;
                                case 'L':
                                    _lastPoint = ReadPoint(cmd, !AllowComma);
                                    break;
                                case 'h':
                                    _lastPoint.X += ReadNumber(!AllowComma);
                                    break;
                                case 'H':
                                    _lastPoint.X = ReadNumber(!AllowComma);
                                    break;
                                case 'v':
                                    _lastPoint.Y += ReadNumber(!AllowComma);
                                    break;
                                case 'V':
                                    _lastPoint.Y = ReadNumber(!AllowComma);
                                    break;
                            }

                            var _lineSegment = new LineSegment();
                            _lineSegment.Point = _lastPoint;
                            _figure.Segments.Add(_lineSegment);
                            //context.LineTo(_lastPoint, IsStroked, !IsSmoothJoin);
                        } while (IsNumber(AllowComma));

                        last_cmd = 'L';
                        break;

                    case 'c':
                    case 'C': // cubic Bezier
                    case 's':
                    case 'S': // smooth cublic Bezier
                        EnsureFigure();

                        do
                        {
                            Point p;

                            if ((cmd == 's') || (cmd == 'S'))
                            {
                                p = last_cmd == 'C' ? Reflect() : _lastPoint;

                                _secondLastPoint = ReadPoint(cmd, !AllowComma);
                            }
                            else
                            {
                                p = ReadPoint(cmd, !AllowComma);

                                _secondLastPoint = ReadPoint(cmd, AllowComma);
                            }

                            _lastPoint = ReadPoint(cmd, AllowComma);

                            var _bizierSegment = new BezierSegment();
                            _bizierSegment.Point1 = p;
                            _bizierSegment.Point2 = _secondLastPoint;
                            _bizierSegment.Point3 = _lastPoint;
                            _figure.Segments.Add(_bizierSegment);
                            //context.BezierTo(p, _secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin);

                            last_cmd = 'C';
                        } while (IsNumber(AllowComma));

                        break;

                    case 'q':
                    case 'Q': // quadratic Bezier
                    case 't':
                    case 'T': // smooth quadratic Bezier
                        EnsureFigure();

                        do
                        {
                            if ((cmd == 't') || (cmd == 'T'))
                            {
                                _secondLastPoint = last_cmd == 'Q' ? Reflect() : _lastPoint;

                                _lastPoint = ReadPoint(cmd, !AllowComma);
                            }
                            else
                            {
                                _secondLastPoint = ReadPoint(cmd, !AllowComma);
                                _lastPoint = ReadPoint(cmd, AllowComma);
                            }

                            var _quadraticBezierSegment = new QuadraticBezierSegment();
                            _quadraticBezierSegment.Point1 = _secondLastPoint;
                            _quadraticBezierSegment.Point2 = _lastPoint;
                            _figure.Segments.Add(_quadraticBezierSegment);
                            //context.QuadraticBezierTo(_secondLastPoint, _lastPoint, IsStroked, !IsSmoothJoin);

                            last_cmd = 'Q';
                        } while (IsNumber(AllowComma));

                        break;

                    case 'a':
                    case 'A':
                        EnsureFigure();

                        do
                        {
                            // A 3,4 5, 0, 0, 6,7
                            double w = ReadNumber(!AllowComma);
                            double h = ReadNumber(AllowComma);
                            double rotation = ReadNumber(AllowComma);
                            bool large = ReadBool();
                            bool sweep = ReadBool();

                            _lastPoint = ReadPoint(cmd, AllowComma);

                            var _arcSegment = new ArcSegment();
                            _arcSegment.Point = _lastPoint;
                            _arcSegment.Size = new Size(w, h);
                            _arcSegment.RotationAngle = rotation;
                            _arcSegment.IsLargeArc = large;
                            _arcSegment.SweepDirection = sweep
                                                             ? SweepDirection.Clockwise
                                                             : SweepDirection.Counterclockwise;
                            _figure.Segments.Add(_arcSegment);
                            //context.ArcTo(
                            //    _lastPoint,
                            //    new Size(w, h),
                            //    rotation,
                            //    large,
                            //    sweep ? SweepDirection.Clockwise : SweepDirection.Counterclockwise,
                            //    IsStroked,
                            //    !IsSmoothJoin
                            //    );
                        } while (IsNumber(AllowComma));

                        last_cmd = 'A';
                        break;

                    case 'z':
                    case 'Z':
                        EnsureFigure();
                        _figure.IsClosed = IsClosed;
                        //context.SetClosedState(IsClosed);

                        _figureStarted = false;
                        last_cmd = 'Z';

                        _lastPoint = _lastStart; // Set reference point to be first point of current figure
                        break;

                    default:
                        ThrowBadToken();
                        break;
                }
            }

            if (null != _figure)
            {
                _pathGeometry = new PathGeometry();
                _pathGeometry.Figures.Add(_figure);
            }
            return _pathGeometry;
        }
示例#22
0
 public void QuadraticBezierTo(Point point1, Point point2, bool isStroked, bool isSmoothJoin) {
   CheckState();
   QuadraticBezierSegment seg = new QuadraticBezierSegment();
   seg.Point1 = point1;
   seg.Point2 = point2;
   _Fig.Segments.Add(seg);
 }
        private void BuildPath
        (
            PdfContents Contents,
            PaintOp PaintOperator
        )
        {
            // every figure is a separated subpath and contains some segments
            foreach (SysMedia.PathFigure SubPath in MediaPath.Figures)
            {
                // get start of sub-path point
                PointD CurPoint   = PathToDrawing(SubPath.StartPoint);
                PointD StartPoint = CurPoint;
                Contents.MoveTo(CurPoint);

                // process all points of one sub-path
                foreach (SysMedia.PathSegment Seg in SubPath.Segments)
                {
                    // line segment
                    if (Seg.GetType() == typeof(SysMedia.LineSegment))
                    {
                        CurPoint = PathToDrawing(((SysMedia.LineSegment)Seg).Point);
                        Contents.LineTo(CurPoint);
                    }

                    // polygon
                    else if (Seg.GetType() == typeof(SysMedia.PolyLineSegment))
                    {
                        SysMedia.PolyLineSegment LineSegArray = (SysMedia.PolyLineSegment)Seg;
                        foreach (SysWin.Point PolyPoint in LineSegArray.Points)
                        {
                            CurPoint = PathToDrawing(PolyPoint);
                            Contents.LineTo(CurPoint);
                        }
                    }

                    // cubic bezier segment
                    else if (Seg.GetType() == typeof(SysMedia.BezierSegment))
                    {
                        SysMedia.BezierSegment BezierSeg = (SysMedia.BezierSegment)Seg;
                        CurPoint = PathToDrawing(BezierSeg.Point3);
                        Contents.DrawBezier(PathToDrawing(BezierSeg.Point1), PathToDrawing(BezierSeg.Point2), CurPoint);
                    }

                    // cubic bezier multi segments
                    else if (Seg.GetType() == typeof(SysMedia.PolyBezierSegment))
                    {
                        SysMedia.PolyBezierSegment BezierSegArray = (SysMedia.PolyBezierSegment)Seg;
                        int Count = BezierSegArray.Points.Count;
                        for (int Index = 0; Index < Count; Index += 3)
                        {
                            CurPoint = PathToDrawing(BezierSegArray.Points[Index + 2]);
                            Contents.DrawBezier(PathToDrawing(BezierSegArray.Points[Index]), PathToDrawing(BezierSegArray.Points[Index + 1]), CurPoint);
                        }
                    }

                    // quadratic bezier segment
                    else if (Seg.GetType() == typeof(SysMedia.QuadraticBezierSegment))
                    {
                        SysMedia.QuadraticBezierSegment BezierSeg = (SysMedia.QuadraticBezierSegment)Seg;
                        PointD NextPoint = PathToDrawing(BezierSeg.Point2);
                        Contents.DrawBezier(new BezierD(CurPoint, PathToDrawing(BezierSeg.Point1), NextPoint), BezierPointOne.Ignore);
                        CurPoint = NextPoint;
                    }

                    // quadratic bezier multi segments
                    else if (Seg.GetType() == typeof(SysMedia.PolyQuadraticBezierSegment))
                    {
                        SysMedia.PolyQuadraticBezierSegment BezierSegArray = (SysMedia.PolyQuadraticBezierSegment)Seg;
                        int Count = BezierSegArray.Points.Count;
                        for (int Index = 0; Index < Count; Index += 2)
                        {
                            PointD NextPoint = PathToDrawing(BezierSegArray.Points[Index + 1]);
                            Contents.DrawBezier(new BezierD(CurPoint, PathToDrawing(BezierSegArray.Points[Index]), NextPoint), BezierPointOne.Ignore);
                            CurPoint = NextPoint;
                        }
                    }

                    // draw arc
                    else if (Seg.GetType() == typeof(SysMedia.ArcSegment))
                    {
                        SysMedia.ArcSegment Arc = (SysMedia.ArcSegment)Seg;
                        PointD  NextPoint       = PathToDrawing(Arc.Point);
                        ArcType ArcType;
                        if (Arc.SweepDirection == (PathYAxis == YAxisDirection.Down ? SysMedia.SweepDirection.Counterclockwise : SysMedia.SweepDirection.Clockwise))
                        {
                            ArcType = Arc.IsLargeArc ? ArcType.LargeCounterClockWise : ArcType.SmallCounterClockWise;
                        }
                        else
                        {
                            ArcType = Arc.IsLargeArc ? ArcType.LargeClockWise : ArcType.SmallClockWise;
                        }
                        Contents.DrawArc(CurPoint, NextPoint, SizeToDrawing(Arc.Size), Arc.RotationAngle, ArcType, BezierPointOne.Ignore);
                        CurPoint = NextPoint;
                    }

                    // should no happen
                    else
                    {
                        throw new ApplicationException("Windows Media path: unknown path segment.");
                    }
                }

                // for stroke set paint operator for each sub-path
                if (SubPath.IsClosed)
                {
                    Contents.SetPaintOp(PaintOp.CloseSubPath);
                }
            }

            // paint operator
            Contents.SetPaintOp(PaintOperator);
            return;
        }
示例#24
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="qbezier"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object dc, XQBezier qbezier, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r)
        {
            var _dc = dc as DrawingContext;

            var style = qbezier.Style;
            if (style == null)
                return;

            double thickness = style.Thickness / _state.Zoom;
            double half = thickness / 2.0;

            Tuple<Brush, Pen> cache = null;
            Brush fill;
            Pen stroke;
            if (_enableStyleCache
                && _styleCache.TryGetValue(style, out cache))
            {
                fill = cache.Item1;
                stroke = cache.Item2;
            }
            else
            {
                fill = CreateBrush(style.Fill);
                stroke = CreatePen(style, thickness);
                if (_enableStyleCache)
                    _styleCache.Add(style, Tuple.Create(fill, stroke));
            }

            PathGeometry pg = null;

            if (_enableQBezierCache
                && _qbezierCache.TryGetValue(qbezier, out pg))
            {
                var pf = pg.Figures[0];
                pf.StartPoint = new Point(qbezier.Point1.X + dx, qbezier.Point1.Y + dy);
                pf.IsFilled = qbezier.IsFilled;
                var qbs = pf.Segments[0] as QuadraticBezierSegment;
                qbs.Point1 = new Point(qbezier.Point2.X + dx, qbezier.Point2.Y + dy);
                qbs.Point2 = new Point(qbezier.Point3.X + dx, qbezier.Point3.Y + dy);
                qbs.IsStroked = qbezier.IsStroked;
            }
            else
            {
                var pf = new PathFigure()
                {
                    StartPoint = new Point(qbezier.Point1.X + dx, qbezier.Point1.Y + dy),
                    IsFilled = qbezier.IsFilled
                };

                var qbs = new QuadraticBezierSegment(
                        new Point(qbezier.Point2.X + dx, qbezier.Point2.Y + dy),
                        new Point(qbezier.Point3.X + dx, qbezier.Point3.Y + dy),
                        qbezier.IsStroked);
                //bs.Freeze();
                pf.Segments.Add(qbs);
                //pf.Freeze();
                pg = new PathGeometry();
                pg.Figures.Add(pf);
                //pg.Freeze();
                if (_enableQBezierCache)
                    _qbezierCache.Add(qbezier, pg);
            }

            DrawPathGeometryInternal(_dc, half, fill, stroke, qbezier.IsStroked, qbezier.IsFilled, pg);
        }
		private void ConvertPart(PathThumb senderThumb, PathPartConvertType convertType)
		{
			if (senderThumb.PathPoint.ParentObject is PathFigure)
			{
				var pathFigure = senderThumb.PathPoint.ParentObject as PathFigure;
				var pathSegment = senderThumb.PathPoint.Object as PathSegment;

				var idx = pathFigure.Segments.IndexOf(pathSegment);

				var point = senderThumb.PathPoint.Point;

				if (pathSegment is PolyLineSegment) {
					var poly = pathSegment as PolyLineSegment;
					var lst = poly.Points.Take(senderThumb.PathPoint.PolyLineIndex);
					var lst2 = poly.Points.Skip(senderThumb.PathPoint.PolyLineIndex + 1);
					var p = poly.Points[senderThumb.PathPoint.PolyLineIndex];
					pathFigure.Segments.RemoveAt(idx);
					var p1 = new PolyLineSegment();
					p1.Points.AddRange(lst);
					pathFigure.Segments.Insert(idx, p1);
					pathSegment =  new LineSegment() {Point = p};
					pathFigure.Segments.Insert(idx+1, pathSegment);
					var p2 = new PolyLineSegment();
					p2.Points.AddRange(lst2);
					pathFigure.Segments.Insert(idx+2, p2);
					idx++;
				} else if (pathSegment is PolyBezierSegment) {
					//TODO
				} else if (pathSegment is PolyQuadraticBezierSegment) {
					//TODO
				}

				pathFigure.Segments.RemoveAt(idx);

				var midp = senderThumb.PathPoint.ParentPathPoint.Point - ((senderThumb.PathPoint.ParentPathPoint.Point - point) / 2);
				
				PathSegment newSegment = null;
				switch (convertType)
				{
					case PathPartConvertType.ToBezierSegment:
						newSegment = new BezierSegment() { Point1 = midp - new Vector(40, 40), Point2 = midp + new Vector(-40, 40), Point3 = point };
						break;
					case PathPartConvertType.ToQuadricBezierSegment:
						newSegment = new QuadraticBezierSegment() { Point1 = point - new Vector(40, 40), Point2 = point  };
						break;
					case PathPartConvertType.ToArcSegment:
						newSegment = new ArcSegment() { Point = point, Size = new Size(20, 20) };
						break;
					case PathPartConvertType.insertPoint:
						pathFigure.Segments.Insert(idx, pathSegment);
						newSegment = new LineSegment() { Point = midp, };
						break;
					default:
						newSegment = new LineSegment() { Point = point };
						break;
				}

				pathFigure.Segments.Insert(idx, newSegment);
			}

			this.ExtendedItem.ReapplyAllExtensions();
		}
示例#26
0
 /// <summary>
 /// Returns new QuadraticBezierSegment by easing startValue to endValue using a time percentage 0 -> 1.
 /// </summary>
 /// <example>XAML: Data="M 10,100 Q 200,200 300,100"</example>
 /// <seealso cref="http://msdn.microsoft.com/en-us/library/system.windows.media.quadraticbeziersegment.aspx"/>
 public static QuadraticBezierSegment EaseValue(QuadraticBezierSegment startValue, QuadraticBezierSegment endValue, double percent)
 {
     return new QuadraticBezierSegment
     {
        Point1 = EaseValue(startValue.Point1, endValue.Point1, percent),
        Point2 = EaseValue(startValue.Point2, endValue.Point2, percent)
     };
 }
        /// <summary>
        /// Method used to connect 2 segments with a common point, defined by 3 points and aplying an arc segment between them
        /// </summary>
        /// <param name="pathFigure"></param>
        /// <param name="p1">First point, of the first segment</param>
        /// <param name="p2">Second point, the common point</param>
        /// <param name="p3">Third point, the second point of the second segment</param>
        /// <param name="roundness">The roundness of the arc</param>
        /// <param name="usePercentage">A value that indicates if the roundness of the arc will be used as a percentage or not</param>
        private static void ConnectLinePoints(PathFigure pathFigure, Point p1, Point p2, Point p3, double roundness, bool usePercentage)
        {
            //The point on the first segment where the curve will start.
            Point backPoint;
            //The point on the second segment where the curve will end.
            Point nextPoint;
            if (usePercentage)
            {
                backPoint = GetPointAtDistancePercent(p1, p2, roundness, false);
                nextPoint = GetPointAtDistancePercent(p2, p3, roundness, true);
            }
            else
            {
                backPoint = GetPointAtDistance(p1, p2, roundness, false);
                nextPoint = GetPointAtDistance(p2, p3, roundness, true);
            }

            int lastSegmentIndex = pathFigure.Segments.Count - 1;
            //Set the ending point of the first segment.
            ((LineSegment)(pathFigure.Segments[lastSegmentIndex])).Point = backPoint;
            //Create and add the curve.
            var curve = new QuadraticBezierSegment { Point1 = p2, Point2 = nextPoint };
            pathFigure.Segments.Add(curve);
            //Create and add the new segment.
            var line = new LineSegment { Point = p3 };
            pathFigure.Segments.Add(line);
        }
        private static void ConnectLinePoints(PathFigure pathFigure, Point p1, Point p2, Point p3, double roundness)
        {
            //The point on the first segment where the curve will start.
            //The point on the second segment where the curve will end.
            Point nextPoint, backPoint;
            if (GetPointAtDistance(p2, p3, roundness, true, out nextPoint) && GetPointAtDistance(p1, p2, roundness, false, out backPoint))
            {
                int lastSegmentIndex = pathFigure.Segments.Count - 1;
                //Set the ending point of the first segment.
                ((LineSegment) (pathFigure.Segments[lastSegmentIndex])).Point = backPoint;

                //Create and add the curve.
                var curve = new QuadraticBezierSegment(p2, nextPoint, true);
                pathFigure.Segments.Add(curve);
            }
            //Create and add the new segment.
            var line = new LineSegment(p3, true);
            pathFigure.Segments.Add(line);
        }
    GetQuadraticBezierCurve
    (
        Point startPoint,
        Point endPoint,
        Point controlPoint
    )
    {
        QuadraticBezierSegment oQuadraticBezierSegment =
            new QuadraticBezierSegment(controlPoint, endPoint, true);

        PathFigure oPathFigure = new PathFigure();
        oPathFigure.StartPoint = startPoint;
        oPathFigure.Segments.Add(oQuadraticBezierSegment);

        PathGeometry oQuadraticBezierCurve = new PathGeometry();
        oQuadraticBezierCurve.Figures.Add(oPathFigure);
        WpfGraphicsUtil.FreezeIfFreezable(oQuadraticBezierCurve);

        return (oQuadraticBezierCurve);
    }
示例#30
0
文件: Wpf.cs 项目: monocraft/RxCanvas
        public WpfQuadraticBezier(IQuadraticBezier qb)
        {
            _xqb = qb;

            _fillBrush = new SolidColorBrush(_xqb.Fill.ToNativeColor());
            _fillBrush.Freeze();
            _strokeBrush = new SolidColorBrush(_xqb.Stroke.ToNativeColor());
            _strokeBrush.Freeze();

            _path = new Path();
            _path.Tag = this;
            _path.Fill = _fillBrush;
            _path.Stroke = _strokeBrush;
            _path.StrokeThickness = qb.StrokeThickness;
            _pg = new PathGeometry();
            _pf = new PathFigure();
            _pf.StartPoint = new Point(qb.Start.X, qb.Start.Y);
            _pf.IsFilled = qb.IsFilled;
            _pf.IsClosed = qb.IsClosed;
            _qbs = new QuadraticBezierSegment();
            _qbs.Point1 = new Point(qb.Point1.X, qb.Point1.Y);
            _qbs.Point2 = new Point(qb.Point2.X, qb.Point2.Y);
            _pf.Segments.Add(_qbs);
            _pg.Figures.Add(_pf);
            _path.Data = _pg;

            Native = _path;
        }