public virtual void OrphansWidowsAwareAndDirectLayoutProduceSameResult() { PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new MemoryStream())); Document document = new Document(pdfDocument); int minAllowedWidows = 3; int overflowedToNextPageLinesNum = 5; Paragraph widowsParagraph = new Paragraph(OrphansWidowsTestUtil.PARA_TEXT); IRenderer paragraphRenderer = widowsParagraph.CreateRendererSubTree().SetParent(document.GetRenderer()); Rectangle effectiveArea = document.GetPageEffectiveArea(pdfDocument.GetDefaultPageSize()); float linesHeight = OrphansWidowsTestUtil.CalculateHeightForLinesNum(document, widowsParagraph, effectiveArea .GetWidth(), overflowedToNextPageLinesNum, false); Rectangle layoutAreaRect = new Rectangle(effectiveArea).SetHeight(linesHeight + OrphansWidowsTestUtil.LINES_SPACE_EPS ); LayoutContext layoutContext = new LayoutContext(new LayoutArea(1, layoutAreaRect)); LayoutResult noWidowsControlLayoutResult = paragraphRenderer.Layout(layoutContext); ParagraphWidowsControl widowsControl = new ParagraphWidowsControl(minAllowedWidows, 1, false); widowsParagraph.SetWidowsControl(widowsControl); LayoutResult widowsControlLayoutResult = paragraphRenderer.Layout(layoutContext); // toString() comparison is used since it contains report on status, areaBreak and occupiedArea NUnit.Framework.Assert.AreEqual(noWidowsControlLayoutResult.ToString(), widowsControlLayoutResult.ToString ()); ParagraphRenderer firstSplitRenderer = (ParagraphRenderer)noWidowsControlLayoutResult.GetSplitRenderer(); ParagraphRenderer secondSplitRenderer = (ParagraphRenderer)widowsControlLayoutResult.GetSplitRenderer(); NUnit.Framework.Assert.IsNotNull(firstSplitRenderer); NUnit.Framework.Assert.IsNotNull(secondSplitRenderer); NUnit.Framework.Assert.AreEqual(firstSplitRenderer.ToString(), secondSplitRenderer.ToString()); NUnit.Framework.Assert.IsNotNull(noWidowsControlLayoutResult.GetOverflowRenderer()); NUnit.Framework.Assert.IsNotNull(widowsControlLayoutResult.GetOverflowRenderer()); }