From c348106b3ff6bfd7550ee3d4204c4d1123ec7fa5 Mon Sep 17 00:00:00 2001 From: MarcinZiabek Date: Wed, 19 Oct 2022 21:45:16 +0200 Subject: [PATCH] Page fluent: added possibility to select content direction --- .../Layouts/TableOfContentsTemplate.cs | 8 +++--- QuestPDF/Elements/Page.cs | 2 ++ QuestPDF/Fluent/ContentDirectionExtensions.cs | 4 +-- QuestPDF/Fluent/PageExtensions.cs | 26 +++++++++++++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/QuestPDF.ReportSample/Layouts/TableOfContentsTemplate.cs b/QuestPDF.ReportSample/Layouts/TableOfContentsTemplate.cs index dd59f7a..bb8c933 100644 --- a/QuestPDF.ReportSample/Layouts/TableOfContentsTemplate.cs +++ b/QuestPDF.ReportSample/Layouts/TableOfContentsTemplate.cs @@ -68,9 +68,11 @@ namespace QuestPDF.ReportSample.Layouts var lengthStyle = TextStyle.Default.FontColor(Colors.Grey.Medium); - text.Span(" (").Style(lengthStyle); - text.TotalPagesWithinSection(locationName).Style(lengthStyle).Format(x => x == 1 ? "1 page long" : $"{x} pages long"); - text.Span(")").Style(lengthStyle); + text.TotalPagesWithinSection(locationName).Style(lengthStyle).Format(x => + { + var formatted = x == 1 ? "1 page long" : $"{x} pages long"; + return $"({formatted})"; + }); }); }); } diff --git a/QuestPDF/Elements/Page.cs b/QuestPDF/Elements/Page.cs index 176ecfa..be93cc8 100644 --- a/QuestPDF/Elements/Page.cs +++ b/QuestPDF/Elements/Page.cs @@ -8,6 +8,7 @@ namespace QuestPDF.Elements { internal class Page : IComponent { + public ContentDirection ContentDirection { get; set; } public TextStyle DefaultTextStyle { get; set; } = TextStyle.Default; public Size MinSize { get; set; } = PageSizes.A4; @@ -30,6 +31,7 @@ namespace QuestPDF.Elements public void Compose(IContainer container) { container + .ContentDirection(ContentDirection) .Background(BackgroundColor) .Layers(layers => { diff --git a/QuestPDF/Fluent/ContentDirectionExtensions.cs b/QuestPDF/Fluent/ContentDirectionExtensions.cs index 82bd734..4d44aa4 100644 --- a/QuestPDF/Fluent/ContentDirectionExtensions.cs +++ b/QuestPDF/Fluent/ContentDirectionExtensions.cs @@ -5,9 +5,9 @@ namespace QuestPDF.Fluent { public static class ContentDirectionExtensions { - private static IContainer ContentDirection(this IContainer element, ContentDirection direction) + internal static IContainer ContentDirection(this IContainer element, ContentDirection direction) { - return element.Element(new ContentDirectionSetter() + return element.Element(new ContentDirectionSetter { ContentDirection = direction }); diff --git a/QuestPDF/Fluent/PageExtensions.cs b/QuestPDF/Fluent/PageExtensions.cs index 98d2b73..19fb5de 100644 --- a/QuestPDF/Fluent/PageExtensions.cs +++ b/QuestPDF/Fluent/PageExtensions.cs @@ -10,6 +10,8 @@ namespace QuestPDF.Fluent { internal Page Page { get; } = new Page(); + #region Size + public void Size(float width, float height, Unit unit = Unit.Inch) { var pageSize = new PageSize(width, height, unit); @@ -39,6 +41,10 @@ namespace QuestPDF.Fluent { Page.MaxSize = pageSize; } + + #endregion + + #region Margin public void MarginLeft(float value, Unit unit = Unit.Point) { @@ -78,6 +84,10 @@ namespace QuestPDF.Fluent MarginHorizontal(value, unit); } + #endregion + + #region Properties + public void DefaultTextStyle(TextStyle textStyle) { Page.DefaultTextStyle = textStyle; @@ -88,6 +98,16 @@ namespace QuestPDF.Fluent DefaultTextStyle(handler(TextStyle.Default)); } + public void ContentFromLeftToRight() + { + Page.ContentDirection = ContentDirection.LeftToRight; + } + + public void ContentFromRightToLeft() + { + Page.ContentDirection = ContentDirection.RightToLeft; + } + public void PageColor(string color) { Page.BackgroundColor = color; @@ -99,6 +119,10 @@ namespace QuestPDF.Fluent PageColor(color); } + #endregion + + #region Slots + public IContainer Background() { var container = new Container(); @@ -133,6 +157,8 @@ namespace QuestPDF.Fluent Page.Footer = container; return container; } + + #endregion } public static class PageExtensions