From 0477c09d03cca25d6f4790c695e776b0c883d19f Mon Sep 17 00:00:00 2001 From: Rich Date: Fri, 27 Feb 2015 10:51:13 +0000 Subject: [PATCH] If a blank paragraph is followed by a large table and both will not fit on a page, but the table will fit by itself, move the break directl in front of the table. --- PROMS/Volian.Print.Library/Pagination.cs | 39 +++++++++++++++++------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/PROMS/Volian.Print.Library/Pagination.cs b/PROMS/Volian.Print.Library/Pagination.cs index cbc777e8..5497e05e 100644 --- a/PROMS/Volian.Print.Library/Pagination.cs +++ b/PROMS/Volian.Print.Library/Pagination.cs @@ -171,25 +171,25 @@ namespace Volian.Print.Library if (KeepStepsOnPage && firstSubstepExceedsSpaceAvailable && !isFirstChild) KeepStepsOnPage = false; if (ySizeIncludingFirst == YSize) KeepStepsOnPage = false; - float ySectionEndMsg = !_skipEndMessage && MyItemInfo.IsSection && MyItemInfo.Steps != null && MyItemInfo.Steps.Count == 1 && (MyItemInfo.MyDocStyle.End.Message ?? "") != "" ? 2 * SixLinesPerInch : 0; - if (ySizeIncludingFirstStep < yWithinMargins && ySizeIncludingFirst > yWithinMargins && yWithinMargins > (yPageSize / 2)) + float ySectionEndMsg = !_skipEndMessage && MyItemInfo.IsSection && MyItemInfo.Steps != null && MyItemInfo.Steps.Count == 1 && (MyItemInfo.MyDocStyle.End.Message ?? "") != "" ? 2 * SixLinesPerInch : 0; + if (ySizeIncludingFirstStep < yWithinMargins && ySizeIncludingFirst > yWithinMargins && yWithinMargins > (yPageSize/2)) ySizeIncludingFirst = ySizeIncludingFirstStep; if (!KeepStepsOnPage && (ySizeIncludingFirst + ySectionEndMsg) > (yLocation - yBottomMargin) && !nearTheTop) { if (!MyItemInfo.ActiveFormat.PlantFormat.FormatData.PrintData.SpecialCaseCalvert || (ySizeIncludingFirst < yPageSize || yWithinMargins < (yPageSize - (2 * 72)))) { - ShowPageBreak(4, "Page Break Before Continuous Step Section", "Yes", YSize, yPageSize, yWithinMargins, ManualPageBreak); - return 1; + ShowPageBreak(4, "Page Break Before Continuous Step Section", "Yes", YSize, yPageSize, yWithinMargins, ManualPageBreak); + return 1; + } + } + if (ChildrenBelow.Count > 0) + { + vlnParagraph firstHLS = ChildrenBelow[0]; + if (firstHLS.MyItemInfo.IsHigh) + firstHLS.BreakHighLevelStepWithSection = true; } } - if (ChildrenBelow.Count > 0) - { - vlnParagraph firstHLS = ChildrenBelow[0]; - if (firstHLS.MyItemInfo.IsHigh) - firstHLS.BreakHighLevelStepWithSection = true; - } - } return 0; // Don't Paginate (page break) on a Step Section if it's first thing on page } if (!MyItemInfo.IsHigh) return 0; // Don't Paginate on a Substep level @@ -816,6 +816,8 @@ namespace Volian.Print.Library // yTopNew is y Location of this page break. YTopMost is top of HLS, including any Cautions/Notes/Boxes/etc //float yTopNew = paraBreak.YVeryTop - YTopMost; //float yTopNew = paraBreak.YTopMost - YTopMost; + if (JustATableThatWillFit(paraBreak, yPageSize - (myTopMsgSpace + yEndMsg))) + paraBreak = paraBreak.ChildrenBelow[0]; float yTopNew = Math.Min(paraBreak.YTopMost, paraBreak.YVeryTop) - YTopMost; // This is for formats that break on all HLS, Cautions & Notes (often backgrounds): @@ -857,6 +859,21 @@ namespace Volian.Print.Library } ProfileTimer.Pop(profileDepth); } + + private bool JustATableThatWillFit(vlnParagraph paraBreak, float ypagesize) + { + if (paraBreak.MyItemInfo.MyContent.Text.Replace(" ", "").Replace(@"\u160?", "").Replace(@"\'A0", "") != "") return false; + if (paraBreak.YSize < ypagesize) return false; + if (paraBreak.ChildrenAbove.Count > 0) return false; + if (paraBreak.ChildrenLeft.Count > 0) return false; + if (paraBreak.ChildrenRight.Count > 0) return false; + if (paraBreak.ChildrenBelow.Count != 1) return false; + if (!paraBreak.ChildrenBelow[0].MyItemInfo.IsTable) return false; + vlnParagraph paraTable = paraBreak.ChildrenBelow[0]; + if (paraTable.YSize < ypagesize) + return true; + return false; + } /// /// Finds the highest StepLevel (lowest StepLevel number, 0 = HLS, 1 = first substep) that /// fills the page sufficiently (more than half-full)