CubicTo() public method

public CubicTo ( SKPoint point0, SKPoint point1, SKPoint point2 ) : void
point0 SKPoint
point1 SKPoint
point2 SKPoint
return void
示例#1
0
                #pragma warning restore 414

        public static void DrawXamagon(SKCanvas canvas, int width, int height)
        {
            // Width 41.6587026 => 144.34135
            // Height 56 => 147

            var paddingFactor = .6f;
            var imageLeft     = 41.6587026f;
            var imageRight    = 144.34135f;
            var imageTop      = 56f;
            var imageBottom   = 147f;

            var imageWidth = imageRight - imageLeft;

            var scale = (((float)height > width ? width : height) / imageWidth) * paddingFactor;

            var translateX = (imageLeft + imageRight) / -2 + width / scale * 1 / 2;
            var translateY = (imageBottom + imageTop) / -2 + height / scale * 1 / 2;

            canvas.Scale(scale, scale);
            canvas.Translate(translateX, translateY);


            using (var paint = new SKPaint()) {
                paint.IsAntialias = true;
                paint.Color       = SKColors.White;
                canvas.DrawPaint(paint);

                paint.StrokeCap = SKStrokeCap.Round;
                var t = paint.StrokeCap;


                using (var path = new SKPath()) {
                    path.MoveTo(71.4311121f, 56f);
                    path.CubicTo(68.6763107f, 56.0058575f, 65.9796704f, 57.5737917f, 64.5928855f, 59.965729f);
                    path.LineTo(43.0238921f, 97.5342563f);
                    path.CubicTo(41.6587026f, 99.9325978f, 41.6587026f, 103.067402f, 43.0238921f, 105.465744f);
                    path.LineTo(64.5928855f, 143.034271f);
                    path.CubicTo(65.9798162f, 145.426228f, 68.6763107f, 146.994582f, 71.4311121f, 147f);
                    path.LineTo(114.568946f, 147f);
                    path.CubicTo(117.323748f, 146.994143f, 120.020241f, 145.426228f, 121.407172f, 143.034271f);
                    path.LineTo(142.976161f, 105.465744f);
                    path.CubicTo(144.34135f, 103.067402f, 144.341209f, 99.9325978f, 142.976161f, 97.5342563f);
                    path.LineTo(121.407172f, 59.965729f);
                    path.CubicTo(120.020241f, 57.5737917f, 117.323748f, 56.0054182f, 114.568946f, 56f);
                    path.LineTo(71.4311121f, 56f);
                    path.Close();

                    paint.Color = XamDkBlue;
                    canvas.DrawPath(path, paint);
                }

                using (var path = new SKPath()) {
                    path.MoveTo(71.8225901f, 77.9780432f);
                    path.CubicTo(71.8818491f, 77.9721857f, 71.9440029f, 77.9721857f, 72.0034464f, 77.9780432f);
                    path.LineTo(79.444074f, 77.9780432f);
                    path.CubicTo(79.773437f, 77.9848769f, 80.0929203f, 78.1757336f, 80.2573978f, 78.4623994f);
                    path.LineTo(92.8795281f, 101.015639f);
                    path.CubicTo(92.9430615f, 101.127146f, 92.9839987f, 101.251384f, 92.9995323f, 101.378901f);
                    path.CubicTo(93.0150756f, 101.251354f, 93.055974f, 101.127107f, 93.1195365f, 101.015639f);
                    path.LineTo(105.711456f, 78.4623994f);
                    path.CubicTo(105.881153f, 78.167045f, 106.215602f, 77.975134f, 106.554853f, 77.9780432f);
                    path.LineTo(113.995483f, 77.9780432f);
                    path.CubicTo(114.654359f, 77.9839007f, 115.147775f, 78.8160066f, 114.839019f, 79.4008677f);
                    path.LineTo(102.518299f, 101.500005f);
                    path.LineTo(114.839019f, 123.568869f);
                    path.CubicTo(115.176999f, 124.157088f, 114.671442f, 125.027775f, 113.995483f, 125.021957f);
                    path.LineTo(106.554853f, 125.021957f);
                    path.CubicTo(106.209673f, 125.019028f, 105.873247f, 124.81384f, 105.711456f, 124.507327f);
                    path.LineTo(93.1195365f, 101.954088f);
                    path.CubicTo(93.0560031f, 101.84258f, 93.0150659f, 101.718333f, 92.9995323f, 101.590825f);
                    path.CubicTo(92.983989f, 101.718363f, 92.9430906f, 101.842629f, 92.8795281f, 101.954088f);
                    path.LineTo(80.2573978f, 124.507327f);
                    path.CubicTo(80.1004103f, 124.805171f, 79.7792269f, 125.008397f, 79.444074f, 125.021957f);
                    path.LineTo(72.0034464f, 125.021957f);
                    path.CubicTo(71.3274867f, 125.027814f, 70.8220664f, 124.157088f, 71.1600463f, 123.568869f);
                    path.LineTo(83.4807624f, 101.500005f);
                    path.LineTo(71.1600463f, 79.400867f);
                    path.CubicTo(70.8647037f, 78.86725f, 71.2250368f, 78.0919422f, 71.8225901f, 77.9780432f);
                    path.LineTo(71.8225901f, 77.9780432f);
                    path.Close();

                    paint.Color = SKColors.White;
                    canvas.DrawPath(path, paint);
                }
            }
        }
示例#2
0
        /// <inheritdoc/>
        public override void Draw(object dc, XCubicBezier cubicBezier, double dx, double dy, ImmutableArray<XProperty> db, XRecord r)
        {
            var canvas = dc as SKCanvas;

            using (SKPaint brush = ToSKPaintBrush(cubicBezier.Style.Fill))
            using (SKPaint pen = ToSKPaintPen(cubicBezier.Style, _scaleToPage, _sourceDpi, _targetDpi))
            using (var path = new SKPath())
            {
                path.MoveTo(
                    _scaleToPage(cubicBezier.Point1.X + dx),
                    _scaleToPage(cubicBezier.Point1.Y + dy));
                path.CubicTo(
                    _scaleToPage(cubicBezier.Point2.X + dx),
                    _scaleToPage(cubicBezier.Point2.Y + dy),
                    _scaleToPage(cubicBezier.Point3.X + dx),
                    _scaleToPage(cubicBezier.Point3.Y + dy),
                    _scaleToPage(cubicBezier.Point4.X + dx),
                    _scaleToPage(cubicBezier.Point4.Y + dy));
                DrawPathInternal(canvas, brush, pen, cubicBezier.IsStroked, cubicBezier.IsFilled, path);
            }
        }
        static SkiaSharp.SKPath ResolveGraphicsPath(GraphicsPath path)
        {
            //convert from graphics path to internal presentation
            SkiaSharp.SKPath innerPath = path.InnerPath as SkiaSharp.SKPath;
            if (innerPath != null)
            {
                return(innerPath);
            }
            //--------
            innerPath      = new SkiaSharp.SKPath();
            path.InnerPath = innerPath;
            List <float>       points;
            List <PathCommand> cmds;

            GraphicsPath.GetPathData(path, out points, out cmds);
            int j       = cmds.Count;
            int p_index = 0;

            for (int i = 0; i < j; ++i)
            {
                PathCommand cmd = cmds[i];
                switch (cmd)
                {
                default:
                    throw new NotSupportedException();

                case PathCommand.Arc:

                    var oval = SkiaSharp.SKRect.Create(points[p_index],
                                                       points[p_index + 1],
                                                       points[p_index + 2],
                                                       points[p_index + 3]);

                    innerPath.ArcTo(oval,
                                    points[p_index + 4],
                                    points[p_index + 5],
                                    true);
                    p_index += 6;
                    break;

                case PathCommand.Bezier:
                    innerPath.MoveTo(points[p_index]
                                     , points[p_index + 1]);
                    innerPath.CubicTo(
                        points[p_index + 2],
                        points[p_index + 3],
                        points[p_index + 4],
                        points[p_index + 5],
                        points[p_index + 6],
                        points[p_index + 7]);
                    p_index += 8;
                    break;

                case PathCommand.CloseFigure:
                    //?
                    break;

                case PathCommand.Ellipse:

                    innerPath.AddOval(
                        SkiaSharp.SKRect.Create(
                            points[p_index],
                            points[p_index + 1],
                            points[p_index + 2],
                            points[p_index + 3]
                            ));

                    p_index += 4;
                    break;

                case PathCommand.Line:

                    innerPath.MoveTo(points[p_index],
                                     points[p_index + 1]);
                    innerPath.LineTo(
                        points[p_index + 2],
                        points[p_index + 3]);
                    p_index += 4;
                    break;

                case PathCommand.Rect:
                    innerPath.AddRect(
                        SkiaSharp.SKRect.Create(
                            points[p_index],
                            points[p_index + 1],
                            points[p_index + 2],
                            points[p_index + 3]
                            ));
                    p_index += 4;
                    break;

                case PathCommand.StartFigure:
                    break;
                }
            }


            return(innerPath);
        }
示例#4
0
 private void DrawLineCurveInternal(SKCanvas canvas, SKPaint pen, bool isStroked, ref SKPoint pt1, ref SKPoint pt2, double curvature, CurveOrientation orientation, PointAlignment pt1a, PointAlignment pt2a)
 {
     if (isStroked)
     {
         using (var path = new SKPath())
         {
             path.MoveTo(pt1.X, pt1.Y);
             double p1x = pt1.X;
             double p1y = pt1.Y;
             double p2x = pt2.X;
             double p2y = pt2.Y;
             XLineExtensions.GetCurvedLineBezierControlPoints(orientation, curvature, pt1a, pt2a, ref p1x, ref p1y, ref p2x, ref p2y);
             path.CubicTo(
                 (float)p1x,
                 (float)p1y,
                 (float)p2x,
                 (float)p2y,
                 pt2.X, pt2.Y);
             canvas.DrawPath(path, pen);
         }
     }
 }
 public override void DrawBezierCurve(float startX, float startY, float endX, float endY, float controlX1, float controlY1, float controlX2, float controlY2)
 {
     using (SKPath p = new SKPath())
     {
         p.MoveTo(startX, startY);
         p.CubicTo(controlX1, controlY1,
             controlY1, controlY2,
             endX, endY);
         _skCanvas.DrawPath(p, _stroke);
     }
 }
		#pragma warning restore 414

		public static void DrawXamagon (SKCanvas canvas, int width, int height)
		{
			// Width 41.6587026 => 144.34135
			// Height 56 => 147

			var paddingFactor = .6f;
			var imageLeft = 41.6587026f;
			var imageRight = 144.34135f;
			var imageTop = 56f;
			var imageBottom = 147f;

			var imageWidth = imageRight - imageLeft;

			var scale = (((float)height > width ? width : height) / imageWidth) * paddingFactor;

			var translateX =  (imageLeft + imageRight) / -2 + width/scale * 1/2;
			var translateY =  (imageBottom + imageTop) / -2 + height/scale * 1/2;

			canvas.Scale (scale, scale);
			canvas.Translate (translateX , translateY);


			using (var paint = new SKPaint ()) {
				paint.IsAntialias = true;
				paint.Color = SKColors.White;
				canvas.DrawPaint (paint);

				paint.StrokeCap = SKStrokeCap.Round;
				var t = paint.StrokeCap;


				using (var path = new SKPath ()) {
					path.MoveTo (71.4311121f, 56f);
					path.CubicTo (68.6763107f, 56.0058575f, 65.9796704f, 57.5737917f, 64.5928855f, 59.965729f);
					path.LineTo (43.0238921f, 97.5342563f);
					path.CubicTo (41.6587026f, 99.9325978f, 41.6587026f, 103.067402f, 43.0238921f, 105.465744f);
					path.LineTo (64.5928855f, 143.034271f);
					path.CubicTo (65.9798162f, 145.426228f, 68.6763107f, 146.994582f, 71.4311121f, 147f);
					path.LineTo (114.568946f, 147f);
					path.CubicTo (117.323748f, 146.994143f, 120.020241f, 145.426228f, 121.407172f, 143.034271f);
					path.LineTo (142.976161f, 105.465744f);
					path.CubicTo (144.34135f, 103.067402f, 144.341209f, 99.9325978f, 142.976161f, 97.5342563f);
					path.LineTo (121.407172f, 59.965729f);
					path.CubicTo (120.020241f, 57.5737917f, 117.323748f, 56.0054182f, 114.568946f, 56f);
					path.LineTo (71.4311121f, 56f);
					path.Close ();

					paint.Color = XamDkBlue;
					canvas.DrawPath (path, paint);

				}

				using (var path = new SKPath ()) {

					path.MoveTo (71.8225901f, 77.9780432f);
					path.CubicTo (71.8818491f, 77.9721857f, 71.9440029f, 77.9721857f, 72.0034464f, 77.9780432f);
					path.LineTo (79.444074f, 77.9780432f);
					path.CubicTo (79.773437f, 77.9848769f, 80.0929203f, 78.1757336f, 80.2573978f, 78.4623994f);
					path.LineTo (92.8795281f, 101.015639f);
					path.CubicTo (92.9430615f, 101.127146f, 92.9839987f, 101.251384f, 92.9995323f, 101.378901f);
					path.CubicTo (93.0150756f, 101.251354f, 93.055974f, 101.127107f, 93.1195365f, 101.015639f);
					path.LineTo (105.711456f, 78.4623994f);
					path.CubicTo (105.881153f, 78.167045f, 106.215602f, 77.975134f, 106.554853f, 77.9780432f);
					path.LineTo (113.995483f, 77.9780432f);
					path.CubicTo (114.654359f, 77.9839007f, 115.147775f, 78.8160066f, 114.839019f, 79.4008677f);
					path.LineTo (102.518299f, 101.500005f);
					path.LineTo (114.839019f, 123.568869f);
					path.CubicTo (115.176999f, 124.157088f, 114.671442f, 125.027775f, 113.995483f, 125.021957f);
					path.LineTo (106.554853f, 125.021957f);
					path.CubicTo (106.209673f, 125.019028f, 105.873247f, 124.81384f, 105.711456f, 124.507327f);
					path.LineTo (93.1195365f, 101.954088f);
					path.CubicTo (93.0560031f, 101.84258f, 93.0150659f, 101.718333f, 92.9995323f, 101.590825f);
					path.CubicTo (92.983989f, 101.718363f, 92.9430906f, 101.842629f, 92.8795281f, 101.954088f);
					path.LineTo (80.2573978f, 124.507327f);
					path.CubicTo (80.1004103f, 124.805171f, 79.7792269f, 125.008397f, 79.444074f, 125.021957f);
					path.LineTo (72.0034464f, 125.021957f);
					path.CubicTo (71.3274867f, 125.027814f, 70.8220664f, 124.157088f, 71.1600463f, 123.568869f);
					path.LineTo (83.4807624f, 101.500005f);
					path.LineTo (71.1600463f, 79.400867f);
					path.CubicTo (70.8647037f, 78.86725f, 71.2250368f, 78.0919422f, 71.8225901f, 77.9780432f);
					path.LineTo (71.8225901f, 77.9780432f);
					path.Close ();

					paint.Color = SKColors.White;
					canvas.DrawPath (path, paint);
				}
			}
		}
示例#7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xpg"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        public static SKPath ToSKPath(this XPathGeometry xpg, double dx, double dy, Func<double, float> scale)
        {
            var path = new SKPath();
            path.FillType = xpg.FillRule == XFillRule.EvenOdd ? SKPathFillType.EvenOdd : SKPathFillType.Winding;

            foreach (var xpf in xpg.Figures)
            {
                var previous = default(XPoint);

                // Begin new figure.
                path.MoveTo(
                    scale(xpf.StartPoint.X + dx),
                    scale(xpf.StartPoint.Y + dy));

                previous = xpf.StartPoint;

                foreach (var segment in xpf.Segments)
                {
                    if (segment is XArcSegment)
                    {
                        var arcSegment = segment as XArcSegment;
                        path.ArcTo(
                            scale(arcSegment.Size.Width),
                            scale(arcSegment.Size.Height), 
                            (float)arcSegment.RotationAngle, 
                            arcSegment.IsLargeArc ? SKPathArcSize.Large : SKPathArcSize.Small,
                            arcSegment.SweepDirection == XSweepDirection.Clockwise ? SKPathDirection.Clockwise : SKPathDirection.CounterClockwise,
                            scale(arcSegment.Point.X + dx),
                            scale(arcSegment.Point.Y + dy));

                        previous = arcSegment.Point;
                    }
                    else if (segment is XCubicBezierSegment)
                    {
                        var cubicBezierSegment = segment as XCubicBezierSegment;
                        path.CubicTo(
                            scale(cubicBezierSegment.Point1.X + dx),
                            scale(cubicBezierSegment.Point1.Y + dy),
                            scale(cubicBezierSegment.Point2.X + dx),
                            scale(cubicBezierSegment.Point2.Y + dy),
                            scale(cubicBezierSegment.Point3.X + dx),
                            scale(cubicBezierSegment.Point3.Y + dy));

                        previous = cubicBezierSegment.Point3;
                    }
                    else if (segment is XLineSegment)
                    {
                        var lineSegment = segment as XLineSegment;
                        path.LineTo(
                            scale(lineSegment.Point.X + dx),
                            scale(lineSegment.Point.Y + dy));

                        previous = lineSegment.Point;
                    }
                    else if (segment is XPolyCubicBezierSegment)
                    {
                        var polyCubicBezierSegment = segment as XPolyCubicBezierSegment;
                        if (polyCubicBezierSegment.Points.Length >= 3)
                        {
                            path.CubicTo(
                                scale(polyCubicBezierSegment.Points[0].X + dx),
                                scale(polyCubicBezierSegment.Points[0].Y + dy),
                                scale(polyCubicBezierSegment.Points[1].X + dx),
                                scale(polyCubicBezierSegment.Points[1].Y + dy),
                                scale(polyCubicBezierSegment.Points[2].X + dx),
                                scale(polyCubicBezierSegment.Points[2].Y + dy));

                            previous = polyCubicBezierSegment.Points[2];
                        }

                        if (polyCubicBezierSegment.Points.Length > 3
                            && polyCubicBezierSegment.Points.Length % 3 == 0)
                        {
                            for (int i = 3; i < polyCubicBezierSegment.Points.Length; i += 3)
                            {
                                path.CubicTo(
                                    scale(polyCubicBezierSegment.Points[i].X + dx),
                                    scale(polyCubicBezierSegment.Points[i].Y + dy),
                                    scale(polyCubicBezierSegment.Points[i + 1].X + dx),
                                    scale(polyCubicBezierSegment.Points[i + 1].Y + dy),
                                    scale(polyCubicBezierSegment.Points[i + 2].X + dx),
                                    scale(polyCubicBezierSegment.Points[i + 2].Y + dy));

                                previous = polyCubicBezierSegment.Points[i + 2];
                            }
                        }
                    }
                    else if (segment is XPolyLineSegment)
                    {
                        var polyLineSegment = segment as XPolyLineSegment;
                        if (polyLineSegment.Points.Length >= 1)
                        {
                            path.LineTo(
                                scale(polyLineSegment.Points[0].X + dx),
                                scale(polyLineSegment.Points[0].Y + dy));

                            previous = polyLineSegment.Points[0];
                        }

                        if (polyLineSegment.Points.Length > 1)
                        {
                            for (int i = 1; i < polyLineSegment.Points.Length; i++)
                            {
                                path.LineTo(
                                    scale(polyLineSegment.Points[i].X + dx),
                                    scale(polyLineSegment.Points[i].Y + dy));

                                previous = polyLineSegment.Points[i];
                            }
                        }
                    }
                    else if (segment is XPolyQuadraticBezierSegment)
                    {
                        var polyQuadraticSegment = segment as XPolyQuadraticBezierSegment;
                        if (polyQuadraticSegment.Points.Length >= 2)
                        {
                            path.QuadTo(
                                scale(polyQuadraticSegment.Points[0].X + dx),
                                scale(polyQuadraticSegment.Points[0].Y + dy),
                                scale(polyQuadraticSegment.Points[1].X + dx),
                                scale(polyQuadraticSegment.Points[1].Y + dy));

                            previous = polyQuadraticSegment.Points[1];
                        }

                        if (polyQuadraticSegment.Points.Length > 2
                            && polyQuadraticSegment.Points.Length % 2 == 0)
                        {
                            for (int i = 3; i < polyQuadraticSegment.Points.Length; i += 3)
                            {
                                path.QuadTo(
                                    scale(polyQuadraticSegment.Points[i].X + dx),
                                    scale(polyQuadraticSegment.Points[i].Y + dy),
                                    scale(polyQuadraticSegment.Points[i + 1].X + dx),
                                    scale(polyQuadraticSegment.Points[i + 1].Y + dy));

                                previous = polyQuadraticSegment.Points[i + 1];
                            }
                        }
                    }
                    else if (segment is XQuadraticBezierSegment)
                    {
                        var quadraticBezierSegment = segment as XQuadraticBezierSegment;
                        path.QuadTo(
                            scale(quadraticBezierSegment.Point1.X + dx),
                            scale(quadraticBezierSegment.Point1.Y + dy),
                            scale(quadraticBezierSegment.Point2.X + dx),
                            scale(quadraticBezierSegment.Point2.Y + dy));

                        previous = quadraticBezierSegment.Point2;
                    }
                    else
                    {
                        throw new NotSupportedException("Not supported segment type: " + segment.GetType());
                    }
                }

                if (xpf.IsClosed)
                {
                    path.Close();
                }
            }

            return path;
        }
        static SkiaSharp.SKPath ResolveGraphicsPath(GraphicsPath path)
        {
            //convert from graphics path to internal presentation
            SkiaSharp.SKPath innerPath = path.InnerPath as SkiaSharp.SKPath;
            if (innerPath != null)
            {
                return innerPath;
            }
            //--------
            innerPath = new SkiaSharp.SKPath();
            path.InnerPath = innerPath;
            List<float> points;
            List<PathCommand> cmds;
            GraphicsPath.GetPathData(path, out points, out cmds);
            int j = cmds.Count;
            int p_index = 0;
            for (int i = 0; i < j; ++i)
            {
                PathCommand cmd = cmds[i];
                switch (cmd)
                {
                    default:
                        throw new NotSupportedException();
                    case PathCommand.Arc:

                        var oval = SkiaSharp.SKRect.Create(points[p_index],
                            points[p_index + 1],
                            points[p_index + 2],
                            points[p_index + 3]);

                        innerPath.ArcTo(oval,
                            points[p_index + 4],
                            points[p_index + 5],
                            true);
                        p_index += 6;
                        break;
                    case PathCommand.Bezier:
                        innerPath.MoveTo(points[p_index]
                            , points[p_index + 1]);
                        innerPath.CubicTo(
                            points[p_index + 2],
                            points[p_index + 3],
                            points[p_index + 4],
                            points[p_index + 5],
                            points[p_index + 6],
                            points[p_index + 7]);
                        p_index += 8;
                        break;
                    case PathCommand.CloseFigure:
                        //?
                        break;
                    case PathCommand.Ellipse:

                        innerPath.AddOval(
                            SkiaSharp.SKRect.Create(
                                points[p_index],
                            points[p_index + 1],
                            points[p_index + 2],
                            points[p_index + 3]
                                ));

                        p_index += 4;
                        break;
                    case PathCommand.Line:

                        innerPath.MoveTo(points[p_index],
                            points[p_index + 1]);
                        innerPath.LineTo(
                            points[p_index + 2],
                            points[p_index + 3]);
                        p_index += 4;
                        break;
                    case PathCommand.Rect:
                        innerPath.AddRect(
                            SkiaSharp.SKRect.Create(
                                points[p_index],
                            points[p_index + 1],
                            points[p_index + 2],
                            points[p_index + 3]
                                ));
                        p_index += 4;
                        break;
                    case PathCommand.StartFigure:
                        break;
                }
            }


            return innerPath;
        }