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 Jul 24, 2024
2 parents 7847abb + a1ea9cf commit b0e1788
Show file tree
Hide file tree
Showing 34 changed files with 76 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public virtual void ReverseWrapStartTest() {
}

[NUnit.Framework.Test]
[LogMessage(iText.IO.Logs.IoLogMessageConstant.TYPOGRAPHY_NOT_FOUND, Count = 556)]
[LogMessage(iText.IO.Logs.IoLogMessageConstant.TYPOGRAPHY_NOT_FOUND, Count = 553)]
public virtual void RowWrapRtlStartTest() {
String outFileName = DESTINATION_FOLDER + "rowWrapRtlStartTest.pdf";
String cmpFileName = SOURCE_FOLDER + "cmp_rowWrapRtlStartTest.pdf";
Expand All @@ -219,7 +219,7 @@ public virtual void RowWrapRtlStartTest() {
}

[NUnit.Framework.Test]
[LogMessage(iText.IO.Logs.IoLogMessageConstant.TYPOGRAPHY_NOT_FOUND, Count = 556)]
[LogMessage(iText.IO.Logs.IoLogMessageConstant.TYPOGRAPHY_NOT_FOUND, Count = 553)]
public virtual void ReverseRowWrapRtlStartTest() {
String outFileName = DESTINATION_FOLDER + "reverseRowWrapRtlStartTest.pdf";
String cmpFileName = SOURCE_FOLDER + "cmp_reverseRowWrapRtlStartTest.pdf";
Expand Down Expand Up @@ -308,6 +308,30 @@ public virtual void SimpleWrapCenterTest() {
, "diff"));
}

[NUnit.Framework.Test]
public virtual void TableInFlexOnSplitTest() {
String outFileName = DESTINATION_FOLDER + "tableInFlexOnSplitTest.pdf";
String cmpFileName = SOURCE_FOLDER + "tableInFlexOnSplitTest.pdf";
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName))) {
Document document = new Document(pdfDocument);
pdfDocument.SetDefaultPageSize(PageSize.A5);
Div flexContainer = new FlexContainer();
flexContainer.SetBackgroundColor(ColorConstants.LIGHT_GRAY);
flexContainer.SetBorder(new SolidBorder(2));
Table table = new Table(UnitValue.CreatePercentArray(new float[] { 10, 10, 10 }));
for (int i = 1; i <= 3; i++) {
table.AddHeaderCell("Header" + i);
}
for (int i = 1; i <= 150; i++) {
table.AddCell("Cell" + i);
}
flexContainer.Add(table);
document.Add(flexContainer);
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, DESTINATION_FOLDER
, "diff"));
}

private Div CreateDefaultFlexContainer() {
Div flexContainer = new FlexContainer();
flexContainer.SetProperty(Property.BORDER, new SolidBorder(2));
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
58 changes: 45 additions & 13 deletions itext/itext.layout/itext/layout/renderer/FlexContainerRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ You should have received a copy of the GNU Affero General Public License
using System;
using System.Collections.Generic;
using System.Linq;
using iText.Commons.Datastructures;
using iText.Commons.Utils;
using iText.Kernel.Geom;
using iText.Layout.Borders;
Expand All @@ -34,17 +35,22 @@ You should have received a copy of the GNU Affero General Public License

namespace iText.Layout.Renderer {
public class FlexContainerRenderer : DivRenderer {
/* Used for caching purposes in FlexUtil
* We couldn't find the real use case when this map contains more than 1 entry
* but let it still be a map to be on a safe(r) side
* Map mainSize (always width in our case) - hypotheticalCrossSize
*/
/// <summary>
/// Used for caching purposes in FlexUtil
/// We couldn't find the real use case when this map contains more than 1 entry
/// but let it still be a map to be on a safe(r) side
/// Map mainSize (always width in our case) - hypotheticalCrossSize
/// </summary>
private readonly IDictionary<float, float?> hypotheticalCrossSizes = new Dictionary<float, float?>();

private IList<IList<FlexItemInfo>> lines;

private IFlexItemMainDirector flexItemMainDirector = null;

/// <summary>Child renderers and their heights and min heights before the layout.</summary>
private readonly IDictionary<IRenderer, Tuple2<UnitValue, UnitValue>> heights = new Dictionary<IRenderer,
Tuple2<UnitValue, UnitValue>>();

/// <summary>Creates a FlexContainerRenderer from its corresponding layout object.</summary>
/// <param name="modelElement">
/// the
Expand Down Expand Up @@ -90,8 +96,6 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
AddAllChildRenderers(renderers);
IList<IRenderer> renderersToOverflow = RetrieveRenderersToOverflow(layoutContextRectangle);
IList<UnitValue> previousWidths = new List<UnitValue>();
IList<UnitValue> previousHeights = new List<UnitValue>();
IList<UnitValue> previousMinHeights = new List<UnitValue>();
foreach (IList<FlexItemInfo> line in lines) {
foreach (FlexItemInfo itemInfo in line) {
Rectangle rectangleWithoutBordersMarginsPaddings;
Expand All @@ -103,9 +107,9 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
rectangleWithoutBordersMarginsPaddings = itemInfo.GetRenderer().ApplyMarginsBordersPaddings(itemInfo.GetRectangle
().Clone(), false);
}
heights.Put(itemInfo.GetRenderer(), new Tuple2<UnitValue, UnitValue>(itemInfo.GetRenderer().GetProperty<UnitValue
>(Property.HEIGHT), itemInfo.GetRenderer().GetProperty<UnitValue>(Property.MIN_HEIGHT)));
previousWidths.Add(itemInfo.GetRenderer().GetProperty<UnitValue>(Property.WIDTH));
previousHeights.Add(itemInfo.GetRenderer().GetProperty<UnitValue>(Property.HEIGHT));
previousMinHeights.Add(itemInfo.GetRenderer().GetProperty<UnitValue>(Property.MIN_HEIGHT));
itemInfo.GetRenderer().SetProperty(Property.WIDTH, UnitValue.CreatePointValue(rectangleWithoutBordersMarginsPaddings
.GetWidth()));
itemInfo.GetRenderer().SetProperty(Property.HEIGHT, UnitValue.CreatePointValue(rectangleWithoutBordersMarginsPaddings
Expand All @@ -131,8 +135,9 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
foreach (IList<FlexItemInfo> line in lines) {
foreach (FlexItemInfo itemInfo in line) {
itemInfo.GetRenderer().SetProperty(Property.WIDTH, previousWidths[counter]);
itemInfo.GetRenderer().SetProperty(Property.HEIGHT, previousHeights[counter]);
itemInfo.GetRenderer().SetProperty(Property.MIN_HEIGHT, previousMinHeights[counter]);
Tuple2<UnitValue, UnitValue> curHeights = heights.Get(itemInfo.GetRenderer());
itemInfo.GetRenderer().SetProperty(Property.HEIGHT, curHeights.GetFirst());
itemInfo.GetRenderer().SetProperty(Property.MIN_HEIGHT, curHeights.GetSecond());
++counter;
}
}
Expand Down Expand Up @@ -488,6 +493,7 @@ private static void AddSimulateDiv(AbstractRenderer overflowRenderer, float widt

private void FillSplitOverflowRenderersForPartialResult(AbstractRenderer splitRenderer, AbstractRenderer overflowRenderer
, IList<FlexItemInfo> line, IRenderer childRenderer, LayoutResult childResult) {
RestoreHeightForOverflowRenderer(childRenderer, childResult.GetOverflowRenderer());
float occupiedSpace = 0;
float maxHeightInLine = 0;
bool metChildRendererInLine = false;
Expand All @@ -502,7 +508,7 @@ private void FillSplitOverflowRenderersForPartialResult(AbstractRenderer splitRe
// Get rid of vertical alignment for item with partial result. For column direction, justify-content
// is applied to the entire line, not the single item, so there is no point in getting rid of it
if (!FlexUtil.IsColumnDirection(this)) {
childResult.GetOverflowRenderer().SetProperty(Property.ALIGN_SELF, AlignmentPropertyValue.START);
SetAlignSelfIfNotStretch(childResult.GetOverflowRenderer());
}
overflowRenderer.AddChildRenderer(childResult.GetOverflowRenderer());
}
Expand All @@ -526,6 +532,7 @@ private void FillSplitOverflowRenderersForPartialResult(AbstractRenderer splitRe
).GetY(), itemInfo.GetRectangle().GetWidth(), maxHeightInLine - itemInfo.GetRectangle().GetY());
LayoutResult neighbourLayoutResult = itemInfo.GetRenderer().Layout(new LayoutContext(new LayoutArea(childResult
.GetOccupiedArea().GetPageNumber(), neighbourBbox)));
RestoreHeightForOverflowRenderer(itemInfo.GetRenderer(), neighbourLayoutResult.GetOverflowRenderer());
// Handle result
if (neighbourLayoutResult.GetStatus() == LayoutResult.PARTIAL && neighbourLayoutResult.GetSplitRenderer()
!= null) {
Expand All @@ -540,7 +547,7 @@ private void FillSplitOverflowRenderersForPartialResult(AbstractRenderer splitRe
if (neighbourLayoutResult.GetOverflowRenderer() != null) {
if (neighbourLayoutResult.GetStatus() == LayoutResult.PARTIAL) {
// Get rid of cross alignment for item with partial result
neighbourLayoutResult.GetOverflowRenderer().SetProperty(Property.ALIGN_SELF, AlignmentPropertyValue.START);
SetAlignSelfIfNotStretch(neighbourLayoutResult.GetOverflowRenderer());
}
overflowRenderer.AddChildRenderer(neighbourLayoutResult.GetOverflowRenderer());
}
Expand All @@ -565,6 +572,31 @@ private void FillSplitOverflowRenderersForPartialResult(AbstractRenderer splitRe
}
}

private void SetAlignSelfIfNotStretch(IRenderer overflowRenderer) {
AlignmentPropertyValue alignItems = (AlignmentPropertyValue)this.GetProperty<AlignmentPropertyValue?>(Property
.ALIGN_ITEMS, AlignmentPropertyValue.STRETCH);
AlignmentPropertyValue alignSelf = (AlignmentPropertyValue)overflowRenderer.GetProperty<AlignmentPropertyValue?
>(Property.ALIGN_SELF, alignItems);
if (alignSelf != AlignmentPropertyValue.STRETCH) {
overflowRenderer.SetProperty(Property.ALIGN_SELF, AlignmentPropertyValue.START);
}
}

private void RestoreHeightForOverflowRenderer(IRenderer childRenderer, IRenderer overflowRenderer) {
if (overflowRenderer == null) {
return;
}
// childRenderer is the original renderer we set the height for before the layout
// And we need to remove the height from the corresponding overflow renderer
Tuple2<UnitValue, UnitValue> curHeights = heights.Get(childRenderer);
if (curHeights.GetFirst() == null) {
overflowRenderer.DeleteOwnProperty(Property.HEIGHT);
}
if (curHeights.GetSecond() == null) {
overflowRenderer.DeleteOwnProperty(Property.MIN_HEIGHT);
}
}

private void FindMinMaxWidthIfCorrespondingPropertiesAreNotSet(MinMaxWidth minMaxWidth, AbstractWidthHandler
minMaxWidthHandler) {
float initialMinWidth = minMaxWidth.GetChildrenMinWidth();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ private GridContainerRenderer.GridLayoutResult LayoutGrid(LayoutContext layoutCo
cellToRender.SetProperty(Property.HEIGHT, UnitValue.CreatePointValue(itemHeight));
// Adjust cell BBox to the remaining part of the layout bbox
// This way we can lay out elements partially
cellBBox.SetHeight(cellBBox.GetTop() - actualBBox.GetBottom()).SetY(actualBBox.GetY());
cellToRender.SetProperty(Property.FILL_AVAILABLE_AREA, true);
cellBBox.SetHeight(cellBBox.GetTop() - layoutContext.GetArea().GetBBox().GetBottom()).SetY(layoutContext.GetArea
().GetBBox().GetY());
cellToRender.SetProperty(Property.FILL_AVAILABLE_AREA_ON_SPLIT, true);
LayoutResult cellResult = cellToRender.Layout(cellContext);
notLayoutedRow = Math.Min(notLayoutedRow, ProcessLayoutResult(layoutResult, cell, cellResult));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public override void SetProperty(int property, Object value) {
break;
}

case Property.FILL_AVAILABLE_AREA: {
case Property.FILL_AVAILABLE_AREA_ON_SPLIT: {
renderer.SetProperty(property, value);
break;
}
Expand Down
2 changes: 0 additions & 2 deletions itext/itext.layout/itext/layout/renderer/GridTrackSizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
using iText.Commons.Utils;
using iText.Kernel.Geom;
using iText.Layout.Layout;
using iText.Layout.Properties;
using iText.Layout.Properties.Grid;

namespace iText.Layout.Renderer {
Expand Down Expand Up @@ -941,7 +940,6 @@ private float CalculateMinMaxContribution(GridCell cell, bool minTypeContributio
// https://drafts.csswg.org/css-sizing-3/#auto-box-sizes:
// min-content block size - For block containers, tables, and
// inline boxes, this is equivalent to the max-content block size.
cell.GetValue().SetProperty(Property.FILL_AVAILABLE_AREA, false);
LayoutContext layoutContext = new LayoutContext(new LayoutArea(1, new Rectangle(cell.GetLayoutArea().GetWidth
(), AbstractRenderer.INF)));
LayoutResult inifiniteHeighLayoutResult = cell.GetValue().Layout(layoutContext);
Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a06646c229f7e94041f4b6c778397fd4af03c1f3
dc0868d5ded45799dee31604dfbbc4afa685f48e

0 comments on commit b0e1788

Please sign in to comment.