RTL: table, decoration, minimal box

This commit is contained in:
MarcinZiabek
2022-09-29 14:46:56 +02:00
parent 5ff9d03f20
commit e277c6a8dc
5 changed files with 91 additions and 17 deletions
+54 -1
View File
@@ -42,7 +42,6 @@ namespace QuestPDF.Examples
.Padding(25)
.ContentFromRightToLeft()
.Border(1)
.MinimalBox()
.Row(row =>
{
row.ConstantItem(200).Background(Colors.Red.Lighten2).Height(200);
@@ -51,5 +50,59 @@ namespace QuestPDF.Examples
});
});
}
[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);
});
});
}
}
}
+9 -3
View File
@@ -14,8 +14,10 @@ namespace QuestPDF.Elements
public Position Offset { get; set; }
}
internal class Decoration : Element, ICacheable
internal class Decoration : Element, ICacheable, IContentDirectionAware
{
public ContentDirection ContentDirection { get; set; }
internal Element Before { get; set; } = new Empty();
internal Element Content { get; set; } = new Empty();
internal Element After { get; set; } = new Empty();
@@ -64,9 +66,13 @@ namespace QuestPDF.Elements
{
var elementSize = new Size(width, command.Measurement.Height);
Canvas.Translate(command.Offset);
var offset = ContentDirection == ContentDirection.LeftToRight
? command.Offset
: new Position(availableSpace.Width - command.Offset.X - command.Measurement.Width, command.Offset.Y);
Canvas.Translate(offset);
command.Element.Draw(elementSize);
Canvas.Translate(command.Offset.Reverse());
Canvas.Translate(offset.Reverse());
}
}
+9 -1
View File
@@ -3,8 +3,10 @@ using QuestPDF.Infrastructure;
namespace QuestPDF.Elements
{
internal class MinimalBox : ContainerElement
internal class MinimalBox : ContainerElement, IContentDirectionAware
{
public ContentDirection ContentDirection { get; set; }
internal override void Draw(Size availableSpace)
{
var targetSize = base.Measure(availableSpace);
@@ -12,7 +14,13 @@ namespace QuestPDF.Elements
if (targetSize.Type == SpacePlanType.Wrap)
return;
var translate = ContentDirection == ContentDirection.RightToLeft
? new Position(availableSpace.Width - targetSize.Width, 0)
: Position.Zero;
Canvas.Translate(translate);
base.Draw(targetSize);
Canvas.Translate(translate.Reverse());
}
}
}
+7 -6
View File
@@ -64,7 +64,7 @@ namespace QuestPDF.Elements
if (renderingCommands.Any(x => !x.RowItem.IsRendered && x.Measurement.Type == SpacePlanType.Wrap))
return SpacePlan.Wrap();
var width = renderingCommands.Max(c => c.Offset.X + c.Size.Width);
var width = renderingCommands.Last().Offset.X + renderingCommands.Last().Size.Width;
var height = renderingCommands.Max(x => x.Size.Height);
var size = new Size(width, height);
@@ -93,9 +93,13 @@ namespace QuestPDF.Elements
if (command.Measurement.Type == SpacePlanType.Wrap)
continue;
Canvas.Translate(command.Offset);
var offset = ContentDirection == ContentDirection.LeftToRight
? command.Offset
: new Position(availableSpace.Width - command.Offset.X - command.Size.Width, 0);
Canvas.Translate(offset);
command.RowItem.Draw(command.Size);
Canvas.Translate(command.Offset.Reverse());
Canvas.Translate(offset.Reverse());
}
if (Items.All(x => x.IsRendered))
@@ -154,9 +158,6 @@ namespace QuestPDF.Elements
{
command.Size = new Size(command.Size.Width, rowHeight);
command.Measurement = command.RowItem.Measure(command.Size);
if (ContentDirection == ContentDirection.RightToLeft)
command.Offset = new Position(availableSpace.Width - command.Offset.X - command.Size.Width, 0);
}
return renderingCommands;
+12 -6
View File
@@ -9,10 +9,12 @@ using QuestPDF.Infrastructure;
namespace QuestPDF.Elements.Table
{
internal class Table : Element, IStateResettable
internal class Table : Element, IStateResettable, IContentDirectionAware
{
public List<TableColumnDefinition> Columns { get; set; } = new List<TableColumnDefinition>();
public List<TableCell> Cells { get; set; } = new List<TableCell>();
public ContentDirection ContentDirection { get; set; }
public List<TableColumnDefinition> Columns { get; set; } = new();
public List<TableCell> Cells { get; set; } = new();
public bool ExtendLastCellsToTableBottom { get; set; }
private int StartingRowsCount { get; set; }
@@ -109,9 +111,13 @@ namespace QuestPDF.Elements.Table
if (command.Measurement.Type == SpacePlanType.Wrap)
continue;
Canvas.Translate(command.Offset);
var offset = ContentDirection == ContentDirection.LeftToRight
? command.Offset
: new Position(availableSpace.Width - command.Offset.X - command.Size.Width, 0);
Canvas.Translate(offset);
command.Cell.Draw(command.Size);
Canvas.Translate(command.Offset.Reverse());
Canvas.Translate(offset.Reverse());
}
CurrentRow = FindLastRenderedRow(renderingCommands) + 1;
@@ -158,7 +164,7 @@ namespace QuestPDF.Elements.Table
if (ExtendLastCellsToTableBottom)
AdjustLastCellSizes(tableHeight, commands);
return commands;
static float[] GetColumnLeftOffsets(IList<TableColumnDefinition> columns)