diff --git a/QuestPDF.Examples/DebuggingTesting.cs b/QuestPDF.Examples/DebuggingTesting.cs index 4021eb2..166f795 100644 --- a/QuestPDF.Examples/DebuggingTesting.cs +++ b/QuestPDF.Examples/DebuggingTesting.cs @@ -13,7 +13,6 @@ namespace QuestPDF.Examples RenderingTest .Create() .PageSize(500, 360) - .FileName() .Render(container => { container diff --git a/QuestPDF.ReportSample/DataSource.cs b/QuestPDF.ReportSample/DataSource.cs index 6f92802..ba18930 100644 --- a/QuestPDF.ReportSample/DataSource.cs +++ b/QuestPDF.ReportSample/DataSource.cs @@ -86,7 +86,6 @@ namespace QuestPDF.ReportSample return new ReportSectionMap { Label = "Location", - ImageSource = Placeholders.Image, Location = Helpers.RandomLocation() }; } @@ -96,10 +95,7 @@ namespace QuestPDF.ReportSample return new ReportSectionPhotos { Label = "Photos", - Photos = Enumerable - .Range(0, Helpers.Random.Next(1, 15)) - .Select(x => Placeholders.Image(400, 300)) - .ToList() + PhotoCount = Helpers.Random.Next(1, 15) }; } @@ -107,14 +103,9 @@ namespace QuestPDF.ReportSample { return new ReportPhoto() { - PhotoData = Placeholders.Image(800, 600), - Comments = Placeholders.Sentence(), Date = DateTime.Now - TimeSpan.FromDays(Helpers.Random.NextDouble() * 100), - Location = Helpers.RandomLocation(), - - MapContextSource = Placeholders.Image, - MapDetailsSource = Placeholders.Image + Location = Helpers.RandomLocation() }; } } diff --git a/QuestPDF.ReportSample/Layouts/SectionTemplate.cs b/QuestPDF.ReportSample/Layouts/SectionTemplate.cs index df712e2..fa1eb5e 100644 --- a/QuestPDF.ReportSample/Layouts/SectionTemplate.cs +++ b/QuestPDF.ReportSample/Layouts/SectionTemplate.cs @@ -1,3 +1,4 @@ +using System.Linq; using QuestPDF.Fluent; using QuestPDF.Helpers; using QuestPDF.Infrastructure; @@ -49,7 +50,7 @@ namespace QuestPDF.ReportSample.Layouts void MapElement(IContainer container, ReportSectionMap model) { - if (model.ImageSource == null || model.Location == null) + if (model.Location == null) { container.Text("No location provided"); return; @@ -66,18 +67,21 @@ namespace QuestPDF.ReportSample.Layouts void PhotosElement(IContainer container, ReportSectionPhotos model) { - if (model.Photos.Count == 0) + if (model.PhotoCount == 0) { container.Text("No photos", Typography.Normal); return; } - container.Debug("Photos").Grid(grid => + container.DebugArea("Photos").Grid(grid => { grid.Spacing(5); grid.Columns(3); - model.Photos.ForEach(x => grid.Item().AspectRatio(4 / 3f).Component()); + Enumerable + .Range(0, model.PhotoCount) + .ToList() + .ForEach(x => grid.Item().AspectRatio(4 / 3f).Component()); }); } } diff --git a/QuestPDF.ReportSample/Models.cs b/QuestPDF.ReportSample/Models.cs index 593b1e6..cd5e963 100644 --- a/QuestPDF.ReportSample/Models.cs +++ b/QuestPDF.ReportSample/Models.cs @@ -44,22 +44,16 @@ namespace QuestPDF.ReportSample public class ReportSectionMap : ReportSectionElement { - public Func ImageSource { get; set; } public Location Location { get; set; } } public class ReportSectionPhotos : ReportSectionElement { - public List Photos { get; set; } + public int PhotoCount { get; set; } } public class ReportPhoto - { - public byte[] PhotoData { get; set; } - - public Func MapDetailsSource { get; set; } - public Func MapContextSource { get; set; } - + { public Location Location { get; set; } public DateTime? Date { get; set; } diff --git a/QuestPDF.ReportSample/PerformanceTests.cs b/QuestPDF.ReportSample/PerformanceTests.cs index 7e50249..338e7fd 100644 --- a/QuestPDF.ReportSample/PerformanceTests.cs +++ b/QuestPDF.ReportSample/PerformanceTests.cs @@ -16,7 +16,7 @@ using QuestPDF.ReportSample.Layouts; namespace QuestPDF.ReportSample { - [SimpleJob(RunStrategy.Monitoring, launchCount: 0, warmupCount: 1, targetCount: 100)] + [SimpleJob(RunStrategy.Monitoring, launchCount: 0, warmupCount: 1, targetCount: 256)] [MinColumn, MaxColumn, MeanColumn, MedianColumn] public class PerformanceTests { @@ -27,6 +27,8 @@ namespace QuestPDF.ReportSample [Test] public void Run() { + ImagePlaceholder.Solid = true; + var configuration = ManualConfig .Create(DefaultConfig.Instance) .WithOptions(ConfigOptions.DisableOptimizationsValidator); @@ -37,6 +39,8 @@ namespace QuestPDF.ReportSample [IterationSetup] public void GenerateReportData() { + ImagePlaceholder.Solid = true; + var model = DataSource.GetReport(); var report = new StandardReport(model); Metadata = report.GetMetadata(); diff --git a/QuestPDF.ReportSample/Tests.cs b/QuestPDF.ReportSample/Tests.cs index 6983880..ccbc781 100644 --- a/QuestPDF.ReportSample/Tests.cs +++ b/QuestPDF.ReportSample/Tests.cs @@ -17,8 +17,12 @@ namespace QuestPDF.ReportSample [SetUp] public void SetUp() { + ImagePlaceholder.Solid = true; + var model = DataSource.GetReport(); Report = new StandardReport(model); + + ImagePlaceholder.Solid = true; } [Test] @@ -33,8 +37,6 @@ namespace QuestPDF.ReportSample [Test] public void Profile() { - ImagePlaceholder.Solid = true; - var container = new DocumentContainer(); Report.Compose(container); var content = container.Compose(); diff --git a/QuestPDF.UnitTests/ConstrainedTests.cs b/QuestPDF.UnitTests/ConstrainedTests.cs index 99490f1..0c85a0e 100644 --- a/QuestPDF.UnitTests/ConstrainedTests.cs +++ b/QuestPDF.UnitTests/ConstrainedTests.cs @@ -104,7 +104,7 @@ namespace QuestPDF.UnitTests MinWidth = 100 }) .MeasureElement(new Size(50, 400)) - .CheckMeasureResult(new Wrap()); + .CheckMeasureResult(SpacePlan.Wrap()); } [Test] @@ -117,8 +117,8 @@ namespace QuestPDF.UnitTests Child = x.CreateChild() }) .MeasureElement(new Size(200, 400)) - .ExpectChildMeasure(new Size(200, 400), new FullRender(50, 400)) - .CheckMeasureResult(new FullRender(100, 400)); + .ExpectChildMeasure(new Size(200, 400), SpacePlan.FullRender(50, 400)) + .CheckMeasureResult(SpacePlan.FullRender(100, 400)); } [Test] @@ -131,8 +131,8 @@ namespace QuestPDF.UnitTests Child = x.CreateChild() }) .MeasureElement(new Size(200, 400)) - .ExpectChildMeasure(new Size(200, 400), new FullRender(150, 400)) - .CheckMeasureResult(new FullRender(150, 400)); + .ExpectChildMeasure(new Size(200, 400), SpacePlan.FullRender(150, 400)) + .CheckMeasureResult(SpacePlan.FullRender(150, 400)); } [Test] @@ -144,7 +144,7 @@ namespace QuestPDF.UnitTests MaxWidth = 100 }) .MeasureElement(new Size(150, 400)) - .CheckMeasureResult(new FullRender(0, 0)); + .CheckMeasureResult(SpacePlan.FullRender(0, 0)); } [Test] @@ -157,8 +157,8 @@ namespace QuestPDF.UnitTests Child = x.CreateChild() }) .MeasureElement(new Size(200, 400)) - .ExpectChildMeasure(new Size(100, 400), new PartialRender(75, 400)) - .CheckMeasureResult(new PartialRender(75, 400)); + .ExpectChildMeasure(new Size(100, 400), SpacePlan.PartialRender(75, 400)) + .CheckMeasureResult(SpacePlan.PartialRender(75, 400)); } [Test] @@ -171,8 +171,8 @@ namespace QuestPDF.UnitTests Child = x.CreateChild() }) .MeasureElement(new Size(200, 400)) - .ExpectChildMeasure(new Size(100, 400), new Wrap()) - .CheckMeasureResult(new Wrap()); + .ExpectChildMeasure(new Size(100, 400), SpacePlan.Wrap()) + .CheckMeasureResult(SpacePlan.Wrap()); } #endregion diff --git a/QuestPDF/Elements/Inlined.cs b/QuestPDF/Elements/Inlined.cs index 8f0cb0b..71cbd2a 100644 --- a/QuestPDF/Elements/Inlined.cs +++ b/QuestPDF/Elements/Inlined.cs @@ -1,21 +1,21 @@ using System; using System.Collections.Generic; using System.Linq; -using QuestPDF.Drawing.SpacePlan; +using QuestPDF.Drawing; using QuestPDF.Infrastructure; namespace QuestPDF.Elements { internal class InlinedElement : Container { - public ISpacePlan? MeasureCache { get; set; } + public SpacePlan? MeasureCache { get; set; } - internal override ISpacePlan Measure(Size availableSpace) + internal override SpacePlan Measure(Size availableSpace) { // TODO: once element caching proxy is introduces, this can be removed MeasureCache ??= Child.Measure(Size.Max); - return MeasureCache; + return MeasureCache.Value; } } @@ -50,15 +50,15 @@ namespace QuestPDF.Elements base.HandleVisitor(visit); } - internal override ISpacePlan Measure(Size availableSpace) + internal override SpacePlan Measure(Size availableSpace) { if (!ChildrenQueue.Any()) - return new FullRender(Size.Zero); + return SpacePlan.FullRender(Size.Zero); var lines = Compose(availableSpace); if (!lines.Any()) - return new Wrap(); + return SpacePlan.Wrap(); var lineSizes = lines .Select(line => @@ -76,9 +76,9 @@ namespace QuestPDF.Elements var isPartiallyRendered = lines.Sum(x => x.Count) != ChildrenQueue.Count; if (isPartiallyRendered) - return new PartialRender(targetSize); + return SpacePlan.PartialRender(targetSize); - return new FullRender(targetSize); + return SpacePlan.FullRender(targetSize); } internal override void Draw(Size availableSpace) @@ -88,7 +88,11 @@ namespace QuestPDF.Elements foreach (var line in lines) { - var height = line.Select(x => x.Measure(Size.Max) as Size).Where(x => x != null).Max(x => x.Height); + var height = line + .Select(x => x.Measure(Size.Max)) + .Where(x => x.Type != SpacePlanType.Wrap) + .Max(x => x.Height); + DrawLine(line); topOffset += height + VerticalSpacing; @@ -108,7 +112,7 @@ namespace QuestPDF.Elements foreach (var element in elements) { - var size = element.Measure(Size.Max) as Size; + var size = element.Measure(Size.Max); var baselineOffset = BaselineOffset(size, lineSize.Height); Canvas.Translate(new Position(0, baselineOffset)); @@ -177,8 +181,8 @@ namespace QuestPDF.Elements Size GetLineSize(ICollection elements) { var sizes = elements - .Select(x => x.Measure(Size.Max) as Size) - .Where(x => x != null) + .Select(x => x.Measure(Size.Max)) + .Where(x => x.Type != SpacePlanType.Wrap) .ToList(); var width = sizes.Sum(x => x.Width); @@ -203,8 +207,8 @@ namespace QuestPDF.Elements break; var height = line - .Select(x => x.Measure(availableSize) as Size) - .Where(x => x != null) + .Select(x => x.Measure(availableSize)) + .Where(x => x.Type != SpacePlanType.Wrap) .Max(x => x.Height); if (topOffset + height > availableSize.Height + Size.Epsilon) @@ -227,9 +231,9 @@ namespace QuestPDF.Elements break; var element = queue.Peek(); - var size = element.Measure(Size.Max) as Size; + var size = element.Measure(Size.Max); - if (size == null) + if (size.Type == SpacePlanType.Wrap) break; if (leftOffset + size.Width > availableSize.Width + Size.Epsilon) diff --git a/QuestPDF/Elements/SkipOnce.cs b/QuestPDF/Elements/SkipOnce.cs index b1bb9c2..4c4e331 100644 --- a/QuestPDF/Elements/SkipOnce.cs +++ b/QuestPDF/Elements/SkipOnce.cs @@ -1,4 +1,4 @@ -using QuestPDF.Drawing.SpacePlan; +using QuestPDF.Drawing; using QuestPDF.Infrastructure; namespace QuestPDF.Elements @@ -12,10 +12,10 @@ namespace QuestPDF.Elements FirstPageWasSkipped = false; } - internal override ISpacePlan Measure(Size availableSpace) + internal override SpacePlan Measure(Size availableSpace) { if (Child == null || !FirstPageWasSkipped) - return new FullRender(Size.Zero); + return SpacePlan.FullRender(Size.Zero); return Child.Measure(availableSpace); } diff --git a/QuestPDF/Helpers/PageSizes.cs b/QuestPDF/Helpers/PageSizes.cs index f7a59c1..740a7f2 100644 --- a/QuestPDF/Helpers/PageSizes.cs +++ b/QuestPDF/Helpers/PageSizes.cs @@ -65,12 +65,12 @@ namespace QuestPDF.Helpers public static class PageSizeExtensions { - public static PageSize Portrait(this Size size) + public static PageSize Portrait(this PageSize size) { return new PageSize(Math.Min(size.Width, size.Height), Math.Max(size.Width, size.Height)); } - public static PageSize Landscape(this Size size) + public static PageSize Landscape(this PageSize size) { return new PageSize(Math.Max(size.Width, size.Height), Math.Min(size.Width, size.Height)); }