diff --git a/QuestPDF.Examples/ChartExamples.cs b/QuestPDF.Examples/ChartExamples.cs index 240a672..2d61057 100644 --- a/QuestPDF.Examples/ChartExamples.cs +++ b/QuestPDF.Examples/ChartExamples.cs @@ -1,3 +1,4 @@ +using System.Linq; using NUnit.Framework; using QuestPDF.Examples.Engine; using QuestPDF.Fluent; @@ -43,19 +44,41 @@ namespace QuestPDF.Examples RenderingTest .Create() - .PageSize(300, 300) + .PageSize(400, 600) + .ProduceImages() .ShowResults() .Render(container => { - container.Extend().Canvas((canvas, size) => - { - var bar = new BarChart + container + .Background(Colors.White) + .Padding(25) + .Stack(stack => { - Entries = entries, - IsAnimated = false, - }; - bar.Draw(canvas, (int)size.Width, (int)size.Height); - }); + stack + .Item() + .PaddingBottom(10) + .Text("Chart example", TextStyle.Default.Size(20).SemiBold().Color(Colors.Blue.Medium)); + + stack + .Item() + .Border(1) + .ExtendHorizontal() + .Height(300) + .Canvas((canvas, size) => + { + var chart = new BarChart + { + Entries = entries, + + LabelOrientation = Orientation.Horizontal, + ValueLabelOrientation = Orientation.Horizontal, + + IsAnimated = false, + }; + + chart.DrawContent(canvas, (int)size.Width, (int)size.Height); + }); + }); }); } } diff --git a/QuestPDF.Examples/ComplexLayoutBenchmark.cs b/QuestPDF.Examples/ComplexLayoutBenchmark.cs index 8f7df56..60538f4 100644 --- a/QuestPDF.Examples/ComplexLayoutBenchmark.cs +++ b/QuestPDF.Examples/ComplexLayoutBenchmark.cs @@ -16,8 +16,7 @@ namespace QuestPDF.Examples .PageSize(PageSizes.A4) .ProducePdf() .ShowResults() - .Render(x => x.Image(new byte[] { 1, 2, 3 })); - //.Render(x => GenerateStructure(x, 16)); + .Render(x => GenerateStructure(x, 16)); } private void GenerateStructure(IContainer container, int level) @@ -33,7 +32,7 @@ namespace QuestPDF.Examples if (level % 3 == 0) { container - .Border(level / 10f) + .Border(level / 4f) .BorderColor(Colors.Black) .Row(row => { @@ -44,7 +43,7 @@ namespace QuestPDF.Examples else { container - .Border(level / 10f) + .Border(level / 4f) .BorderColor(Colors.Black) .Stack(stack => { diff --git a/QuestPDF.Examples/LoremPicsumExample.cs b/QuestPDF.Examples/LoremPicsumExample.cs index c20094a..3dca20c 100644 --- a/QuestPDF.Examples/LoremPicsumExample.cs +++ b/QuestPDF.Examples/LoremPicsumExample.cs @@ -36,6 +36,8 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(350, 280) + .ProducePdf() + .ShowResults() .Render(container => { container diff --git a/QuestPDF/Drawing/DocumentGenerator.cs b/QuestPDF/Drawing/DocumentGenerator.cs index a370db6..0ff8bc8 100644 --- a/QuestPDF/Drawing/DocumentGenerator.cs +++ b/QuestPDF/Drawing/DocumentGenerator.cs @@ -46,16 +46,10 @@ namespace QuestPDF.Drawing var metadata = document.GetMetadata(); var pageContext = new PageContext(); - DebuggingState debuggingState = null; - - if (System.Diagnostics.Debugger.IsAttached) - { - debuggingState = ApplyDebugging(content); - } - else - { + var debuggingState = metadata.ApplyDebugging ? ApplyDebugging(content) : null; + + if (metadata.ApplyCaching) ApplyCaching(content); - } RenderPass(pageContext, new FreeCanvas(), content, metadata, debuggingState); RenderPass(pageContext, canvas, content, metadata, debuggingState); diff --git a/QuestPDF/Drawing/DocumentMetadata.cs b/QuestPDF/Drawing/DocumentMetadata.cs index ad30de9..5db70ff 100644 --- a/QuestPDF/Drawing/DocumentMetadata.cs +++ b/QuestPDF/Drawing/DocumentMetadata.cs @@ -23,7 +23,10 @@ namespace QuestPDF.Drawing /// (likely due to infinite layout), the exception is thrown. /// public int DocumentLayoutExceptionThreshold { get; set; } = 250; - + + public bool ApplyCaching { get; set; } = !System.Diagnostics.Debugger.IsAttached; + public bool ApplyDebugging { get; set; } = System.Diagnostics.Debugger.IsAttached; + public static DocumentMetadata Default => new DocumentMetadata(); } } \ No newline at end of file diff --git a/QuestPDF/Drawing/Proxy/DebuggingState.cs b/QuestPDF/Drawing/Proxy/DebuggingState.cs index eaf41b5..2df40cb 100644 --- a/QuestPDF/Drawing/Proxy/DebuggingState.cs +++ b/QuestPDF/Drawing/Proxy/DebuggingState.cs @@ -109,7 +109,7 @@ namespace QuestPDF.Drawing.Proxy Value = x.GetValue(element) }) .Where(x => !(x.Value is IElement)) - .Where(x => !(x.Value is IEnumerable)) + .Where(x => !(x.Value is IEnumerable)) .Where(x => !(x.Value is TextStyle)) .Select(x => $"{x.Property}: {FormatValue(x.Value)}"); diff --git a/QuestPDF/Drawing/SpacePlan.cs b/QuestPDF/Drawing/SpacePlan.cs index 9d71c9e..abaab78 100644 --- a/QuestPDF/Drawing/SpacePlan.cs +++ b/QuestPDF/Drawing/SpacePlan.cs @@ -31,7 +31,7 @@ namespace QuestPDF.Drawing if (Type == SpacePlanType.Wrap) return Type.ToString(); - return $"{Type} | width {Width:N2} | height {Height:N2}"; + return $"{Type} (Width: {Width:N2}, Height: {Height:N2})"; } public static implicit operator Size(SpacePlan spacePlan) diff --git a/QuestPDF/Elements/Canvas.cs b/QuestPDF/Elements/Canvas.cs index 7394882..8dc55e3 100644 --- a/QuestPDF/Elements/Canvas.cs +++ b/QuestPDF/Elements/Canvas.cs @@ -22,9 +22,9 @@ namespace QuestPDF.Elements if (Handler == null || skiaCanvas == null) return; - var currentMatrix = skiaCanvas.TotalMatrix; + var originalMatrix = skiaCanvas.TotalMatrix; Handler.Invoke(skiaCanvas, availableSpace); - skiaCanvas.SetMatrix(currentMatrix); + skiaCanvas.SetMatrix(originalMatrix); } } } \ No newline at end of file diff --git a/QuestPDF/Elements/Text/TextBlock.cs b/QuestPDF/Elements/Text/TextBlock.cs index 283a294..b2953a7 100644 --- a/QuestPDF/Elements/Text/TextBlock.cs +++ b/QuestPDF/Elements/Text/TextBlock.cs @@ -13,8 +13,10 @@ namespace QuestPDF.Elements.Text public HorizontalAlignment Alignment { get; set; } = HorizontalAlignment.Left; public List Children { get; set; } = new List(); - public Queue RenderingQueue { get; set; } - public int CurrentElementIndex { get; set; } + public string Text => string.Join(" ", Children.Where(x => x is TextBlockSpan).Cast().Select(x => x.Text)); + + private Queue RenderingQueue { get; set; } + private int CurrentElementIndex { get; set; } public void ResetState() { diff --git a/QuestPDF/Infrastructure/Size.cs b/QuestPDF/Infrastructure/Size.cs index 4baee1a..b8f847d 100644 --- a/QuestPDF/Infrastructure/Size.cs +++ b/QuestPDF/Infrastructure/Size.cs @@ -16,6 +16,6 @@ Height = height; } - public override string ToString() => $"(W: {Width}, H: {Height})"; + public override string ToString() => $"(Width: {Width}, Height: {Height})"; } } \ No newline at end of file diff --git a/QuestPDF/QuestPDF.csproj b/QuestPDF/QuestPDF.csproj index 5fb415a..a4f7262 100644 --- a/QuestPDF/QuestPDF.csproj +++ b/QuestPDF/QuestPDF.csproj @@ -4,7 +4,7 @@ MarcinZiabek CodeFlint QuestPDF - 2021.12.0-alpha0 + 2021.12.0-alpha1 QuestPDF is an open-source, modern and battle-tested library that can help you with generating PDF documents by offering friendly, discoverable and predictable C# fluent API. $([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/Resources/ReleaseNotes.txt")) 8