Skip to content

Commit 35c39fb

Browse files
committed
Fix an issue with processing tabs inside of a paragraph.
Move not only a renderer itself, but its children as well. DEVSIX-1830
1 parent 3f0b06e commit 35c39fb

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,11 @@ public LayoutResult layout(LayoutContext layoutContext) {
415415
tabRenderer.layout(new LayoutContext(new LayoutArea(layoutContext.getArea().getPageNumber(), bbox), wasParentsHeightClipped));
416416
float sumOfAffectedRendererWidths = 0;
417417
for (IRenderer renderer : affectedRenderers) {
418-
renderer.getOccupiedArea().getBBox().moveRight(tabWidth + sumOfAffectedRendererWidths);
418+
renderer.move(tabWidth + sumOfAffectedRendererWidths, 0);
419419
sumOfAffectedRendererWidths += renderer.getOccupiedArea().getBBox().getWidth();
420420
}
421421
if (childResult.getSplitRenderer() != null) {
422-
childResult.getSplitRenderer().getOccupiedArea().getBBox().moveRight(tabWidth + sumOfAffectedRendererWidths - childResult.getSplitRenderer().getOccupiedArea().getBBox().getWidth());
422+
childResult.getSplitRenderer().move(tabWidth + sumOfAffectedRendererWidths - childResult.getSplitRenderer().getOccupiedArea().getBBox().getWidth(), 0);
423423
}
424424

425425
float tabAndNextElemWidth = tabWidth + childResult.getOccupiedArea().getBBox().getWidth();

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ This file is part of the iText (R) project.
5959
import com.itextpdf.layout.element.Paragraph;
6060
import com.itextpdf.layout.element.Tab;
6161
import com.itextpdf.layout.element.TabStop;
62+
import com.itextpdf.layout.element.Table;
6263
import com.itextpdf.layout.element.Text;
6364
import com.itextpdf.layout.property.Property;
6465
import com.itextpdf.layout.property.TabAlignment;
@@ -273,6 +274,49 @@ public void anchorTabStopsTest02() throws IOException, InterruptedException {
273274
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, "diff" + outFileName));
274275
}
275276

277+
@Test
278+
public void tablesAndTabInsideOfParagraph() throws IOException, InterruptedException {
279+
String testName = "tablesAndTabInsideOfParagraph.pdf";
280+
String outFileName = destinationFolder + testName;
281+
String cmpFileName = sourceFolder + "cmp_" + testName;
282+
283+
Document doc = initDocument(outFileName, false);
284+
285+
286+
Table leftTable = new Table(1);
287+
for(int x=0; x<3; x++){
288+
leftTable.addCell("Table 1, Line " + (x + 1));
289+
}
290+
Table rightTable = new Table(1);
291+
for(int x=0; x<3; x++){
292+
rightTable.addCell("Table 2, Line " + (x + 1));
293+
}
294+
295+
Paragraph p = new Paragraph().add(leftTable);
296+
p.add(new Tab());
297+
p.addTabStops(new TabStop(300, TabAlignment.LEFT));
298+
p.add(rightTable);
299+
doc.add(new Paragraph("TabAlignment: LEFT"));
300+
doc.add(p);
301+
302+
p = new Paragraph().add(leftTable);
303+
p.add(new Tab());
304+
p.addTabStops(new TabStop(300, TabAlignment.CENTER));
305+
p.add(rightTable);
306+
doc.add(new Paragraph("TabAlignment: CENTER"));
307+
doc.add(p);
308+
309+
p = new Paragraph().add(leftTable);
310+
p.add(new Tab());
311+
p.addTabStops(new TabStop(300, TabAlignment.RIGHT));
312+
p.add(rightTable);
313+
doc.add(new Paragraph("TabAlignment: RIGHT"));
314+
doc.add(p);
315+
316+
doc.close();
317+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, testName + "_diff"));
318+
}
319+
276320
@Test
277321
public void severalTabsInRowTest() throws IOException, InterruptedException {
278322
String fileName = "severalTabsInRowTest.pdf";

0 commit comments

Comments
 (0)