Browse Source

Fixed detecting infinite layout exception in specific cases

Marcin Ziąbek 4 years ago
parent
commit
feab280a27
2 changed files with 11 additions and 3 deletions
  1. 10 2
      QuestPDF/Drawing/DocumentGenerator.cs
  2. 1 1
      QuestPDF/QuestPDF.csproj

+ 10 - 2
QuestPDF/Drawing/DocumentGenerator.cs

@@ -60,7 +60,10 @@ namespace QuestPDF.Drawing
                 var spacePlan = content.Measure(Size.Max) as Size;
                 var spacePlan = content.Measure(Size.Max) as Size;
 
 
                 if (spacePlan == null)
                 if (spacePlan == null)
-                    break;
+                {
+                    canvas.EndDocument();
+                    ThrowLayoutException();
+                }
 
 
                 try
                 try
                 {
                 {
@@ -78,7 +81,7 @@ namespace QuestPDF.Drawing
                 if (currentPage >= documentMetadata.DocumentLayoutExceptionThreshold)
                 if (currentPage >= documentMetadata.DocumentLayoutExceptionThreshold)
                 {
                 {
                     canvas.EndDocument();
                     canvas.EndDocument();
-                    throw new DocumentLayoutException("Composed layout generates infinite document.");
+                    ThrowLayoutException();
                 }
                 }
                 
                 
                 if (spacePlan is FullRender)
                 if (spacePlan is FullRender)
@@ -88,6 +91,11 @@ namespace QuestPDF.Drawing
             }
             }
             
             
             canvas.EndDocument();
             canvas.EndDocument();
+            
+            void ThrowLayoutException()
+            {
+                throw new DocumentLayoutException("Composed layout generates infinite document.");
+            }
         }
         }
     }
     }
 }
 }

+ 1 - 1
QuestPDF/QuestPDF.csproj

@@ -4,7 +4,7 @@
         <Authors>MarcinZiabek</Authors>
         <Authors>MarcinZiabek</Authors>
         <Company>CodeFlint</Company>
         <Company>CodeFlint</Company>
         <PackageId>QuestPDF</PackageId>
         <PackageId>QuestPDF</PackageId>
-        <Version>2021.9.2</Version>
+        <Version>2021.9.3</Version>
         <PackageDescription>QuestPDF is an open-source, modern and battle-tested library that can help you with generating PDF documents by offering friendly, discoverable and predictable C# fluent API.</PackageDescription>
         <PackageDescription>QuestPDF is an open-source, modern and battle-tested library that can help you with generating PDF documents by offering friendly, discoverable and predictable C# fluent API.</PackageDescription>
         <PackageReleaseNotes>Added support for registering custom fonts from a stream. Fixed continuous page setting. Improved exception messages.</PackageReleaseNotes>
         <PackageReleaseNotes>Added support for registering custom fonts from a stream. Fixed continuous page setting. Improved exception messages.</PackageReleaseNotes>
         <LangVersion>8</LangVersion>
         <LangVersion>8</LangVersion>