Browse Source

Fixed: the AspectRatio element rarely positioned its content incorrectly.

Marcin Ziąbek 9 months ago
parent
commit
4522c96095
2 changed files with 6 additions and 1 deletions
  1. 1 1
      Source/QuestPDF/Elements/AspectRatio.cs
  2. 5 0
      Source/QuestPDF/Helpers/Helpers.cs

+ 1 - 1
Source/QuestPDF/Elements/AspectRatio.cs

@@ -20,7 +20,7 @@ namespace QuestPDF.Elements
             if (Child.IsEmpty())
                 return SpacePlan.Empty();
             
-            if (availableSpace.Width == 0 && availableSpace.Height == 0)
+            if (availableSpace.IsCloseToZero())
                 return SpacePlan.Wrap("The available space is zero.");
             
             var targetSize = GetTargetSize(availableSpace);

+ 5 - 0
Source/QuestPDF/Helpers/Helpers.cs

@@ -84,6 +84,11 @@ namespace QuestPDF.Helpers
         {
             return size.Width < -Size.Epsilon || size.Height < -Size.Epsilon;
         }
+        
+        internal static bool IsCloseToZero(this Size size)
+        {
+            return Math.Abs(size.Width) < Size.Epsilon && Math.Abs(size.Height) < Size.Epsilon;
+        }
 
         internal static bool IsEmpty(this Element element)
         {