Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="gfx"></param>
        /// <param name="arc"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object gfx, XArc arc, double dx, double dy, ImmutableArray <ShapeProperty> db, Record r)
        {
            var a = GdiArc.FromXArc(arc, dx, dy);

            if (a.Width <= 0.0 || a.Height <= 0.0)
            {
                return;
            }

            var _gfx = gfx as Graphics;

            Brush brush = ToSolidBrush(arc.Style.Fill);
            Pen   pen   = ToPen(arc.Style, _scaleToPage);

            if (arc.IsFilled)
            {
                var path = new GraphicsPath();
                path.AddArc(
                    _scaleToPage(a.X),
                    _scaleToPage(a.Y),
                    _scaleToPage(a.Width),
                    _scaleToPage(a.Height),
                    (float)a.StartAngle,
                    (float)a.SweepAngle);

                _gfx.FillPath(brush, path);

                if (arc.IsStroked)
                {
                    _gfx.DrawPath(pen, path);
                }

                path.Dispose();
            }
            else
            {
                if (arc.IsStroked)
                {
                    _gfx.DrawArc(
                        pen,
                        _scaleToPage(a.X),
                        _scaleToPage(a.Y),
                        _scaleToPage(a.Width),
                        _scaleToPage(a.Height),
                        (float)a.StartAngle,
                        (float)a.SweepAngle);
                }
            }

            brush.Dispose();
            pen.Dispose();
        }
Пример #2
0
        /// <inheritdoc/>
        public override void Draw(object dc, XArc arc, double dx, double dy, ImmutableArray <XProperty> db, XRecord r)
        {
            var a = new GdiArc(
                Point2.FromXY(arc.Point1.X, arc.Point1.Y),
                Point2.FromXY(arc.Point2.X, arc.Point2.Y),
                Point2.FromXY(arc.Point3.X, arc.Point3.Y),
                Point2.FromXY(arc.Point4.X, arc.Point4.Y));

            if (a.Width <= 0.0 || a.Height <= 0.0)
            {
                return;
            }

            var _gfx = dc as Graphics;

            Brush brush = ToSolidBrush(arc.Style.Fill);
            Pen   pen   = ToPen(arc.Style, _scaleToPage);

            if (arc.IsFilled)
            {
                var path = new GraphicsPath();
                path.AddArc(
                    _scaleToPage(a.X + dx),
                    _scaleToPage(a.Y + dy),
                    _scaleToPage(a.Width),
                    _scaleToPage(a.Height),
                    (float)a.StartAngle,
                    (float)a.SweepAngle);
                _gfx.FillPath(brush, path);
            }

            if (arc.IsStroked)
            {
                _gfx.DrawArc(
                    pen,
                    _scaleToPage(a.X + dx),
                    _scaleToPage(a.Y + dy),
                    _scaleToPage(a.Width),
                    _scaleToPage(a.Height),
                    (float)a.StartAngle,
                    (float)a.SweepAngle);
            }

            brush.Dispose();
            pen.Dispose();
        }
Пример #3
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, dx, dy);
                        var rect = new SKRect(
                            _scaleToPage(a.X),
                            _scaleToPage(a.Y),
                            _scaleToPage(a.X + a.Width),
                            _scaleToPage(a.Y + a.Height));
                        path.AddArc(rect, (float)a.StartAngle, (float)a.SweepAngle);
                        DrawPathInternal(canvas, brush, pen, arc.IsStroked, arc.IsFilled, path);
                    }
        }
Пример #4
0
        /// <inheritdoc/>
        public override void Draw(object dc, ArcShape arc, double dx, double dy, object db, object 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 = new GdiArc(
                            Point2.FromXY(arc.Point1.X, arc.Point1.Y),
                            Point2.FromXY(arc.Point2.X, arc.Point2.Y),
                            Point2.FromXY(arc.Point3.X, arc.Point3.Y),
                            Point2.FromXY(arc.Point4.X, arc.Point4.Y));
                        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);
                    }
        }
Пример #5
0
        public static SKPath ToSKPath(this IEnumerable <IBaseShape> shapes, double dx, double dy, Func <double, float> scale)
        {
            var path = new SKPath
            {
                FillType = SKPathFillType.Winding
            };
            var previous = default(IPointShape);

            foreach (var shape in shapes)
            {
                switch (shape)
                {
                case ILineShape lineShape:
                {
                    if (previous == null || previous != lineShape.Start)
                    {
                        path.MoveTo(
                            scale(lineShape.Start.X + dx),
                            scale(lineShape.Start.Y + dy));
                    }
                    path.LineTo(
                        scale(lineShape.End.X + dx),
                        scale(lineShape.End.Y + dy));
                    previous = lineShape.End;
                }
                break;

                case IRectangleShape rectangleShape:
                {
                    path.AddRect(
                        SkiaSharpRenderer.CreateRect(rectangleShape.TopLeft, rectangleShape.BottomRight, dx, dy, scale),
                        SKPathDirection.Clockwise);
                }
                break;

                case IEllipseShape ellipseShape:
                {
                    path.AddOval(
                        SkiaSharpRenderer.CreateRect(ellipseShape.TopLeft, ellipseShape.BottomRight, dx, dy, scale),
                        SKPathDirection.Clockwise);
                }
                break;

                case IArcShape arcShape:
                {
                    var a = new GdiArc(
                        Point2.FromXY(arcShape.Point1.X, arcShape.Point1.Y),
                        Point2.FromXY(arcShape.Point2.X, arcShape.Point2.Y),
                        Point2.FromXY(arcShape.Point3.X, arcShape.Point3.Y),
                        Point2.FromXY(arcShape.Point4.X, arcShape.Point4.Y));
                    var rect = new SKRect(
                        scale(a.X + dx),
                        scale(a.Y + dy),
                        scale(a.X + dx + a.Width),
                        scale(a.Y + dy + a.Height));
                    path.AddArc(rect, (float)a.StartAngle, (float)a.SweepAngle);
                }
                break;

                case ICubicBezierShape cubicBezierShape:
                {
                    if (previous == null || previous != cubicBezierShape.Point1)
                    {
                        path.MoveTo(
                            scale(cubicBezierShape.Point1.X + dx),
                            scale(cubicBezierShape.Point1.Y + dy));
                    }
                    path.CubicTo(
                        scale(cubicBezierShape.Point2.X + dx),
                        scale(cubicBezierShape.Point2.Y + dy),
                        scale(cubicBezierShape.Point3.X + dx),
                        scale(cubicBezierShape.Point3.Y + dy),
                        scale(cubicBezierShape.Point4.X + dx),
                        scale(cubicBezierShape.Point4.Y + dy));
                    previous = cubicBezierShape.Point4;
                }
                break;

                case IQuadraticBezierShape quadraticBezierShape:
                {
                    if (previous == null || previous != quadraticBezierShape.Point1)
                    {
                        path.MoveTo(
                            scale(quadraticBezierShape.Point1.X + dx),
                            scale(quadraticBezierShape.Point1.Y + dy));
                    }
                    path.QuadTo(
                        scale(quadraticBezierShape.Point2.X + dx),
                        scale(quadraticBezierShape.Point2.Y + dy),
                        scale(quadraticBezierShape.Point3.X + dx),
                        scale(quadraticBezierShape.Point3.Y + dy));
                    previous = quadraticBezierShape.Point3;
                }
                break;

                case ITextShape textShape:
                {
                    var resultPath = ToSKPath(textShape, dx, dy, scale);
                    if (resultPath != null && !resultPath.IsEmpty)
                    {
                        path.AddPath(resultPath, SKPathAddMode.Append);
                    }
                }
                break;

                case IPathShape pathShape:
                {
                    var resultPath = ToSKPath(pathShape, dx, dy, scale);
                    if (resultPath != null && !resultPath.IsEmpty)
                    {
                        path.AddPath(resultPath, SKPathAddMode.Append);
                    }
                }
                break;

                case IGroupShape groupShape:
                {
                    var resultPath = ToSKPath(groupShape.Shapes, dx, dy, scale);
                    if (resultPath != null && !resultPath.IsEmpty)
                    {
                        path.AddPath(resultPath, SKPathAddMode.Append);
                    }
                }
                break;
                }
            }
            return(path);
        }
Пример #6
0
    public static SKPath ToSKPath(this IEnumerable <BaseShapeViewModel> shapes)
    {
        var path = new SKPath
        {
            FillType = SKPathFillType.Winding
        };
        var previous = default(PointShapeViewModel);

        foreach (var shape in shapes)
        {
            switch (shape)
            {
            case LineShapeViewModel lineShape:
            {
                if (previous is null || previous != lineShape.Start)
                {
                    path.MoveTo(
                        (float)(lineShape.Start.X),
                        (float)(lineShape.Start.Y));
                }
                path.LineTo(
                    (float)(lineShape.End.X),
                    (float)(lineShape.End.Y));
                previous = lineShape.End;
            }
            break;

            case RectangleShapeViewModel rectangleShape:
            {
                path.AddRect(
                    SkiaSharpDrawUtil.CreateRect(rectangleShape.TopLeft, rectangleShape.BottomRight),
                    SKPathDirection.Clockwise);
            }
            break;

            case EllipseShapeViewModel ellipseShape:
            {
                path.AddOval(
                    SkiaSharpDrawUtil.CreateRect(ellipseShape.TopLeft, ellipseShape.BottomRight),
                    SKPathDirection.Clockwise);
            }
            break;

            case ArcShapeViewModel arcShape:
            {
                var a = new GdiArc(
                    Point2.FromXY(arcShape.Point1.X, arcShape.Point1.Y),
                    Point2.FromXY(arcShape.Point2.X, arcShape.Point2.Y),
                    Point2.FromXY(arcShape.Point3.X, arcShape.Point3.Y),
                    Point2.FromXY(arcShape.Point4.X, arcShape.Point4.Y));
                var rect = new SKRect(
                    (float)(a.X),
                    (float)(a.Y),
                    (float)(a.X + a.Width),
                    (float)(a.Y + a.Height));
                path.AddArc(rect, (float)a.StartAngle, (float)a.SweepAngle);
            }
            break;

            case CubicBezierShapeViewModel cubicBezierShape:
            {
                if (previous is null || previous != cubicBezierShape.Point1)
                {
                    path.MoveTo(
                        (float)(cubicBezierShape.Point1.X),
                        (float)(cubicBezierShape.Point1.Y));
                }
                path.CubicTo(
                    (float)(cubicBezierShape.Point2.X),
                    (float)(cubicBezierShape.Point2.Y),
                    (float)(cubicBezierShape.Point3.X),
                    (float)(cubicBezierShape.Point3.Y),
                    (float)(cubicBezierShape.Point4.X),
                    (float)(cubicBezierShape.Point4.Y));
                previous = cubicBezierShape.Point4;
            }
            break;

            case QuadraticBezierShapeViewModel quadraticBezierShape:
            {
                if (previous is null || previous != quadraticBezierShape.Point1)
                {
                    path.MoveTo(
                        (float)(quadraticBezierShape.Point1.X),
                        (float)(quadraticBezierShape.Point1.Y));
                }
                path.QuadTo(
                    (float)(quadraticBezierShape.Point2.X),
                    (float)(quadraticBezierShape.Point2.Y),
                    (float)(quadraticBezierShape.Point3.X),
                    (float)(quadraticBezierShape.Point3.Y));
                previous = quadraticBezierShape.Point3;
            }
            break;

            case TextShapeViewModel textShape:
            {
                var resultPath = ToSKPath(textShape);
                if (resultPath is { } && !resultPath.IsEmpty)
                {
                    path.AddPath(resultPath, SKPathAddMode.Append);
                }
            }
            break;