From 1b9b1645833da1a6b8e14076555464e559b31604 Mon Sep 17 00:00:00 2001 From: MarcinZiabek Date: Sat, 12 Mar 2022 16:11:03 +0100 Subject: [PATCH] DefaultTextStyle API improvements --- QuestPDF.Examples/PageBackgroundForeground.cs | 12 ++---------- QuestPDF/Fluent/ElementExtensions.cs | 10 +++++++++- QuestPDF/Fluent/PageExtensions.cs | 5 +++++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/QuestPDF.Examples/PageBackgroundForeground.cs b/QuestPDF.Examples/PageBackgroundForeground.cs index ac36a67..23a3fd0 100644 --- a/QuestPDF.Examples/PageBackgroundForeground.cs +++ b/QuestPDF.Examples/PageBackgroundForeground.cs @@ -11,7 +11,7 @@ namespace QuestPDF.Examples public class PageBackgroundForeground { [Test] - public void Frame() + public void Test() { RenderingTest .Create() @@ -31,7 +31,7 @@ namespace QuestPDF.Examples .AlignCenter() .Text("Watermark") .FontSize(64) - .FontColor(Colors.Blue.Lighten4); + .FontColor(Colors.Blue.Lighten3); page.Header().Text("Background and foreground").Bold().FontColor(Colors.Blue.Medium).FontSize(24); @@ -42,14 +42,6 @@ namespace QuestPDF.Examples foreach (var i in Enumerable.Range(0, 100)) column.Item().Background(Colors.Grey.Lighten2).Height(75); }); - - page.Footer() - .AlignCenter() - .Text(x => - { - x.Span("Page "); - x.CurrentPageNumber(); - }); }); }); } diff --git a/QuestPDF/Fluent/ElementExtensions.cs b/QuestPDF/Fluent/ElementExtensions.cs index a85a2e4..804dc84 100644 --- a/QuestPDF/Fluent/ElementExtensions.cs +++ b/QuestPDF/Fluent/ElementExtensions.cs @@ -177,7 +177,15 @@ namespace QuestPDF.Fluent TextStyle = textStyle }); } - + + public static IContainer DefaultTextStyle(this IContainer element, Func handler) + { + return element.Element(new DefaultTextStyle + { + TextStyle = handler(TextStyle.Default) + }); + } + public static IContainer StopPaging(this IContainer element) { return element.Element(new StopPaging()); diff --git a/QuestPDF/Fluent/PageExtensions.cs b/QuestPDF/Fluent/PageExtensions.cs index c336160..e043ed3 100644 --- a/QuestPDF/Fluent/PageExtensions.cs +++ b/QuestPDF/Fluent/PageExtensions.cs @@ -83,6 +83,11 @@ namespace QuestPDF.Fluent Page.DefaultTextStyle = textStyle; } + public void DefaultTextStyle(Func handler) + { + DefaultTextStyle(handler(TextStyle.Default)); + } + public void Background(string color) { Page.BackgroundColor = color;