Browse Source

Fix: resolved an issue where the Column element applies double spacing when its child does not occupy any space

Marcin Ziąbek 1 year ago
parent
commit
550504b51d

+ 52 - 0
Source/QuestPDF.Examples/ColumnExamples.cs

@@ -37,6 +37,58 @@ namespace QuestPDF.Examples
                 });
         }
         
+        [Test]
+        public void ColumnDoesNotPutDoubleSpacingWhenChildIsEmpty()
+        {
+            RenderingTest
+                .Create()
+                .PageSize(PageSizes.A4)
+                .ShowResults()
+                .ProducePdf()
+                .Render(container =>
+                {
+                    container.Padding(50).Shrink().Border(1).Background(Colors.Grey.Lighten3).Column(column =>
+                    {
+                        column.Spacing(30);
+                        
+                        column.Item();
+                        column.Item();
+                        column.Item();
+                        
+                        foreach (var i in Enumerable.Range(0, 5))
+                        {
+                            column.Item().Element(Block);
+                            column.Item().Element(Block);
+                            column.Item().Element(Block);
+                        
+                            column.Item();
+                        
+                            column.Item().Element(Block);
+                            column.Item().Element(Block);
+                            column.Item().Element(Block);
+                            column.Item().Element(Block);
+                        
+                            column.Item();
+                            column.Item();
+                        
+                            column.Item().Element(Block);
+                            column.Item().Element(Block);
+                        
+                            column.Item();
+                            column.Item();
+                        }
+                        
+                        static void Block(IContainer container)
+                        {
+                            container
+                                .Width(100)
+                                .Height(30)
+                                .Background(Placeholders.Color());
+                        }
+                    });
+                });
+        }
+        
         [Test]
         public void Stability_NoItems()
         {

+ 4 - 0
Source/QuestPDF/Elements/Column.cs

@@ -106,6 +106,10 @@ namespace QuestPDF.Elements
                 if (measurement.Type == SpacePlanType.Wrap)
                     break;
 
+                // when the item does not take any space, do not add spacing
+                if (measurement.Width < Size.Epsilon && measurement.Height < Size.Epsilon)
+                    topOffset -= Spacing;
+                
                 commands.Add(new ColumnItemRenderingCommand
                 {
                     ColumnItem = item,

+ 8 - 7
Source/QuestPDF/Resources/ReleaseNotes.txt

@@ -16,14 +16,15 @@ Version 2023.12.2
 - Maintenance: The QuestPDF Previewer application has been updated to utilize the latest version of the Avalonia library
 
 Version 2023.12.3
-- Improvement: enhanced the automated layout issue detection algorithm to cover a broader range of cases.
-- Update: upgraded the SkiaSharp dependency to version 2.88.7. This update addresses issues with JPEG images being incorrectly encoded/decoded on ARM devices.
-- Maintenance: added .NET 8 as an official build target for the library.
+- Improvement: enhanced the automated layout issue detection algorithm to cover a broader range of cases
+- Update: upgraded the SkiaSharp dependency to version 2.88.7. This update addresses issues with JPEG images being incorrectly encoded/decoded on ARM devices
+- Maintenance: added .NET 8 as an official build target for the library
 
 Version 2023.12.4
-- Fixed: the TextStyle.LetterSpacing property was not documented correctly, and the FluentAPI code prevented its correct use.
+- Fixed: the TextStyle.LetterSpacing property was not documented correctly, and the FluentAPI code prevented its correct use
 
 Version 2023.12.5
-- Improvement: redesigned the automated layout issue detection algorithm,
-- Improvement: when drawing content with the Canvas element, the library clips drawn content to the element's boundaries, preventing potential overflow when integrating with other libraries.
-- Improved layout stability.
+- Improvement: redesigned the automated layout issue detection algorithm
+- Improvement: when drawing content with the Canvas element, the library now clips drawn content to the element's boundaries. This prevents potential overflow when integrating with other libraries
+- Fix: resolved an issue where the Column element applies double spacing when its child does not occupy any space
+- Improvement: enhanced layout stability