Quellcode durchsuchen

2024.6.4 Fixed a bug where Text elements, containing only null, empty, or whitespace content, could cause document layout issues.

Marcin Ziąbek vor 1 Jahr
Ursprung
Commit
fafb5d6bc9

+ 12 - 2
Source/QuestPDF/Elements/Text/TextBlock.cs

@@ -5,6 +5,7 @@ using System.Linq;
 using QuestPDF.Drawing;
 using QuestPDF.Drawing;
 using QuestPDF.Drawing.Exceptions;
 using QuestPDF.Drawing.Exceptions;
 using QuestPDF.Elements.Text.Items;
 using QuestPDF.Elements.Text.Items;
+using QuestPDF.Helpers;
 using QuestPDF.Infrastructure;
 using QuestPDF.Infrastructure;
 using QuestPDF.Skia;
 using QuestPDF.Skia;
 using QuestPDF.Skia.Text;
 using QuestPDF.Skia.Text;
@@ -62,13 +63,22 @@ namespace QuestPDF.Elements.Text
             
             
             if (IsRendered)
             if (IsRendered)
                 return SpacePlan.Empty();
                 return SpacePlan.Empty();
+            
+            if (availableSpace.IsNegative())
+                return SpacePlan.Wrap();
 
 
             // if the text block does not contain any items, or all items are null, return SpacePlan.Empty
             // if the text block does not contain any items, or all items are null, return SpacePlan.Empty
             // but if the text block contains only whitespace, return SpacePlan.FullRender with zero width and font-based height
             // but if the text block contains only whitespace, return SpacePlan.FullRender with zero width and font-based height
             ContainsOnlyWhiteSpace ??= CheckIfContainsOnlyWhiteSpace();
             ContainsOnlyWhiteSpace ??= CheckIfContainsOnlyWhiteSpace();
-            
+
             if (ContainsOnlyWhiteSpace == true)
             if (ContainsOnlyWhiteSpace == true)
-                return SpacePlan.FullRender(0, MeasureHeightOfParagraphContainingOnlyWhiteSpace());
+            {
+                var requiredHeight = MeasureHeightOfParagraphContainingOnlyWhiteSpace();
+                
+                return requiredHeight < availableSpace.Height + Size.Epsilon 
+                    ? SpacePlan.FullRender(0, requiredHeight) 
+                    : SpacePlan.Wrap();
+            }
             
             
             Initialize();
             Initialize();
             
             

+ 1 - 1
Source/QuestPDF/QuestPDF.csproj

@@ -3,7 +3,7 @@
         <Authors>MarcinZiabek</Authors>
         <Authors>MarcinZiabek</Authors>
         <Company>CodeFlint</Company>
         <Company>CodeFlint</Company>
         <PackageId>QuestPDF</PackageId>
         <PackageId>QuestPDF</PackageId>
-        <Version>2024.6.3</Version>
+        <Version>2024.6.4</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. Easily generate PDF reports, invoices, exports, etc.</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. Easily generate PDF reports, invoices, exports, etc.</PackageDescription>
         <PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/Resources/ReleaseNotes.txt"))</PackageReleaseNotes>
         <PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/Resources/ReleaseNotes.txt"))</PackageReleaseNotes>
         <LangVersion>10</LangVersion>
         <LangVersion>10</LangVersion>

+ 4 - 0
Source/QuestPDF/Resources/ReleaseNotes.txt

@@ -43,3 +43,7 @@ Version 2024.6.2
 
 
 Version 2024.6.3
 Version 2024.6.3
 - Improved performance of Text elements containing null, empty, or whitespace content only.
 - Improved performance of Text elements containing null, empty, or whitespace content only.
+
+
+Version 2024.6.4
+- Fixed a bug where Text elements, containing only null, empty, or whitespace content, could cause document layout issues.