private static SKPath ToSkia(IViewport viewport, Polygon polygon) { var vertices = polygon.ExteriorRing.Vertices; var path = new SKPath(); { // todo: use transform matrix var first = viewport.WorldToScreen(vertices[0].X, vertices[0].Y); path.MoveTo((float)first.X, (float) first.Y); for (var i = 1; i < vertices.Count; i++) { var point = viewport.WorldToScreen(vertices[i].X, vertices[i].Y); path.LineTo((float) point.X, (float) point.Y); } path.Close(); foreach (var interiorRing in polygon.InteriorRings) { // note: For Skia inner rings need to be clockwise and outer rings // need to be counter clockwise (if this is the other way around it also // seems to work) // this is not a requirement of the OGC polygon. var firstInner = viewport.WorldToScreen(interiorRing.Vertices[0].X, interiorRing.Vertices[0].Y); path.MoveTo((float)firstInner.X, (float)firstInner.Y); for (var i = 1; i < interiorRing.Vertices.Count; i++) { var point = viewport.WorldToScreen(interiorRing.Vertices[i].X, interiorRing.Vertices[i].Y); path.LineTo((float)point.X, (float)point.Y); } } path.Close(); return path; } }
static SkiaSharp.SKPath CreatePolygon(PixelFarm.Drawing.PointF[] points) { SkiaSharp.SKPath p = new SkiaSharp.SKPath(); int j = points.Length; PixelFarm.Drawing.PointF p0 = new PixelFarm.Drawing.PointF(); for (int i = 0; i < j; ++i) { if (i == 0) { p0 = points[0]; p.MoveTo(p0.X, p0.Y); } else if (i == j - 1) { //last one var point = points[i]; p.LineTo(point.X, point.Y); p.LineTo(p0.X, p0.Y); p.Close(); break; } else { var point = points[i]; p.LineTo(point.X, point.Y); } } return(p); }
public static SKPath CreateGraphicsPath(VertexStore vxs) { //render vertice in store int vcount = vxs.Count; double prevX = 0; double prevY = 0; double prevMoveToX = 0; double prevMoveToY = 0; //var brush_path = new System.Drawing.Drawing2D.GraphicsPath(FillMode.Winding);//*** winding for overlapped path var brushPath = new SKPath(); //how to set widening mode for (int i = 0; i < vcount; ++i) { double x, y; PixelFarm.Agg.VertexCmd cmd = vxs.GetVertex(i, out x, out y); switch (cmd) { case PixelFarm.Agg.VertexCmd.MoveTo: prevMoveToX = prevX = x; prevMoveToY = prevY = y; //brush_path.StartFigure(); brushPath.MoveTo((float)x, (float)y); break; case PixelFarm.Agg.VertexCmd.LineTo: //brush_path.AddLine((float)prevX, (float)prevY, (float)x, (float)y); brushPath.LineTo((float)x, (float)y); prevX = x; prevY = y; break; case PixelFarm.Agg.VertexCmd.CloseAndEndFigure: //brush_path.AddLine((float)prevX, (float)prevY, (float)prevMoveToX, (float)prevMoveToY); brushPath.LineTo((float)prevMoveToX, (float)prevMoveToY); prevMoveToX = prevX = x; prevMoveToY = prevY = y; //brush_path.CloseFigure(); brushPath.Close(); break; case PixelFarm.Agg.VertexCmd.EndFigure: break; case PixelFarm.Agg.VertexCmd.Stop: i = vcount + 1;//exit from loop break; default: throw new NotSupportedException(); } } return brushPath; }
/// <summary> /// we do NOT store vxsSnap /// </summary> /// <param name="vxsSnap"></param> /// <returns></returns> public static SKPath CreateGraphicsPath(VertexStoreSnap vxsSnap) { VertexSnapIter vxsIter = vxsSnap.GetVertexSnapIter(); double prevX = 0; double prevY = 0; double prevMoveToX = 0; double prevMoveToY = 0; //var brush_path = new System.Drawing.Drawing2D.GraphicsPath(FillMode.Winding);//*** winding for overlapped path var brushPath = new SKPath(); for (;;) { double x, y; VertexCmd cmd = vxsIter.GetNextVertex(out x, out y); switch (cmd) { case PixelFarm.Agg.VertexCmd.MoveTo: prevMoveToX = prevX = x; prevMoveToY = prevY = y; brushPath.MoveTo((float)x, (float)y); break; case PixelFarm.Agg.VertexCmd.LineTo: //brushPath.AddLine((float)prevX, (float)prevY, (float)x, (float)y); brushPath.LineTo((float)x, (float)y); prevX = x; prevY = y; break; case PixelFarm.Agg.VertexCmd.CloseAndEndFigure: //from current point //brushPath.AddLine((float)prevX, (float)prevY, (float)prevMoveToX, (float)prevMoveToY); brushPath.LineTo((float)prevMoveToX, (float)prevMoveToY); prevX = prevMoveToX; prevY = prevMoveToY; //brushPath.CloseFigure(); brushPath.Close(); break; case PixelFarm.Agg.VertexCmd.EndFigure: goto EXIT_LOOP; case PixelFarm.Agg.VertexCmd.Stop: goto EXIT_LOOP; default: throw new NotSupportedException(); } } EXIT_LOOP: return brushPath; }
private static SKPath ToSkia(List<Point> vertices) { var points = new SKPath(); for (var i = 0; i < vertices.Count; i++) { if (i == 0) { points.MoveTo((float)vertices[i].X, (float)vertices[i].Y); } else { points.LineTo((float)vertices[i].X, (float)vertices[i].Y); } } return points; }
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); }
void DrawArc (SKCanvas canvas, SKPaint paint, double startAngleInDegrees, double endAngleInDegrees) { // find center and radius var centerx = (float)Bounds.Width / 2; var centery = (float)Bounds.Height / 2; var radius = Bounds.Width < Bounds.Height ? (float)Bounds.Width / 2 : (float)Bounds.Height / 2; var w = 0.558f; // convert degrees to radians var startAngleRadians = startAngleInDegrees * Math.PI / 180; var endAngleRadians = endAngleInDegrees * Math.PI / 180; // find x,y coordinates for start and end points var startx = centerx + radius * (float)Math.Cos (startAngleRadians); var starty = centery + radius * (float)Math.Sin (startAngleRadians); var startPoint = new SKPoint (startx, starty); var endx = centerx + radius * (float)Math.Cos (endAngleRadians); var endy = centery + radius * (float)Math.Sin (endAngleRadians); var endPoint = new SKPoint (endx, endy); // find linear distance & midpoint between start and end points var linearDistance = Math.Sqrt(Math.Pow(endy - starty, 2) / Math.Pow(endx - startx, 2)); var midx = (startx + endx) / 2; var midy = (starty + endy) / 2; var midPoint = new SKPoint (midx, midy); // rotate end point 45 degrees counterclockwise around midpoint to find Conic function anchor var anchorPoint = RotatePoint (endPoint, midPoint, 45); // build path var path = new SKPath (); //path.MoveTo (startx, starty); //path.ConicTo (anchorPoint.X, anchorPoint.Y, endx, endy, w); path.MoveTo (centerx, centery - radius); path.ConicTo (centerx + radius, centery - radius, centerx + radius, centery, w); path.ConicTo (centerx + radius, centery + radius, centerx, centery + radius, w); path.ConicTo (centerx - radius, centery + radius, centerx - radius, centery, w); //path.ConicTo (centerx - radius, centery - radius, centerx, centery - radius, w); //canvas.DrawPoints (SKPointMode.Points, new SKPoint [] { }, paint); canvas.DrawPath (path, paint); }
#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); } } }
/// <inheritdoc/> public override void Draw(object dc, XQuadraticBezier quadraticBezier, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var canvas = dc as SKCanvas; using (SKPaint brush = ToSKPaintBrush(quadraticBezier.Style.Fill)) using (SKPaint pen = ToSKPaintPen(quadraticBezier.Style, _scaleToPage, _sourceDpi, _targetDpi)) using (var path = new SKPath()) { path.MoveTo( _scaleToPage(quadraticBezier.Point1.X + dx), _scaleToPage(quadraticBezier.Point1.Y + dy)); path.QuadTo( _scaleToPage(quadraticBezier.Point2.X + dx), _scaleToPage(quadraticBezier.Point2.Y + dy), _scaleToPage(quadraticBezier.Point3.X + dx), _scaleToPage(quadraticBezier.Point3.Y + dy)); DrawPathInternal(canvas, brush, pen, quadraticBezier.IsStroked, quadraticBezier.IsFilled, path); } }
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); } }
public static void FilledHeptagram (SKCanvas canvas, int width, int height) { var size = ((float)height > width ? width : height) * 0.75f; var R = 0.45f * size; var TAU = 6.2831853f; using (var path = new SKPath ()) { path.MoveTo (R, 0.0f); for (int i = 1; i < 7; ++i) { var theta = 3f * i * TAU / 7f; path.LineTo (R * (float)Math.Cos (theta), R * (float)Math.Sin (theta)); } path.Close (); using (var paint = new SKPaint ()) { paint.IsAntialias = true; canvas.Clear (SKColors.White); canvas.Translate (width / 2f, height / 2f); canvas.DrawPath (path, paint); } } }
#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); } } }
/// <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 CreatePolygon(PixelFarm.Drawing.PointF[] points) { SkiaSharp.SKPath p = new SkiaSharp.SKPath(); int j = points.Length; PixelFarm.Drawing.PointF p0 = new PixelFarm.Drawing.PointF(); for (int i = 0; i < j; ++i) { if (i == 0) { p0 = points[0]; p.MoveTo(p0.X, p0.Y); } else if (i == j - 1) { //last one var point = points[i]; p.LineTo(point.X, point.Y); p.LineTo(p0.X, p0.Y); p.Close(); break; } else { var point = points[i]; p.LineTo(point.X, point.Y); } } return p; }
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; }