Improved Row element stability
This commit is contained in:
@@ -67,6 +67,12 @@ namespace QuestPDF.Examples.Engine
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RenderingTest MaxPages(int value)
|
||||||
|
{
|
||||||
|
MaxPagesThreshold = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public void Render(Action<IContainer> content)
|
public void Render(Action<IContainer> content)
|
||||||
{
|
{
|
||||||
RenderDocument(container =>
|
RenderDocument(container =>
|
||||||
@@ -78,11 +84,6 @@ namespace QuestPDF.Examples.Engine
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MaxPages(int value)
|
|
||||||
{
|
|
||||||
MaxPagesThreshold = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RenderDocument(Action<IDocumentContainer> content)
|
public void RenderDocument(Action<IDocumentContainer> content)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
using NUnit.Framework;
|
||||||
|
using QuestPDF.Examples.Engine;
|
||||||
|
using QuestPDF.Fluent;
|
||||||
|
using QuestPDF.Helpers;
|
||||||
|
using QuestPDF.Infrastructure;
|
||||||
|
|
||||||
|
namespace QuestPDF.Examples
|
||||||
|
{
|
||||||
|
public class RowExamples
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void Stability()
|
||||||
|
{
|
||||||
|
// up to version 2021.12, this code would always result with the infinite layout exception
|
||||||
|
|
||||||
|
RenderingTest
|
||||||
|
.Create()
|
||||||
|
.ProducePdf()
|
||||||
|
.MaxPages(100)
|
||||||
|
.PageSize(250, 150)
|
||||||
|
.ShowResults()
|
||||||
|
.Render(container =>
|
||||||
|
{
|
||||||
|
container
|
||||||
|
.Padding(25)
|
||||||
|
.Row(row =>
|
||||||
|
{
|
||||||
|
row.RelativeColumn().Stack(stack =>
|
||||||
|
{
|
||||||
|
stack.Item().ShowOnce().Element(CreateBox).Text("X");
|
||||||
|
stack.Item().Element(CreateBox).Text("1");
|
||||||
|
stack.Item().Element(CreateBox).Text("2");
|
||||||
|
});
|
||||||
|
|
||||||
|
row.RelativeColumn().Stack(stack =>
|
||||||
|
{
|
||||||
|
stack.Item().Element(CreateBox).Text("1");
|
||||||
|
stack.Item().Element(CreateBox).Text("2");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
static IContainer CreateBox(IContainer container)
|
||||||
|
{
|
||||||
|
return container
|
||||||
|
.ExtendHorizontal()
|
||||||
|
.ExtendVertical()
|
||||||
|
.Background(Colors.Grey.Lighten4)
|
||||||
|
.Border(1)
|
||||||
|
.AlignCenter()
|
||||||
|
.AlignMiddle()
|
||||||
|
.ShowOnce();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,11 +34,20 @@ namespace QuestPDF.Elements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class BinaryRow : Element, ICacheable
|
internal class BinaryRow : Element, ICacheable, IStateResettable
|
||||||
{
|
{
|
||||||
internal Element Left { get; set; }
|
internal Element Left { get; set; }
|
||||||
internal Element Right { get; set; }
|
internal Element Right { get; set; }
|
||||||
|
|
||||||
|
private bool IsLeftRendered { get; set; }
|
||||||
|
private bool IsRightRendered { get; set; }
|
||||||
|
|
||||||
|
public void ResetState()
|
||||||
|
{
|
||||||
|
IsLeftRendered = false;
|
||||||
|
IsRightRendered = false;
|
||||||
|
}
|
||||||
|
|
||||||
internal override void HandleVisitor(Action<Element?> visit)
|
internal override void HandleVisitor(Action<Element?> visit)
|
||||||
{
|
{
|
||||||
Left.HandleVisitor(visit);
|
Left.HandleVisitor(visit);
|
||||||
@@ -52,27 +61,34 @@ namespace QuestPDF.Elements
|
|||||||
Left = create(Left);
|
Left = create(Left);
|
||||||
Right = create(Right);
|
Right = create(Right);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal override SpacePlan Measure(Size availableSpace)
|
internal override SpacePlan Measure(Size availableSpace)
|
||||||
{
|
{
|
||||||
var leftMeasurement = Left.Measure(new Size(availableSpace.Width, availableSpace.Height));
|
var leftMeasurement = Left.Measure(new Size(availableSpace.Width, availableSpace.Height));
|
||||||
|
|
||||||
if (leftMeasurement.Type == SpacePlanType.Wrap)
|
if (leftMeasurement.Type == SpacePlanType.Wrap)
|
||||||
return SpacePlan.Wrap();
|
return SpacePlan.Wrap();
|
||||||
|
|
||||||
|
if (leftMeasurement.Type == SpacePlanType.FullRender)
|
||||||
|
IsLeftRendered = true;
|
||||||
|
|
||||||
var rightMeasurement = Right.Measure(new Size(availableSpace.Width - leftMeasurement.Width, availableSpace.Height));
|
var rightMeasurement = Right.Measure(new Size(availableSpace.Width - leftMeasurement.Width, availableSpace.Height));
|
||||||
|
|
||||||
if (rightMeasurement.Type == SpacePlanType.Wrap)
|
if (rightMeasurement.Type == SpacePlanType.Wrap)
|
||||||
return SpacePlan.Wrap();
|
return SpacePlan.Wrap();
|
||||||
|
|
||||||
|
if (leftMeasurement.Type == SpacePlanType.FullRender)
|
||||||
|
IsRightRendered = true;
|
||||||
|
|
||||||
var totalWidth = leftMeasurement.Width + rightMeasurement.Width;
|
var totalWidth = leftMeasurement.Width + rightMeasurement.Width;
|
||||||
var totalHeight = Math.Max(leftMeasurement.Height, rightMeasurement.Height);
|
var totalHeight = Math.Max(leftMeasurement.Height, rightMeasurement.Height);
|
||||||
|
|
||||||
var targetSize = new Size(totalWidth, totalHeight);
|
var targetSize = new Size(totalWidth, totalHeight);
|
||||||
|
|
||||||
if (leftMeasurement.Type == SpacePlanType.PartialRender || rightMeasurement.Type == SpacePlanType.PartialRender)
|
if ((!IsLeftRendered && leftMeasurement.Type == SpacePlanType.PartialRender) ||
|
||||||
|
(!IsRightRendered && rightMeasurement.Type == SpacePlanType.PartialRender))
|
||||||
return SpacePlan.PartialRender(targetSize);
|
return SpacePlan.PartialRender(targetSize);
|
||||||
|
|
||||||
return SpacePlan.FullRender(targetSize);
|
return SpacePlan.FullRender(targetSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,10 +28,5 @@ namespace QuestPDF.Infrastructure
|
|||||||
|
|
||||||
internal abstract SpacePlan Measure(Size availableSpace);
|
internal abstract SpacePlan Measure(Size availableSpace);
|
||||||
internal abstract void Draw(Size availableSpace);
|
internal abstract void Draw(Size availableSpace);
|
||||||
|
|
||||||
protected virtual IEnumerable<string> GetDebugInformation()
|
|
||||||
{
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user