This commit is contained in:
Wiesław Šoltés 2022-02-02 10:39:22 +01:00
Родитель 15556d4335
Коммит e00b610105
11 изменённых файлов: 31 добавлений и 23 удалений

Просмотреть файл

@ -14,7 +14,7 @@ namespace Draw2D.Export
using var wstream = new SKFileWStream(path);
using var canvas = SKSvgCanvas.Create(SKRect.Create(0, 0, (int)containerView.Width, (int)containerView.Height), wstream);
using var skiaContainerPresenter = new SkiaExportContainerPresenter(context, containerView);
skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0);
skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0, 1.0);
}
internal static void ExportPdf(IToolContext context, string path, IContainerView containerView)
@ -23,7 +23,7 @@ namespace Draw2D.Export
using var pdf = SKDocument.CreatePdf(stream, SKDocument.DefaultRasterDpi);
using var canvas = pdf.BeginPage((float)containerView.Width, (float)containerView.Height);
using var skiaContainerPresenter = new SkiaExportContainerPresenter(context, containerView);
skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0);
skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0, 1.0);
pdf.Close();
}
@ -33,7 +33,7 @@ namespace Draw2D.Export
using var xps = SKDocument.CreateXps(stream, SKDocument.DefaultRasterDpi);
using var canvas = xps.BeginPage((float)containerView.Width, (float)containerView.Height);
using var skiaContainerPresenter = new SkiaExportContainerPresenter(context, containerView);
skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0);
skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0, 1.0);
xps.Close();
}
@ -44,7 +44,7 @@ namespace Draw2D.Export
var canvas = recorder.BeginRecording(rect);
using (var skiaContainerPresenter = new SkiaExportContainerPresenter(context, containerView))
{
skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0);
skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0, 1.0);
}
var picture = recorder.EndRecording();
var dimensions = new SKSizeI((int)containerView.Width, (int)containerView.Height);
@ -67,7 +67,7 @@ namespace Draw2D.Export
using (var canvas = new SKCanvas(bitmap))
using (var skiaContainerPresenter = new SkiaExportContainerPresenter(context, containerView))
{
skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0);
skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0, 1.0);
}
using var image = SKImage.FromBitmap(bitmap);
using var data = image.Encode(format, quality);

Просмотреть файл

@ -37,12 +37,12 @@ namespace Draw2D.Export
if (containerView.SelectionState?.Shapes?.Count > 0)
{
using var skiaSelectedPresenter = new SkiaExportSelectedPresenter(context, containerView);
skiaSelectedPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0);
skiaSelectedPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0, 1.0);
}
else
{
using var skiaContainerPresenter = new SkiaExportContainerPresenter(context, containerView);
skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0);
skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0, 1.0);
}
}

Просмотреть файл

@ -203,7 +203,7 @@ namespace Draw2D.Presenters
canvas.Restore();
}
public void Draw(object context, double width, double height, double dx, double dy, double zx, double zy)
public void Draw(object context, double width, double height, double dx, double dy, double zx, double zy, double renderScaling)
{
bool isStyleLibraryDirty = _context.DocumentContainer.StyleLibrary.IsTreeDirty();
bool isCurrentContainerDirty = _view.CurrentContainer.IsTreeDirty();

Просмотреть файл

@ -20,7 +20,7 @@ namespace Draw2D.Presenters
{
}
public void Draw(object context, double width, double height, double dx, double dy, double zx, double zy)
public void Draw(object context, double width, double height, double dx, double dy, double zx, double zy, double renderScaling)
{
using var renderer = new SkiaShapeRenderer(_context, _view, _view.SelectionState);
using var disposable = new CompositeDisposable();

Просмотреть файл

@ -28,7 +28,7 @@ namespace Draw2D.Presenters
return !(shape is IPointShape || shape is FigureShape);
}
public void Draw(object context, double width, double height, double dx, double dy, double zx, double zy)
public void Draw(object context, double width, double height, double dx, double dy, double zx, double zy, double renderScaling)
{
using var renderer = new SkiaShapeRenderer(_context, _view, _view.SelectionState);
using var disposable = new CompositeDisposable();

Просмотреть файл

@ -126,9 +126,9 @@ namespace Draw2D.ViewModels.Containers
return new PointShape(x, y, context?.DocumentContainer?.PointTemplate);
}
public void Draw(object context, double width, double height, double dx, double dy, double zx, double zy)
public void Draw(object context, double width, double height, double dx, double dy, double zx, double zy, double renderScaling)
{
_containerPresenter?.Draw(context, width, height, dx, dy, zx, zy);
_containerPresenter?.Draw(context, width, height, dx, dy, zx, zy, renderScaling);
}
public void Add(IBaseShape shape)

Просмотреть файл

@ -4,6 +4,6 @@ namespace Draw2D.ViewModels.Containers
{
public interface IContainerPresenter : IDisposable
{
void Draw(object context, double width, double height, double dx, double dy, double zx, double zy);
void Draw(object context, double width, double height, double dx, double dy, double zx, double zy, double renderScaling);
}
}

Просмотреть файл

@ -1,4 +1,5 @@
using Avalonia;
using System;
using Avalonia;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Skia;
@ -12,6 +13,7 @@ namespace Draw2D.Presenters
private readonly IToolContext _context;
private readonly IContainerView _view;
private RenderTargetBitmap _renderTarget;
private double _renderScaling;
private IContainerPresenter _editorContainerPresenter;
public AvaloniaContainerPresenter(IToolContext context, IContainerView view)
@ -19,6 +21,7 @@ namespace Draw2D.Presenters
_context = context;
_view = view;
_renderTarget = null;
_renderScaling = 1.0;
_editorContainerPresenter = new SkiaEditorContainerPresenter(_context, _view);
}
@ -37,24 +40,26 @@ namespace Draw2D.Presenters
}
}
public void Draw(object context, double width, double height, double dx, double dy, double zx, double zy)
public void Draw(object context, double width, double height, double dx, double dy, double zx, double zy, double renderScaling)
{
if (context is DrawingContext drawingContext && width > 0 && height > 0)
{
if (_renderTarget == null)
{
_renderTarget = new RenderTargetBitmap(new PixelSize((int)width, (int)height), new Vector(96, 96));
_renderScaling = renderScaling;
_renderTarget = new RenderTargetBitmap(new PixelSize((int)width, (int)height), new Vector(96 * _renderScaling, 96 * _renderScaling));
}
else if (_renderTarget.PixelSize.Width != (int)width || _renderTarget.PixelSize.Height != (int)height)
else if (_renderTarget.PixelSize.Width != (int)width || _renderTarget.PixelSize.Height != (int)height || Math.Abs(_renderScaling - renderScaling) > double.Epsilon)
{
_renderScaling = renderScaling;
_renderTarget.Dispose();
_renderTarget = new RenderTargetBitmap(new PixelSize((int)width, (int)height), new Vector(96, 96));
_renderTarget = new RenderTargetBitmap(new PixelSize((int)width, (int)height), new Vector(96* _renderScaling, 96 * _renderScaling));
}
using var drawingContextImpl = _renderTarget.CreateDrawingContext(null);
var skiaDrawingContextImpl = drawingContextImpl as ISkiaDrawingContextImpl;
_editorContainerPresenter.Draw(skiaDrawingContextImpl.SkCanvas, width, height, dx, dy, zx, zy);
_editorContainerPresenter.Draw(skiaDrawingContextImpl.SkCanvas, width, height, dx, dy, zx, zy, renderScaling);
drawingContext.DrawImage(_renderTarget,
new Rect(0, 0, _renderTarget.PixelSize.Width, _renderTarget.PixelSize.Height),

Просмотреть файл

@ -110,9 +110,9 @@ namespace Draw2D.ViewModels.Tools
return _context.DocumentContainer.ContainerView.GetNextPoint(_context, x, y, connect, radius, scale, modifier);
}
public void Draw(object context, double width, double height, double dx, double dy, double zx, double zy)
public void Draw(object context, double width, double height, double dx, double dy, double zx, double zy, double renderScaling)
{
_context.DocumentContainer.ContainerView.Draw(context, width, height, dx, dy, zx, zy);
_context.DocumentContainer.ContainerView.Draw(context, width, height, dx, dy, zx, zy, renderScaling);
}
public void Add(IBaseShape shape)

Просмотреть файл

@ -5,6 +5,6 @@ namespace Core2D.UI.Zoom.Input
{
IInputService InputService { get; set; }
IZoomService ZoomService { get; set; }
void Draw(object context, double width, double height, double dx, double dy, double zx, double zy);
void Draw(object context, double width, double height, double dx, double dy, double zx, double zy, double renderScaling);
}
}

Просмотреть файл

@ -5,6 +5,7 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Media;
using Avalonia.Rendering;
using Avalonia.VisualTree;
using Core2D.UI.Zoom.Input;
@ -649,7 +650,9 @@ namespace Core2D.UI.Zoom
GetOffset(out double dx, out double dy, out double zx, out double zy);
_drawTarget.Draw(context, Bounds.Width, Bounds.Height, dx, dy, zx, zy);
var renderScaling = this.GetVisualRoot().RenderScaling;
_drawTarget.Draw(context, Bounds.Width, Bounds.Height, dx, dy, zx, zy, renderScaling);
if (_zoomServiceState.IsZooming == true)
{