diff --git a/QuestPDF.Examples/ElementExamples.cs b/QuestPDF.Examples/ElementExamples.cs index 5900f2a..44c046d 100644 --- a/QuestPDF.Examples/ElementExamples.cs +++ b/QuestPDF.Examples/ElementExamples.cs @@ -18,6 +18,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(200, 150) + .FileName() .Render(container => { container @@ -33,6 +34,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 300) + .FileName() .Render(container => { container @@ -55,49 +57,14 @@ namespace QuestPDF.Examples }); }); } - - // [Test] - // public void Page() - // { - // RenderingTest - // .Create() - // .PageSize(298, 421) - // .Render(container => - // { - // container - // .Background("#FFF") - // .Padding(15) - // .Page(page => - // { - // page.Header() - // .Height(60) - // .Background(Colors.Grey.Lighten1) - // .AlignCenter() - // .AlignMiddle() - // .Text("Header"); - // - // page.Content() - // .Background(Colors.Grey.Lighten2) - // .AlignCenter() - // .AlignMiddle() - // .Text("Content"); - // - // page.Footer() - // .Height(30) - // .Background(Colors.Grey.Lighten1) - // .AlignCenter() - // .AlignMiddle() - // .Text("Footer"); - // }); - // }); - // } - + [Test] public void Row() { RenderingTest .Create() .PageSize(740, 200) + .FileName() .Render(container => { container @@ -138,6 +105,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(740, 200) + .FileName() .Render(container => { container @@ -159,6 +127,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(500, 360) + .FileName() .Render(container => { container @@ -181,6 +150,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(210, 210) + .FileName() .Render(container => { container @@ -203,6 +173,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 200) + .FileName() .Render(container => { var text = ""; @@ -225,6 +196,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(400, 230) + .FileName() .Render(container => { var textStyle = TextStyle.Default.Size(14); @@ -259,6 +231,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 200) + .FileName() .Render(container => { container @@ -288,6 +261,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(400, 250) + .FileName() .Render(container => { container @@ -363,6 +337,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 300) + .FileName() .Render(container => { container @@ -407,6 +382,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(450, 150) + .FileName() .Render(container => { container @@ -439,6 +415,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(500, 175) + .FileName() .Render(container => { container @@ -465,6 +442,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 300) + .FileName() .Render(container => { container @@ -504,6 +482,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(300, 150) + .FileName() .Render(container => { container @@ -523,21 +502,25 @@ namespace QuestPDF.Examples { RenderingTest .Create() - .PageSize(400, 400) + .PageSize(400, 250) + .FileName() .Render(container => { - var style = TextStyle.Default.Size(20); - container - .Background("#FFF") .Padding(25) .Stack(stack => { - stack.Spacing(5); - stack.Item().Background(Placeholders.BackgroundColor()).Scale(0.5f).Text("Smaller text", style); - stack.Item().Background(Placeholders.BackgroundColor()).Text("Normal text", style); - stack.Item().Background(Placeholders.BackgroundColor()).Scale(2f).Text("Bigger text", style); - stack.Item().Background(Placeholders.BackgroundColor()).Scale(-1.5f).Text("Flipped text", style); + var scales = new[] { 0.75f, 1f, 1.25f, 1.5f }; + + foreach (var scale in scales) + { + stack + .Item() + .Border(1) + .Scale(scale) + .Padding(10) + .Text($"Content with {scale} scale.", TextStyle.Default.Size(20)); + } }); }); } @@ -547,31 +530,39 @@ namespace QuestPDF.Examples { RenderingTest .Create() - .PageSize(500, 300) + .PageSize(300, 200) + .FileName() .Render(container => { container .Background("#FFF") - .Padding(25) .Box() - .Background(Colors.Green.Lighten4) - .Padding(5) + + .Padding(25) + + .Background(Colors.Green.Lighten3) + .TranslateX(15) .TranslateY(15) - .Text("Text outside of bounds"); + + .Border(2) + .BorderColor(Colors.Green.Darken1) + + .Padding(50) + .Text("Moved text", TextStyle.Default.Size(25)); }); } [Test] - public void Rotate() + public void ConstrainedRotate() { RenderingTest .Create() - .PageSize(450, 450) + .PageSize(350, 350) + .FileName() .Render(container => { container - .Background("#FFF") .Padding(20) .Grid(grid => { @@ -581,11 +572,10 @@ namespace QuestPDF.Examples foreach (var turns in Enumerable.Range(0, 4)) { grid.Item() - .Width(200) - .Height(200) - .Background(Colors.Grey.Lighten3) + .Width(150) + .Height(150) + .Background(Colors.Grey.Lighten2) .Padding(10) - //.Box() .Element(element => { foreach (var x in Enumerable.Range(0, turns)) @@ -594,23 +584,83 @@ namespace QuestPDF.Examples return element; }) .Box() - .Background(Colors.Grey.Lighten1) - .Text($"Rotated {turns * 90} degrees.", TextStyle.Default.Size(14)); + .Background(Colors.White) + .Padding(10) + .Text($"Rotated {turns * 90}°", TextStyle.Default.Size(16)); } }); }); } + [Test] + public void FreeRotate() + { + RenderingTest + .Create() + .PageSize(300, 300) + .FileName() + .Render(container => + { + container + .Padding(25) + .Background(Colors.Grey.Lighten2) + + .AlignCenter() + .AlignMiddle() + + + .Background(Colors.White) + + .Rotate(30) + + .Width(100) + .Height(100) + .Background(Colors.Blue.Medium); + }); + } + + [Test] + public void FreeRotateCenter() + { + RenderingTest + .Create() + .PageSize(300, 300) + .FileName() + .Render(container => + { + container + .Padding(25) + .Background(Colors.Grey.Lighten2) + + .AlignCenter() + .AlignMiddle() + + .Background(Colors.White) + + .TranslateX(50) + .TranslateY(50) + + .Rotate(30) + + .TranslateX(-50) + .TranslateY(-50) + + .Width(100) + .Height(100) + .Background(Colors.Blue.Medium); + }); + } + [Test] public void Flip() { RenderingTest .Create() - .PageSize(450, 450) + .PageSize(350, 350) + .FileName() .Render(container => { container - .Background("#FFF") .Padding(20) .Grid(grid => { @@ -620,21 +670,24 @@ namespace QuestPDF.Examples foreach (var turns in Enumerable.Range(0, 4)) { grid.Item() - .Width(200) - .Height(200) + .Width(150) + .Height(150) .Background(Colors.Grey.Lighten3) .Padding(10) .Element(element => { if (turns == 1 || turns == 2) - element = element.FlipX(); + element = element.FlipHorizontal(); if (turns == 2 || turns == 3) - element = element.FlipY(); + element = element.FlipVertical(); return element; }) - .Text($"Flipped.", TextStyle.Default.Size(14)); + .Box() + .Background(Colors.White) + .Padding(10) + .Text($"Flipped {turns}", TextStyle.Default.Size(16)); } }); }); @@ -646,6 +699,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(200, 200) + .FileName() .Render(container => { container @@ -666,30 +720,38 @@ namespace QuestPDF.Examples } [Test] - public void Floating() + public void Unconstrained() { RenderingTest .Create() - .PageSize(400, 300) + .PageSize(400, 350) + .FileName() .Render(container => { container - .Padding(50) - .Layers(layers => + .Padding(25) + .PaddingLeft(75) + .Stack(stack => { - layers - .PrimaryLayer() - .Background(Colors.Green.Lighten4) - .Extend(); + stack.Item().Width(300).Height(150).Background(Colors.Blue.Lighten4); - layers - .Layer() - .Rotate(17) - .TranslateX(-100) + stack + .Item() + + // creates an infinite space for its child + .Unconstrained() + + // moves the child up and left + .TranslateX(-50) .TranslateY(-50) - .Width(200) + + // limits the space for the child + .Width(100) .Height(100) - .Background(Colors.Green.Medium); + + .Background(Colors.Blue.Darken1); + + stack.Item().Width(300).Height(150).Background(Colors.Blue.Lighten3); }); }); } diff --git a/QuestPDF.Examples/Engine/RenderingTest.cs b/QuestPDF.Examples/Engine/RenderingTest.cs index fc95be5..98b3254 100644 --- a/QuestPDF.Examples/Engine/RenderingTest.cs +++ b/QuestPDF.Examples/Engine/RenderingTest.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.Runtime.CompilerServices; using QuestPDF.Drawing; using QuestPDF.Elements; using QuestPDF.Fluent; @@ -23,7 +24,7 @@ namespace QuestPDF.Examples.Engine return new RenderingTest(); } - public RenderingTest FileName(string fileName) + public RenderingTest FileName([CallerMemberName] string fileName = "test") { FileNamePrefix = fileName; return this; diff --git a/QuestPDF.Examples/FrameExample.cs b/QuestPDF.Examples/FrameExample.cs index 319f1fb..9f11f2c 100644 --- a/QuestPDF.Examples/FrameExample.cs +++ b/QuestPDF.Examples/FrameExample.cs @@ -28,6 +28,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(550, 400) + .FileName() .Render(container => { container diff --git a/QuestPDF.Examples/LoremPicsumExample.cs b/QuestPDF.Examples/LoremPicsumExample.cs index c20094a..3919bec 100644 --- a/QuestPDF.Examples/LoremPicsumExample.cs +++ b/QuestPDF.Examples/LoremPicsumExample.cs @@ -36,6 +36,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(350, 280) + .FileName() .Render(container => { container diff --git a/QuestPDF.Examples/Padding.cs b/QuestPDF.Examples/Padding.cs index 6a3446f..6bf96c8 100644 --- a/QuestPDF.Examples/Padding.cs +++ b/QuestPDF.Examples/Padding.cs @@ -13,6 +13,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(200, 150) + .FileName() .Render(container => { container @@ -35,6 +36,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(200, 150) + .FileName() .Render(container => { container @@ -58,6 +60,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(200, 150) + .FileName() .Render(container => { container @@ -108,6 +111,7 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(200, 150) + .FileName() .Render(container => { container diff --git a/QuestPDF/Elements/Rotate.cs b/QuestPDF/Elements/Rotate.cs index eeae4a9..8ad368c 100644 --- a/QuestPDF/Elements/Rotate.cs +++ b/QuestPDF/Elements/Rotate.cs @@ -5,7 +5,7 @@ namespace QuestPDF.Elements internal class Rotate : ContainerElement { public float Angle { get; set; } = 0; - + internal override void Draw(Size availableSpace) { var skiaCanvas = (Canvas as Drawing.SkiaCanvasBase)?.Canvas; diff --git a/QuestPDF/Elements/Translate.cs b/QuestPDF/Elements/Translate.cs index dcffa78..d027eed 100644 --- a/QuestPDF/Elements/Translate.cs +++ b/QuestPDF/Elements/Translate.cs @@ -5,8 +5,8 @@ namespace QuestPDF.Elements { internal class Translate : ContainerElement { - public float TranslateX { get; set; } = 1; - public float TranslateY { get; set; } = 1; + public float TranslateX { get; set; } = 0; + public float TranslateY { get; set; } = 0; internal override void Draw(Size availableSpace) { diff --git a/QuestPDF/Elements/Unconstrained.cs b/QuestPDF/Elements/Unconstrained.cs index eb9c43b..6734ca2 100644 --- a/QuestPDF/Elements/Unconstrained.cs +++ b/QuestPDF/Elements/Unconstrained.cs @@ -21,7 +21,12 @@ namespace QuestPDF.Elements internal override void Draw(Size availableSpace) { - Child?.Draw(Size.Max); + var measurement = Child?.Measure(Size.Max) as Size; + + if (measurement == null) + return; + + Child?.Draw(measurement); } } } \ No newline at end of file diff --git a/QuestPDF/Fluent/ElementExtensions.cs b/QuestPDF/Fluent/ElementExtensions.cs index df4e006..591afd4 100644 --- a/QuestPDF/Fluent/ElementExtensions.cs +++ b/QuestPDF/Fluent/ElementExtensions.cs @@ -104,7 +104,7 @@ namespace QuestPDF.Fluent style.Alignment = alignment.Horizontal; } - element.Element(new Text() + element.Element(new Text { Value = text.ToString(), Style = style diff --git a/QuestPDF/Fluent/GenerateExtensions.cs b/QuestPDF/Fluent/GenerateExtensions.cs index 1d698ee..0027da0 100644 --- a/QuestPDF/Fluent/GenerateExtensions.cs +++ b/QuestPDF/Fluent/GenerateExtensions.cs @@ -39,6 +39,10 @@ namespace QuestPDF.Fluent foreach (var imageData in document.GenerateImages()) { var path = filePath(index); + + if (File.Exists(path)) + File.Delete(path); + File.WriteAllBytes(path, imageData); index++; } diff --git a/QuestPDF/Fluent/ScaleExtensions.cs b/QuestPDF/Fluent/ScaleExtensions.cs index 6e1e9ca..58ae16a 100644 --- a/QuestPDF/Fluent/ScaleExtensions.cs +++ b/QuestPDF/Fluent/ScaleExtensions.cs @@ -16,32 +16,32 @@ namespace QuestPDF.Fluent public static IContainer Scale(this IContainer element, float value) { - return element.ScaleX(value).ScaleY(value); + return element.ScaleHorizontal(value).ScaleVertical(value); } - public static IContainer ScaleX(this IContainer element, float value) + public static IContainer ScaleHorizontal(this IContainer element, float value) { return element.Scale(x => x.ScaleX = value); } - public static IContainer FlipX(this IContainer element) + public static IContainer FlipHorizontal(this IContainer element) { - return element.ScaleX(-1); + return element.ScaleHorizontal(-1); } - public static IContainer ScaleY(this IContainer element, float value) + public static IContainer ScaleVertical(this IContainer element, float value) { return element.Scale(x => x.ScaleY = value); } - public static IContainer FlipY(this IContainer element) + public static IContainer FlipVertical(this IContainer element) { - return element.ScaleY(-1); + return element.ScaleVertical(-1); } public static IContainer FlipOver(this IContainer element) { - return element.FlipX().FlipY(); + return element.FlipHorizontal().FlipVertical(); } } } \ No newline at end of file