diff --git a/QuestPDF.Examples/ContentDirectionExamples.cs b/QuestPDF.Examples/ContentDirectionExamples.cs new file mode 100644 index 0000000..ed322d1 --- /dev/null +++ b/QuestPDF.Examples/ContentDirectionExamples.cs @@ -0,0 +1,356 @@ +using System; +using System.Linq; +using NUnit.Framework; +using QuestPDF.Drawing.Exceptions; +using QuestPDF.Elements; +using QuestPDF.Examples.Engine; +using QuestPDF.Fluent; +using QuestPDF.Helpers; +using QuestPDF.Infrastructure; + +namespace QuestPDF.Examples +{ + public class ContentDirectionExamples + { + private Action ContentDirectionTemplate(Action content) + { + return container => + { + container + .Padding(20) + .MinimalBox() + .Border(1) + .ExtendHorizontal() + .Table(table => + { + table.ColumnsDefinition(columns => + { + columns.RelativeColumn(); + columns.RelativeColumn(); + }); + + table.Header(header => + { + header.Cell().ContentFromLeftToRight().Element(HeaderCell("Left-to-right")); + header.Cell().ContentFromRightToLeft().Element(HeaderCell("Right-to-left")); + + static Action HeaderCell(string label) + { + return container => container + .Border(1) + .BorderColor(Colors.Grey.Medium) + .Background(Colors.Grey.Lighten3) + .PaddingHorizontal(10) + .PaddingVertical(5) + .Text(label) + .FontSize(18) + .SemiBold(); + } + }); + + table.Cell().Element(TestCell).ContentFromLeftToRight().Element(content); + + table.Cell() + .Element(TestCell) + .ContentFromRightToLeft() + .Element(content); + + static IContainer TestCell(IContainer container) + { + return container.Border(1).BorderColor(Colors.Grey.Medium).Padding(10); + } + }); + }; + } + + [Test] + public void Page() + { + RenderingTest + .Create() + .ProduceImages() + .ShowResults() + .EnableDebugging() + .RenderDocument(document => + { + document.Page(page => + { + page.Size(PageSizes.A5); + page.Margin(20); + page.PageColor(Colors.White); + + //page.ContentFromRightToLeft(); + + page.Content().Column(column => + { + column.Spacing(20); + + column.Item().Row(row => + { + row.Spacing(10); + + row.AutoItem().AlignMiddle().Width(20).Height(20).Image(Placeholders.Image); + + row.RelativeItem() + .Text("Document title") + .FontSize(24).FontColor(Colors.Blue.Accent1).SemiBold(); + }); + + column.Item().Table(table => + { + table.ColumnsDefinition(columns => + { + columns.RelativeColumn(); + columns.RelativeColumn(); + columns.RelativeColumn(); + columns.RelativeColumn(); + }); + + foreach (var i in Enumerable.Range(0, 9)) + { + var width = (i % 4 == 0) ? 2 : 1; + + table + .Cell() + .ColumnSpan((uint)width) + .Background(i % 4 == 0 ? Colors.Grey.Lighten1 : Colors.Grey.Lighten2) + .Padding(5) + .AlignCenter() + .Text(i) + .FontSize(20); + } + }); + }); + }); + }); + } + + [Test] + public void Column() + { + RenderingTest + .Create() + .PageSize(PageSizes.A4) + .ProduceImages() + .ShowResults() + .EnableDebugging() + .Render(ContentDirectionTemplate(Content)); + + void Content(IContainer container) + { + container.Column(column => + { + column.Spacing(5); + + column.Item().Height(50).Width(50).Background(Colors.Red.Lighten1); + column.Item().Height(50).Width(100).Background(Colors.Green.Lighten1); + column.Item().Height(50).Width(150).Background(Colors.Blue.Lighten1); + }); + } + } + + [Test] + public void Row() + { + RenderingTest + .Create() + .PageSize(PageSizes.A4) + .ProduceImages() + .ShowResults() + .EnableDebugging() + .Render(ContentDirectionTemplate(Content)); + + void Content(IContainer container) + { + container.Row(row => + { + row.Spacing(5); + + row.AutoItem().Height(50).Width(50).Background(Colors.Red.Lighten1); + row.AutoItem().Height(50).Width(50).Background(Colors.Green.Lighten1); + row.AutoItem().Height(50).Width(75).Background(Colors.Blue.Lighten1); + }); + } + } + + [Test] + public void Table() + { + RenderingTest + .Create() + .PageSize(PageSizes.A4) + .ProduceImages() + .ShowResults() + .EnableDebugging() + .Render(ContentDirectionTemplate(Content)); + + void Content(IContainer container) + { + container.Table(table => + { + table.ColumnsDefinition(columns => + { + columns.RelativeColumn(); + columns.RelativeColumn(); + columns.RelativeColumn(); + }); + + table.Cell().Height(50).Background(Colors.Red.Lighten1); + table.Cell().Height(50).Background(Colors.Green.Lighten1); + table.Cell().Height(50).Background(Colors.Blue.Lighten1); + table.Cell().ColumnSpan(2).Height(50).Background(Colors.Orange.Lighten1); + }); + } + } + + [Test] + public void Constrained() + { + RenderingTest + .Create() + .PageSize(PageSizes.A4) + .ProduceImages() + .ShowResults() + .EnableDebugging() + .Render(ContentDirectionTemplate(Content)); + + void Content(IContainer container) + { + container.Width(50).Height(50).Background(Colors.Red.Lighten1); + } + } + + [Test] + public void Unconstrained() + { + RenderingTest + .Create() + .PageSize(PageSizes.A4) + .ProduceImages() + .ShowResults() + .EnableDebugging() + .Render(ContentDirectionTemplate(Content)); + + void Content(IContainer container) + { + container + .Width(100) + .Height(100) + .Background(Colors.Grey.Lighten3) + .AlignCenter() + .AlignMiddle() + + .Unconstrained() + + .Width(50) + .Height(50) + .Background(Colors.Red.Lighten1); + } + } + + [Test] + public void Inlined() + { + RenderingTest + .Create() + .PageSize(PageSizes.A4) + .ProduceImages() + .ShowResults() + .EnableDebugging() + .Render(ContentDirectionTemplate(Content)); + + void Content(IContainer container) + { + container.Inlined(inlined => + { + inlined.Spacing(5); + + inlined.Item().Height(50).Width(50).Background(Colors.Red.Lighten1); + inlined.Item().Height(50).Width(75).Background(Colors.Green.Lighten1); + inlined.Item().Height(50).Width(100).Background(Colors.Blue.Lighten1); + inlined.Item().Height(50).Width(125).Background(Colors.Orange.Lighten1); + }); + } + } + + [Test] + public void Text() + { + RenderingTest + .Create() + .PageSize(PageSizes.A4) + .ProduceImages() + .ShowResults() + .EnableDebugging() + .Render(ContentDirectionTemplate(Content)); + + void Content(IContainer container) + { + container.Text(Placeholders.LoremIpsum()); + } + } + + [Test] + public void Decoration() + { + RenderingTest + .Create() + .PageSize(PageSizes.A4) + .ProduceImages() + .ShowResults() + .EnableDebugging() + .Render(ContentDirectionTemplate(Content)); + + void Content(IContainer container) + { + container.Decoration(decoration => + { + decoration.Before().Background(Colors.Green.Lighten1).Padding(5).Text("Before").FontSize(16); + decoration.Content().Background(Colors.Green.Lighten2).Padding(5).Text("Content").FontSize(16); + decoration.After().Background(Colors.Green.Lighten3).Padding(5).Text("After").FontSize(16); + }); + } + } + + [Test] + public void Dynamic() + { + RenderingTest + .Create() + .PageSize(PageSizes.A4) + .ProduceImages() + .ShowResults() + .EnableDebugging() + .Render(ContentDirectionTemplate(Content)); + + void Content(IContainer container) + { + container.Dynamic(new SimpleDynamic()); + } + } + + class SimpleDynamic : IDynamicComponent + { + public int State { get; set; } + + public DynamicComponentComposeResult Compose(DynamicContext context) + { + var content = context.CreateElement(container => + { + container.Row(row => + { + row.ConstantItem(50).Background(Colors.Red.Lighten2).Height(50); + row.ConstantItem(75).Background(Colors.Green.Lighten2).Height(50); + row.ConstantItem(100).Background(Colors.Blue.Lighten2).Height(50); + }); + }); + + return new DynamicComponentComposeResult + { + Content = content, + HasMoreContent = false + }; + } + } + } +} \ No newline at end of file diff --git a/QuestPDF.Examples/RightToLeftExamples.cs b/QuestPDF.Examples/RightToLeftExamples.cs deleted file mode 100644 index a6e0994..0000000 --- a/QuestPDF.Examples/RightToLeftExamples.cs +++ /dev/null @@ -1,269 +0,0 @@ -using System.Linq; -using NUnit.Framework; -using QuestPDF.Elements; -using QuestPDF.Examples.Engine; -using QuestPDF.Fluent; -using QuestPDF.Helpers; -using QuestPDF.Infrastructure; - -namespace QuestPDF.Examples -{ - public class RightToLeftExamples - { - [Test] - public void Unconstrained() - { - RenderingTest - .Create() - .ProduceImages() - .PageSize(600, 600) - .ShowResults() - .Render(container => - { - container - .AlignCenter() - .AlignMiddle() - .ContentFromRightToLeft() - .Unconstrained() - .Background(Colors.Red.Medium) - .Height(200) - .Width(200); - }); - } - - [Test] - public void Row() - { - RenderingTest - .Create() - .ProduceImages() - .PageSize(600, 600) - .ShowResults() - .Render(container => - { - container - .Padding(25) - .ContentFromRightToLeft() - .Border(1) - .Row(row => - { - row.ConstantItem(200).Background(Colors.Red.Lighten2).Height(200); - row.ConstantItem(150).Background(Colors.Green.Lighten2).Height(200); - row.ConstantItem(100).Background(Colors.Blue.Lighten2).Height(200); - }); - }); - } - - [Test] - public void MinimalBox() - { - RenderingTest - .Create() - .ProduceImages() - .PageSize(600, 600) - .ShowResults() - .Render(container => - { - container - .Padding(25) - .ContentFromRightToLeft() - .Border(1) - .MinimalBox() - .Column(column => - { - column.Item().Background(Colors.Red.Lighten2).Width(200).Height(200); - column.Item().Background(Colors.Green.Lighten2).Width(150).Height(150); - column.Item().Background(Colors.Blue.Lighten2).Width(100).Height(100); - }); - }); - } - - [Test] - public void Table() - { - RenderingTest - .Create() - .ProduceImages() - .PageSize(600, 600) - .ShowResults() - .Render(container => - { - container - .Padding(25) - .ContentFromRightToLeft() - .Border(1) - .Table(table => - { - table.ColumnsDefinition(columns => - { - columns.ConstantColumn(200); - columns.ConstantColumn(150); - columns.ConstantColumn(100); - }); - - table.Cell().Background(Colors.Red.Lighten2).Height(200); - table.Cell().Background(Colors.Green.Lighten2).Height(200); - table.Cell().Background(Colors.Blue.Lighten2).Height(200); - }); - }); - } - - [Test] - public void AspectRatio() - { - RenderingTest - .Create() - .ProduceImages() - .PageSize(600, 600) - .ShowResults() - .Render(container => - { - container - .Padding(25) - .ContentFromRightToLeft() - .Border(1) - .AspectRatio(0.55f, AspectRatioOption.FitArea) - .Background(Colors.Red.Medium); - }); - } - - [Test] - public void Constrained() - { - RenderingTest - .Create() - .ProduceImages() - .PageSize(600, 600) - .ShowResults() - .Render(container => - { - container - .Padding(25) - .ContentFromRightToLeft() - .Border(1) - .MaxWidth(100) - .Background(Colors.Red.Medium); - }); - } - - [Test] - public void Dynamic() - { - RenderingTest - .Create() - .ProduceImages() - .PageSize(600, 600) - .ShowResults() - .Render(container => - { - container - .Padding(25) - .ContentFromRightToLeft() - .Dynamic(new SimpleDynamic()); - }); - } - - class SimpleDynamic : IDynamicComponent - { - public int State { get; set; } - - public DynamicComponentComposeResult Compose(DynamicContext context) - { - var content = context.CreateElement(container => - { - container - .Row(row => - { - row.ConstantItem(200).Background(Colors.Red.Lighten2).Height(200); - row.ConstantItem(150).Background(Colors.Green.Lighten2).Height(200); - row.ConstantItem(100).Background(Colors.Blue.Lighten2).Height(200); - }); - }); - - return new DynamicComponentComposeResult - { - Content = content, - HasMoreContent = false - }; - } - } - - [Test] - public void Grid() - { - RenderingTest - .Create() - .ProduceImages() - .PageSize(600, 600) - .ShowResults() - .Render(container => - { - container - .Padding(25) - .Border(1) - .ContentFromRightToLeft() - .Grid(grid => - { - grid.Spacing(25); - grid.AlignRight(); - - foreach (var i in Enumerable.Range(1, 6)) - { - grid.Item(i).Background(Placeholders.BackgroundColor()).Height(100); - } - }); - }); - } - - [Test] - public void Inlined() - { - RenderingTest - .Create() - .ProduceImages() - .PageSize(600, 800) - .ShowResults() - .Render(container => - { - container - .Padding(25) - .Border(1) - .ContentFromRightToLeft() - .Inlined(inlined => - { - inlined.Spacing(25); - - foreach (var i in Enumerable.Range(5, 10)) - { - inlined.Item().Background(Placeholders.BackgroundColor()).Height(25 + i * 5).Width(i * 25); - } - }); - }); - } - - [Test] - public void Text() - { - RenderingTest - .Create() - .ProduceImages() - .PageSize(600, 600) - .ShowResults() - .Render(container => - { - container - .Padding(25) - .MinimalBox() - .Border(1) - .ContentFromRightToLeft() - .Text(text => - { - text.DefaultTextStyle(x => x.FontSize(32)); - - foreach (var i in Enumerable.Range(1, 100)) - text.Span($"{i}").FontColor(Placeholders.Color()).BackgroundColor("#2000"); - }); - }); - } - } -} \ No newline at end of file