2
0
Эх сурвалжийг харах

Layout Debugging: fixed rare exceptions and improved compatibility

Marcin Ziąbek 1 жил өмнө
parent
commit
3c702236ee

+ 8 - 2
Source/QuestPDF/Drawing/Proxy/LayoutDebugging.cs

@@ -57,6 +57,12 @@ internal static class LayoutDebugging
         
         void Traverse(TreeNode<OverflowDebuggingProxy> element)
         {
+            if (element.Value.Child is DebugPointer or SourceCodePointer or Container)
+            {
+                Traverse(element.Children.First());
+                return;
+            }
+            
             if (element.Value.AvailableSpace is null)
                 return;
             
@@ -96,7 +102,7 @@ internal static class LayoutDebugging
             // strategy:
             // the current contains wrapping children, they are likely the root cause,
             // traverse them and attempt to fix them
-            foreach (var child in element.Children.Where(x => x.Value.SpacePlan?.Type is SpacePlanType.Wrap))
+            foreach (var child in element.Children.Where(x => x.Value.SpacePlan?.Type is SpacePlanType.Wrap).ToList())
                 Traverse(child);
                 
             // check if fixing wrapping children helped
@@ -106,7 +112,7 @@ internal static class LayoutDebugging
             // strategy:
             // the current has layout issues but no obvious/trivial root causes
             // possibly the problem is in nested children of partial rendering children
-            foreach (var child in element.Children.Where(x => x.Value.SpacePlan?.Type is SpacePlanType.PartialRender))
+            foreach (var child in element.Children.Where(x => x.Value.SpacePlan?.Type is SpacePlanType.PartialRender).ToList())
                 Traverse(child);
                 
             // check if fixing partial children helped

+ 10 - 1
Source/QuestPDF/Drawing/Proxy/LayoutOverflowVisualization.cs

@@ -1,3 +1,4 @@
+using System;
 using QuestPDF.Helpers;
 using QuestPDF.Infrastructure;
 using QuestPDF.Skia;
@@ -22,8 +23,16 @@ internal class LayoutOverflowVisualization : ElementProxy, IContentDirectionAwar
         
         if (childSize.Type == SpacePlanType.FullRender)
             return childSize;
+
+        var minimalSize = Child.TryMeasureWithOverflow(availableSpace);
+
+        if (minimalSize.Type is SpacePlanType.Wrap)
+            return minimalSize;
+        
+        var width = Math.Min(availableSpace.Width, minimalSize.Width);
+        var height = Math.Min(availableSpace.Height, minimalSize.Height);
         
-        return Child.TryMeasureWithOverflow(availableSpace);
+        return new SpacePlan(minimalSize.Type, width, height);
     }
         
     internal override void Draw(Size availableSpace)