Browse Source

Fixed scroll, more code refactoring

MarcinZiabek 3 years ago
parent
commit
47e9a49fe5

+ 4 - 6
QuestPDF.Previewer/DocumentPreviewerExtensions.cs

@@ -3,18 +3,16 @@ using QuestPDF.Infrastructure;
 
 namespace QuestPDF.Previewer
 {
-    /// <summary>
-    /// Extensions for <see cref="IDocument"/> for previewer
-    /// </summary>
     public static class DocumentPreviewerExtensions
     {
         /// <summary>
-        /// Displays the document in a previewer which supports hot reloading.
+        /// Opens document in the QuestPDF previewer tool.
+        /// Improves development speed by supporting hot reloading.
+        /// Shows document preview and refreshes it after each code change.
         /// </summary>
         /// <remarks>
-        /// Intended for development only. Not intended for shipping.
+        /// Intended for development only. Do not use in production environment.
         /// </remarks>
-        /// <param name="document"></param>
         public static void ShowInPreviewer(this IDocument document)
         {
             ArgumentNullException.ThrowIfNull(document);

+ 0 - 6
QuestPDF.Previewer/DocumentRenderer.cs

@@ -8,8 +8,6 @@ namespace QuestPDF.Previewer
 {
     internal class DocumentRenderer : INotifyPropertyChanged
     {
-        public float PageSpacing { get; set; }
-        public Size Bounds { get; private set; }
         public IDocument? Document { get; private set; }
 
         public event PropertyChangedEventHandler? PropertyChanged;
@@ -71,10 +69,6 @@ namespace QuestPDF.Previewer
 
             DocumentGenerator.RenderDocument(canvas, document);
             
-            var width = canvas.Pictures.Max(p => p.Size.Width);
-            var height = canvas.Pictures.Sum(p => p.Size.Height) + (canvas.Pictures.Count - 1) * PageSpacing;
-            Bounds = new Size(width, height);
-
             foreach (var pages in Pages)
                 pages?.Picture?.Dispose();
             

+ 6 - 3
QuestPDF.Previewer/InteractiveCanvas.cs

@@ -21,7 +21,7 @@ class InteractiveCanvas : ICustomDrawOperation
     private const float MinScale = 0.1f;
     private const float MaxScale = 10f;
     
-    private const float PageSpacing = 50f;
+    private const float PageSpacing = 25f;
     private const float SafeZone = 50f;
 
     #region transformations
@@ -37,8 +37,8 @@ class InteractiveCanvas : ICustomDrawOperation
         var totalHeight = Pages.Sum(x => x.Size.Height) + (Pages.Count - 1) * PageSpacing;
         var maxWidth = Pages.Max(x => x.Size.Width);
 
-        var maxTranslateY = SafeZone / Scale;
-        var minTranslateY = (Height - SafeZone) / Scale - totalHeight;
+        var maxTranslateY = - (Height / 2 - SafeZone) / Scale;
+        var minTranslateY = (Height / 2 - SafeZone) / Scale - totalHeight;
         
         TranslateY = Math.Min(TranslateY, maxTranslateY);
         TranslateY = Math.Max(TranslateY, minTranslateY);
@@ -88,6 +88,9 @@ class InteractiveCanvas : ICustomDrawOperation
         if (Pages.Count <= 0)
             return;
 
+        LimitScale();
+        LimitTranslate();
+        
         var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas;
         
         if (canvas == null)

+ 2 - 2
QuestPDF.Previewer/PreviewerCanvas.cs

@@ -4,9 +4,9 @@ using SkiaSharp;
 
 namespace QuestPDF.Previewer
 {
-    public record PreviewPage(SKPicture Picture, Size Size);
+    record PreviewPage(SKPicture Picture, Size Size);
     
-    internal sealed class PreviewerCanvas : SkiaCanvasBase, IRenderingCanvas
+    sealed class PreviewerCanvas : SkiaCanvasBase, IRenderingCanvas
     {
         private SKPictureRecorder? PictureRecorder { get; set; }
         private Size? CurrentPageSize { get; set; }

+ 1 - 1
QuestPDF.Previewer/PreviewerControl.cs

@@ -6,7 +6,7 @@ using Avalonia.Media;
 
 namespace QuestPDF.Previewer
 {
-    internal class PreviewerControl : Control
+    class PreviewerControl : Control
     {
         public static readonly StyledProperty<ObservableCollection<PreviewPage>?> PagesProperty =
             AvaloniaProperty.Register<PreviewerControl, ObservableCollection<PreviewPage>>(nameof(Pages));

+ 1 - 1
QuestPDF.Previewer/PreviewerUtils.cs

@@ -5,7 +5,7 @@ using QuestPDF.Infrastructure;
 
 namespace QuestPDF.Previewer
 {
-    internal static class PreviewerUtils
+    static class PreviewerUtils
     {
         public static async Task<bool> SavePdfWithDialog(IDocument? document, Window dialogOwner)
         {

+ 1 - 1
QuestPDF.Previewer/PreviewerWindow.axaml.cs

@@ -6,7 +6,7 @@ using QuestPDF.Infrastructure;
 
 namespace QuestPDF.Previewer
 {
-    internal class PreviewerWindow : Window
+    class PreviewerWindow : Window
     {
         public DocumentRenderer DocumentRenderer { get; } = new();