Browse Source

Page fluent: added possibility to select content direction

MarcinZiabek 3 years ago
parent
commit
c348106b3f

+ 5 - 3
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})";
+                        });
                     });
                 });
         }

+ 2 - 0
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 =>
                 {

+ 2 - 2
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
             });

+ 26 - 0
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