Browse Source

Fixed: The Text element is not visible when it consists only of the page number.

Marcin Ziąbek 1 year ago
parent
commit
fd0004d685
1 changed files with 15 additions and 1 deletions
  1. 15 1
      Source/QuestPDF/Elements/Text/TextBlock.cs

+ 15 - 1
Source/QuestPDF/Elements/Text/TextBlock.cs

@@ -64,7 +64,7 @@ namespace QuestPDF.Elements.Text
 
             // 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
-            ContainsOnlyWhiteSpace ??= Items.All(x => x is TextBlockSpan textBlockSpan && string.IsNullOrWhiteSpace(textBlockSpan.Text));
+            ContainsOnlyWhiteSpace ??= CheckIfContainsOnlyWhiteSpace();
             
             if (ContainsOnlyWhiteSpace == true)
                 return SpacePlan.FullRender(0, MeasureHeightOfParagraphContainingOnlyWhiteSpace());
@@ -512,6 +512,20 @@ namespace QuestPDF.Elements.Text
                 $"However, this may result with text glyphs being incorrectly rendered without any warning.");
         }
 
+        private bool CheckIfContainsOnlyWhiteSpace()
+        {
+            foreach (var textBlockItem in Items)
+            {
+                if (textBlockItem is TextBlockPageNumber)
+                    return false;
+                
+                if (textBlockItem is TextBlockSpan textBlockSpan && !string.IsNullOrWhiteSpace(textBlockSpan.Text))
+                    return false;
+            }
+            
+            return true;
+        }
+        
         private float MeasureHeightOfParagraphContainingOnlyWhiteSpace()
         {
             var paragraphStyle = new ParagraphStyleConfiguration