From 17d0839e6c3e85c2d9a2c1257522071cef851ca1 Mon Sep 17 00:00:00 2001 From: Rich Date: Fri, 21 Sep 2012 15:30:59 +0000 Subject: [PATCH] Keep headers with related text Break a page if the item will not fit on the current page Created ToString method for vlnParagraph Created ToString method for ParagraphLocation Changed Between logic for overlap to exclude exact match --- PROMS/Volian.Print.Library/Pagination.cs | 29 ++++++++++++---------- PROMS/Volian.Print.Library/vlnParagraph.cs | 10 +++++++- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/PROMS/Volian.Print.Library/Pagination.cs b/PROMS/Volian.Print.Library/Pagination.cs index a4fc981d..362c1397 100644 --- a/PROMS/Volian.Print.Library/Pagination.cs +++ b/PROMS/Volian.Print.Library/Pagination.cs @@ -42,9 +42,11 @@ namespace Volian.Print.Library bool ManualPageBreak = false; float yEndMsg = !MyItemInfo.IsSection && MyItemInfo.MyHLS.NextItem == null && (MyItemInfo.MyDocStyle.End.Message ?? "") != "" ? 2 * SixLinesPerInch : 0; float yWithinMargins = CalculateYLocation(yLocation, yTopMargin) - yBottomMargin; // -SixLinesPerInch; + bool isFirstChild = MyItemInfo.MyPrevious == null; + bool nearTheTop = (yWithinMargins < yPageSize) && (yWithinMargins > (yPageSize - 5 * SixLinesPerInch)); // if step is breaking over a number of pages, determine if the current step is the // location of a pagebreak. - if (MyItemInfo.ItemID == 54 || MyItemInfo.ItemID == 54) Console.WriteLine("here"); + if (MyItemInfo.ItemID == 23383 || MyItemInfo.ItemID == 23384) Console.WriteLine("here"); if (MyPageHelper.ParaBreaks.Count > 0) { if (this == MyPageHelper.ParaBreaks[0] || this.YTopMost > MyPageHelper.ParaBreaks[0].YTopMost) @@ -97,10 +99,8 @@ namespace Volian.Print.Library //while (firstStepChild.MyItemInfo.IsSection && firstStepChild.ChildrenBelow.Count > 0) firstStepChild = firstStepChild.ChildrenBelow[0]; while (firstStepChild.ChildrenBelow.Count > 0 && (firstStepChild.MyItemInfo.IsSection || firstStepChild.MyItemInfo.IsHigh)) firstStepChild = firstStepChild.ChildrenBelow[0]; float ySizeIncludingFirstStep = firstStepChild.YSize + (firstStepChild.YTopMost - YTopMost); - bool isFirstSection = MyItemInfo.MyPrevious == null; - bool nearTheTop = yWithinMargins > (yPageSize - 5 * SixLinesPerInch); bool firstSubstepExceedsSpaceAvailable = ySizeIncludingFirstStep > yWithinMargins; - if (KeepStepsOnPage && firstSubstepExceedsSpaceAvailable && !isFirstSection) + if (KeepStepsOnPage && firstSubstepExceedsSpaceAvailable && !isFirstChild) KeepStepsOnPage = false; if (!KeepStepsOnPage && ySizeIncludingFirst > (yLocation - yBottomMargin)) { @@ -136,6 +136,7 @@ namespace Volian.Print.Library float yExtra2 = (SixLinesPerInch - MyItemInfo.MyDocStyle.Layout.FooterLength) ?? 0; if (KeepStepsOnPage && ySizeIncludingFirst > yWithinMargins) KeepStepsOnPage = false; + bool KeepWithHeader = isFirstChild && nearTheTop; if (!ManualPageBreak && mySize + yEndMsg <= yWithinMargins + yExtra) // Don't Paginate if there is enough room, will fit on page //if (!ManualPageBreak && mySize + yEndMsg <= yWithinMargins + SixLinesPerInch) // Don't Paginate if there is enough room, will fit on page { @@ -147,7 +148,7 @@ namespace Volian.Print.Library // YSize includes a blank line after the step which we don't want to include in the page break test, thus the // YSize - SixLinesPerInch: - if (!KeepStepsOnPage && YSize - SixLinesPerInch + yEndMsg <= yPageSize) // if the entire step can fit on one page, do a page break + if (!KeepWithHeader && !KeepStepsOnPage && YSize - SixLinesPerInch + yEndMsg <= yPageSize) // if the entire step can fit on one page, do a page break { // Don't want extra line before step //Console.WriteLine("'PageBreak',2,'Yes','HLS will fit on 1 Page',{0},{1},{2}, {3}, {4},'{5}'", MyItemInfo.ItemID, YSize, yPageSize, yWithinMargins, (int)(100 * yWithinMargins / yPageSize), MyItemInfo.ShortPath); @@ -171,8 +172,8 @@ namespace Volian.Print.Library if (_Match16BitPagination) myFirstPieceSize += 2 * SixLinesPerInch; // TODO: Put this line back to case 0, i.e. previous line. This fixes a 16-bit vs 32-bit pagination diff in EO30 Step 20. //float myFirstPieceSize = GetFirstPieceSize() + 2 * SixLinesPerInch; //Case 10 - this is to match 16bit - if (!ManualPageBreak && ((MyItemInfo.ActiveFormat.MyStepSectionLayoutData.SpecialPageBreakFlag && yWithinMargins > yPageSize / 2 && - myFirstPieceSize < yWithinMargins) || KeepStepsOnPage)) + if (KeepWithHeader ||( !ManualPageBreak && ((MyItemInfo.ActiveFormat.MyStepSectionLayoutData.SpecialPageBreakFlag && yWithinMargins > yPageSize / 2 && + myFirstPieceSize < yWithinMargins) || KeepStepsOnPage))) { //Console.WriteLine("'PageBreak',4,'No','HLS will have to split anyway',{0},{1},{2}, {3}, {4},'{5}'", MyItemInfo.ItemID, YSize, yPageSize, yWithinMargins, (int)(100 * yWithinMargins / yPageSize), MyItemInfo.ShortPath); if(firstStep == "Yes") @@ -291,6 +292,7 @@ namespace Volian.Print.Library { foreach (float yLocation in myList[stepLevel].Keys) // loop thru yLocation { + vlnParagraph myPara = myList[stepLevel][yLocation]; // The top of this step will fit onto page (-yLocation < yWithinMargins) if (-yLocation <= yUpperLimit) // Fix for OFN-RJ-23 //if (-yLocation < yUpperLimit) // Before @@ -301,13 +303,14 @@ namespace Volian.Print.Library //if (myList[stepLevel][yLocation].MyItemInfo.ItemID == 4312) Console.WriteLine("rno"); // The top of this step is more than 1/2 way down the page if ((-yLocation + yStart) >= yLowerLimit) - { - return myList[stepLevel][yLocation]; - } + return myPara; + // If this item will not fit on the current page, put a page break + if (myPara.YBottom - myPara.YTop > (yUpperLimit - (-yLocation + yStart))) + return myPara; // if is a caution or note & parent is a substep and entire substep doesn't fit, break. - if ((myList[stepLevel][yLocation].MyItemInfo.IsNote || myList[stepLevel][yLocation].MyItemInfo.IsCaution) && - !myList[stepLevel][yLocation].MyParent.MyItemInfo.IsHigh && - myList[stepLevel][yLocation].MyParent.YSize > (yUpperLimit + yLocation)) + if ((myPara.MyItemInfo.IsNote || myPara.MyItemInfo.IsCaution) && + !myPara.MyParent.MyItemInfo.IsHigh && + myPara.MyParent.YSize > (yUpperLimit + yLocation)) { return myList[stepLevel][yLocation]; } diff --git a/PROMS/Volian.Print.Library/vlnParagraph.cs b/PROMS/Volian.Print.Library/vlnParagraph.cs index ae93dca3..7bbcc681 100644 --- a/PROMS/Volian.Print.Library/vlnParagraph.cs +++ b/PROMS/Volian.Print.Library/vlnParagraph.cs @@ -119,6 +119,10 @@ namespace Volian.Print.Library } public partial class vlnParagraph : vlnPrintObject { + public override string ToString() + { + return string.Format("{0} - {1} - '{2}'", this.YTop, this.YSize, this.MyItemInfo.ShortPath); + } private vlnTable _MyGrid; public vlnTable MyGrid { @@ -2144,6 +2148,10 @@ namespace Volian.Print.Library } public class ParagraphLocation { + public override string ToString() + { + return string.Format("{0} - {1} - '{2}'", this.StepLevel, this.YTop, this.MyParagraph.MyItemInfo.ShortPath); + } private float _YTop; public float YTop { @@ -2184,7 +2192,7 @@ namespace Volian.Print.Library return false; } public static bool Between(float x, float lower, float higher) - { return x >= lower && x <= higher; } + { return x > lower && x < higher; } public bool Overlap(ParagraphLocation otherParagraphLocation) { if (Between(otherParagraphLocation.YTop, YTop, YBottom)) return true; // The top is within the other