Skip to content

Commit 1dfb78f

Browse files
committed
Merge branch 'feature/inline_blocks_support_and_leading_improvements' into develop
2 parents 7731715 + 8f20ec7 commit 1dfb78f

22 files changed

+247
-37
lines changed

io/src/main/java/com/itextpdf/io/LogMessageConstant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public final class LogMessageConstant {
7676
public static final String IMAGE_HAS_JPXDECODE_FILTER = "Image cannot be inline if it has JPXDecode filter. It will be added as an ImageXObject";
7777
public static final String IMAGE_SIZE_CANNOT_BE_MORE_4KB = "Inline image size cannot be more than 4KB. It will be added as an ImageXObject";
7878
public static final String INCORRECT_PAGEROTATION = "Encounterd a page rotation that was not a multiple of 90°/ (Pi/2) when generating default appearances for form fields";
79+
public static final String INLINE_BLOCK_ELEMENT_WILL_BE_CLIPPED = "Inline block element does not fit into parent element and will be clipped";
7980
public static final String INPUT_STREAM_CONTENT_IS_LOST_ON_PDFSTREAM_SERIALIZATION = "PdfStream contains not null input stream. It's content will be lost in serialized object.";
8081
public static final String INVALID_INDIRECT_REFERENCE = "Invalid indirect reference {0} {1} R";
8182
public static final String INVALID_KEY_VALUE_KEY_0_HAS_NULL_VALUE = "Invalid key value: key {0} has null value.";

layout/src/main/java/com/itextpdf/layout/element/Paragraph.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ public Paragraph add(ILeafElement element) {
106106
return this;
107107
}
108108

109+
public Paragraph add(IBlockElement element) {
110+
childElements.add(element);
111+
return this;
112+
}
113+
109114
/**
110115
* Adds a {@link java.util.List} of layout elements to the Paragraph.
111116
* @param elements the content to be added, any {@link ILeafElement}

layout/src/main/java/com/itextpdf/layout/margincollapse/MarginsCollapseHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ This file is part of the iText (R) project.
4646
import com.itextpdf.layout.IPropertyContainer;
4747
import com.itextpdf.layout.property.FloatPropertyValue;
4848
import com.itextpdf.layout.property.Property;
49+
import com.itextpdf.layout.renderer.AbstractRenderer;
4950
import com.itextpdf.layout.renderer.BlockRenderer;
5051
import com.itextpdf.layout.renderer.CellRenderer;
5152
import com.itextpdf.layout.renderer.IRenderer;
53+
import com.itextpdf.layout.renderer.LineRenderer;
5254
import com.itextpdf.layout.renderer.RootRenderer;
5355
import com.itextpdf.layout.renderer.TableRenderer;
5456

@@ -473,7 +475,9 @@ private static boolean marginsCouldBeSelfCollapsing(IRenderer renderer) {
473475
return !(renderer instanceof TableRenderer)
474476
&& !rendererIsFloated(renderer)
475477
&& !hasBottomBorders(renderer) && !hasTopBorders(renderer)
476-
&& !hasBottomPadding(renderer) && !hasTopPadding(renderer) && !hasPositiveHeight(renderer);
478+
&& !hasBottomPadding(renderer) && !hasTopPadding(renderer) && !hasPositiveHeight(renderer)
479+
// inline block
480+
&& !(isBlockElement(renderer) && renderer instanceof AbstractRenderer && ((AbstractRenderer) renderer).getParent() instanceof LineRenderer);
477481
}
478482

479483
private static boolean firstChildMarginAdjoinedToParent(IRenderer parent) {
@@ -486,7 +490,6 @@ private static boolean lastChildMarginAdjoinedToParent(IRenderer parent) {
486490
&& !rendererIsFloated(parent) && !hasBottomBorders(parent) && !hasBottomPadding(parent) && !hasHeightProp(parent);
487491
}
488492

489-
490493
private static boolean isBlockElement(IRenderer renderer) {
491494
return renderer instanceof BlockRenderer || renderer instanceof TableRenderer;
492495
}

layout/src/main/java/com/itextpdf/layout/renderer/AbstractRenderer.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,20 @@ This file is part of the iText (R) project.
4949
import com.itextpdf.kernel.geom.AffineTransform;
5050
import com.itextpdf.kernel.geom.Point;
5151
import com.itextpdf.kernel.geom.Rectangle;
52-
import com.itextpdf.kernel.pdf.*;
52+
import com.itextpdf.kernel.pdf.PdfArray;
53+
import com.itextpdf.kernel.pdf.PdfDictionary;
54+
import com.itextpdf.kernel.pdf.PdfDocument;
55+
import com.itextpdf.kernel.pdf.PdfName;
56+
import com.itextpdf.kernel.pdf.PdfNumber;
57+
import com.itextpdf.kernel.pdf.PdfObject;
58+
import com.itextpdf.kernel.pdf.PdfPage;
5359
import com.itextpdf.kernel.pdf.action.PdfAction;
5460
import com.itextpdf.kernel.pdf.annot.PdfLinkAnnotation;
5561
import com.itextpdf.kernel.pdf.canvas.CanvasArtifact;
5662
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
5763
import com.itextpdf.kernel.pdf.extgstate.PdfExtGState;
5864
import com.itextpdf.kernel.pdf.tagging.PdfStructElem;
5965
import com.itextpdf.kernel.pdf.tagutils.IAccessibleElement;
60-
import com.itextpdf.layout.Document;
6166
import com.itextpdf.kernel.pdf.tagutils.TagTreePointer;
6267
import com.itextpdf.layout.IPropertyContainer;
6368
import com.itextpdf.layout.border.Border;
@@ -69,12 +74,22 @@ This file is part of the iText (R) project.
6974
import com.itextpdf.layout.layout.LayoutPosition;
7075
import com.itextpdf.layout.minmaxwidth.MinMaxWidth;
7176
import com.itextpdf.layout.minmaxwidth.MinMaxWidthUtils;
72-
import com.itextpdf.layout.property.*;
77+
import com.itextpdf.layout.property.Background;
78+
import com.itextpdf.layout.property.BackgroundImage;
79+
import com.itextpdf.layout.property.HorizontalAlignment;
80+
import com.itextpdf.layout.property.Property;
81+
import com.itextpdf.layout.property.TransparentColor;
82+
import com.itextpdf.layout.property.UnitValue;
7383
import org.slf4j.Logger;
7484
import org.slf4j.LoggerFactory;
7585

7686
import java.text.MessageFormat;
77-
import java.util.*;
87+
import java.util.ArrayList;
88+
import java.util.Arrays;
89+
import java.util.Collections;
90+
import java.util.HashMap;
91+
import java.util.List;
92+
import java.util.Map;
7893

7994
/**
8095
* Defines the most common properties and behavior that are shared by most
@@ -741,6 +756,19 @@ protected Float getFirstYLineRecursively() {
741756
return ((AbstractRenderer) childRenderers.get(0)).getFirstYLineRecursively();
742757
}
743758

759+
protected Float getLastYLineRecursively() {
760+
for (int i = childRenderers.size() - 1; i >= 0; i--) {
761+
IRenderer child = childRenderers.get(i);
762+
if (child instanceof AbstractRenderer) {
763+
Float lastYLine = ((AbstractRenderer) child).getLastYLineRecursively();
764+
if (lastYLine != null) {
765+
return lastYLine;
766+
}
767+
}
768+
}
769+
return null;
770+
}
771+
744772
/**
745773
* Applies margins of the renderer on the given rectangle
746774
*

0 commit comments

Comments
 (0)