forked from pipeline-foundation/itext7-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix border\margin\padding treating for grid and mutlicol
DEVSIX-8418 Autoported commit. Original commit hash: [ca150c317]
- Loading branch information
Showing
15 changed files
with
262 additions
and
206 deletions.
There are no files selected for viewing
155 changes: 92 additions & 63 deletions
155
itext.tests/itext.layout.tests/itext/layout/element/GridContainerTest.cs
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+1.31 KB
...sts/resources/itext/layout/GridContainerTest/cmp_autoRepeatPaddingsBordersMarginsTest.pdf
Binary file not shown.
Binary file modified
BIN
-27 Bytes
(98%)
...sts/resources/itext/layout/MulticolContainerTest/cmp_continuousColumContainerSetWidth.pdf
Binary file not shown.
Binary file modified
BIN
-38 Bytes
(99%)
itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_maxWidth.pdf
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
....layout.tests/resources/itext/layout/MulticolContainerTest/cmp_minWidthBiggerThenPage.pdf
Binary file not shown.
Binary file modified
BIN
-32 Bytes
(98%)
...s/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthBorderTest.pdf
Binary file not shown.
Binary file modified
BIN
-96 Bytes
(95%)
...t.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthHeightMarginTest.pdf
Binary file not shown.
Binary file modified
BIN
-75 Bytes
(96%)
...s/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthMarginTest.pdf
Binary file not shown.
Binary file modified
BIN
+11 Bytes
(100%)
...ts/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthMultiPage.pdf
Binary file not shown.
Binary file modified
BIN
-61 Bytes
(97%)
.../itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthPaddingTest.pdf
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
itext/itext.layout/itext/layout/renderer/GridMulticolUtil.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
This file is part of the iText (R) project. | ||
Copyright (c) 1998-2024 Apryse Group NV | ||
Authors: Apryse Software. | ||
This program is offered under a commercial and under the AGPL license. | ||
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. | ||
AGPL licensing: | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
using System; | ||
using System.Collections.Generic; | ||
using iText.Layout.Borders; | ||
using iText.Layout.Properties; | ||
|
||
namespace iText.Layout.Renderer { | ||
//\cond DO_NOT_DOCUMENT | ||
/// <summary>The class stores common logic for multicol and grid layout.</summary> | ||
internal sealed class GridMulticolUtil { | ||
private GridMulticolUtil() { | ||
} | ||
|
||
//\cond DO_NOT_DOCUMENT | ||
// do nothing | ||
/// <summary>Creates a split renderer.</summary> | ||
/// <param name="children">children of the split renderer</param> | ||
/// <param name="renderer">parent renderer</param> | ||
/// <returns> | ||
/// a new | ||
/// <see cref="AbstractRenderer"/> | ||
/// instance | ||
/// </returns> | ||
internal static AbstractRenderer CreateSplitRenderer(IList<IRenderer> children, AbstractRenderer renderer) { | ||
AbstractRenderer splitRenderer = (AbstractRenderer)renderer.GetNextRenderer(); | ||
splitRenderer.parent = renderer.parent; | ||
splitRenderer.modelElement = renderer.modelElement; | ||
splitRenderer.occupiedArea = renderer.occupiedArea; | ||
splitRenderer.isLastRendererForModelElement = false; | ||
splitRenderer.SetChildRenderers(children); | ||
splitRenderer.AddAllProperties(renderer.GetOwnProperties()); | ||
ContinuousContainer.SetupContinuousContainerIfNeeded(splitRenderer); | ||
return splitRenderer; | ||
} | ||
//\endcond | ||
|
||
//\cond DO_NOT_DOCUMENT | ||
internal static float UpdateOccupiedWidth(float initialWidth, AbstractRenderer renderer) { | ||
float result = initialWidth; | ||
result += SafelyRetrieveFloatProperty(Property.PADDING_LEFT, renderer); | ||
result += SafelyRetrieveFloatProperty(Property.PADDING_RIGHT, renderer); | ||
result += SafelyRetrieveFloatProperty(Property.MARGIN_LEFT, renderer); | ||
result += SafelyRetrieveFloatProperty(Property.MARGIN_RIGHT, renderer); | ||
if (!renderer.HasOwnProperty(Property.BORDER) || renderer.GetProperty<Border>(Property.BORDER) == null) { | ||
result += SafelyRetrieveFloatProperty(Property.BORDER_LEFT, renderer); | ||
} | ||
if (!renderer.HasOwnProperty(Property.BORDER) || renderer.GetProperty<Border>(Property.BORDER) == null) { | ||
result += SafelyRetrieveFloatProperty(Property.BORDER_RIGHT, renderer); | ||
} | ||
result += SafelyRetrieveFloatProperty(Property.BORDER, renderer) * 2; | ||
return result; | ||
} | ||
//\endcond | ||
|
||
//\cond DO_NOT_DOCUMENT | ||
internal static float UpdateOccupiedHeight(float initialHeight, bool isFull, bool isFirstLayout, AbstractRenderer | ||
renderer) { | ||
float result = initialHeight; | ||
if (isFull) { | ||
result += SafelyRetrieveFloatProperty(Property.PADDING_BOTTOM, renderer); | ||
result += SafelyRetrieveFloatProperty(Property.MARGIN_BOTTOM, renderer); | ||
if (!renderer.HasOwnProperty(Property.BORDER) || renderer.GetProperty<Border>(Property.BORDER) == null) { | ||
result += SafelyRetrieveFloatProperty(Property.BORDER_BOTTOM, renderer); | ||
} | ||
} | ||
result += SafelyRetrieveFloatProperty(Property.PADDING_TOP, renderer); | ||
result += SafelyRetrieveFloatProperty(Property.MARGIN_TOP, renderer); | ||
if (!renderer.HasOwnProperty(Property.BORDER) || renderer.GetProperty<Border>(Property.BORDER) == null) { | ||
result += SafelyRetrieveFloatProperty(Property.BORDER_TOP, renderer); | ||
} | ||
// isFirstLayout is necessary to handle the case when multicol container layouted in more | ||
// than 2 pages, and on the last page layout result is full, but there is no bottom border | ||
float TOP_AND_BOTTOM = isFull && isFirstLayout ? 2 : 1; | ||
// Multicol container layouted in more than 3 pages, and there is a page where there are no bottom and top borders | ||
if (!isFull && !isFirstLayout) { | ||
TOP_AND_BOTTOM = 0; | ||
} | ||
result += SafelyRetrieveFloatProperty(Property.BORDER, renderer) * TOP_AND_BOTTOM; | ||
return result; | ||
} | ||
//\endcond | ||
|
||
private static float SafelyRetrieveFloatProperty(int property, AbstractRenderer renderer) { | ||
Object value = renderer.GetProperty<Object>(property); | ||
if (value is UnitValue) { | ||
return ((UnitValue)value).GetValue(); | ||
} | ||
if (value is Border) { | ||
return ((Border)value).GetWidth(); | ||
} | ||
return 0F; | ||
} | ||
} | ||
//\endcond | ||
} |
Oops, something went wrong.