Skip to content

Commit

Permalink
Merge branch 'develop' into devsecops
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed Jan 6, 2024
2 parents 23c83df + ed8f6d9 commit b0e0781
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 189 deletions.
315 changes: 188 additions & 127 deletions itext.tests/itext.layout.tests/itext/layout/KeepTogetherTest.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ public virtual void KeepTogetherWidows() {
}

[NUnit.Framework.Test]
[LogMessage(LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)]
[LogMessage(LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA, Count = 2)]
public virtual void KeepTogetherLargeParagraphOrphans() {
RunKeepTogether("keepTogetherLargeParagraphOrphans", true, true);
}

[NUnit.Framework.Test]
[LogMessage(LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)]
[LogMessage(LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA, Count = 2)]
public virtual void KeepTogetherLargeParagraphWidows() {
RunKeepTogether("keepTogetherLargeParagraphWidows", false, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,7 @@ public virtual void TableBorderPriorityTest() {
}

[NUnit.Framework.Test]
[LogMessage(LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)]
[LogMessage(LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA, Count = 2)]
public virtual void SplitRowspanKeepTogetherTest() {
fileName = "splitRowspanKeepTogetherTest.pdf";
Document doc = CreateDocument();
Expand Down
2 changes: 1 addition & 1 deletion itext.tests/itext.layout.tests/itext/layout/TableTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2854,7 +2854,7 @@ public virtual void BigRowSpanTooFarPartialTest() {
}

[NUnit.Framework.Test]
[LogMessage(LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA, Count = 1)]
[LogMessage(LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA, Count = 2)]
public virtual void BigRowSpanTooFarNothingTest() {
String filename = "bigRowSpanTooFarNothingTest.pdf";
PdfDocument pdf = new PdfDocument(new PdfWriter(destinationFolder + filename));
Expand Down
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
4 changes: 2 additions & 2 deletions itext/itext.layout/itext/layout/renderer/BlockRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ internal virtual AbstractRenderer[] CreateSplitAndOverflowRenderers(int childPos
AbstractRenderer overflowRenderer = CreateOverflowRenderer(layoutStatus);
overflowRenderer.childRenderers.AddAll(waitingOverflowFloatRenderers);
if (childResult.GetOverflowRenderer() != null) {
overflowRenderer.childRenderers.Add(childResult.GetOverflowRenderer());
overflowRenderer.AddChildRenderer(childResult.GetOverflowRenderer());
}
overflowRenderer.childRenderers.AddAll(childRenderers.SubList(childPos + 1, childRenderers.Count));
ContinuousContainer.ClearPropertiesFromOverFlowRenderer(overflowRenderer);
Expand Down Expand Up @@ -868,7 +868,7 @@ internal virtual LayoutResult ProcessNotFullChildResult(LayoutContext layoutCont
if (keepTogether) {
splitRenderer = null;
overflowRenderer.childRenderers.Clear();
overflowRenderer.childRenderers = new List<IRenderer>(childRenderers);
overflowRenderer.AddAllChildRenderers(childRenderers);
}
CorrectFixedLayout(layoutBox);
ApplyPaddings(occupiedArea.GetBBox(), paddings, true);
Expand Down
3 changes: 3 additions & 0 deletions itext/itext.layout/itext/layout/renderer/MulticolRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
elementRenderer.SetParent(this);
MulticolRenderer.MulticolLayoutResult layoutResult = LayoutInColumns(layoutContext, actualBBox);
if (layoutResult.GetSplitRenderers().IsEmpty()) {
foreach (IRenderer child in elementRenderer.GetChildRenderers()) {
child.SetParent(elementRenderer);
}
return new LayoutResult(LayoutResult.NOTHING, null, null, this, layoutResult.GetCauseOfNothing());
}
else {
Expand Down
6 changes: 1 addition & 5 deletions itext/itext.layout/itext/layout/renderer/RootRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,7 @@ private bool TryDisableKeepTogether(LayoutResult result, bool rendererIsFloat, R
if (toDisableKeepTogether == null) {
return false;
}
// Ideally the disabling of keep together property should be done on the renderers layer,
// but due to the problem with renderers tree (parent links from causeOfNothing
// may not lead to overflowRenderer) such approach does not work now. So we are
// disabling keep together on the models layer.
toDisableKeepTogether.GetModelElement().SetProperty(Property.KEEP_TOGETHER, false);
toDisableKeepTogether.SetProperty(Property.KEEP_TOGETHER, false);
ILogger logger = ITextLogManager.GetLogger(typeof(RootRenderer));
if (logger.IsEnabled(LogLevel.Warning)) {
logger.LogWarning(MessageFormatUtil.Format(LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA, "KeepTogether property will be ignored."
Expand Down
92 changes: 42 additions & 50 deletions itext/itext.layout/itext/layout/renderer/TableRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -798,56 +798,52 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
splitResult[1].DeleteOwnProperty(Property.BORDER_BOTTOM);
}
}
if (split) {
int[] rowspans = new int[currentRow.Length];
bool[] columnsWithCellToBeEnlarged = new bool[currentRow.Length];
for (col = 0; col < currentRow.Length; col++) {
if (splits[col] != null) {
CellRenderer cellSplit = (CellRenderer)splits[col].GetSplitRenderer();
if (null != cellSplit) {
rowspans[col] = ((Cell)cellSplit.GetModelElement()).GetRowspan();
}
if (splits[col].GetStatus() != LayoutResult.NOTHING && (hasContent || cellWithBigRowspanAdded)) {
childRenderers.Add(cellSplit);
}
LayoutArea cellOccupiedArea = currentRow[col].GetOccupiedArea();
if (hasContent || cellWithBigRowspanAdded || splits[col].GetStatus() == LayoutResult.NOTHING) {
CellRenderer cellOverflow = (CellRenderer)splits[col].GetOverflowRenderer();
CellRenderer originalCell = currentRow[col];
currentRow[col] = null;
rows[targetOverflowRowIndex[col]][col] = originalCell;
overflowRows.SetCell(0, col, null);
overflowRows.SetCell(targetOverflowRowIndex[col] - row, col, (CellRenderer)cellOverflow.SetParent(splitResult
[1]));
}
else {
overflowRows.SetCell(targetOverflowRowIndex[col] - row, col, (CellRenderer)currentRow[col].SetParent(splitResult
[1]));
}
overflowRows.GetCell(targetOverflowRowIndex[col] - row, col).occupiedArea = cellOccupiedArea;
int[] rowspans = new int[currentRow.Length];
bool[] columnsWithCellToBeEnlarged = new bool[currentRow.Length];
for (col = 0; col < currentRow.Length; col++) {
if (splits[col] != null) {
CellRenderer cellSplit = (CellRenderer)splits[col].GetSplitRenderer();
if (null != cellSplit) {
rowspans[col] = ((Cell)cellSplit.GetModelElement()).GetRowspan();
}
if (splits[col].GetStatus() != LayoutResult.NOTHING && (hasContent || cellWithBigRowspanAdded)) {
childRenderers.Add(cellSplit);
}
LayoutArea cellOccupiedArea = currentRow[col].GetOccupiedArea();
if (hasContent || cellWithBigRowspanAdded || splits[col].GetStatus() == LayoutResult.NOTHING) {
CellRenderer cellOverflow = (CellRenderer)splits[col].GetOverflowRenderer();
CellRenderer originalCell = currentRow[col];
currentRow[col] = null;
rows[targetOverflowRowIndex[col]][col] = originalCell;
overflowRows.SetCell(0, col, null);
overflowRows.SetCell(targetOverflowRowIndex[col] - row, col, cellOverflow);
}
else {
if (currentRow[col] != null) {
if (hasContent) {
rowspans[col] = ((Cell)currentRow[col].GetModelElement()).GetRowspan();
}
bool isBigRowspannedCell = 1 != ((Cell)currentRow[col].GetModelElement()).GetRowspan();
if (hasContent || isBigRowspannedCell) {
columnsWithCellToBeEnlarged[col] = true;
}
}
overflowRows.SetCell(targetOverflowRowIndex[col] - row, col, currentRow[col]);
}
overflowRows.GetCell(targetOverflowRowIndex[col] - row, col).occupiedArea = cellOccupiedArea;
}
int minRowspan = int.MaxValue;
for (col = 0; col < rowspans.Length; col++) {
if (0 != rowspans[col]) {
minRowspan = Math.Min(minRowspan, rowspans[col]);
else {
if (currentRow[col] != null) {
if (hasContent) {
rowspans[col] = ((Cell)currentRow[col].GetModelElement()).GetRowspan();
}
bool isBigRowspannedCell = 1 != ((Cell)currentRow[col].GetModelElement()).GetRowspan();
if (hasContent || isBigRowspannedCell) {
columnsWithCellToBeEnlarged[col] = true;
}
}
}
for (col = 0; col < numberOfColumns; col++) {
if (columnsWithCellToBeEnlarged[col]) {
EnlargeCell(col, row, minRowspan, currentRow, overflowRows, targetOverflowRowIndex, splitResult);
}
}
int minRowspan = int.MaxValue;
for (col = 0; col < rowspans.Length; col++) {
if (0 != rowspans[col]) {
minRowspan = Math.Min(minRowspan, rowspans[col]);
}
}
for (col = 0; col < numberOfColumns; col++) {
if (columnsWithCellToBeEnlarged[col]) {
EnlargeCell(col, row, minRowspan, currentRow, overflowRows, targetOverflowRowIndex, splitResult);
}
}
ApplySpacing(layoutBox, horizontalBorderSpacing, verticalBorderSpacing, true);
Expand Down Expand Up @@ -1264,13 +1260,13 @@ protected internal virtual iText.Layout.Renderer.TableRenderer[] Split(int row,
splitRenderer.columnWidths = columnWidths;
splitRenderer.countedColumnWidth = countedColumnWidth;
splitRenderer.totalWidthForColumns = totalWidthForColumns;
splitRenderer.occupiedArea = occupiedArea;
iText.Layout.Renderer.TableRenderer overflowRenderer = CreateOverflowRenderer(new Table.RowRange(rowRange.
GetStartRow() + row, rowRange.GetFinishRow()));
if (0 == row && !(hasContent || cellWithBigRowspanAdded) && 0 == rowRange.GetStartRow()) {
overflowRenderer.isOriginalNonSplitRenderer = isOriginalNonSplitRenderer;
}
overflowRenderer.rows = rows.SubList(row, rows.Count);
splitRenderer.occupiedArea = occupiedArea;
overflowRenderer.bordersHandler = bordersHandler;
return new iText.Layout.Renderer.TableRenderer[] { splitRenderer, overflowRenderer };
}
Expand Down Expand Up @@ -1897,8 +1893,6 @@ public CellRendererInfo(CellRenderer cellRenderer, int column, int finishRow) {
private class OverflowRowsWrapper {
private TableRenderer overflowRenderer;

private Dictionary<int, bool?> isRowReplaced = new Dictionary<int, bool?>();

private bool isReplaced = false;

public OverflowRowsWrapper(TableRenderer overflowRenderer) {
Expand All @@ -1914,9 +1908,7 @@ public virtual CellRenderer SetCell(int row, int col, CellRenderer newCell) {
overflowRenderer.rows = new List<CellRenderer[]>(overflowRenderer.rows);
isReplaced = true;
}
if (!true.Equals(isRowReplaced.Get(row))) {
overflowRenderer.rows[row] = (CellRenderer[])overflowRenderer.rows[row].Clone();
}
overflowRenderer.rows[row] = (CellRenderer[])overflowRenderer.rows[row].Clone();
return overflowRenderer.rows[row][col] = newCell;
}
}
Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c277cd7dc90b08e38b4d6ffb7d4d09e7953deae6
bc6666faacd4ec5f4ac133a8d23fee1ee5e4884a

0 comments on commit b0e0781

Please sign in to comment.