Native SkiaSharp shape renderer.
Inheritance: Core2D.Renderer.ShapeRenderer
Esempio n. 1
0
        /// <inheritdoc/>
        void IFileWriter.Save(string path, object item, object options)
        {
            if (string.IsNullOrEmpty(path) || item == null)
                return;

            var ic = options as IImageCache;
            if (options == null)
                return;

            var renderer = new SkiaRenderer(true, 96.0);
            renderer.State.DrawShapeState.Flags = ShapeStateFlags.Printable;
            renderer.State.ImageCache = ic;

            var presenter = new ExportPresenter();

            IProjectExporter exporter = new SvgExporter(renderer, presenter);

            if (item is XContainer)
            {
                exporter.Save(path, item as XContainer);
            }
            else if (item is XDocument)
            {
                throw new NotSupportedException("Saving documents as svg drawing is not supported.");
            }
            else if (item is XProject)
            {
                throw new NotSupportedException("Saving projects as svg drawing is not supported.");
            }
        }
Esempio n. 2
0
        /// <inheritdoc/>
        void IFileWriter.Save(string path, object item, object options)
        {
            if (string.IsNullOrEmpty(path) || item == null)
                return;

            var ic = options as IImageCache;
            if (options == null)
                return;

            ShapeRenderer renderer = new SkiaRenderer(true, 72.0);
            renderer.State.DrawShapeState.Flags = ShapeStateFlags.Printable;
            renderer.State.ImageCache = ic;

            var presenter = new ExportPresenter();

            IProjectExporter exporter = new PdfExporter(renderer, presenter, 72.0f);

            if (item is XContainer)
            {
                exporter.Save(path, item as XContainer);
            }
            else if (item is XDocument)
            {
                exporter.Save(path, item as XDocument);
            }
            else if (item is XProject)
            {
                exporter.Save(path, item as XProject);
            }
        }
Esempio n. 3
0
        private void UpdateSvg()
        {
            bool exportPresenter = _previewWindow.svgExport.IsChecked == true;
            bool showPrintable = _previewWindow.svgPrintable.IsChecked == true;

            Task.Factory.StartNew(() =>
            {
                try
                {
                    IImageCache ic = _projectEditor.Project;
                    var container = _projectEditor.Project.CurrentContainer;

                    var renderer = new SkiaRenderer(true, 96.0);
                    if (!showPrintable)
                    {
                        renderer.State.DrawShapeState.Flags = ShapeStateFlags.Printable;
                    }
                    renderer.State.ImageCache = _projectEditor.Project;

                    var presenter = exportPresenter ? (ContainerPresenter)new ExportPresenter() : (ContainerPresenter)new EditorPresenter();

                    using (var ms = new MemoryStream())
                    {
                        using (var stream = new SKManagedWStream(ms))
                        {
                            using (var writer = new SKXmlStreamWriter(stream))
                            using (var canvas = SKSvgCanvas.Create(SKRect.Create(0, 0, (int)container.Width, (int)container.Height), writer))
                            {
                                presenter.Render(canvas, renderer, container, 0, 0);
                            }
                            stream.Flush();
                        }

                        var svg = Encoding.ASCII.GetString(ms.GetBuffer(), 0, (int)ms.Length);

                        Dispatcher.Invoke(() =>
                        {
                            _previewWindow.svgText.Text = svg;
                        });
                    }
                }
                catch (Exception) { }
            });
        }