예제 #1
0
        /// <inheritdoc/>
        public void OnCopyAsSvg(object item)
        {
            try
            {
                if (item == null)
                {
                    var editor    = _serviceProvider.GetService <IProjectEditor>();
                    var exporter  = new SvgSvgExporter(_serviceProvider);
                    var container = editor.Project.CurrentContainer;

                    var source = editor.PageState?.SelectedShape;
                    if (source != null)
                    {
                        var xaml = exporter.Create(source, container.Width, container.Height);
                        if (!string.IsNullOrEmpty(xaml))
                        {
                            editor.TextClipboard?.SetText(xaml);
                        }
                        return;
                    }

                    var sources = editor.PageState?.SelectedShapes;
                    if (sources != null)
                    {
                        var xaml = exporter.Create(sources, container.Width, container.Height);
                        if (!string.IsNullOrEmpty(xaml))
                        {
                            editor.TextClipboard?.SetText(xaml);
                        }
                        return;
                    }

                    var shapes = container.Layers.SelectMany(x => x.Shapes);
                    if (shapes != null)
                    {
                        var xaml = exporter.Create(shapes, container.Width, container.Height);
                        if (!string.IsNullOrEmpty(xaml))
                        {
                            editor.TextClipboard?.SetText(xaml);
                        }
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                _serviceProvider.GetService <ILog>()?.LogException(ex);
            }
        }
예제 #2
0
        /// <inheritdoc/>
        public void Save(Stream stream, object item, object options)
        {
            if (item == null)
            {
                return;
            }

            var ic = options as IImageCache;

            if (options == null)
            {
                return;
            }

            var exporter = new SvgSvgExporter(_serviceProvider);

            if (item is IPageContainer page)
            {
                var dataFlow = _serviceProvider.GetService <IDataFlow>();
                var db       = (object)page.Data.Properties;
                var record   = (object)page.Data.Record;

                dataFlow.Bind(page.Template, db, record);
                dataFlow.Bind(page, db, record);

                var shapes = page.Layers.SelectMany(x => x.Shapes);
                if (shapes != null)
                {
                    var xaml = exporter.Create(shapes, page.Width, page.Height);
                    if (!string.IsNullOrEmpty(xaml))
                    {
                        byte[] bytes = Encoding.UTF8.GetBytes(xaml);
                        stream.Write(bytes, 0, bytes.Length);
                    }
                }
            }
            else if (item is IDocumentContainer document)
            {
                throw new NotSupportedException("Saving documents as svg drawing is not supported.");
            }
            else if (item is IProjectContainer project)
            {
                throw new NotSupportedException("Saving projects as svg drawing is not supported.");
            }
        }