diff --git a/QuestPDF/Drawing/DocumentGenerator.cs b/QuestPDF/Drawing/DocumentGenerator.cs index b64baac..f8eecf3 100644 --- a/QuestPDF/Drawing/DocumentGenerator.cs +++ b/QuestPDF/Drawing/DocumentGenerator.cs @@ -64,6 +64,8 @@ namespace QuestPDF.Drawing var container = new DocumentContainer(); document.Compose(container); var content = container.Compose(); + + ApplyRepeatContent(content); ApplyDefaultTextStyle(content, TextStyle.LibraryDefault); var debuggingState = Settings.EnableDebugging ? ApplyDebugging(content) : null; @@ -192,5 +194,23 @@ namespace QuestPDF.Drawing foreach (var child in content.GetChildren()) ApplyDefaultTextStyle(child, documentDefaultTextStyle); } + + internal static void ApplyRepeatContent(this Element? content, bool enabled = false) + { + if (content == null) + return; + + if (content is RepeatContent repeatContent) + { + ApplyRepeatContent(repeatContent.Child, repeatContent.Repeat); + return; + } + + foreach (var child in content.GetChildren()) + ApplyRepeatContent(child, enabled); + + if (!enabled) + content.CreateProxy(y => y is IContent ? new ShowOnce { Child = y } : y); + } } } \ No newline at end of file diff --git a/QuestPDF/Elements/Canvas.cs b/QuestPDF/Elements/Canvas.cs index 0d25db0..dfafb94 100644 --- a/QuestPDF/Elements/Canvas.cs +++ b/QuestPDF/Elements/Canvas.cs @@ -7,7 +7,7 @@ namespace QuestPDF.Elements { public delegate void DrawOnCanvas(SKCanvas canvas, Size availableSpace); - internal class Canvas : Element, ICacheable + internal class Canvas : Element, ICacheable, IContent { public DrawOnCanvas Handler { get; set; } diff --git a/QuestPDF/Elements/Dynamic.cs b/QuestPDF/Elements/Dynamic.cs index 482704a..2040cc6 100644 --- a/QuestPDF/Elements/Dynamic.cs +++ b/QuestPDF/Elements/Dynamic.cs @@ -6,7 +6,7 @@ using QuestPDF.Infrastructure; namespace QuestPDF.Elements { - internal class DynamicHost : Element, IStateResettable + internal class DynamicHost : Element, IStateResettable, IContent { private DynamicComponentProxy Child { get; } private object InitialComponentState { get; set; } diff --git a/QuestPDF/Elements/DynamicImage.cs b/QuestPDF/Elements/DynamicImage.cs index 514fe16..48fcedd 100644 --- a/QuestPDF/Elements/DynamicImage.cs +++ b/QuestPDF/Elements/DynamicImage.cs @@ -6,7 +6,7 @@ using SkiaSharp; namespace QuestPDF.Elements { - internal class DynamicImage : Element + internal class DynamicImage : Element, IContent { public Func? Source { get; set; } diff --git a/QuestPDF/Elements/Image.cs b/QuestPDF/Elements/Image.cs index e38475c..a052486 100644 --- a/QuestPDF/Elements/Image.cs +++ b/QuestPDF/Elements/Image.cs @@ -5,7 +5,7 @@ using SkiaSharp; namespace QuestPDF.Elements { - internal class Image : Element, ICacheable + internal class Image : Element, ICacheable, IContent { public SKImage? InternalImage { get; set; } diff --git a/QuestPDF/Elements/Line.cs b/QuestPDF/Elements/Line.cs index 4ec04d1..fa61aca 100644 --- a/QuestPDF/Elements/Line.cs +++ b/QuestPDF/Elements/Line.cs @@ -15,7 +15,7 @@ namespace QuestPDF.Elements Horizontal } - internal class Line : Element, ILine, ICacheable + internal class Line : Element, ILine, ICacheable, IContent { public LineType Type { get; set; } = LineType.Vertical; public string Color { get; set; } = Colors.Black; diff --git a/QuestPDF/Elements/RepeatContent.cs b/QuestPDF/Elements/RepeatContent.cs new file mode 100644 index 0000000..c3c6a57 --- /dev/null +++ b/QuestPDF/Elements/RepeatContent.cs @@ -0,0 +1,9 @@ +using QuestPDF.Infrastructure; + +namespace QuestPDF.Elements +{ + internal class RepeatContent : ContainerElement + { + public bool Repeat { get; set; } + } +} \ No newline at end of file diff --git a/QuestPDF/Elements/Text/TextBlock.cs b/QuestPDF/Elements/Text/TextBlock.cs index c14f8cc..76d909d 100644 --- a/QuestPDF/Elements/Text/TextBlock.cs +++ b/QuestPDF/Elements/Text/TextBlock.cs @@ -8,7 +8,7 @@ using QuestPDF.Infrastructure; namespace QuestPDF.Elements.Text { - internal class TextBlock : Element, IStateResettable + internal class TextBlock : Element, IStateResettable, IContent { public HorizontalAlignment Alignment { get; set; } = HorizontalAlignment.Left; public List Items { get; set; } = new List(); diff --git a/QuestPDF/Fluent/DecorationExtensions.cs b/QuestPDF/Fluent/DecorationExtensions.cs index 97a4428..4aec0b0 100644 --- a/QuestPDF/Fluent/DecorationExtensions.cs +++ b/QuestPDF/Fluent/DecorationExtensions.cs @@ -12,7 +12,7 @@ namespace QuestPDF.Fluent { var container = new Container(); Decoration.Before = container; - return container; + return container.RepeatContent(); } public void Before(Action handler) @@ -36,7 +36,7 @@ namespace QuestPDF.Fluent { var container = new Container(); Decoration.After = container; - return container; + return container.RepeatContent(); } public void After(Action handler) diff --git a/QuestPDF/Fluent/ElementExtensions.cs b/QuestPDF/Fluent/ElementExtensions.cs index 804dc84..469542c 100644 --- a/QuestPDF/Fluent/ElementExtensions.cs +++ b/QuestPDF/Fluent/ElementExtensions.cs @@ -195,5 +195,13 @@ namespace QuestPDF.Fluent { return element.Element(new ScaleToFit()); } + + public static IContainer RepeatContent(this IContainer element, bool enabled = true) + { + return element.Element(new RepeatContent + { + Repeat = enabled + }); + } } } diff --git a/QuestPDF/Infrastructure/IContent.cs b/QuestPDF/Infrastructure/IContent.cs new file mode 100644 index 0000000..cf6ec3a --- /dev/null +++ b/QuestPDF/Infrastructure/IContent.cs @@ -0,0 +1,7 @@ +namespace QuestPDF.Infrastructure +{ + internal interface IContent + { + + } +} \ No newline at end of file