示例#1
0
 public void Save(Stream stream, PageContainerViewModel container)
 {
     using var pictureRecorder = new SKPictureRecorder();
     using var canvas          = pictureRecorder.BeginRecording(SKRect.Create(0, 0, (int)container.Template.Width, (int)container.Template.Height));
     _presenter.Render(canvas, _renderer, null, container, 0, 0);
     using var picture = pictureRecorder.EndRecording();
     picture.Serialize(stream);
 }
示例#2
0
        public void Save(Stream stream, PageContainerViewModel container)
        {
            var presenter = new ExportPresenter();

            using var pdf = new PdfDocument();
            Add(pdf, container, presenter);
            pdf.Save(stream);
        }
示例#3
0
        public void Save(Stream stream, PageContainerViewModel container)
        {
            var info = new SKImageInfo((int)container.Template.Width, (int)container.Template.Height, SKImageInfo.PlatformColorType, SKAlphaType.Unpremul);

            using var bitmap = new SKBitmap(info);
            using (var canvas = new SKCanvas(bitmap))
            {
                canvas.Clear();
                _presenter.Render(canvas, _renderer, null, container, 0, 0);
            }
            using var image = SKImage.FromBitmap(bitmap);
            using var data  = image.Encode(SKEncodedImageFormat.Png, 100);
            data.SaveTo(stream);
        }
示例#4
0
    public override object Copy(IDictionary <object, object>?shared)
    {
        var styleLibraries = _styleLibraries.CopyShared(shared).ToImmutable();
        var groupLibraries = _groupLibraries.CopyShared(shared).ToImmutable();
        var databases      = _databases.CopyShared(shared).ToImmutable();
        var templates      = _templates.CopyShared(shared).ToImmutable();
        var scripts        = _scripts.CopyShared(shared).ToImmutable();
        var documents      = _documents.CopyShared(shared).ToImmutable();

        var currentStyleLibrary = _currentStyleLibrary.GetCurrentItem(ref _styleLibraries, ref styleLibraries);
        var currentGroupLibrary = _currentGroupLibrary.GetCurrentItem(ref _styleLibraries, ref styleLibraries);
        var currentDatabase     = _currentDatabase.GetCurrentItem(ref _databases, ref databases);
        var currentTemplate     = _currentTemplate.GetCurrentItem(ref _templates, ref templates);
        var currentScript       = _currentScript.GetCurrentItem(ref _scripts, ref scripts);
        var currentDocument     = _currentDocument.GetCurrentItem(ref _documents, ref documents);
        var currentContainer    = _currentContainer switch
        {
            PageContainerViewModel page => page.GetCurrentItem(ref _documents, ref documents, x => x.Pages),
            TemplateContainerViewModel template => template.GetCurrentItem(ref _templates, ref templates),
            _ => default(FrameContainerViewModel?)
        };

        var copy = new ProjectContainerViewModel(ServiceProvider)
        {
            Options             = _options?.CopyShared(shared),
            StyleLibraries      = styleLibraries,
            GroupLibraries      = groupLibraries,
            Databases           = databases,
            Templates           = templates,
            Scripts             = scripts,
            Documents           = documents,
            CurrentStyleLibrary = currentStyleLibrary,
            CurrentGroupLibrary = currentGroupLibrary,
            CurrentDatabase     = currentDatabase,
            CurrentTemplate     = currentTemplate,
            CurrentScript       = currentScript,
            CurrentDocument     = currentDocument,
            CurrentContainer    = currentContainer
        };

        if (_selected is { } && shared is { })
示例#5
0
        private PdfPage Add(PdfDocument pdf, PageContainerViewModel container, IContainerPresenter presenter)
        {
            // Create A3 page size with Landscape orientation.
            var pdfPage = pdf.AddPage();

            pdfPage.Size        = PageSize.A3;
            pdfPage.Orientation = PageOrientation.Landscape;

            var dataFlow = _serviceProvider.GetService <DataFlow>();
            var db       = (object)container.Properties;
            var record   = (object)container.Record;

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

            using (XGraphics gfx = XGraphics.FromPdfPage(pdfPage))
            {
                // Calculate x and y page scale factors.
                double scaleX = pdfPage.Width.Value / container.Template.Width;
                double scaleY = pdfPage.Height.Value / container.Template.Height;
                double scale  = Math.Min(scaleX, scaleY);

                // Set scaling function.
                _scaleToPage = (value) => value * scale;

                // Draw container template contents to pdf graphics.
                Fill(gfx, 0, 0, pdfPage.Width.Value / scale, pdfPage.Height.Value / scale, container.Template.Background);


                // Draw template contents to pdf graphics.
                presenter.Render(gfx, this, null, container.Template, 0, 0);

                // Draw page contents to pdf graphics.
                presenter.Render(gfx, this, null, container, 0, 0);
            }

            return(pdfPage);
        }
示例#6
0
    public override object Copy(IDictionary <object, object>?shared)
    {
        var layers       = _layers.CopyShared(shared).ToImmutable();
        var currentLayer = _currentLayer.GetCurrentItem(ref _layers, ref layers);
        var currentShape = _currentShape.GetCurrentItem(ref _layers, ref layers, x => x.Shapes);
        var properties   = _properties.CopyShared(shared).ToImmutable();

        var copy = new PageContainerViewModel(ServiceProvider)
        {
            Name         = Name,
            IsVisible    = IsVisible,
            IsExpanded   = IsExpanded,
            Layers       = layers,
            CurrentLayer = currentLayer,
            WorkingLayer = _workingLayer?.CopyShared(shared),
            HelperLayer  = _helperLayer?.CopyShared(shared),
            CurrentShape = currentShape,
            Properties   = properties,
            Record       = _record,
            Template     = _template?.CopyShared(shared)
        };

        return(copy);
    }
示例#7
0
 public void Save(Stream stream, PageContainerViewModel container)
 {
     using var wstream = new SKManagedWStream(stream);
     using var canvas  = SKSvgCanvas.Create(SKRect.Create(0, 0, (int)container.Template.Width, (int)container.Template.Height), stream);
     _presenter.Render(canvas, _renderer, null, container, 0, 0);
 }
 public void Save(Stream stream, PageContainerViewModel container)
 {
     using var pdf = SKDocument.CreatePdf(stream, _targetDpi);
     Add(pdf, container);
     pdf.Close();
 }
 private void Add(SKDocument pdf, PageContainerViewModel container)
 {
     using var canvas = pdf.BeginPage((float)container.Template.Width, (float)container.Template.Height);
     _presenter.Render(canvas, _renderer, null, container, 0, 0);
 }
示例#10
0
 public void Save(Stream stream, PageContainerViewModel container, IImageCache ic)
 {
     if (container?.Template is { })