|
| 1 | +package com.itextpdf.layout; |
| 2 | + |
| 3 | +import com.itextpdf.io.logs.IoLogMessageConstant; |
| 4 | +import com.itextpdf.kernel.colors.ColorConstants; |
| 5 | +import com.itextpdf.kernel.pdf.PdfDocument; |
| 6 | +import com.itextpdf.kernel.pdf.PdfWriter; |
| 7 | +import com.itextpdf.kernel.utils.CompareTool; |
| 8 | +import com.itextpdf.layout.borders.SolidBorder; |
| 9 | +import com.itextpdf.layout.element.Div; |
| 10 | +import com.itextpdf.layout.element.List; |
| 11 | +import com.itextpdf.layout.element.Paragraph; |
| 12 | +import com.itextpdf.layout.element.Text; |
| 13 | +import com.itextpdf.test.ExtendedITextTest; |
| 14 | +import com.itextpdf.test.annotations.LogMessage; |
| 15 | +import com.itextpdf.test.annotations.LogMessages; |
| 16 | +import com.itextpdf.test.annotations.type.IntegrationTest; |
| 17 | + |
| 18 | +import java.io.IOException; |
| 19 | +import org.junit.Assert; |
| 20 | +import org.junit.BeforeClass; |
| 21 | +import org.junit.Test; |
| 22 | +import org.junit.experimental.categories.Category; |
| 23 | + |
| 24 | +@Category(IntegrationTest.class) |
| 25 | +public class FixedHeightTest extends ExtendedITextTest { |
| 26 | + |
| 27 | + private static final String sourceFolder = "./src/test/resources/com/itextpdf/layout/FloatAndAlignmentTest/"; |
| 28 | + private static final String destinationFolder = "./target/test/com/itextpdf/layout/FloatAndAlignmentTest/"; |
| 29 | + |
| 30 | + private static final String textByron = |
| 31 | + "When a man hath no freedom to fight for at home,\n" + |
| 32 | + " Let him combat for that of his neighbours;\n" + |
| 33 | + "Let him think of the glories of Greece and of Rome,\n" + |
| 34 | + " And get knocked on the head for his labours.\n" + |
| 35 | + "\n" + |
| 36 | + "To do good to Mankind is the chivalrous plan,\n" + |
| 37 | + " And is always as nobly requited;\n" + |
| 38 | + "Then battle for Freedom wherever you can,\n" + |
| 39 | + " And, if not shot or hanged, you'll get knighted."; |
| 40 | + |
| 41 | + @BeforeClass |
| 42 | + public static void beforeClass() { |
| 43 | + createOrClearDestinationFolder(destinationFolder); |
| 44 | + } |
| 45 | + |
| 46 | + @LogMessages(messages = { |
| 47 | + @LogMessage(messageTemplate = IoLogMessageConstant.CLIP_ELEMENT, count = 1), |
| 48 | + // TODO DEVSIX-1977 partial layout result due to fixed height should not contain not layouted kids |
| 49 | + @LogMessage(messageTemplate = IoLogMessageConstant.OCCUPIED_AREA_HAS_NOT_BEEN_INITIALIZED, count = 6) |
| 50 | + }) |
| 51 | + @Test |
| 52 | + public void divWithParagraphsAndFixedPositionTest() throws IOException, InterruptedException { |
| 53 | + String outFileName = destinationFolder + "blockWithLimitedHeightAndFixedPositionTest.pdf"; |
| 54 | + String cmpFileName = sourceFolder + "cmp_blockWithLimitedHeightAndFixedPositionTest.pdf"; |
| 55 | + PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName)); |
| 56 | + |
| 57 | + Document doc = new Document(pdfDocument); |
| 58 | + |
| 59 | + Div block = new Div(); |
| 60 | + block.setBorder(new SolidBorder(ColorConstants.BLUE, 1)); |
| 61 | + block.setHeight(120); |
| 62 | + |
| 63 | + for (String line : textByron.split("\n")) { |
| 64 | + Paragraph p = new Paragraph(); |
| 65 | + p.add(new Text(line)); |
| 66 | + p.setBorder(new SolidBorder(0.5f)); |
| 67 | + block.add(p); |
| 68 | + } |
| 69 | + block.setFixedPosition(100, 600, 300); |
| 70 | + doc.add(block); |
| 71 | + |
| 72 | + doc.close(); |
| 73 | + |
| 74 | + Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder)); |
| 75 | + } |
| 76 | + |
| 77 | + @LogMessages(messages = { |
| 78 | + @LogMessage(messageTemplate = IoLogMessageConstant.CLIP_ELEMENT, count = 1), |
| 79 | + // TODO DEVSIX-1977 partial layout result due to fixed height should not contain not layouted kids |
| 80 | + @LogMessage(messageTemplate = IoLogMessageConstant.OCCUPIED_AREA_HAS_NOT_BEEN_INITIALIZED, count = 2) |
| 81 | + }) |
| 82 | + @Test |
| 83 | + public void listWithFixedPositionTest() throws IOException, InterruptedException { |
| 84 | + String outFileName = destinationFolder + "listWithFixedPositionTest.pdf"; |
| 85 | + String cmpFileName = sourceFolder + "cmp_listWithFixedPositionTest.pdf"; |
| 86 | + PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName)); |
| 87 | + |
| 88 | + Document doc = new Document(pdfDocument); |
| 89 | + |
| 90 | + List list = new List(); |
| 91 | + list.setBorder(new SolidBorder(ColorConstants.BLUE, 1)); |
| 92 | + list.setHeight(120); |
| 93 | + |
| 94 | + for (String line : textByron.split("\n")) { |
| 95 | + list.add(line); |
| 96 | + } |
| 97 | + list.setFixedPosition(100, 600, 300); |
| 98 | + doc.add(list); |
| 99 | + |
| 100 | + doc.close(); |
| 101 | + |
| 102 | + Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder)); |
| 103 | + } |
| 104 | +} |
0 commit comments