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 10, 2024
2 parents e7fe705 + c6432b3 commit f22a655
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ You should have received a copy of the GNU Affero General Public License
using iText.Kernel.Utils;
using iText.Layout;
using iText.Layout.Borders;
using iText.Layout.Exceptions;
using iText.Layout.Properties;
using iText.Layout.Properties.Grid;
using iText.Test;
Expand Down Expand Up @@ -344,12 +343,48 @@ public virtual void FixedColumnRowGoesFirstTest() {
}

[NUnit.Framework.Test]
public virtual void OverlapWithExistingColumnTest() {
String filename = DESTINATION_FOLDER + "overlapWithExistingColumnTest.pdf";
public virtual void OverlapWithExistingItemTest() {
String filename = DESTINATION_FOLDER + "overlapWithExistingItemTest.pdf";
String cmpName = SOURCE_FOLDER + "cmp_overlapWithExistingItemTest.pdf";
IList<TemplateValue> templateColumns = new List<TemplateValue>();
templateColumns.Add(new PointValue(100.0f));
templateColumns.Add(new PointValue(100.0f));
templateColumns.Add(new PointValue(100.0f));
templateColumns.Add(MinContentValue.VALUE);
templateColumns.Add(MinContentValue.VALUE);
templateColumns.Add(MinContentValue.VALUE);
using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) {
GridContainer grid = new GridContainer();
SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1);
grid.SetProperty(Property.GRID_TEMPLATE_COLUMNS, templateColumns);
Paragraph paragraph1 = new Paragraph("Two");
paragraph1.SetProperty(Property.GRID_COLUMN_START, 1);
paragraph1.SetProperty(Property.GRID_COLUMN_END, 3);
paragraph1.SetProperty(Property.GRID_ROW_START, 1);
paragraph1.SetProperty(Property.GRID_ROW_END, 3);
paragraph1.SetBorder(border);
grid.Add(paragraph1);
grid.Add(new Paragraph("Three").SetBorder(border));
grid.Add(new Paragraph("Four").SetBorder(border));
grid.Add(new Paragraph("Five").SetBorder(border));
Paragraph paragraph2 = new Paragraph("One (long content)");
paragraph2.SetProperty(Property.GRID_COLUMN_START, 1);
paragraph2.SetProperty(Property.GRID_COLUMN_END, 2);
paragraph2.SetProperty(Property.GRID_ROW_START, 1);
paragraph2.SetProperty(Property.GRID_ROW_END, 2);
paragraph2.SetBorder(border);
grid.Add(paragraph2);
document.Add(grid);
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpName, DESTINATION_FOLDER, "diff_"
));
}

[NUnit.Framework.Test]
public virtual void CoverExistingItemTest() {
String filename = DESTINATION_FOLDER + "coverExistingItemTest.pdf";
String cmpName = SOURCE_FOLDER + "cmp_coverExistingItemTest.pdf";
IList<TemplateValue> templateColumns = new List<TemplateValue>();
templateColumns.Add(MinContentValue.VALUE);
templateColumns.Add(MinContentValue.VALUE);
templateColumns.Add(MinContentValue.VALUE);
using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) {
GridContainer grid = new GridContainer();
SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1);
Expand All @@ -364,16 +399,17 @@ public virtual void OverlapWithExistingColumnTest() {
grid.Add(new Paragraph("Three").SetBorder(border));
grid.Add(new Paragraph("Four").SetBorder(border));
grid.Add(new Paragraph("Five").SetBorder(border));
Paragraph paragraph2 = new Paragraph("One");
Paragraph paragraph2 = new Paragraph("One (long content)");
paragraph2.SetProperty(Property.GRID_COLUMN_START, 1);
paragraph2.SetProperty(Property.GRID_COLUMN_END, 3);
paragraph2.SetProperty(Property.GRID_ROW_START, 1);
paragraph2.SetProperty(Property.GRID_ROW_END, 3);
paragraph2.SetBorder(border);
grid.Add(paragraph2);
Exception e = NUnit.Framework.Assert.Catch(typeof(ArgumentException), () => document.Add(grid));
NUnit.Framework.Assert.AreEqual(LayoutExceptionMessageConstant.INVALID_CELL_INDEXES, e.Message);
document.Add(grid);
}
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpName, DESTINATION_FOLDER, "diff_"
));
}

[NUnit.Framework.Test]
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ public virtual void GapWithTwoValidValuesTest() {
NUnit.Framework.Assert.AreEqual("15px", resolvedShorthand[1].GetExpression());
}

[NUnit.Framework.Test]
public virtual void GridGapWithTwoValidValuesTest() {
IShorthandResolver resolver = new GapShorthandResolver(CommonCssConstants.GRID_GAP);
String shorthand = "10px 15px";
IList<CssDeclaration> resolvedShorthand = resolver.ResolveShorthand(shorthand);
NUnit.Framework.Assert.AreEqual(2, resolvedShorthand.Count);
NUnit.Framework.Assert.AreEqual(CommonCssConstants.ROW_GAP, resolvedShorthand[0].GetProperty());
NUnit.Framework.Assert.AreEqual("10px", resolvedShorthand[0].GetExpression());
NUnit.Framework.Assert.AreEqual(CommonCssConstants.COLUMN_GAP, resolvedShorthand[1].GetProperty());
NUnit.Framework.Assert.AreEqual("15px", resolvedShorthand[1].GetExpression());
}

[NUnit.Framework.Test]
[LogMessage(iText.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION)]
public virtual void GapWithValidAndInvalidValuesTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,24 @@ public virtual void MulticolValidationTest() {
.COLUMN_GAP, "10")));
}

[NUnit.Framework.Test]
public virtual void GridRowColumnGapTest() {
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
.GRID_ROW_GAP, "normal")));
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
.GRID_COLUMN_GAP, "30px")));
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
.GRID_ROW_GAP, "15%")));
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
.GRID_ROW_GAP, "2em")));
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
.GRID_COLUMN_GAP, "3rem")));
NUnit.Framework.Assert.IsFalse(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
.GRID_COLUMN_GAP, "-5em")));
NUnit.Framework.Assert.IsFalse(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
.GRID_ROW_GAP, "10")));
}

[NUnit.Framework.Test]
public virtual void ChangeValidatorTest() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public ImageRenderInfo(Stack<CanvasTag> canvasTagHierarchy, CanvasGraphicsState
/// <see cref="System.Drawing.Bitmap"/>
/// with
/// <see cref="iText.Kernel.Pdf.Xobject.PdfImageXObject.GetBufferedImage()"/>
/// ;
/// ; // Android-Conversion-Skip-Line (java.awt library isn't available on Android)
/// </description></item>
/// </list>
/// </remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public sealed class LayoutExceptionMessageConstant {

public const String INVALID_COLUMN_PROPERTIES = "Invalid column-count/column-width/column-gap properties, they're absent or have negative value";

public const String INVALID_CELL_INDEXES = "Invalid grid-column/grid-row properties, cells overlapping";

public const String INVALID_FONT_PROPERTY_VALUE = "Invalid FONT property value type.";

public const String TAGGING_HINTKEY_SHOULD_HAVE_ACCES = "TaggingHintKey should have accessibility properties";
Expand Down
19 changes: 15 additions & 4 deletions itext/itext.layout/itext/layout/renderer/Grid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ You should have received a copy of the GNU Affero General Public License
using System.Collections.Generic;
using System.Linq;
using iText.Commons.Utils;
using iText.Layout.Exceptions;
using iText.Layout.Properties.Grid;

namespace iText.Layout.Renderer {
Expand All @@ -42,6 +41,8 @@ internal class Grid {
//Using array list instead of array for .NET portability
private readonly IList<ICollection<GridCell>> uniqueCells = new List<ICollection<GridCell>>(2);

private readonly IList<GridCell> itemsWithoutPlace = new List<GridCell>();

//\cond DO_NOT_DOCUMENT
/// <summary>Creates a new grid instance.</summary>
/// <param name="initialRowsCount">initial number of row for the grid</param>
Expand Down Expand Up @@ -138,6 +139,7 @@ internal virtual ICollection<GridCell> GetUniqueGridCells(Grid.GridOrder iterati
}
}
}
result.AddAll(itemsWithoutPlace);
uniqueCells[(int)(iterationOrder)] = result;
return result;
}
Expand All @@ -149,6 +151,7 @@ internal virtual ICollection<GridCell> GetUniqueGridCells(Grid.GridOrder iterati
}
}
}
result.AddAll(itemsWithoutPlace);
uniqueCells[(int)(iterationOrder)] = result;
return result;
}
Expand Down Expand Up @@ -224,11 +227,18 @@ internal virtual int CollapseNullLines(Grid.GridOrder order, int minSize) {
/// <summary>Add cell in the grid, checking that it would fit and initializing it bottom left corner (x, y).</summary>
/// <param name="cell">cell to and in the grid</param>
private void AddCell(GridCell cell) {
bool placeFound = false;
for (int i = cell.GetRowStart(); i < cell.GetRowEnd(); ++i) {
for (int j = cell.GetColumnStart(); j < cell.GetColumnEnd(); ++j) {
rows[i][j] = cell;
if (rows[i][j] == null) {
rows[i][j] = cell;
placeFound = true;
}
}
}
if (!placeFound) {
itemsWithoutPlace.Add(cell);
}
}

private int DetermineNullLinesStart(Grid.GridOrder order) {
Expand Down Expand Up @@ -471,9 +481,10 @@ internal virtual void Fit(GridCell cell) {
//Move grid view cursor
pos = view.Next();
}
//If cell restricts both x and y position grow and can't be fitted on a grid, throw an excpetion
// If cell restricts both x and y position grow and can't be fitted on a grid,
// exit occupying fixed position
if (view.IsFixed()) {
throw new ArgumentException(LayoutExceptionMessageConstant.INVALID_CELL_INDEXES);
break;
}
//If cell was not fitted while iterating grid, then there is not enough space to fit it, and grid
//has to be resized
Expand Down
18 changes: 10 additions & 8 deletions itext/itext.layout/itext/layout/renderer/GridContainerRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public override LayoutResult Layout(LayoutContext layoutContext) {

/// <summary><inheritDoc/></summary>
public override void AddChild(IRenderer renderer) {
// The grid's items are not affected by the 'float' and 'clear' properties.
// Still let clear them on renderer level not model element
renderer.SetProperty(Property.FLOAT, null);
renderer.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE);
renderer.SetProperty(Property.OVERFLOW_Y, OverflowPropertyValue.VISIBLE);
renderer.SetProperty(Property.COLLAPSING_MARGINS, DetermineCollapsingMargins(renderer));
Expand Down Expand Up @@ -171,20 +174,19 @@ private GridContainerRenderer.GridLayoutResult LayoutGrid(LayoutContext layoutCo

private static int ProcessLayoutResult(GridContainerRenderer.GridLayoutResult layoutResult, GridCell cell,
LayoutResult cellResult) {
IRenderer cellToRenderer = cell.GetValue();
IRenderer overflowRenderer = cellResult.GetOverflowRenderer();
if (cellResult.GetStatus() == LayoutResult.NOTHING) {
cellToRenderer.SetProperty(Property.GRID_COLUMN_START, cell.GetColumnStart() + 1);
cellToRenderer.SetProperty(Property.GRID_COLUMN_END, cell.GetColumnEnd() + 1);
cellToRenderer.SetProperty(Property.GRID_ROW_START, cell.GetRowStart() + 1);
cellToRenderer.SetProperty(Property.GRID_ROW_END, cell.GetRowEnd() + 1);
layoutResult.GetOverflowRenderers().Add(cellToRenderer);
overflowRenderer.SetProperty(Property.GRID_COLUMN_START, cell.GetColumnStart() + 1);
overflowRenderer.SetProperty(Property.GRID_COLUMN_END, cell.GetColumnEnd() + 1);
overflowRenderer.SetProperty(Property.GRID_ROW_START, cell.GetRowStart() + 1);
overflowRenderer.SetProperty(Property.GRID_ROW_END, cell.GetRowEnd() + 1);
layoutResult.GetOverflowRenderers().Add(overflowRenderer);
layoutResult.SetCauseOfNothing(cellResult.GetCauseOfNothing());
return cell.GetRowStart();
}
// PARTIAL + FULL result handling
layoutResult.GetSplitRenderers().Add(cellToRenderer);
layoutResult.GetSplitRenderers().Add(cell.GetValue());
if (cellResult.GetStatus() == LayoutResult.PARTIAL) {
IRenderer overflowRenderer = cellResult.GetOverflowRenderer();
overflowRenderer.SetProperty(Property.GRID_COLUMN_START, cell.GetColumnStart() + 1);
overflowRenderer.SetProperty(Property.GRID_COLUMN_END, cell.GetColumnEnd() + 1);
int rowStart = cell.GetRowStart() + 1;
Expand Down
21 changes: 14 additions & 7 deletions itext/itext.layout/itext/layout/renderer/GridItemRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ public override T1 GetProperty<T1>(int key) {
case Property.GRID_ROW_START:
case Property.GRID_ROW_END:
case Property.GRID_ROW_SPAN: {
return renderer.GetProperty<T1>(key);
T1 ownValue = this.GetOwnProperty<T1>(key);
if (ownValue != null) {
return ownValue;
}
else {
return renderer.GetProperty<T1>(key);
}
goto default;
}

default: {
Expand All @@ -93,18 +100,18 @@ public override void SetProperty(int property, Object value) {
break;
}

case Property.FILL_AVAILABLE_AREA:
case Property.FILL_AVAILABLE_AREA: {
renderer.SetProperty(property, value);
break;
}

case Property.COLLAPSING_MARGINS:
case Property.GRID_COLUMN_START:
case Property.GRID_COLUMN_END:
case Property.GRID_COLUMN_SPAN:
case Property.GRID_ROW_START:
case Property.GRID_ROW_END:
case Property.GRID_ROW_SPAN: {
renderer.SetProperty(property, value);
break;
}

case Property.COLLAPSING_MARGINS: {
base.SetProperty(property, value);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,21 @@ static CommonCssConstants() {
/// <summary>The Constant GRID_COLUMN_END.</summary>
public const String GRID_COLUMN_END = "grid-column-end";

/// <summary>The Constant GRID_COLUMN_GAP.</summary>
public const String GRID_COLUMN_GAP = "grid-column-gap";

/// <summary>The Constant GRID_COLUMN_START.</summary>
public const String GRID_COLUMN_START = "grid-column-start";

/// <summary>The Constant GRID_GAP.</summary>
public const String GRID_GAP = "grid-gap";

/// <summary>The Constant GRID_ROW_END.</summary>
public const String GRID_ROW_END = "grid-row-end";

/// <summary>The Constant GRID_ROW_GAP.</summary>
public const String GRID_ROW_GAP = "grid-row-gap";

/// <summary>The Constant GRID_ROW_START.</summary>
public const String GRID_ROW_START = "grid-row-start";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ static ShorthandResolverFactory() {
shorthandResolvers.Put(CommonCssConstants.TEXT_DECORATION, new TextDecorationShorthandResolver());
shorthandResolvers.Put(CommonCssConstants.FLEX, new FlexShorthandResolver());
shorthandResolvers.Put(CommonCssConstants.FLEX_FLOW, new FlexFlowShorthandResolver());
shorthandResolvers.Put(CommonCssConstants.GAP, new GapShorthandResolver());
shorthandResolvers.Put(CommonCssConstants.GAP, new GapShorthandResolver(CommonCssConstants.GAP));
shorthandResolvers.Put(CommonCssConstants.GRID_GAP, new GapShorthandResolver(CommonCssConstants.GRID_GAP));
shorthandResolvers.Put(CommonCssConstants.PLACE_ITEMS, new PlaceItemsShorthandResolver());
shorthandResolvers.Put(CommonCssConstants.COLUMNS, new ColumnsShorthandResolver());
shorthandResolvers.Put(CommonCssConstants.COLUMN_RULE, new ColumnRuleShortHandResolver());
Expand Down
Loading

0 comments on commit f22a655

Please sign in to comment.