Browse Source

Example report fixes

Marcin Ziąbek 4 years ago
parent
commit
a08a7b85c9

+ 1 - 1
QuestPDF.Examples/ElementExamples.cs

@@ -295,7 +295,7 @@ namespace QuestPDF.Examples
                             layers
                                 .Layer()
                                 .AlignBottom()
-                                .PageNumber("Page {pdf:currentPage}", TextStyle.Default.Size(16).Color(Colors.Green.Medium));
+                                .Text(text => text.CurrentPageNumber(TextStyle.Default.Size(16).Color(Colors.Green.Medium)));
                         });
                 });
         }

+ 2 - 2
QuestPDF.Examples/TextBenchmark.cs

@@ -143,8 +143,8 @@ namespace QuestPDF.Examples
                     .AlignBottom()
                     .Stack(stack =>
                     {
-                        stack.Item().Debug().Text("Quo Vadis", TextStyle.Default.Size(72).Bold().Color(Colors.Blue.Darken2));
-                        stack.Item().Debug().Text("Henryk Sienkiewicz", TextStyle.Default.Size(24).Color(Colors.Grey.Darken2));
+                        stack.Item().Text("Quo Vadis", TextStyle.Default.Size(72).Bold().Color(Colors.Blue.Darken2));
+                        stack.Item().Text("Henryk Sienkiewicz", TextStyle.Default.Size(24).Color(Colors.Grey.Darken2));
                     });
             }
 

+ 1 - 1
QuestPDF.Examples/TextExamples.cs

@@ -37,7 +37,7 @@ namespace QuestPDF.Examples
                             text.Span(Placeholders.LoremIpsum(), TextStyle.Default.Size(12));
                             
                             text.Span("Before element - ");
-                            text.Element().PaddingBottom(-10).Background(Colors.Red.Lighten4).Width(50).Height(20);
+                            text.Element().PaddingBottom(-10).Background(Colors.Red.Lighten4).Height(20).PaddingHorizontal(5).AlignMiddle().Text("Text inside text", TextStyle.Default.Size(8));
                             text.Span(" - end of element.");
                             
                             text.NewLine();

+ 1 - 1
QuestPDF.Examples/optimization.md

@@ -4,7 +4,7 @@
 
 Attempts:
 
-```angular2html
+```
 Attempt 0: 18389,00
 Attempt 1: 18627,00
 Attempt 2: 19745,00

+ 2 - 2
QuestPDF.ReportSample/DataSource.cs

@@ -18,8 +18,8 @@ namespace QuestPDF.ReportSample
                 HeaderFields = HeaderFields(),
                 
                 LogoData = Helpers.GetImage("Logo.png"),
-                Sections = Enumerable.Range(0, 50).Select(x => GenerateSection()).ToList(),
-                Photos = Enumerable.Range(0, 30).Select(x => GetReportPhotos()).ToList()
+                Sections = Enumerable.Range(0, 40).Select(x => GenerateSection()).ToList(),
+                Photos = Enumerable.Range(0, 25).Select(x => GetReportPhotos()).ToList()
             };
 
             List<ReportHeaderField> HeaderFields()

+ 2 - 2
QuestPDF.ReportSample/Layouts/SectionTemplate.cs

@@ -28,13 +28,13 @@ namespace QuestPDF.ReportSample.Layouts
                     {
                         foreach (var part in Model.Parts)
                         {
-                            stack.Item().Row(row =>
+                            stack.Item().EnsureSpace(25).Row(row =>
                             {
                                 row.ConstantColumn(150).LabelCell().Text(part.Label, Typography.Normal);
                                 var frame = row.RelativeColumn().ValueCell();
                             
                                 if (part is ReportSectionText text)
-                                    frame.Text(text.Text, Typography.Normal);
+                                    frame.ShowEntire().Text(text.Text, Typography.Normal);
                         
                                 if (part is ReportSectionMap map)
                                     frame.Element(x => MapElement(x, map));

+ 11 - 1
QuestPDF.ReportSample/Layouts/StandardReport.cs

@@ -34,7 +34,15 @@ namespace QuestPDF.ReportSample.Layouts
                         
                     page.Header().Element(ComposeHeader);
                     page.Content().Element(ComposeContent);
-                    page.Footer().AlignCenter().PageNumber();
+                    
+                    page.Footer().AlignCenter().Text(text =>
+                    {
+                        text.DefaultTextStyle(Typography.Normal);
+                        
+                        text.CurrentPageNumber();
+                        text.Span(" / ");
+                        text.TotalPages();
+                    });
                 });
         }
 
@@ -77,6 +85,8 @@ namespace QuestPDF.ReportSample.Layouts
 
                 stack.Item().Component(new TableOfContentsTemplate(Model.Sections));
                 
+                stack.Item().PageBreak();
+                
                 foreach (var section in Model.Sections)
                     stack.Item().Location(section.Title).Component(new SectionTemplate(section));
 

+ 1 - 1
QuestPDF.ReportSample/Layouts/TableOfContentsTemplate.cs

@@ -43,7 +43,7 @@ namespace QuestPDF.ReportSample.Layouts
                 {
                     row.ConstantColumn(25).Text($"{number}.", Typography.Normal);
                     row.RelativeColumn().Text(locationName, Typography.Normal);
-                    row.ConstantColumn(150).AlignRight().PageNumber($"Page {{pdf:{locationName}}}");
+                    row.ConstantColumn(150).AlignRight().Text(text => text.PageNumberOfLocation(locationName, Typography.Normal));
                 });
         }
     }

+ 1 - 1
QuestPDF.ReportSample/Tests.cs

@@ -28,7 +28,7 @@ namespace QuestPDF.ReportSample
             // target document length should be around 100 pages
             
             // test size
-            const int testSize = 25;
+            const int testSize = 10;
             const decimal performanceTarget = 1; // documents per second
 
             // create report models

+ 0 - 53
QuestPDF/Elements/PageNumber.cs

@@ -1,53 +0,0 @@
-using System;
-using System.Text.RegularExpressions;
-using QuestPDF.Drawing.SpacePlan;
-using QuestPDF.Infrastructure;
-using Size = QuestPDF.Infrastructure.Size;
-
-namespace QuestPDF.Elements
-{
-    internal class PageNumber : Element
-    {
-        public string TextFormat { get; set; } = "";
-        //private Text TextElement { get; set; } = new Text();
-
-        // public TextStyle? TextStyle
-        // {
-        //     get => TextElement?.Style;
-        //     set => TextElement.Style = value;
-        // }
-
-        internal override void HandleVisitor(Action<Element?> visit)
-        {
-            //TextElement?.HandleVisitor(visit);
-            base.HandleVisitor(visit);
-        }
-
-        internal override ISpacePlan Measure(Size availableSpace)
-        {
-            //TextElement.Value = GetText();
-            //return TextElement.Measure(availableSpace);
-            return new FullRender(Size.Zero);
-        }
-
-        internal override void Draw(Size availableSpace)
-        {
-            //TextElement.Value = GetText();
-            //TextElement.Draw(availableSpace);
-        }
-
-        private string GetText()
-        {
-            var result = TextFormat;
-            
-            // replace known locations
-            foreach (var location in PageContext.GetRegisteredLocations())
-                result = result.Replace($"{{pdf:{location}}}", PageContext.GetLocationPage(location).ToString());
-
-            // placeholder unknown locations
-            result = Regex.Replace(result, @"{pdf:[ \w]+}", "123");
-            
-            return result;
-        }
-    }
-}

+ 0 - 9
QuestPDF/Fluent/ElementExtensions.cs

@@ -40,15 +40,6 @@ namespace QuestPDF.Fluent
         {
             return handler(parent.Container()).Container();
         }
-
-        public static void PageNumber(this IContainer element, string textFormat = "{pdf:currentPage} / {pdf:totalPages}", TextStyle? style = null)
-        {
-            element.Element(new PageNumber
-            {
-                TextFormat = textFormat,
-                //TextStyle = style ?? TextStyle.Default // TODO
-            });
-        }
         
         public static IContainer AspectRatio(this IContainer element, float ratio, AspectRatioOption option = AspectRatioOption.FitWidth)
         {