|
@@ -1,9 +1,7 @@
|
|
|
-using System.Diagnostics;
|
|
|
|
|
-using Avalonia;
|
|
|
|
|
|
|
+using Avalonia;
|
|
|
using Avalonia.Platform;
|
|
using Avalonia.Platform;
|
|
|
using Avalonia.Rendering.SceneGraph;
|
|
using Avalonia.Rendering.SceneGraph;
|
|
|
using Avalonia.Skia;
|
|
using Avalonia.Skia;
|
|
|
-using QuestPDF.Helpers;
|
|
|
|
|
using SkiaSharp;
|
|
using SkiaSharp;
|
|
|
|
|
|
|
|
namespace QuestPDF.Previewer;
|
|
namespace QuestPDF.Previewer;
|
|
@@ -11,7 +9,7 @@ namespace QuestPDF.Previewer;
|
|
|
class InteractiveCanvas : ICustomDrawOperation
|
|
class InteractiveCanvas : ICustomDrawOperation
|
|
|
{
|
|
{
|
|
|
public Rect Bounds { get; set; }
|
|
public Rect Bounds { get; set; }
|
|
|
- public ICollection<RenderedPageInfo> Pages { get; set; }
|
|
|
|
|
|
|
+ public ICollection<PreviewPage> Pages { get; set; }
|
|
|
|
|
|
|
|
private float Width => (float)Bounds.Width;
|
|
private float Width => (float)Bounds.Width;
|
|
|
private float Height => (float)Bounds.Height;
|
|
private float Height => (float)Bounds.Height;
|
|
@@ -26,6 +24,8 @@ class InteractiveCanvas : ICustomDrawOperation
|
|
|
private const float PageSpacing = 50f;
|
|
private const float PageSpacing = 50f;
|
|
|
private const float SafeZone = 50f;
|
|
private const float SafeZone = 50f;
|
|
|
|
|
|
|
|
|
|
+ #region transformations
|
|
|
|
|
+
|
|
|
private void LimitScale()
|
|
private void LimitScale()
|
|
|
{
|
|
{
|
|
|
Scale = Math.Max(Scale, MinScale);
|
|
Scale = Math.Max(Scale, MinScale);
|
|
@@ -79,15 +79,15 @@ class InteractiveCanvas : ICustomDrawOperation
|
|
|
LimitTranslate();
|
|
LimitTranslate();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ #endregion
|
|
|
|
|
+
|
|
|
|
|
+ #region rendering
|
|
|
|
|
+
|
|
|
public void Render(IDrawingContextImpl context)
|
|
public void Render(IDrawingContextImpl context)
|
|
|
{
|
|
{
|
|
|
if (Pages.Count <= 0)
|
|
if (Pages.Count <= 0)
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
- LimitScale();
|
|
|
|
|
- LimitTranslate();
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas;
|
|
var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas;
|
|
|
|
|
|
|
|
if (canvas == null)
|
|
if (canvas == null)
|
|
@@ -95,7 +95,6 @@ class InteractiveCanvas : ICustomDrawOperation
|
|
|
|
|
|
|
|
var originalMatrix = canvas.TotalMatrix;
|
|
var originalMatrix = canvas.TotalMatrix;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
canvas.Translate(Width / 2, Height / 2);
|
|
canvas.Translate(Width / 2, Height / 2);
|
|
|
|
|
|
|
|
canvas.Scale(Scale);
|
|
canvas.Scale(Scale);
|
|
@@ -104,7 +103,7 @@ class InteractiveCanvas : ICustomDrawOperation
|
|
|
foreach (var page in Pages)
|
|
foreach (var page in Pages)
|
|
|
{
|
|
{
|
|
|
canvas.Translate(-page.Size.Width / 2f, 0);
|
|
canvas.Translate(-page.Size.Width / 2f, 0);
|
|
|
- DrawPageShadow(canvas, page.Size);
|
|
|
|
|
|
|
+ DrawBlankPage(canvas, page.Size);
|
|
|
canvas.DrawPicture(page.Picture);
|
|
canvas.DrawPicture(page.Picture);
|
|
|
canvas.Translate(page.Size.Width / 2f, page.Size.Height + PageSpacing);
|
|
canvas.Translate(page.Size.Width / 2f, page.Size.Height + PageSpacing);
|
|
|
}
|
|
}
|
|
@@ -119,19 +118,27 @@ class InteractiveCanvas : ICustomDrawOperation
|
|
|
public bool Equals(ICustomDrawOperation? other) => false;
|
|
public bool Equals(ICustomDrawOperation? other) => false;
|
|
|
public bool HitTest(Point p) => true;
|
|
public bool HitTest(Point p) => true;
|
|
|
|
|
|
|
|
- #region page shadow
|
|
|
|
|
|
|
+ #endregion
|
|
|
|
|
+
|
|
|
|
|
+ #region blank page
|
|
|
|
|
|
|
|
- private static readonly SKImageFilter PageShadow1 = SKImageFilter.CreateDropShadowOnly(0, 6, 6, 6, SKColors.Black.WithAlpha(64));
|
|
|
|
|
- private static readonly SKImageFilter PageShadow2 = SKImageFilter.CreateDropShadowOnly(0, 10, 14, 14, SKColors.Black.WithAlpha(32));
|
|
|
|
|
|
|
+ private static SKPaint BlankPagePaint = new SKPaint
|
|
|
|
|
+ {
|
|
|
|
|
+ Color = SKColors.White
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- private static SKPaint PageShadowPaint = new SKPaint
|
|
|
|
|
|
|
+ private static SKPaint BlankPageShadowPaint = new SKPaint
|
|
|
{
|
|
{
|
|
|
- ImageFilter = SKImageFilter.CreateBlendMode(SKBlendMode.Overlay, PageShadow1, PageShadow2)
|
|
|
|
|
|
|
+ ImageFilter = SKImageFilter.CreateBlendMode(
|
|
|
|
|
+ SKBlendMode.Overlay,
|
|
|
|
|
+ SKImageFilter.CreateDropShadowOnly(0, 6, 6, 6, SKColors.Black.WithAlpha(64)),
|
|
|
|
|
+ SKImageFilter.CreateDropShadowOnly(0, 10, 14, 14, SKColors.Black.WithAlpha(32)))
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- private void DrawPageShadow(SKCanvas canvas, QuestPDF.Infrastructure.Size size)
|
|
|
|
|
|
|
+ private void DrawBlankPage(SKCanvas canvas, QuestPDF.Infrastructure.Size size)
|
|
|
{
|
|
{
|
|
|
- canvas.DrawRect(0, 0, size.Width, size.Height, PageShadowPaint);
|
|
|
|
|
|
|
+ canvas.DrawRect(0, 0, size.Width, size.Height, BlankPageShadowPaint);
|
|
|
|
|
+ canvas.DrawRect(0, 0, size.Width, size.Height, BlankPagePaint);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
#endregion
|