Exemple #1
0
        /// <inheritdoc/>
        public string ToSvgPathData(IBaseShape shape)
        {
            var path = PathGeometryConverter.ToSKPath(shape);

            if (path == null)
            {
                return(null);
            }
            return(path.ToSvgPathData());
        }
Exemple #2
0
        /// <inheritdoc/>
        public IPathShape Op(IEnumerable <IBaseShape> shapes, PathOp op)
        {
            if (shapes == null || shapes.Count() <= 0)
            {
                return(null);
            }

            var paths = new List <SKPath>();

            foreach (var s in shapes)
            {
                var path = PathGeometryConverter.ToSKPath(s, 0.0, 0.0, (value) => (float)value);
                if (path != null)
                {
                    paths.Add(path);
                }
            }

            if (paths == null || paths.Count <= 0)
            {
                return(null);
            }

            PathGeometryConverter.Op(paths, PathGeometryConverter.ToSKPathOp(op), out var result, out var haveResult);
            if (haveResult == false || result == null || result.IsEmpty)
            {
                return(null);
            }

            var editor  = _serviceProvider.GetService <IProjectEditor>();
            var factory = _serviceProvider.GetService <IFactory>();
            var shape   = shapes.FirstOrDefault();
            var style   = shape.Style != null ?
                          (IShapeStyle)shape.Style?.Copy(null) :
                          factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName);
            var geometry  = PathGeometryConverter.ToPathGeometry(result, 0.0, 0.0, factory);
            var pathShape = factory.CreatePathShape(
                "Path",
                style,
                geometry,
                shape.IsStroked,
                shape.IsFilled);

            result.Dispose();
            return(pathShape);
        }
Exemple #3
0
        /// <inheritdoc/>
        public IPathShape ToPathShape(IBaseShape shape)
        {
            var factory = _serviceProvider.GetService <IFactory>();
            var style   = shape.Style != null ?
                          (IShapeStyle)shape.Style?.Copy(null) :
                          factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName);
            var path      = PathGeometryConverter.ToSKPath(shape, 0.0, 0.0, (value) => (float)value);
            var geometry  = PathGeometryConverter.ToPathGeometry(path, 0.0, 0.0, factory);
            var pathShape = factory.CreatePathShape(
                "Path",
                style,
                geometry,
                shape.IsStroked,
                shape.IsFilled);

            return(pathShape);
        }
Exemple #4
0
        /// <inheritdoc/>
        public IPathShape ToPathShape(IEnumerable <IBaseShape> shapes)
        {
            var editor  = _serviceProvider.GetService <IProjectEditor>();
            var factory = _serviceProvider.GetService <IFactory>();
            var first   = shapes.FirstOrDefault();
            var style   = first.Style != null ?
                          (IShapeStyle)first.Style?.Copy(null) :
                          factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName);
            var path      = PathGeometryConverter.ToSKPath(shapes, 0.0, 0.0, (value) => (float)value);
            var geometry  = PathGeometryConverter.ToPathGeometry(path, 0.0, 0.0, factory);
            var pathShape = factory.CreatePathShape(
                "Path",
                style,
                geometry,
                first.IsStroked,
                first.IsFilled);

            return(pathShape);
        }
Exemple #5
0
        /// <inheritdoc/>
        public IPathShape FromSvgPathData(string svgPath, bool isStroked, bool isFilled)
        {
            var path = SKPath.ParseSvgPathData(svgPath);

            if (path == null)
            {
                return(null);
            }
            var factory   = _serviceProvider.GetService <IFactory>();
            var style     = factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName);
            var geometry  = PathGeometryConverter.ToPathGeometry(path, factory);
            var pathShape = factory.CreatePathShape(
                "Path",
                style,
                geometry,
                isStroked,
                isFilled);

            return(pathShape);
        }
        private void FromDrawablePath(DrawablePath drawablePath, IList <IBaseShape> shapes, IFactory factory)
        {
            var path = drawablePath.Path;

            if (path == null)
            {
                return;
            }
            var stroke    = drawablePath.Stroke;
            var fill      = drawablePath.Fill;
            var style     = factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName);
            var geometry  = PathGeometryConverter.ToPathGeometry(path, 0.0, 0.0, factory);
            var pathShape = factory.CreatePathShape(
                "Path",
                style,
                geometry,
                stroke != null,
                fill != null);

            shapes.Add(pathShape);
        }
Exemple #7
0
        /// <inheritdoc/>
        public IPathShape ToStrokePathShape(IBaseShape shape)
        {
            var path = PathGeometryConverter.ToSKPath(shape, 0.0, 0.0, (value) => (float)value);

            if (path == null)
            {
                return(null);
            }
            var factory = _serviceProvider.GetService <IFactory>();
            var style   = shape.Style != null ?
                          (IShapeStyle)shape.Style?.Copy(null) :
                          factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName);
            var stroke = (IColor)style.Stroke.Copy(null);
            var fill   = (IColor)style.Fill.Copy(null);

            style.Stroke  = fill;
            style.Fill    = stroke;
            using var pen = new SKPaint();
            SkiaSharpRenderer.ToSKPaintPen(style, (value) => (float)value, 96.0, 96.0, true, pen);
            var result = pen.GetFillPath(path, 1.0f);

            if (result != null)
            {
                if (result.IsEmpty)
                {
                    result.Dispose();
                    return(null);
                }
                var geometry  = PathGeometryConverter.ToPathGeometry(result, 0.0, 0.0, factory);
                var pathShape = factory.CreatePathShape(
                    "Path",
                    style,
                    geometry,
                    true,
                    false);
                result.Dispose();
                return(pathShape);
            }
            return(null);
        }
Exemple #8
0
        /// <inheritdoc/>
        public IPathShape ToWindingPathShape(IBaseShape shape)
        {
            var path = PathGeometryConverter.ToSKPath(shape);

            if (path == null)
            {
                return(null);
            }
            var result  = path.ToWinding();
            var factory = _serviceProvider.GetService <IFactory>();
            var style   = shape.Style != null ?
                          (IShapeStyle)shape.Style?.Copy(null) :
                          factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName);
            var geometry  = PathGeometryConverter.ToPathGeometry(result, factory);
            var pathShape = factory.CreatePathShape(
                "Path",
                style,
                geometry,
                shape.IsStroked,
                shape.IsFilled);

            return(pathShape);
        }
Exemple #9
0
        /// <inheritdoc/>
        public IPathShape ToFillPathShape(IBaseShape shape)
        {
            var path = PathGeometryConverter.ToSKPath(shape, 0.0, 0.0, (value) => (float)value);

            if (path == null)
            {
                return(null);
            }
            var editor  = _serviceProvider.GetService <IProjectEditor>();
            var factory = _serviceProvider.GetService <IFactory>();
            var style   = shape.Style != null ?
                          (IShapeStyle)shape.Style?.Copy(null) :
                          factory.CreateShapeStyle(ProjectEditorConfiguration.DefaulStyleName);

            using var paint = SkiaSharpRenderer.ToSKPaintBrush(shape.Style.Fill, true);
            var result = paint.GetFillPath(path, 1.0f);

            if (result != null)
            {
                if (result.IsEmpty)
                {
                    result.Dispose();
                    return(null);
                }
                var geometry  = PathGeometryConverter.ToPathGeometry(result, 0.0, 0.0, factory);
                var pathShape = factory.CreatePathShape(
                    "Path",
                    style,
                    geometry,
                    shape.IsStroked,
                    shape.IsFilled);
                result.Dispose();
                return(pathShape);
            }
            return(null);
        }