Refactor custom drawing operation.
This commit is contained in:
@@ -65,7 +65,9 @@ namespace QuestPDF.Previewer
|
||||
if (_renderer.Picture == null)
|
||||
return;
|
||||
|
||||
context.Custom(new SkPictureRenderOperation(_renderer.Picture, new Rect(0, 0, Bounds.Width, Bounds.Height)));
|
||||
context.Custom(new SkCustomDrawOperation(
|
||||
new Rect(0, 0, Bounds.Width, Bounds.Height),
|
||||
c => c.DrawPicture(_renderer.Picture)));
|
||||
}
|
||||
|
||||
internal void InvalidateDocument()
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
</ExperimentalAcrylicBorder.Material>
|
||||
</ExperimentalAcrylicBorder>
|
||||
|
||||
<Grid Margin="0,40,0,0">
|
||||
<Grid Margin="10,40,10,0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="40"/>
|
||||
<RowDefinition Height="*"/>
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
using Avalonia;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using QuestPDF.Fluent;
|
||||
using QuestPDF.Infrastructure;
|
||||
|
||||
namespace QuestPDF.Previewer
|
||||
@@ -27,7 +25,7 @@ namespace QuestPDF.Previewer
|
||||
_previewHost = this.FindControl<PreviewerControl>("PreviewerSurface");
|
||||
|
||||
this.FindControl<Button>("GeneratePdf")
|
||||
.Click += (_, __) => _ = PreviewerUtils.SavePdfWithDialog(Document, this);
|
||||
.Click += (_, _) => _ = PreviewerUtils.SavePdfWithDialog(Document, this);
|
||||
|
||||
DocumentProperty.Changed.Subscribe(v => _previewHost.Document = v.NewValue.Value);
|
||||
HotReloadManager.Register(InvalidatePreview);
|
||||
|
||||
+5
-10
@@ -6,24 +6,22 @@ using SkiaSharp;
|
||||
|
||||
namespace QuestPDF.Previewer
|
||||
{
|
||||
internal class SkPictureRenderOperation : ICustomDrawOperation
|
||||
internal sealed class SkCustomDrawOperation : ICustomDrawOperation
|
||||
{
|
||||
public SKPicture? Picture { get; }
|
||||
private readonly Action<SKCanvas> _renderFunc;
|
||||
public Rect Bounds { get; }
|
||||
|
||||
public SkPictureRenderOperation(SKPicture picture, Rect bounds)
|
||||
public SkCustomDrawOperation(Rect bounds, Action<SKCanvas> renderFunc)
|
||||
{
|
||||
Picture = picture;
|
||||
Bounds = bounds;
|
||||
_renderFunc = renderFunc;
|
||||
}
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
public bool Equals(ICustomDrawOperation? other)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool HitTest(Point p)
|
||||
{
|
||||
return false;
|
||||
@@ -31,14 +29,11 @@ namespace QuestPDF.Previewer
|
||||
|
||||
public void Render(IDrawingContextImpl context)
|
||||
{
|
||||
if (Picture == null)
|
||||
return;
|
||||
|
||||
var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas;
|
||||
if (canvas == null)
|
||||
throw new InvalidOperationException($"Context needs to be ISkiaDrawingContextImpl but got {nameof(context)}");
|
||||
|
||||
canvas.DrawPicture(Picture);
|
||||
_renderFunc(canvas);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user