Skip to content

Commit 6dbdfe0

Browse files
Introduce generic approach for y-line extraction control; make some of the util methods public in AbstractRenderer
DEVSIX-984 Autoported commit. Original commit hash: [cee74eb0c5]
1 parent 35b17c9 commit 6dbdfe0

File tree

7 files changed

+94
-69
lines changed

7 files changed

+94
-69
lines changed

itext.tests/itext.forms.tests/itext/forms/FormFieldFlatteningTest.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ public virtual void FormFlatteningTest01() {
7373
, destinationFolder, "diff_"));
7474
}
7575

76+
/// <exception cref="System.IO.IOException"/>
77+
/// <exception cref="System.Exception"/>
78+
[NUnit.Framework.Test]
79+
public virtual void FormFlatteningChoiceFieldTest01() {
80+
String srcFilename = sourceFolder + "formFlatteningSourceChoiceField.pdf";
81+
String filename = destinationFolder + "formFlatteningChoiceFieldTest01.pdf";
82+
PdfDocument doc = new PdfDocument(new PdfReader(srcFilename), new PdfWriter(filename));
83+
PdfAcroForm form = PdfAcroForm.GetAcroForm(doc, true);
84+
form.FlattenFields();
85+
doc.Close();
86+
CompareTool compareTool = new CompareTool();
87+
String errorMessage = compareTool.CompareByContent(filename, sourceFolder + "cmp_formFlatteningChoiceFieldTest01.pdf"
88+
, destinationFolder, "diff_");
89+
if (errorMessage != null) {
90+
NUnit.Framework.Assert.Fail(errorMessage);
91+
}
92+
}
93+
7694
/// <exception cref="System.IO.IOException"/>
7795
/// <exception cref="System.Exception"/>
7896
[NUnit.Framework.Test]

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

Lines changed: 67 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,58 @@ public virtual Rectangle GetInnerAreaBBox() {
943943
return rect;
944944
}
945945

946+
/// <summary>Applies margins of the renderer on the given rectangle</summary>
947+
/// <param name="rect">a rectangle margins will be applied on.</param>
948+
/// <param name="reverse">
949+
/// indicates whether margins will be applied
950+
/// inside (in case of false) or outside (in case of true) the rectangle.
951+
/// </param>
952+
/// <returns>
953+
/// a
954+
/// <see cref="iText.Kernel.Geom.Rectangle">border box</see>
955+
/// of the renderer
956+
/// </returns>
957+
/// <seealso cref="GetMargins()"/>
958+
public virtual Rectangle ApplyMargins(Rectangle rect, bool reverse) {
959+
return this.ApplyMargins(rect, GetMargins(), reverse);
960+
}
961+
962+
/// <summary>
963+
/// Applies the border box of the renderer on the given rectangle
964+
/// If the border of a certain side is null, the side will remain as it was.
965+
/// </summary>
966+
/// <param name="rect">a rectangle the border box will be applied on.</param>
967+
/// <param name="reverse">
968+
/// indicates whether the border box will be applied
969+
/// inside (in case of false) or outside (in case of false) the rectangle.
970+
/// </param>
971+
/// <returns>
972+
/// a
973+
/// <see cref="iText.Kernel.Geom.Rectangle">border box</see>
974+
/// of the renderer
975+
/// </returns>
976+
/// <seealso cref="GetBorders()"/>
977+
public virtual Rectangle ApplyBorderBox(Rectangle rect, bool reverse) {
978+
Border[] borders = GetBorders();
979+
return ApplyBorderBox(rect, borders, reverse);
980+
}
981+
982+
/// <summary>Applies paddings of the renderer on the given rectangle</summary>
983+
/// <param name="rect">a rectangle paddings will be applied on.</param>
984+
/// <param name="reverse">
985+
/// indicates whether paddings will be applied
986+
/// inside (in case of false) or outside (in case of false) the rectangle.
987+
/// </param>
988+
/// <returns>
989+
/// a
990+
/// <see cref="iText.Kernel.Geom.Rectangle">border box</see>
991+
/// of the renderer
992+
/// </returns>
993+
/// <seealso cref="GetPaddings()"/>
994+
public virtual Rectangle ApplyPaddings(Rectangle rect, bool reverse) {
995+
return ApplyPaddings(rect, GetPaddings(), reverse);
996+
}
997+
946998
public virtual bool IsFirstOnRootArea() {
947999
return IsFirstOnRootArea(false);
9481000
}
@@ -953,27 +1005,27 @@ protected internal virtual void ApplyDestinationsAndAnnotation(DrawContext drawC
9531005
ApplyLinkAnnotation(drawContext.GetDocument());
9541006
}
9551007

956-
internal static bool IsBorderBoxSizing(IRenderer renderer) {
1008+
protected internal static bool IsBorderBoxSizing(IRenderer renderer) {
9571009
BoxSizingPropertyValue? boxSizing = renderer.GetProperty<BoxSizingPropertyValue?>(Property.BOX_SIZING);
9581010
return boxSizing != null && boxSizing.Equals(BoxSizingPropertyValue.BORDER_BOX);
9591011
}
9601012

961-
internal virtual bool IsOverflowProperty(OverflowPropertyValue? equalsTo, int overflowProperty) {
1013+
protected internal virtual bool IsOverflowProperty(OverflowPropertyValue? equalsTo, int overflowProperty) {
9621014
return IsOverflowProperty(equalsTo, this.GetProperty<OverflowPropertyValue?>(overflowProperty));
9631015
}
9641016

965-
internal static bool IsOverflowProperty(OverflowPropertyValue? equalsTo, IRenderer renderer, int overflowProperty
966-
) {
1017+
protected internal static bool IsOverflowProperty(OverflowPropertyValue? equalsTo, IRenderer renderer, int
1018+
overflowProperty) {
9671019
return IsOverflowProperty(equalsTo, renderer.GetProperty<OverflowPropertyValue?>(overflowProperty));
9681020
}
9691021

970-
internal static bool IsOverflowProperty(OverflowPropertyValue? equalsTo, OverflowPropertyValue? rendererOverflowProperty
971-
) {
1022+
protected internal static bool IsOverflowProperty(OverflowPropertyValue? equalsTo, OverflowPropertyValue?
1023+
rendererOverflowProperty) {
9721024
return equalsTo.Equals(rendererOverflowProperty) || equalsTo.Equals(OverflowPropertyValue.FIT) && rendererOverflowProperty
9731025
== null;
9741026
}
9751027

976-
internal static bool IsOverflowFit(OverflowPropertyValue? rendererOverflowProperty) {
1028+
protected internal static bool IsOverflowFit(OverflowPropertyValue? rendererOverflowProperty) {
9771029
return rendererOverflowProperty == null || OverflowPropertyValue.FIT.Equals(rendererOverflowProperty);
9781030
}
9791031

@@ -1128,7 +1180,7 @@ internal static void ProcessWaitingDrawing(IRenderer child, Transform transformP
11281180
/// property value.
11291181
/// </remarks>
11301182
/// <param name="updatedWidthValue">element's new fixed content box width.</param>
1131-
internal virtual void UpdateWidth(UnitValue updatedWidthValue) {
1183+
protected internal virtual void UpdateWidth(UnitValue updatedWidthValue) {
11321184
if (updatedWidthValue.IsPointValue() && IsBorderBoxSizing(this)) {
11331185
updatedWidthValue.SetValue(updatedWidthValue.GetValue() + CalculatePaddingBorderWidth(this));
11341186
}
@@ -1236,7 +1288,7 @@ private float[] CalculateRadii(BorderRadius[] radii, Rectangle area, bool horizo
12361288
/// property value.
12371289
/// </remarks>
12381290
/// <param name="updatedHeight">element's new fixed content box height, shall be not null.</param>
1239-
internal virtual void UpdateHeight(UnitValue updatedHeight) {
1291+
protected internal virtual void UpdateHeight(UnitValue updatedHeight) {
12401292
if (IsBorderBoxSizing(this) && updatedHeight.IsPointValue()) {
12411293
updatedHeight.SetValue(updatedHeight.GetValue() + CalculatePaddingBorderHeight(this));
12421294
}
@@ -1297,7 +1349,7 @@ internal virtual void UpdateHeight(UnitValue updatedHeight) {
12971349
/// property value.
12981350
/// </remarks>
12991351
/// <param name="updatedMaxHeight">element's new content box max-height, shall be not null.</param>
1300-
internal virtual void UpdateMaxHeight(UnitValue updatedMaxHeight) {
1352+
protected internal virtual void UpdateMaxHeight(UnitValue updatedMaxHeight) {
13011353
if (IsBorderBoxSizing(this) && updatedMaxHeight.IsPointValue()) {
13021354
updatedMaxHeight.SetValue(updatedMaxHeight.GetValue() + CalculatePaddingBorderHeight(this));
13031355
}
@@ -1349,7 +1401,7 @@ internal virtual void UpdateMaxHeight(UnitValue updatedMaxHeight) {
13491401
/// property value.
13501402
/// </remarks>
13511403
/// <param name="updatedMinHeight">element's new content box min-height, shall be not null.</param>
1352-
internal virtual void UpdateMinHeight(UnitValue updatedMinHeight) {
1404+
protected internal virtual void UpdateMinHeight(UnitValue updatedMinHeight) {
13531405
if (IsBorderBoxSizing(this) && updatedMinHeight.IsPointValue()) {
13541406
updatedMinHeight.SetValue(updatedMinHeight.GetValue() + CalculatePaddingBorderHeight(this));
13551407
}
@@ -1407,9 +1459,7 @@ protected internal virtual void AddAllProperties(IDictionary<int, Object> proper
14071459
}
14081460

14091461
protected internal virtual float? GetLastYLineRecursively() {
1410-
if (IsOverflowProperty(OverflowPropertyValue.HIDDEN, Property.OVERFLOW_X) || IsOverflowProperty(OverflowPropertyValue
1411-
.HIDDEN, Property.OVERFLOW_Y)) {
1412-
// TODO may be this logic should also be based on BlockFormattingContextUtil?
1462+
if (!AllowLastYLineRecursiveExtraction()) {
14131463
return null;
14141464
}
14151465
for (int i = childRenderers.Count - 1; i >= 0; i--) {
@@ -1424,20 +1474,9 @@ protected internal virtual void AddAllProperties(IDictionary<int, Object> proper
14241474
return null;
14251475
}
14261476

1427-
/// <summary>Applies margins of the renderer on the given rectangle</summary>
1428-
/// <param name="rect">a rectangle margins will be applied on.</param>
1429-
/// <param name="reverse">
1430-
/// indicates whether margins will be applied
1431-
/// inside (in case of false) or outside (in case of true) the rectangle.
1432-
/// </param>
1433-
/// <returns>
1434-
/// a
1435-
/// <see cref="iText.Kernel.Geom.Rectangle">border box</see>
1436-
/// of the renderer
1437-
/// </returns>
1438-
/// <seealso cref="GetMargins()"/>
1439-
protected internal virtual Rectangle ApplyMargins(Rectangle rect, bool reverse) {
1440-
return this.ApplyMargins(rect, GetMargins(), reverse);
1477+
protected internal virtual bool AllowLastYLineRecursiveExtraction() {
1478+
return !IsOverflowProperty(OverflowPropertyValue.HIDDEN, Property.OVERFLOW_X) && !IsOverflowProperty(OverflowPropertyValue
1479+
.HIDDEN, Property.OVERFLOW_Y);
14411480
}
14421481

14431482
/// <summary>Applies given margins on the given rectangle</summary>
@@ -1497,22 +1536,6 @@ protected internal virtual UnitValue[] GetPaddings() {
14971536
return GetPaddings(this);
14981537
}
14991538

1500-
/// <summary>Applies paddings of the renderer on the given rectangle</summary>
1501-
/// <param name="rect">a rectangle paddings will be applied on.</param>
1502-
/// <param name="reverse">
1503-
/// indicates whether paddings will be applied
1504-
/// inside (in case of false) or outside (in case of false) the rectangle.
1505-
/// </param>
1506-
/// <returns>
1507-
/// a
1508-
/// <see cref="iText.Kernel.Geom.Rectangle">border box</see>
1509-
/// of the renderer
1510-
/// </returns>
1511-
/// <seealso cref="GetPaddings()"/>
1512-
protected internal virtual Rectangle ApplyPaddings(Rectangle rect, bool reverse) {
1513-
return ApplyPaddings(rect, GetPaddings(), reverse);
1514-
}
1515-
15161539
/// <summary>Applies given paddings on the given rectangle</summary>
15171540
/// <param name="rect">a rectangle paddings will be applied on.</param>
15181541
/// <param name="paddings">the paddings to be applied on the given rectangle</param>
@@ -1550,26 +1573,6 @@ protected internal virtual Rectangle ApplyPaddings(Rectangle rect, UnitValue[] p
15501573
3].GetValue(), reverse);
15511574
}
15521575

1553-
/// <summary>
1554-
/// Applies the border box of the renderer on the given rectangle
1555-
/// If the border of a certain side is null, the side will remain as it was.
1556-
/// </summary>
1557-
/// <param name="rect">a rectangle the border box will be applied on.</param>
1558-
/// <param name="reverse">
1559-
/// indicates whether the border box will be applied
1560-
/// inside (in case of false) or outside (in case of false) the rectangle.
1561-
/// </param>
1562-
/// <returns>
1563-
/// a
1564-
/// <see cref="iText.Kernel.Geom.Rectangle">border box</see>
1565-
/// of the renderer
1566-
/// </returns>
1567-
/// <seealso cref="GetBorders()"/>
1568-
protected internal virtual Rectangle ApplyBorderBox(Rectangle rect, bool reverse) {
1569-
Border[] borders = GetBorders();
1570-
return ApplyBorderBox(rect, borders, reverse);
1571-
}
1572-
15731576
/// <summary>Applies the given border box (borders) on the given rectangle</summary>
15741577
/// <param name="rect">a rectangle paddings will be applied on.</param>
15751578
/// <param name="borders">

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,7 @@ public virtual IList<LineRenderer> GetLines() {
529529
}
530530

531531
protected internal override float? GetLastYLineRecursively() {
532-
if (IsOverflowProperty(OverflowPropertyValue.HIDDEN, Property.OVERFLOW_X) || IsOverflowProperty(OverflowPropertyValue
533-
.HIDDEN, Property.OVERFLOW_Y)) {
534-
// TODO may be this logic should also be based on BlockFormattingContextUtil?
532+
if (!AllowLastYLineRecursiveExtraction()) {
535533
return null;
536534
}
537535
if (lines == null || lines.Count == 0) {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ protected internal override Rectangle ApplyPaddings(Rectangle rect, UnitValue[]
151151
return rect;
152152
}
153153

154-
protected internal override Rectangle ApplyPaddings(Rectangle rect, bool reverse) {
154+
public override Rectangle ApplyPaddings(Rectangle rect, bool reverse) {
155155
if (bordersHandler is SeparatedTableBorders) {
156156
base.ApplyPaddings(rect, reverse);
157157
}
@@ -1318,10 +1318,16 @@ protected internal override MinMaxWidth GetMinMaxWidth() {
13181318
return new MinMaxWidth(minWidth, maxColTotalWidth, additionalWidth);
13191319
}
13201320

1321+
[System.ObsoleteAttribute(@"Will be removed in next major release (iText 7.2). The aim of this method overriding here is achieved by overriding AllowLastYLineRecursiveExtraction() method."
1322+
)]
13211323
protected internal override float? GetLastYLineRecursively() {
13221324
return null;
13231325
}
13241326

1327+
protected internal override bool AllowLastYLineRecursiveExtraction() {
1328+
return false;
1329+
}
1330+
13251331
private void InitializeTableLayoutBorders() {
13261332
bool isSeparated = BorderCollapsePropertyValue.SEPARATE.Equals(this.GetProperty<BorderCollapsePropertyValue?
13271333
>(Property.BORDER_COLLAPSE));

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7bf0bd1d4e9c8965022ac0771c0f8b4f34327d1b
1+
cee74eb0c5ee4e92187573eebd97746e27d9fe15

0 commit comments

Comments
 (0)