|
| 1 | +using System; |
| 2 | +using iText.Kernel.Colors; |
| 3 | +using iText.Kernel.Pdf; |
| 4 | +using iText.Kernel.Utils; |
| 5 | +using iText.Layout.Borders; |
| 6 | +using iText.Layout.Element; |
| 7 | +using iText.Test; |
| 8 | +using iText.Test.Attributes; |
| 9 | + |
| 10 | +namespace iText.Layout { |
| 11 | + public class FixedHeightTest : ExtendedITextTest { |
| 12 | + private static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext |
| 13 | + .CurrentContext.TestDirectory) + "/resources/itext/layout/FloatAndAlignmentTest/"; |
| 14 | + |
| 15 | + private static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory |
| 16 | + + "/test/itext/layout/FloatAndAlignmentTest/"; |
| 17 | + |
| 18 | + private const String textByron = "When a man hath no freedom to fight for at home,\n" + " Let him combat for that of his neighbours;\n" |
| 19 | + + "Let him think of the glories of Greece and of Rome,\n" + " And get knocked on the head for his labours.\n" |
| 20 | + + "\n" + "To do good to Mankind is the chivalrous plan,\n" + " And is always as nobly requited;\n" |
| 21 | + + "Then battle for Freedom wherever you can,\n" + " And, if not shot or hanged, you'll get knighted."; |
| 22 | + |
| 23 | + [NUnit.Framework.OneTimeSetUp] |
| 24 | + public static void BeforeClass() { |
| 25 | + CreateOrClearDestinationFolder(destinationFolder); |
| 26 | + } |
| 27 | + |
| 28 | + [LogMessage(iText.IO.Logs.IoLogMessageConstant.CLIP_ELEMENT, Count = 1)] |
| 29 | + // TODO DEVSIX-1977 partial layout result due to fixed height should not contain not layouted kids |
| 30 | + [LogMessage(iText.IO.Logs.IoLogMessageConstant.OCCUPIED_AREA_HAS_NOT_BEEN_INITIALIZED, Count = 6)] |
| 31 | + [NUnit.Framework.Test] |
| 32 | + public virtual void DivWithParagraphsAndFixedPositionTest() { |
| 33 | + String outFileName = destinationFolder + "blockWithLimitedHeightAndFixedPositionTest.pdf"; |
| 34 | + String cmpFileName = sourceFolder + "cmp_blockWithLimitedHeightAndFixedPositionTest.pdf"; |
| 35 | + PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName)); |
| 36 | + Document doc = new Document(pdfDocument); |
| 37 | + Div block = new Div(); |
| 38 | + block.SetBorder(new SolidBorder(ColorConstants.BLUE, 1)); |
| 39 | + block.SetHeight(120); |
| 40 | + foreach (String line in iText.Commons.Utils.StringUtil.Split(textByron, "\n")) { |
| 41 | + Paragraph p = new Paragraph(); |
| 42 | + p.Add(new Text(line)); |
| 43 | + p.SetBorder(new SolidBorder(0.5f)); |
| 44 | + block.Add(p); |
| 45 | + } |
| 46 | + block.SetFixedPosition(100, 600, 300); |
| 47 | + doc.Add(block); |
| 48 | + doc.Close(); |
| 49 | + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder |
| 50 | + )); |
| 51 | + } |
| 52 | + |
| 53 | + [LogMessage(iText.IO.Logs.IoLogMessageConstant.CLIP_ELEMENT, Count = 1)] |
| 54 | + // TODO DEVSIX-1977 partial layout result due to fixed height should not contain not layouted kids |
| 55 | + [LogMessage(iText.IO.Logs.IoLogMessageConstant.OCCUPIED_AREA_HAS_NOT_BEEN_INITIALIZED, Count = 2)] |
| 56 | + [NUnit.Framework.Test] |
| 57 | + public virtual void ListWithFixedPositionTest() { |
| 58 | + String outFileName = destinationFolder + "listWithFixedPositionTest.pdf"; |
| 59 | + String cmpFileName = sourceFolder + "cmp_listWithFixedPositionTest.pdf"; |
| 60 | + PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName)); |
| 61 | + Document doc = new Document(pdfDocument); |
| 62 | + List list = new List(); |
| 63 | + list.SetBorder(new SolidBorder(ColorConstants.BLUE, 1)); |
| 64 | + list.SetHeight(120); |
| 65 | + foreach (String line in iText.Commons.Utils.StringUtil.Split(textByron, "\n")) { |
| 66 | + list.Add(line); |
| 67 | + } |
| 68 | + list.SetFixedPosition(100, 600, 300); |
| 69 | + doc.Add(list); |
| 70 | + doc.Close(); |
| 71 | + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder |
| 72 | + )); |
| 73 | + } |
| 74 | + } |
| 75 | +} |
0 commit comments