Updated base to 2021.11

This commit is contained in:
Marcin Ziąbek
2021-11-04 01:02:44 +01:00
parent 9de87061e4
commit c64754241d
10 changed files with 57 additions and 59 deletions
-1
View File
@@ -13,7 +13,6 @@ namespace QuestPDF.Examples
RenderingTest
.Create()
.PageSize(500, 360)
.FileName()
.Render(container =>
{
container
+2 -11
View File
@@ -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()
};
}
}
@@ -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<ImagePlaceholder>());
Enumerable
.Range(0, model.PhotoCount)
.ToList()
.ForEach(x => grid.Item().AspectRatio(4 / 3f).Component<ImagePlaceholder>());
});
}
}
+2 -8
View File
@@ -44,22 +44,16 @@ namespace QuestPDF.ReportSample
public class ReportSectionMap : ReportSectionElement
{
public Func<Size, byte[]> ImageSource { get; set; }
public Location Location { get; set; }
}
public class ReportSectionPhotos : ReportSectionElement
{
public List<byte[]> Photos { get; set; }
public int PhotoCount { get; set; }
}
public class ReportPhoto
{
public byte[] PhotoData { get; set; }
public Func<Size, byte[]> MapDetailsSource { get; set; }
public Func<Size, byte[]> MapContextSource { get; set; }
{
public Location Location { get; set; }
public DateTime? Date { get; set; }
+5 -1
View File
@@ -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();
+4 -2
View File
@@ -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();
+10 -10
View File
@@ -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
+21 -17
View File
@@ -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<InlinedElement> 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)
+3 -3
View File
@@ -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);
}
+2 -2
View File
@@ -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));
}