浏览代码

Fix(#470): the inlined element is shown only once in the header but should be repeated on each page

MarcinZiabek 2 年之前
父节点
当前提交
22a696fab9
共有 2 个文件被更改,包括 40 次插入0 次删除
  1. 37 0
      Source/QuestPDF.Examples/InlinedExamples.cs
  2. 3 0
      Source/QuestPDF/Elements/Inlined.cs

+ 37 - 0
Source/QuestPDF.Examples/InlinedExamples.cs

@@ -120,5 +120,42 @@ namespace QuestPDF.Examples
                     .Background(Placeholders.BackgroundColor());
                     .Background(Placeholders.BackgroundColor());
             }
             }
         }
         }
+        
+        [Test]
+        public void RepeatingInlinedInHeader_Test()
+        {
+            RenderingTest
+                .Create()
+                .ProduceImages()
+                .ShowResults()
+                .RenderDocument(document =>
+                {
+                    document.Page(page =>
+                    {
+                        page.Size(PageSizes.A4);
+                        page.Margin(1, Unit.Inch);
+                        page.PageColor(Colors.White);
+                        
+                        page.Header()
+                            .Inlined(inlined =>
+                            {
+                                inlined.Spacing(10);
+                                
+                                foreach (var i in Enumerable.Range(5, 5))
+                                    inlined.Item().Width(i * 10).Height(20).Background(Colors.Red.Medium);
+                            });
+                        
+                        page.Content()
+                            .PaddingVertical(20)
+                            .Column(column =>
+                            {
+                                column.Spacing(25);
+                                
+                                foreach (var i in Enumerable.Range(10, 20))
+                                    column.Item().Width(i * 10).Height(50).Background(Colors.Grey.Lighten2);
+                            });
+                    });
+                });
+        }
     }
     }
 }
 }

+ 3 - 0
Source/QuestPDF/Elements/Inlined.cs

@@ -102,6 +102,9 @@ namespace QuestPDF.Elements
             
             
             Canvas.Translate(new Position(0, -topOffset));
             Canvas.Translate(new Position(0, -topOffset));
             lines.SelectMany(x => x).ToList().ForEach(x => ChildrenQueue.Dequeue());
             lines.SelectMany(x => x).ToList().ForEach(x => ChildrenQueue.Dequeue());
+            
+            if (!ChildrenQueue.Any())
+                ResetState();
 
 
             void DrawLine(ICollection<InlinedMeasurement> lineMeasurements)
             void DrawLine(ICollection<InlinedMeasurement> lineMeasurements)
             {
             {