Files
QuestPDF/QuestPDF.Previewer/PreviewerPageControl.cs
T
Bebo-Maker ea2102fe4c WIP Implemented virtualization of pages.
Render pages into seperate SKPictures
2022-03-19 17:26:58 +01:00

45 lines
1.3 KiB
C#

using System.Reactive.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
namespace QuestPDF.Previewer
{
internal class PreviewerPageControl : Control
{
public static readonly StyledProperty<RenderedPageInfo?> PageProperty =
AvaloniaProperty.Register<PreviewerPageControl, RenderedPageInfo?>(nameof(Page));
public RenderedPageInfo? Page
{
get => GetValue(PageProperty);
set => SetValue(PageProperty, value);
}
public PreviewerPageControl()
{
PageProperty.Changed.Take(1).Subscribe(p =>
{
var size = p.NewValue.Value?.Size ?? Infrastructure.Size.Zero;
Width = size.Width;
Height = size.Height;
});
ClipToBounds = true;
}
public override void Render(DrawingContext context)
{
base.Render(context);
//context.DrawRectangle(Brushes.Red, null, new Rect(0, 0, Bounds.Width, Bounds.Height));
var picture = Page?.Picture;
if (picture != null)
context.Custom(new SkCustomDrawOperation(
new Rect(0, 0, Bounds.Width, Bounds.Height),
c => c.DrawPicture(picture)));
}
}
}