Skip to content

Commit 775b457

Browse files
committed
Do not overflow while applying leading on children. Minor changes. Add a test.
DEVSIX-1662
1 parent 115f777 commit 775b457

File tree

5 files changed

+77
-3
lines changed

5 files changed

+77
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,13 +519,13 @@ public void draw(DrawContext drawContext) {
519519
beginElementOpacityApplying(drawContext);
520520
beginRotationIfApplied(drawContext.getCanvas());
521521

522-
drawBackground(drawContext);
523-
drawBorder(drawContext);
524-
525522
OverflowPropertyValue overflowX = this.<OverflowPropertyValue>getProperty(Property.OVERFLOW_X);
526523
OverflowPropertyValue overflowY = this.<OverflowPropertyValue>getProperty(Property.OVERFLOW_Y);
527524
boolean processOverflow = OverflowPropertyValue.HIDDEN.equals(overflowX) || OverflowPropertyValue.HIDDEN.equals(overflowY);
528525

526+
drawBackground(drawContext);
527+
drawBorder(drawContext);
528+
529529
if (processOverflow) {
530530
drawContext.getCanvas().saveState();
531531
Rectangle clippedArea = drawContext.getDocument().getPage(occupiedArea.getPageNumber()).getPageSize();
@@ -541,6 +541,7 @@ public void draw(DrawContext drawContext) {
541541

542542
drawChildren(drawContext);
543543
drawPositionedChildren(drawContext);
544+
544545
if (processOverflow) {
545546
drawContext.getCanvas().restoreState();
546547
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ protected LineRenderer adjustChildrenYLine() {
816816

817817
protected void applyLeading(float deltaY) {
818818
occupiedArea.getBBox().moveUp(deltaY);
819+
occupiedArea.getBBox().decreaseHeight(deltaY);
819820
for (IRenderer child : childRenderers) {
820821
if (!FloatingHelper.isRendererFloating(child)) {
821822
child.move(0, deltaY);

layout/src/test/java/com/itextpdf/layout/TableTest.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,6 +2324,78 @@ public void tableMinMaxWidthTest05() throws IOException, InterruptedException {
23242324
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, testName + "_diff"));
23252325
}
23262326

2327+
@Test
2328+
public void cellsWithEdgeCaseLeadingTest01() throws IOException, InterruptedException {
2329+
String testName = "cellsWithEdgeCaseLeadingTest01.pdf";
2330+
String outFileName = destinationFolder + testName;
2331+
String cmpFileName = sourceFolder + "cmp_" + testName;
2332+
2333+
PdfWriter writer = new PdfWriter(outFileName);
2334+
PdfDocument pdf = new PdfDocument(writer);
2335+
Document document = new Document(pdf);
2336+
2337+
SolidBorder border = new SolidBorder(1f);
2338+
2339+
Table table = new Table(UnitValue.createPointArray(new float[] {20, 20, 20, 20}));
2340+
2341+
Paragraph paragraph5 = new Paragraph(new Text("Cell5"));
2342+
Paragraph paragraph6 = new Paragraph(new Text("Cell6"));
2343+
Paragraph paragraph7 = new Paragraph(new Text("Cell7"));
2344+
Paragraph paragraph8 = new Paragraph(new Text("Cell8"));
2345+
2346+
Paragraph paragraph13 = new Paragraph("Cell13");
2347+
Paragraph paragraph14 = new Paragraph(new Text(""));
2348+
Paragraph paragraph15 = new Paragraph(new Text("Cell15VVVVVVVVV"));
2349+
Paragraph paragraph16 = new Paragraph(new Text(""));
2350+
2351+
Cell cell1 = new Cell().add(new Paragraph().add("Cell1")).setBorder(border);
2352+
Cell cell2 = new Cell().add(new Paragraph().add("Cell2")).setBorder(border);
2353+
Cell cell3 = new Cell().add(new Paragraph().add("Cell3")).setBorder(border);
2354+
Cell cell4 = new Cell().add(new Paragraph().add("Cell4")).setBorder(border);
2355+
Cell cell5 = new Cell().add(paragraph5.setFixedLeading(8)).setBorder(border).setBackgroundColor(ColorConstants.LIGHT_GRAY);
2356+
Cell cell6 = new Cell().add(paragraph6.setFixedLeading(0)).setBorder(border).setBackgroundColor(ColorConstants.LIGHT_GRAY);
2357+
Cell cell7 = new Cell().add(paragraph7.setFixedLeading(8)).setBorder(border).setBackgroundColor(ColorConstants.LIGHT_GRAY);
2358+
Cell cell8 = new Cell().add(paragraph8.setFixedLeading(-4)).setBorder(border).setBackgroundColor(ColorConstants.LIGHT_GRAY);
2359+
Cell cell9 = new Cell().add(new Paragraph().add("Cell9")).setBorder(border);
2360+
Cell cell10 = new Cell().add(new Paragraph().add("Cell10")).setBorder(border);
2361+
Cell cell11 = new Cell().add(new Paragraph().add("Cell11")).setBorder(border);
2362+
Cell cell12 = new Cell().add(new Paragraph().add("Cell12")).setBorder(border);
2363+
Cell cell13 = new Cell().add(paragraph13.setMultipliedLeading(-1)).setBorder(border).setBackgroundColor(ColorConstants.LIGHT_GRAY);
2364+
Cell cell14 = new Cell().add(paragraph14.setMultipliedLeading(4)).setBorder(border).setBackgroundColor(ColorConstants.LIGHT_GRAY);
2365+
Cell cell15 = new Cell().add(paragraph15.setMultipliedLeading(8)).setBorder(border).setBackgroundColor(ColorConstants.LIGHT_GRAY);
2366+
Cell cell16 = new Cell().add(paragraph16.setMultipliedLeading(-4)).setBorder(border).setBackgroundColor(ColorConstants.LIGHT_GRAY);
2367+
Cell cell17 = new Cell().add(new Paragraph().add("Cell17")).setBorder(border);
2368+
Cell cell18 = new Cell().add(new Paragraph().add("Cell18")).setBorder(border);
2369+
Cell cell19 = new Cell().add(new Paragraph().add("Cell19")).setBorder(border);
2370+
Cell cell20 = new Cell().add(new Paragraph().add("Cell20")).setBorder(border);
2371+
2372+
table.addCell(cell1);
2373+
table.addCell(cell2);
2374+
table.addCell(cell3);
2375+
table.addCell(cell4);
2376+
table.addCell(cell5);
2377+
table.addCell(cell6);
2378+
table.addCell(cell7);
2379+
table.addCell(cell8);
2380+
table.addCell(cell9);
2381+
table.addCell(cell10);
2382+
table.addCell(cell11);
2383+
table.addCell(cell12);
2384+
table.addCell(cell13);
2385+
table.addCell(cell14);
2386+
table.addCell(cell15);
2387+
table.addCell(cell16);
2388+
table.addCell(cell17);
2389+
table.addCell(cell18);
2390+
table.addCell(cell19);
2391+
table.addCell(cell20);
2392+
2393+
document.add(table);
2394+
document.close();
2395+
2396+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, testName + "_diff"));
2397+
}
2398+
23272399
static class CustomRenderer extends TableRenderer {
23282400
public CustomRenderer(Table modelElement, Table.RowRange rowRange) {
23292401
super(modelElement, rowRange);
0 Bytes
Binary file not shown.
1.23 KB
Binary file not shown.

0 commit comments

Comments
 (0)