Browse Source

Ensure consistent height calculation in TextBlock by using Ceil for totalHeight

Marcin Ziąbek 5 months ago
parent
commit
0a4140bb58
1 changed files with 3 additions and 1 deletions
  1. 3 1
      Source/QuestPDF/Elements/Text/TextBlock.cs

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

@@ -110,7 +110,7 @@ namespace QuestPDF.Elements.Text
                 var lineMetric = LineMetrics[lineIndex];
                 var lineMetric = LineMetrics[lineIndex];
                 var newTotalHeight = totalHeight + lineMetric.Height;
                 var newTotalHeight = totalHeight + lineMetric.Height;
                 
                 
-                if (newTotalHeight > availableSpace.Height + Size.Epsilon)
+                if ((float)Math.Ceiling(newTotalHeight) > availableSpace.Height + Size.Epsilon)
                     break;
                     break;
                 
                 
                 totalHeight = newTotalHeight;
                 totalHeight = newTotalHeight;
@@ -120,6 +120,8 @@ namespace QuestPDF.Elements.Text
             if (totalLines == 0)
             if (totalLines == 0)
                 return SpacePlan.Wrap("The available space is not sufficient to render even a single line of text.");
                 return SpacePlan.Wrap("The available space is not sufficient to render even a single line of text.");
 
 
+            totalHeight = (float)Math.Ceiling(totalHeight);
+            
             var requiredArea = new Size(
             var requiredArea = new Size(
                 Math.Min(MaximumWidth, availableSpace.Width),
                 Math.Min(MaximumWidth, availableSpace.Width),
                 Math.Min(totalHeight, availableSpace.Height));
                 Math.Min(totalHeight, availableSpace.Height));