Browse Source

Merge branch 'main' into feat-show-when

Marcin Ziąbek 2 years ago
parent
commit
5f6a369ebb

+ 1 - 1
README.md

@@ -56,7 +56,7 @@ Choosing a project dependency could be difficult. We need to ensure stability an
 
 
 ⭐ Please give this repository a star. It takes seconds and help thousands of developers! ⭐
 ⭐ Please give this repository a star. It takes seconds and help thousands of developers! ⭐
 
 
-<img src="https://github.com/QuestPDF/QuestPDF/assets/9263853/1d8fe760-c0e0-4c6d-b7c6-46369f786841" width="700" />
+<img src="https://github.com/QuestPDF/QuestPDF/assets/9263853/37729167-c779-4122-9768-9d80c45d16b7" width="700" />
 
 
 ## Please share with the community
 ## Please share with the community
 
 

+ 1 - 2
Source/QuestPDF.LayoutTests/TestEngine/LayoutTestExecutor.cs

@@ -43,14 +43,13 @@ internal static class LayoutTestExecutor
             while(true)
             while(true)
             {
             {
                 pageContext.IncrementPageNumber();
                 pageContext.IncrementPageNumber();
-                
+              
                 var spacePlan = container.Measure(pageSize);
                 var spacePlan = container.Measure(pageSize);
                 pageSizes.Add(spacePlan);
                 pageSizes.Add(spacePlan);
 
 
                 if (spacePlan.Type == SpacePlanType.Wrap)
                 if (spacePlan.Type == SpacePlanType.Wrap)
                 {
                 {
                     pageContext.DecrementPageNumber();
                     pageContext.DecrementPageNumber();
-                    
                     canvas.EndDocument();
                     canvas.EndDocument();
                     return (pageSizes, true);
                     return (pageSizes, true);
                 }
                 }

+ 6 - 8
Source/QuestPDF/Previewer/PreviewerExtensions.cs

@@ -1,5 +1,3 @@
-
-
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Threading;
 using System.Threading;
@@ -20,19 +18,19 @@ namespace QuestPDF.Previewer
         }
         }
         
         
         /// <include file='../Resources/Documentation.xml' path='documentation/doc[@for="previewer.supported"]/*' />
         /// <include file='../Resources/Documentation.xml' path='documentation/doc[@for="previewer.supported"]/*' />
-        public static async Task ShowInPreviewerAsync(this IDocument document, int port = 12500)
+        public static async Task ShowInPreviewerAsync(this IDocument document, int port = 12500, CancellationToken cancellationToken = default)
         {
         {
             var previewerService = new PreviewerService(port);
             var previewerService = new PreviewerService(port);
             
             
-            using var cancellationTokenSource = new CancellationTokenSource();
+            using var cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
             previewerService.OnPreviewerStopped += () => cancellationTokenSource.Cancel();
             previewerService.OnPreviewerStopped += () => cancellationTokenSource.Cancel();
-            
+
             await previewerService.Connect();
             await previewerService.Connect();
             await RefreshPreview();
             await RefreshPreview();
             
             
             HotReloadManager.UpdateApplicationRequested += (_, _) => RefreshPreview();
             HotReloadManager.UpdateApplicationRequested += (_, _) => RefreshPreview();
             
             
-            await WaitForPreviewerExit(cancellationTokenSource.Token);
+            await KeepApplicationAlive(cancellationTokenSource.Token);
             
             
             Task RefreshPreview()
             Task RefreshPreview()
             {
             {
@@ -53,7 +51,7 @@ namespace QuestPDF.Previewer
                 }
                 }
             }
             }
 
 
-            async Task WaitForPreviewerExit(CancellationToken cancellationToken)
+            async Task KeepApplicationAlive(CancellationToken cancellationToken)
             {
             {
                 while (true)
                 while (true)
                 {
                 {
@@ -74,7 +72,7 @@ namespace QuestPDF.Previewer
         }
         }
 
 
         /// <include file='../Resources/Documentation.xml' path='documentation/doc[@for="previewer.notSupported"]/*' />
         /// <include file='../Resources/Documentation.xml' path='documentation/doc[@for="previewer.notSupported"]/*' />
-        public static async Task ShowInPreviewerAsync(this IDocument document, int port = 12500)
+        public static async Task ShowInPreviewerAsync(this IDocument document, int port = 12500, CancellationToken cancellationToken = default)
         {
         {
             throw new Exception("The hot-reload feature requires .NET 6 or later.");
             throw new Exception("The hot-reload feature requires .NET 6 or later.");
         }
         }