Inheritance: SKObject
		public SKPathMeasure (SKPath path, bool forceClosed = false, float resScale = 1)
			: this (SkiaApi.sk_pathmeasure_new_with_path (path == null ? IntPtr.Zero : path.Handle, forceClosed, resScale), true)
		{
			if (Handle == IntPtr.Zero) {
				throw new InvalidOperationException ("Unable to create a new SKPathMeasure instance.");
			}
		}
        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);
        }
        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;
            }
        }
        public IStreamGeometryContextImpl Open()
        {
            _path = new SKPath();
            _path.FillType = SKPathFillType.EvenOdd;

            return new StreamContext(this);
        }
Exemple #5
0
		public SKPath(SKPath path)
			: this (SkiaApi.sk_path_clone(path.Handle), true)
		{
			if (Handle == IntPtr.Zero) {
				throw new InvalidOperationException ("Unable to copy the SKPath instance.");
			}
		}
Exemple #6
0
		public bool SetPath(SKPath path, SKRegion clip)
		{
			if (path == null)
				throw new ArgumentNullException (nameof (path));
			if (clip == null)
				throw new ArgumentNullException (nameof (clip));
			return SkiaApi.sk_region_set_path(Handle, path.Handle, clip.Handle); 
		}
Exemple #7
0
        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;
        }
        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;
        }
Exemple #9
0
 /// <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;
 }
        void ApplyTransform()
        {
            if (_path == null)
                return;

            if (_transformedPath != null)
            {
                _transformedPath.Dispose();
                _transformedPath = null;
            }

            if (!Transform.IsIdentity)
            {
                _transformedPath = new SKPath(_path);
                _transformedPath.Transform(Transform.ToSKMatrix());
            }
        }
Exemple #11
0
 internal Iterator(SKPath path, bool forceClose)
     : base(SkiaApi.sk_path_create_iter(path.Handle, forceClose ? 1 : 0))
 {
     this.path = path;
 }
Exemple #12
0
 public void AddPath(SKPath other, ref SKMatrix matrix, AddMode mode)
 {
     AddPath(other, ref matrix, (SKPathAddMode)mode);
 }
		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);
		}
Exemple #14
0
 public void DrawTextOnPath(byte[] text, SKPath path, SKPoint offset, SKPaint paint)
 {
     DrawTextOnPath(text, path, offset.X, offset.Y, paint);
 }
Exemple #15
0
		public static SKPathEffect Create1DPath(SKPath path, float advance, float phase, SkPath1DPathEffectStyle style)
		{
			return Create1DPath(path, advance, phase, (SKPath1DPathEffectStyle)style);
		}
Exemple #16
0
 public void DrawPath(SKPath path, SKPaint paint)
 {
     if (paint == null)
         throw new ArgumentNullException (nameof (paint));
     if (path == null)
         throw new ArgumentNullException (nameof (path));
     SkiaApi.sk_canvas_draw_path (Handle, path.Handle, paint.Handle);
 }
Exemple #17
0
        // DrawTextOnPath

        public void DrawTextOnPath(string text, SKPath path, SKPoint offset, SKPaint paint)
        {
            DrawTextOnPath(text, path, offset, true, paint);
        }
Exemple #18
0
 public void DrawText(byte[] text, SKPath path, float hOffset, float vOffset, SKPaint paint)
 {
     DrawTextOnPath(text, path, hOffset, vOffset, paint);
 }
Exemple #19
0
 public void Add(SKPath path, SKPathOp op)
 {
     SkiaApi.sk_opbuilder_add(Handle, path.Handle, op);
 }
 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 StreamContext(StreamGeometryImpl geometryImpl)
 {
     _geometryImpl = geometryImpl;
     _path = _geometryImpl._path;
 }
 public IStreamGeometryContextImpl Open()
 {
     _path = new SKPath();
     return new StreamContext(this);
 }
Exemple #23
0
 public static SKTextBlob CreatePathPositioned(IntPtr text, int length, SKTextEncoding encoding, SKFont font, SKPath path, SKTextAlign textAlign = SKTextAlign.Left, SKPoint origin = default) =>
 CreatePathPositioned(text.AsReadOnlySpan(length), encoding, font, path, textAlign, origin);
Exemple #24
0
        // AddPathPositionedRun

        public void AddPathPositionedRun(ReadOnlySpan <ushort> glyphs, SKFont font, ReadOnlySpan <float> glyphWidths, ReadOnlySpan <SKPoint> glyphOffsets, SKPath path, SKTextAlign textAlign = SKTextAlign.Left)
        {
            using var pathMeasure = new SKPathMeasure(path);

            var contourLength = pathMeasure.Length;

            var textLength  = glyphOffsets[glyphs.Length - 1].X + glyphWidths[glyphs.Length - 1];
            var alignment   = (int)textAlign * 0.5f;
            var startOffset = glyphOffsets[0].X + (contourLength - textLength) * alignment;

            var firstGlyphIndex = 0;
            var pathGlyphCount  = 0;

            using var glyphTransforms = Utils.RentArray <SKRotationScaleMatrix> (glyphs.Length);

            // TODO: deal with multiple contours?
            for (var index = 0; index < glyphOffsets.Length; index++)
            {
                var glyphOffset = glyphOffsets[index];
                var halfWidth   = glyphWidths[index] * 0.5f;
                var pathOffset  = startOffset + glyphOffset.X + halfWidth;

                // TODO: clip glyphs on both ends of paths
                if (pathOffset >= 0 && pathOffset < contourLength && pathMeasure.GetPositionAndTangent(pathOffset, out var position, out var tangent))
                {
                    if (pathGlyphCount == 0)
                    {
                        firstGlyphIndex = index;
                    }

                    var tx = tangent.X;
                    var ty = tangent.Y;

                    var px = position.X;
                    var py = position.Y;

                    // horizontally offset the position using the tangent vector
                    px -= tx * halfWidth;
                    py -= ty * halfWidth;

                    // vertically offset the position using the normal vector  (-ty, tx)
                    var dy = glyphOffset.Y;
                    px -= dy * ty;
                    py += dy * tx;

                    glyphTransforms.Span[pathGlyphCount++] = new SKRotationScaleMatrix(tx, ty, px, py);
                }
            }

            var glyphSubset = glyphs.Slice(firstGlyphIndex, pathGlyphCount);
            var positions   = glyphTransforms.Span.Slice(0, pathGlyphCount);

            AddRotationScaleRun(glyphSubset, font, positions);
        }
Exemple #25
0
 public void ClipPath(SKPath path, SKRegionOperation operation, bool antialias = false)
 {
     ClipPath(path, (SKClipOperation)(int)operation, antialias);
 }
Exemple #26
0
        // SetPath

        public void SetPath(SKPath path) =>
        SetPath(path, false);
		public void SetPath (SKPath path, bool forceClosed)
		{
			SkiaApi.sk_pathmeasure_set_path (Handle, path == null ? IntPtr.Zero : path.Handle, forceClosed);
		}
Exemple #28
0
 public bool Op(SKPath path, SKRegionOperation op)
 {
     using (var pathRegion = new SKRegion(path)) {
         return(Op(pathRegion, op));
     }
 }
Exemple #29
0
 public bool SetPath(SKPath path)
 {
     return(SkiaApi.sk_region_set_path(Handle, path.Handle));
 }
Exemple #30
0
 public SKRegion(SKPath path)
     : this(SKRectI.Ceiling(path.Bounds))
 {
     SetPath(path);
 }
Exemple #31
0
        public void DrawText(string text, SKPath path, float hOffset, float vOffset, SKPaint paint)
        {
            if (text == null)
                throw new ArgumentNullException ("text");
            if (paint == null)
                throw new ArgumentNullException (nameof (paint));
            if (paint == null)
                throw new ArgumentNullException (nameof (paint));

            var bytes = Util.GetEncodedText (text, paint.TextEncoding);
            SkiaApi.sk_canvas_draw_text_on_path (Handle, bytes, bytes.Length, path.Handle, hOffset, vOffset, paint.Handle);
        }
Exemple #32
0
        private void ReadElement(XElement e, SKCanvas canvas, SKPaint stroke, SKPaint fill)
        {
            // transform matrix
            var transform = ReadTransform(e.Attribute("transform")?.Value ?? string.Empty);

            canvas.Save();
            canvas.Concat(ref transform);

            // SVG element
            var elementName = e.Name.LocalName;
            var isGroup     = elementName == "g";

            // read style
            var style = ReadPaints(e, ref stroke, ref fill, isGroup);

            // parse elements
            switch (elementName)
            {
            case "text":
                if (stroke != null || fill != null)
                {
                    ReadText(e, canvas, stroke?.Clone(), fill?.Clone());
                }
                break;

            case "rect":
                if (stroke != null || fill != null)
                {
                    var x      = ReadNumber(e.Attribute("x"));
                    var y      = ReadNumber(e.Attribute("y"));
                    var width  = ReadNumber(e.Attribute("width"));
                    var height = ReadNumber(e.Attribute("height"));
                    var rx     = ReadNumber(e.Attribute("rx"));
                    var ry     = ReadNumber(e.Attribute("ry"));
                    var rect   = SKRect.Create(x, y, width, height);
                    if (rx > 0 || ry > 0)
                    {
                        if (fill != null)
                        {
                            canvas.DrawRoundRect(rect, rx, ry, fill);
                        }
                        if (stroke != null)
                        {
                            canvas.DrawRoundRect(rect, rx, ry, stroke);
                        }
                    }
                    else
                    {
                        if (fill != null)
                        {
                            canvas.DrawRect(rect, fill);
                        }
                        if (stroke != null)
                        {
                            canvas.DrawRect(rect, stroke);
                        }
                    }
                }
                break;

            case "ellipse":
                if (stroke != null || fill != null)
                {
                    var cx = ReadNumber(e.Attribute("cx"));
                    var cy = ReadNumber(e.Attribute("cy"));
                    var rx = ReadNumber(e.Attribute("rx"));
                    var ry = ReadNumber(e.Attribute("ry"));
                    if (fill != null)
                    {
                        canvas.DrawOval(cx, cy, rx, ry, fill);
                    }
                    if (stroke != null)
                    {
                        canvas.DrawOval(cx, cy, rx, ry, stroke);
                    }
                }
                break;

            case "circle":
                if (stroke != null || fill != null)
                {
                    var cx = ReadNumber(e.Attribute("cx"));
                    var cy = ReadNumber(e.Attribute("cy"));
                    var rr = ReadNumber(e.Attribute("r"));
                    if (fill != null)
                    {
                        canvas.DrawCircle(cx, cy, rr, fill);
                    }
                    if (stroke != null)
                    {
                        canvas.DrawCircle(cx, cy, rr, stroke);
                    }
                }
                break;

            case "path":
                if (stroke != null || fill != null)
                {
                    var d = e.Attribute("d")?.Value;
                    if (!string.IsNullOrWhiteSpace(d))
                    {
                        var path = SKPath.ParseSvgPathData(d);
                        if (fill != null)
                        {
                            canvas.DrawPath(path, fill);
                        }
                        if (stroke != null)
                        {
                            canvas.DrawPath(path, stroke);
                        }
                    }
                }
                break;

            case "polygon":
            case "polyline":
                if (stroke != null || fill != null)
                {
                    var close = elementName == "polygon";
                    var p     = e.Attribute("points")?.Value;
                    if (!string.IsNullOrWhiteSpace(p))
                    {
                        var path = ReadPolyPath(p, close);
                        if (fill != null)
                        {
                            canvas.DrawPath(path, fill);
                        }
                        if (stroke != null)
                        {
                            canvas.DrawPath(path, stroke);
                        }
                    }
                }
                break;

            case "g":
                if (e.HasElements)
                {
                    // get current group opacity
                    float groupOpacity = ReadOpacity(style);
                    if (groupOpacity != 1.0f)
                    {
                        var opacity      = (byte)(255 * groupOpacity);
                        var opacityPaint = new SKPaint {
                            Color = SKColors.Black.WithAlpha(opacity)
                        };

                        // apply the opacity
                        canvas.SaveLayer(opacityPaint);
                    }

                    foreach (var gElement in e.Elements())
                    {
                        ReadElement(gElement, canvas, stroke?.Clone(), fill?.Clone());
                    }

                    // restore state
                    if (groupOpacity != 1.0f)
                    {
                        canvas.Restore();
                    }
                }
                break;

            case "use":
                if (e.HasAttributes)
                {
                    var href = ReadHref(e);
                    if (href != null)
                    {
                        // TODO: copy/process other attributes

                        var x            = ReadNumber(e.Attribute("x"));
                        var y            = ReadNumber(e.Attribute("y"));
                        var useTransform = SKMatrix.MakeTranslation(x, y);

                        canvas.Save();
                        canvas.Concat(ref useTransform);

                        ReadElement(href, canvas, stroke?.Clone(), fill?.Clone());

                        canvas.Restore();
                    }
                }
                break;

            case "line":
                if (stroke != null)
                {
                    var x1 = ReadNumber(e.Attribute("x1"));
                    var x2 = ReadNumber(e.Attribute("x2"));
                    var y1 = ReadNumber(e.Attribute("y1"));
                    var y2 = ReadNumber(e.Attribute("y2"));
                    canvas.DrawLine(x1, y1, x2, y2, stroke);
                }
                break;

            case "switch":
                if (e.HasElements)
                {
                    foreach (var ee in e.Elements())
                    {
                        var requiredFeatures   = ee.Attribute("requiredFeatures");
                        var requiredExtensions = ee.Attribute("requiredExtensions");
                        var systemLanguage     = ee.Attribute("systemLanguage");

                        // TODO: evaluate requiredFeatures, requiredExtensions and systemLanguage
                        var isVisible =
                            requiredFeatures == null &&
                            requiredExtensions == null &&
                            systemLanguage == null;

                        if (isVisible)
                        {
                            ReadElement(ee, canvas, stroke?.Clone(), fill?.Clone());
                        }
                    }
                }
                break;

            case "defs":
            case "title":
            case "desc":
            case "description":
                // already read earlier
                break;

            default:
                LogOrThrow($"SVG element '{elementName}' is not supported");
                break;
            }

            // restore matrix
            canvas.Restore();
        }
Exemple #33
0
        internal static SKTextBlob CreatePathPositioned(void *text, int length, SKTextEncoding encoding, SKFont font, SKPath path, SKTextAlign textAlign = SKTextAlign.Left, SKPoint origin = default)
        {
            if (font == null)
            {
                throw new ArgumentNullException(nameof(font));
            }

            var count = font.CountGlyphs(text, length, encoding);

            if (count <= 0)
            {
                return(null);
            }

            // we use temporary arrays because we might only use part of the text
            using var glyphs       = Utils.RentArray <ushort> (count);
            using var glyphWidths  = Utils.RentArray <float> (glyphs.Length);
            using var glyphOffsets = Utils.RentArray <SKPoint> (glyphs.Length);

            font.GetGlyphs(text, length, encoding, glyphs);
            font.GetGlyphWidths(glyphs, glyphWidths, Span <SKRect> .Empty);
            font.GetGlyphPositions(glyphs, glyphOffsets, origin);

            using var builder = new SKTextBlobBuilder();
            builder.AddPathPositionedRun(glyphs, font, glyphWidths, glyphOffsets, path, textAlign);
            return(builder.Build());
        }
Exemple #34
0
		public bool GetFillPath(SKPath src, SKPath dst, float resScale = 1)
		{
			if (src == null)
				throw new ArgumentNullException(nameof(src));
			if (dst == null)
				throw new ArgumentNullException(nameof(dst));
			return SkiaApi.sk_paint_get_fill_path(Handle, src.Handle, dst.Handle, IntPtr.Zero, resScale);
		}
Exemple #35
0
 internal RawIterator(SKPath path, IntPtr handle)
 {
     this.path   = path;
     this.handle = handle;
 }
Exemple #36
0
        // CreatePathPositioned

        public static SKTextBlob CreatePathPositioned(string text, SKFont font, SKPath path, SKTextAlign textAlign = SKTextAlign.Left, SKPoint origin = default) =>
        CreatePathPositioned(text.AsSpan(), font, path, textAlign, origin);
Exemple #37
0
 public void AddPath(SKPath other, float dx, float dy, SKPath.AddMode mode)
 {
     AddPath(other, dx, dy, (SKPathAddMode)mode);
 }
Exemple #38
0
 public SKRegion(SKPath path)
     : this()
 {
     SetPath(path);
 }
Exemple #39
0
 public void AddPath(SKPath other, AddMode mode)
 {
     AddPath(other, (SKPathAddMode)mode);
 }
Exemple #40
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);
         }
     }
 }
Exemple #41
0
 internal RawIterator(SKPath path)
     : base(SkiaApi.sk_path_create_rawiter(path.Handle))
 {
     this.path = path;
 }
Exemple #42
0
        private void DrawPathInternal(SKCanvas canvas, SKPaint brush, SKPaint pen, bool isStroked, bool isFilled, SKPath path)
        {
            if (isFilled)
            {
                canvas.DrawPath(path, brush);
            }

            if (isStroked)
            {
                canvas.DrawPath(path, pen);
            }
        }
Exemple #43
0
 public void SetPath(SKPath path, bool forceClosed)
 {
     SkiaApi.sk_pathmeasure_set_path(Handle, path == null ? IntPtr.Zero : path.Handle, forceClosed);
 }
Exemple #44
0
        /// <inheritdoc/>
        public override void Draw(object dc, XArc arc, double dx, double dy, ImmutableArray<XProperty> db, XRecord r)
        {
            var canvas = dc as SKCanvas;

            using (SKPaint brush = ToSKPaintBrush(arc.Style.Fill))
            using (SKPaint pen = ToSKPaintPen(arc.Style, _scaleToPage, _sourceDpi, _targetDpi))
            using (var path = new SKPath())
            {
                var a = GdiArc.FromXArc(arc);
                var rect = new SKRect(
                    _scaleToPage(a.X + dx),
                    _scaleToPage(a.Y + dy),
                    _scaleToPage(a.X + dx + a.Width),
                    _scaleToPage(a.Y + dy + a.Height));
                path.AddArc(rect, (float)a.StartAngle, (float)a.SweepAngle);
                DrawPathInternal(canvas, brush, pen, arc.IsStroked, arc.IsFilled, path);
            }
        }
Exemple #45
0
 public void DrawText(IntPtr buffer, int length, SKPath path, float hOffset, float vOffset, SKPaint paint)
 {
     DrawTextOnPath(buffer, length, path, hOffset, vOffset, paint);
 }
Exemple #46
0
        /// <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);
            }
        }
Exemple #47
0
		public bool QuickReject (SKPath path)
		{
			if (path == null)
				throw new ArgumentNullException (nameof (path));
			return path.IsEmpty || QuickReject (path.Bounds);
		}
Exemple #48
0
 public static void FillPath(SKCanvas g, SKPath p, SKPaint fill)
 {
     g.DrawPath(p, fill);
 }
		public bool GetSegment (float start, float stop, SKPath dst, bool startWithMoveTo)
		{
			if (dst == null)
				throw new ArgumentNullException (nameof (dst));
			return SkiaApi.sk_pathmeasure_get_segment (Handle, start, stop, dst.Handle, startWithMoveTo);
		}
Exemple #50
0
 public static void DrawPath(SKCanvas g, SKPath p, SKPaint stroke)
 {
     g.DrawPath(p, stroke);
 }
        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);
        }
Exemple #52
0
 public static SKPathEffect Create1DPath(SKPath path, float advance, float phase, SkPath1DPathEffectStyle style)
 {
     return(Create1DPath(path, advance, phase, (SKPath1DPathEffectStyle)style));
 }
Exemple #53
0
        public void ClipPath(SKPath path, SKRegionOperation operation = SKRegionOperation.Intersect, bool antialias = false)
        {
            if (path == null)
                throw new ArgumentNullException (nameof (path));

            SkiaApi.sk_canvas_clip_path_with_operation (Handle, path.Handle, operation, antialias);
        }
Exemple #54
0
 public void DrawTextOnPath(string text, SKPath path, float hOffset, float vOffset, SKPaint paint)
 {
     DrawTextOnPath(text, path, new SKPoint(hOffset, vOffset), true, paint);
 }
Exemple #55
0
        public void DrawText(IntPtr buffer, int length, SKPath path, float hOffset, float vOffset, SKPaint paint)
        {
            if (buffer == IntPtr.Zero)
                throw new ArgumentNullException ("buffer");
            if (paint == null)
                throw new ArgumentNullException (nameof (paint));
            if (paint == null)
                throw new ArgumentNullException (nameof (paint));

            SkiaApi.sk_canvas_draw_text_on_path (Handle, buffer, length, path.Handle, hOffset, vOffset, paint.Handle);
        }
                #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);
                }
            }
        }
Exemple #57
0
		public static SKPathEffect Create1DPath(SKPath path, float advance, float phase, SKPath1DPathEffectStyle style)
		{
			if (path == null)
				throw new ArgumentNullException(nameof(path));
			return GetObject<SKPathEffect>(SkiaApi.sk_path_effect_create_1d_path(path.Handle, advance, phase, style));
		}
Exemple #58
0
 public void DrawTextOnPath(IntPtr buffer, int length, SKPath path, SKPoint offset, SKPaint paint)
 {
     DrawTextOnPath(buffer, length, path, offset.X, offset.Y, paint);
 }
Exemple #59
0
		public static SKPathEffect Create2DPath(SKMatrix matrix, SKPath path)
		{
			if (path == null)
				throw new ArgumentNullException(nameof(path));
			return GetObject<SKPathEffect>(SkiaApi.sk_path_effect_create_2d_path(ref matrix, path.Handle));
		}
Exemple #60
0
 public static SKTextBlob CreatePathPositioned(ReadOnlySpan <byte> text, SKTextEncoding encoding, SKFont font, SKPath path, SKTextAlign textAlign = SKTextAlign.Left, SKPoint origin = default)
 {
     fixed(void *t = text)
     {
         return(CreatePathPositioned(t, text.Length, encoding, font, path, textAlign, origin));
     }
 }