Skip to content

Commit 1561fda

Browse files
yulian-gaponenkoitext-teamcity
authored andcommitted
Fix handling of overflow_x in case of alignment of overflowed content
DEVSIX-1563 Autoported commit. Original commit hash: [0b593d907]
1 parent 7fa902c commit 1561fda

File tree

11 files changed

+112
-68
lines changed

11 files changed

+112
-68
lines changed

itext.tests/itext.layout.tests/itext/layout/OverflowTest.cs

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,24 @@ source product.
4343
using System;
4444
using System.Text;
4545
using iText.IO.Font.Constants;
46+
using iText.IO.Image;
4647
using iText.Kernel.Colors;
4748
using iText.Kernel.Font;
4849
using iText.Kernel.Pdf;
4950
using iText.Kernel.Utils;
51+
using iText.Layout.Borders;
5052
using iText.Layout.Element;
53+
using iText.Layout.Properties;
5154
using iText.Test;
5255

5356
namespace iText.Layout {
5457
public class OverflowTest : ExtendedITextTest {
55-
public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
56-
.CurrentContext.TestDirectory) + "/resources/itext/layout/OverflowTest/";
57-
5858
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
5959
+ "/test/itext/layout/OverflowTest/";
6060

61+
public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
62+
.CurrentContext.TestDirectory) + "/resources/itext/layout/OverflowTest/";
63+
6164
[NUnit.Framework.OneTimeSetUp]
6265
public static void BeforeClass() {
6366
CreateDestinationFolder(destinationFolder);
@@ -132,5 +135,51 @@ public virtual void TextOverflowTest04() {
132135
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
133136
, "diff"));
134137
}
138+
139+
/// <exception cref="System.IO.IOException"/>
140+
/// <exception cref="System.Exception"/>
141+
[NUnit.Framework.Test]
142+
public virtual void AlignedInlineContentOverflowHiddenTest01() {
143+
String outFileName = destinationFolder + "alignedInlineContentOverflowHiddenTest01.pdf";
144+
String cmpFileName = sourceFolder + "cmp_alignedInlineContentOverflowHiddenTest01.pdf";
145+
String imgPath = sourceFolder + "itis.jpg";
146+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
147+
Document document = new Document(pdfDocument);
148+
Div div = new Div().SetHeight(150f).SetWidth(150f).SetBorder(new SolidBorder(5f));
149+
div.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.HIDDEN);
150+
div.SetProperty(Property.OVERFLOW_Y, OverflowPropertyValue.HIDDEN);
151+
iText.Layout.Element.Image img = new Image(ImageDataFactory.Create(imgPath));
152+
Paragraph p = new Paragraph().SetTextAlignment(TextAlignment.CENTER);
153+
p.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE);
154+
p.SetProperty(Property.OVERFLOW_Y, OverflowPropertyValue.VISIBLE);
155+
img.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE);
156+
img.SetProperty(Property.OVERFLOW_Y, OverflowPropertyValue.VISIBLE);
157+
document.Add(div.Add(p.Add(img)));
158+
document.Close();
159+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
160+
, "diff"));
161+
}
162+
163+
/// <exception cref="System.IO.IOException"/>
164+
/// <exception cref="System.Exception"/>
165+
[NUnit.Framework.Test]
166+
public virtual void AlignedInlineContentOverflowHiddenTest02() {
167+
String outFileName = destinationFolder + "alignedInlineContentOverflowHiddenTest02.pdf";
168+
String cmpFileName = sourceFolder + "cmp_alignedInlineContentOverflowHiddenTest02.pdf";
169+
String imgPath = sourceFolder + "itis.jpg";
170+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
171+
Document document = new Document(pdfDocument);
172+
iText.Layout.Element.Image img = new iText.Layout.Element.Image(ImageDataFactory.Create(imgPath));
173+
Paragraph p = new Paragraph().SetTextAlignment(TextAlignment.CENTER).SetHeight(150f).SetWidth(150f).SetBorder
174+
(new SolidBorder(5f));
175+
p.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.HIDDEN);
176+
p.SetProperty(Property.OVERFLOW_Y, OverflowPropertyValue.HIDDEN);
177+
img.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE);
178+
img.SetProperty(Property.OVERFLOW_Y, OverflowPropertyValue.VISIBLE);
179+
document.Add(p.Add(img));
180+
document.Close();
181+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
182+
, "diff"));
183+
}
135184
}
136185
}
12.3 KB
Loading

itext/itext.layout/itext/layout/renderer/AbstractRenderer.cs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -754,11 +754,10 @@ public virtual void DrawChildren(DrawContext drawContext) {
754754
IList<IRenderer> waitingRenderers = new List<IRenderer>();
755755
foreach (IRenderer child in childRenderers) {
756756
Transform transformProp = child.GetProperty<Transform>(Property.TRANSFORM);
757-
Border outlineProp = child.GetProperty<Border>(Property.OUTLINE);
758757
RootRenderer rootRenderer = GetRootRenderer();
759758
IList<IRenderer> waiting = (rootRenderer != null && !rootRenderer.waitingDrawingElements.Contains(child)) ?
760759
rootRenderer.waitingDrawingElements : waitingRenderers;
761-
ProcessWaitingDrawing(child, transformProp, outlineProp, waiting);
760+
ProcessWaitingDrawing(child, transformProp, waiting);
762761
if (!FloatingHelper.IsRendererFloating(child) && transformProp == null) {
763762
child.Draw(drawContext);
764763
}
@@ -768,43 +767,6 @@ public virtual void DrawChildren(DrawContext drawContext) {
768767
}
769768
}
770769

771-
internal static void ProcessWaitingDrawing(IRenderer child, Transform transformProp, Border outlineProp, IList
772-
<IRenderer> waitingDrawing) {
773-
if (FloatingHelper.IsRendererFloating(child) || transformProp != null) {
774-
waitingDrawing.Add(child);
775-
}
776-
if (outlineProp != null && child is iText.Layout.Renderer.AbstractRenderer) {
777-
iText.Layout.Renderer.AbstractRenderer abstractChild = (iText.Layout.Renderer.AbstractRenderer)child;
778-
if (abstractChild.IsRelativePosition()) {
779-
abstractChild.ApplyRelativePositioningTranslation(false);
780-
}
781-
Div outlines = new Div();
782-
outlines.GetAccessibilityProperties().SetRole(null);
783-
if (transformProp != null) {
784-
outlines.SetProperty(Property.TRANSFORM, transformProp);
785-
}
786-
outlines.SetProperty(Property.BORDER, outlineProp);
787-
float offset = outlines.GetProperty<Border>(Property.BORDER).GetWidth();
788-
if (abstractChild.GetPropertyAsFloat(Property.OUTLINE_OFFSET) != null) {
789-
offset += (float)abstractChild.GetPropertyAsFloat(Property.OUTLINE_OFFSET);
790-
}
791-
DivRenderer div = new DivRenderer(outlines);
792-
div.SetParent(abstractChild.GetParent());
793-
Rectangle divOccupiedArea = abstractChild.ApplyMargins(abstractChild.occupiedArea.Clone().GetBBox(), false
794-
).MoveLeft(offset).MoveDown(offset);
795-
divOccupiedArea.SetWidth(divOccupiedArea.GetWidth() + 2 * offset).SetHeight(divOccupiedArea.GetHeight() +
796-
2 * offset);
797-
div.occupiedArea = new LayoutArea(abstractChild.GetOccupiedArea().GetPageNumber(), divOccupiedArea);
798-
float outlineWidth = div.GetProperty<Border>(Property.BORDER).GetWidth();
799-
if (divOccupiedArea.GetWidth() >= outlineWidth * 2 && divOccupiedArea.GetHeight() >= outlineWidth * 2) {
800-
waitingDrawing.Add(div);
801-
}
802-
if (abstractChild.IsRelativePosition()) {
803-
abstractChild.ApplyRelativePositioningTranslation(true);
804-
}
805-
}
806-
}
807-
808770
/// <summary>
809771
/// Performs the drawing operation for the border of this renderer, if
810772
/// defined by any of the
@@ -992,6 +954,44 @@ internal static bool IsBorderBoxSizing(IRenderer renderer) {
992954
return boxSizing != null && boxSizing.Equals(BoxSizingPropertyValue.BORDER_BOX);
993955
}
994956

957+
internal static void ProcessWaitingDrawing(IRenderer child, Transform transformProp, IList<IRenderer> waitingDrawing
958+
) {
959+
if (FloatingHelper.IsRendererFloating(child) || transformProp != null) {
960+
waitingDrawing.Add(child);
961+
}
962+
Border outlineProp = child.GetProperty<Border>(Property.OUTLINE);
963+
if (outlineProp != null && child is iText.Layout.Renderer.AbstractRenderer) {
964+
iText.Layout.Renderer.AbstractRenderer abstractChild = (iText.Layout.Renderer.AbstractRenderer)child;
965+
if (abstractChild.IsRelativePosition()) {
966+
abstractChild.ApplyRelativePositioningTranslation(false);
967+
}
968+
Div outlines = new Div();
969+
outlines.GetAccessibilityProperties().SetRole(null);
970+
if (transformProp != null) {
971+
outlines.SetProperty(Property.TRANSFORM, transformProp);
972+
}
973+
outlines.SetProperty(Property.BORDER, outlineProp);
974+
float offset = outlines.GetProperty<Border>(Property.BORDER).GetWidth();
975+
if (abstractChild.GetPropertyAsFloat(Property.OUTLINE_OFFSET) != null) {
976+
offset += (float)abstractChild.GetPropertyAsFloat(Property.OUTLINE_OFFSET);
977+
}
978+
DivRenderer div = new DivRenderer(outlines);
979+
div.SetParent(abstractChild.GetParent());
980+
Rectangle divOccupiedArea = abstractChild.ApplyMargins(abstractChild.occupiedArea.Clone().GetBBox(), false
981+
).MoveLeft(offset).MoveDown(offset);
982+
divOccupiedArea.SetWidth(divOccupiedArea.GetWidth() + 2 * offset).SetHeight(divOccupiedArea.GetHeight() +
983+
2 * offset);
984+
div.occupiedArea = new LayoutArea(abstractChild.GetOccupiedArea().GetPageNumber(), divOccupiedArea);
985+
float outlineWidth = div.GetProperty<Border>(Property.BORDER).GetWidth();
986+
if (divOccupiedArea.GetWidth() >= outlineWidth * 2 && divOccupiedArea.GetHeight() >= outlineWidth * 2) {
987+
waitingDrawing.Add(div);
988+
}
989+
if (abstractChild.IsRelativePosition()) {
990+
abstractChild.ApplyRelativePositioningTranslation(true);
991+
}
992+
}
993+
}
994+
995995
/// <summary>Retrieves element's fixed content box width, if it's set.</summary>
996996
/// <remarks>
997997
/// Retrieves element's fixed content box width, if it's set.

itext/itext.layout/itext/layout/renderer/BlockRenderer.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
189189
if (result.GetOccupiedArea() != null && result.GetStatus() != LayoutResult.NOTHING) {
190190
occupiedArea.SetBBox(Rectangle.GetCommonRectangle(occupiedArea.GetBBox(), result.GetOccupiedArea().GetBBox
191191
()));
192-
if (occupiedArea.GetBBox().GetWidth() > layoutBox.GetWidth() && !(null == overflowX || OverflowPropertyValue
193-
.FIT.Equals(overflowX))) {
194-
occupiedArea.GetBBox().SetWidth(layoutBox.GetWidth());
195-
}
192+
FixOccupiedAreaWidthAndXPositionIfOverflowed(overflowX, layoutBox);
196193
}
197194
}
198195
// On page split, content will be drawn on next page, i.e. under all floats on this page
@@ -305,10 +302,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
305302
// this check is needed only if margins collapsing is enabled
306303
occupiedArea.SetBBox(Rectangle.GetCommonRectangle(occupiedArea.GetBBox(), result.GetOccupiedArea().GetBBox
307304
()));
308-
if (occupiedArea.GetBBox().GetWidth() > layoutBox.GetWidth() && !(null == overflowX || OverflowPropertyValue
309-
.FIT.Equals(overflowX))) {
310-
occupiedArea.GetBBox().SetWidth(layoutBox.GetWidth());
311-
}
305+
FixOccupiedAreaWidthAndXPositionIfOverflowed(overflowX, layoutBox);
312306
}
313307
}
314308
if (marginsCollapsingEnabled) {
@@ -727,7 +721,7 @@ internal virtual bool ApplyMaxHeight(Rectangle parentBBox, float? blockMaxHeight
727721
return false;
728722
}
729723
bool wasHeightClipped = false;
730-
if (blockMaxHeight < parentBBox.GetHeight()) {
724+
if (blockMaxHeight <= parentBBox.GetHeight()) {
731725
wasHeightClipped = true;
732726
}
733727
float heightDelta = parentBBox.GetHeight() - (float)blockMaxHeight;
@@ -748,6 +742,17 @@ internal virtual float GetOverflowPartHeight(OverflowPropertyValue? overflowY, R
748742
return difference;
749743
}
750744

745+
internal virtual void FixOccupiedAreaWidthAndXPositionIfOverflowed(OverflowPropertyValue? overflowX, Rectangle
746+
layoutBox) {
747+
if (overflowX == null || OverflowPropertyValue.FIT.Equals(overflowX)) {
748+
return;
749+
}
750+
if ((occupiedArea.GetBBox().GetWidth() > layoutBox.GetWidth() || occupiedArea.GetBBox().GetLeft() < layoutBox
751+
.GetLeft())) {
752+
occupiedArea.GetBBox().SetX(layoutBox.GetX()).SetWidth(layoutBox.GetWidth());
753+
}
754+
}
755+
751756
protected internal virtual float ApplyBordersPaddingsMargins(Rectangle parentBBox, Border[] borders, UnitValue
752757
[] paddings) {
753758
float parentWidth = parentBBox.GetWidth();

itext/itext.layout/itext/layout/renderer/CanvasRenderer.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ source product.
4444
using Common.Logging;
4545
using iText.Kernel.Pdf.Tagutils;
4646
using iText.Layout;
47-
using iText.Layout.Borders;
4847
using iText.Layout.Layout;
4948
using iText.Layout.Properties;
5049

@@ -100,9 +99,8 @@ public override void AddChild(IRenderer renderer) {
10099
/// <summary><inheritDoc/></summary>
101100
protected internal override void FlushSingleRenderer(IRenderer resultRenderer) {
102101
Transform transformProp = resultRenderer.GetProperty<Transform>(Property.TRANSFORM);
103-
Border outlineProp = resultRenderer.GetProperty<Border>(Property.OUTLINE);
104102
if (!waitingDrawingElements.Contains(resultRenderer)) {
105-
ProcessWaitingDrawing(resultRenderer, transformProp, outlineProp, waitingDrawingElements);
103+
ProcessWaitingDrawing(resultRenderer, transformProp, waitingDrawingElements);
106104
if (FloatingHelper.IsRendererFloating(resultRenderer) || transformProp != null) {
107105
return;
108106
}

itext/itext.layout/itext/layout/renderer/DocumentRenderer.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ source product.
4747
using iText.Kernel.Pdf;
4848
using iText.Kernel.Pdf.Canvas;
4949
using iText.Layout;
50-
using iText.Layout.Borders;
5150
using iText.Layout.Element;
5251
using iText.Layout.Layout;
5352
using iText.Layout.Properties;
@@ -113,9 +112,8 @@ protected internal override LayoutArea UpdateCurrentArea(LayoutResult overflowRe
113112

114113
protected internal override void FlushSingleRenderer(IRenderer resultRenderer) {
115114
Transform transformProp = resultRenderer.GetProperty<Transform>(Property.TRANSFORM);
116-
Border outlineProp = resultRenderer.GetProperty<Border>(Property.OUTLINE);
117115
if (!waitingDrawingElements.Contains(resultRenderer)) {
118-
ProcessWaitingDrawing(resultRenderer, transformProp, outlineProp, waitingDrawingElements);
116+
ProcessWaitingDrawing(resultRenderer, transformProp, waitingDrawingElements);
119117
if (FloatingHelper.IsRendererFloating(resultRenderer) || transformProp != null) {
120118
return;
121119
}

itext/itext.layout/itext/layout/renderer/ParagraphRenderer.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
307307
if (true.Equals(GetPropertyAsBoolean(Property.FORCED_PLACEMENT))) {
308308
occupiedArea.SetBBox(Rectangle.GetCommonRectangle(occupiedArea.GetBBox(), currentRenderer.GetOccupiedArea(
309309
).GetBBox()));
310-
if (occupiedArea.GetBBox().GetWidth() > layoutBox.GetWidth() && !(null == overflowX || OverflowPropertyValue
311-
.FIT.Equals(overflowX))) {
312-
occupiedArea.GetBBox().SetWidth(layoutBox.GetWidth());
313-
}
310+
FixOccupiedAreaWidthAndXPositionIfOverflowed(overflowX, layoutBox);
314311
parent.SetProperty(Property.FULL, true);
315312
lines.Add(currentRenderer);
316313
// Force placement of children we have and do not force placement of the others
@@ -346,10 +343,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
346343
if (lineHasContent) {
347344
occupiedArea.SetBBox(Rectangle.GetCommonRectangle(occupiedArea.GetBBox(), processedRenderer.GetOccupiedArea
348345
().GetBBox()));
349-
if (occupiedArea.GetBBox().GetWidth() > layoutBox.GetWidth() && !(null == overflowX || OverflowPropertyValue
350-
.FIT.Equals(overflowX))) {
351-
occupiedArea.GetBBox().SetWidth(layoutBox.GetWidth());
352-
}
346+
FixOccupiedAreaWidthAndXPositionIfOverflowed(overflowX, layoutBox);
353347
}
354348
firstLineInBox = false;
355349
layoutBox.SetHeight(processedRenderer.GetOccupiedArea().GetBBox().GetY() - layoutBox.GetY());

itext/itext.layout/itext/layout/renderer/TableRenderer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
255255
}
256256
ApplyMargins(layoutBox, false);
257257
ApplyFixedXOrYPosition(true, layoutBox);
258-
if (null != blockMaxHeight && blockMaxHeight < layoutBox.GetHeight() && !true.Equals(GetPropertyAsBoolean(
259-
Property.FORCED_PLACEMENT))) {
258+
if (null != blockMaxHeight && blockMaxHeight <= layoutBox.GetHeight() && !true.Equals(GetPropertyAsBoolean
259+
(Property.FORCED_PLACEMENT))) {
260260
layoutBox.MoveUp(layoutBox.GetHeight() - (float)blockMaxHeight).SetHeight((float)blockMaxHeight);
261261
wasHeightClipped = true;
262262
}

0 commit comments

Comments
 (0)