diff --git a/PROMS/Volian.Print.Library/Grid2Pdf.cs b/PROMS/Volian.Print.Library/Grid2Pdf.cs index b0af1a36..a47aebd8 100644 --- a/PROMS/Volian.Print.Library/Grid2Pdf.cs +++ b/PROMS/Volian.Print.Library/Grid2Pdf.cs @@ -11,13 +11,87 @@ using Volian.Print.Library; using Volian.Controls.Library; using iTextSharp.text; using iTextSharp.text.pdf; +using VEPROMS.CSLA.Library; namespace Volian.Print.Library { - public class vlnTable + #region Settings // RHM20150429 - Table Scrunch + public partial class vlnTable + { + private string _DebugInfo = null; // RHM20150429 - Table Scrunch + public string DebugInfo + { + get { return _DebugInfo; } + set { _DebugInfo = value; } + } + private int _ItemID = 0; + public int ItemID + { + get { return _ItemID; } + set { _ItemID = value; } + } + private bool _ShowDetails = false; + public bool ShowDetails + { + get { return _ShowDetails; } + set { _ShowDetails = value; } + } + private bool _IsTooBig = false; + public bool IsTooBig + { + get { return _IsTooBig; } + set { _IsTooBig = value; } + } + } + public partial class vlnCells + { + private static float YAdjust_HContent = 4; // 4 + private float YAdjust_SpacingAfter + { + get + { + return 8-8*MyTable.Adjustment;//0; // 8 + } + } + } + public partial class vlnCell + { + public bool ShowDetails + { get { return MyTable.ShowDetails; } } + private static float YAdjust_h = 0; // 0 + private float YAdjust_TextLocation + { + get + { + return 4 - 4 * MyTable.Adjustment; ;//0; // 4 + } + } + } + //public partial class vlnTable + //{ + // private static float YAdjust_RowTop = 0;//8; // 0 + //} + //public partial class vlnCells + //{ + // private static float YAdjust_HContent = 4; // 4 + // private static float YAdjust_SpacingAfter = 8;//0; // 8 + //} + //public partial class vlnCell + //{ + // private static float YAdjust_h = 0; // 0 + // private static float YAdjust_TextLocation = 4;//0; // 4 + //} + #endregion + public partial class vlnTable { #region Properties + private float[] _HContents;// RHM20150525 - Table Scrunch + public float[] HContents + { + get { return _HContents; } + set { _HContents = value; } + } private float[] _RowTop; public float[] RowTop { @@ -99,6 +173,106 @@ namespace Volian.Print.Library { get { return (LineThicknessForThick - LineThicknessForDouble) / 2; }//LineThicknessForThick - 2 * LineThicknessForDouble; } } + private float _TotalContentHeight = 0;// RHM20150525 - Table Scrunc + public float TotalContentHeight + { + get + { + if (_TotalContentHeight == 0) + { + foreach (float h in HContents) + _TotalContentHeight += h; + } + return _TotalContentHeight; + } + } + public float SpaceAvailable// RHM20150525 - Table Scrunc + { + get { return TotalContentHeight ==0 ? 0 : RowTop[RowTop.Length - 1] - TotalContentHeight; } + } + private float _TooBig;// RHM20150525 - Table Scrunc + public float TooBig + { + get { return _TooBig; } + set + { + _TooBig = value; + //_Adjustment = Math.Min(1F, (_TooBig / (RowTop.Length - 1)) / 12); + //if (ShowDetails) Console.WriteLine("TooBig\t{0}\t{1}", value, _Adjustment); + //if(ShowDetails) Console.WriteLine("Before RowTop={0}", RowTop[RowTop.Length-1] ); + float extra=(TooBig < SpaceAvailable)?(SpaceAvailable - TooBig) / HContents.Length:0; + for (int r = 0; r < RowTop.Length - 1; r++) + RowTop[r + 1] = RowTop[r] + HContents[r] + extra; + //if(ShowDetails) Console.WriteLine("After RowTop={0}", RowTop[RowTop.Length-1] ); + } + } + private float _Adjustment = 0;// RHM20150525 - Table Scrunc + public float Adjustment + { + get { return _Adjustment; } + set { _Adjustment = value; } + } + //private float _YAdjust_RowTop = 0;//8; // 0 + public float YAdjust_RowTop + { + get + { + return _Adjustment * 12; + } + } + private void DrawRuler(PdfContentByte cb, float x, float yTop, float height)// RHM20150525 - Table Scrunc + { + VlnSvgPageHelper myPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper; + if (myPageHelper.DebugLayer != null) + { + cb.BeginLayer(myPageHelper.DebugLayer); + cb.SaveState(); + cb.SetLineWidth(.1F); + cb.SetColorStroke(new Color(System.Drawing.Color.Orange)); + float yBottom = yTop - height; + cb.MoveTo(x, yTop); + cb.LineTo(x, yBottom); + int i = 0; + for (float y = yTop; y >= yBottom; y -= 10) + { + float w = 10; + if (i % 10 == 0) w = 30; + else if (i % 5 == 0) w = 20; + cb.SetLineWidth(w / 30); + i++; + cb.MoveTo(x + w, y); + cb.LineTo(x, y); + cb.Stroke(); + } + i = 0; + cb.Stroke(); + cb.RestoreState(); + cb.EndLayer(); + } + } + private void ShowRowTops(string location)// RHM20150525 - Table Scrunc + { + if (!ShowDetails) return; + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < RowTop.Length; i++) + sb.Append("\t" + RowTop[i].ToString()); + Console.WriteLine(location + "\t" + sb.ToString()); + } + private void EndSetup()// RHM20150525 - Table Scrunc + { + if (ShowDetails) ShowRowTops("vlnTable.ctor.2"); + if (ShowDetails) Console.WriteLine("^^^^^^vlnTable============{0}===============", ItemID); + } + private void SetupDebug(VlnFlexGrid myFlexGrid)// RHM20150525 - Table Scrunc + { + //ShowDetails = myFlexGrid.GetMyItemInfo().InList(38329); + //if(ShowDetails) Console.WriteLine("vvvvvvlnTable============{0}===============", ItemID); + ItemInfo myItemInfo = myFlexGrid.GetMyItemInfo(); + ItemID = myItemInfo.ItemID; + DebugInfo = string.Format("DebugID = {0}, ID={1} Type={2} TypeName='{3}' StepLevel={4} ShortPath={5} Width={6} Left={7} YOffset={8}", + 0, myItemInfo.ItemID, myItemInfo.FormatStepType, myItemInfo.FormatStepData == null ? "NoStepData" : myItemInfo.FormatStepData.Type, + myItemInfo.StepLevel, myItemInfo.ShortPath, Width, XOffset, YOffset); + } #endregion #region Constructors public vlnTable(VlnFlexGrid myFlexGrid, iTextSharp.text.pdf.PdfContentByte myContentByte) @@ -106,13 +280,16 @@ namespace Volian.Print.Library MyFlexGrid = myFlexGrid; MyContentByte = myContentByte; InitializeSizes(); + SetupDebug(myFlexGrid);// RHM20150525 - Table Scrunc MyCells = new vlnCells(this, MyFlexGrid, MyContentByte); + EndSetup();// RHM20150525 - Table Scrunc } #endregion #region Private Methods private void InitializeSizes() { RowTop = new float[MyFlexGrid.Rows.Count + 1]; + HContents = new float[MyFlexGrid.Rows.Count];// RHM20150525 - Table Scrunc RowTop[0] = 0; for (int r = 0; r < MyFlexGrid.Rows.Count; r++) RowTop[r + 1] = RowTop[r] + 72 * (MyFlexGrid.Rows[r].Height == -1 @@ -120,7 +297,7 @@ namespace Volian.Print.Library ColLeft = new float[MyFlexGrid.Cols.Count + 1]; ColLeft[0] = 0; for (int c = 0; c < MyFlexGrid.Cols.Count; c++) - ColLeft[c + 1] = ColLeft[c] + 72 * (MyFlexGrid.Cols[c].Width == -1 + ColLeft[c + 1] = 2 + ColLeft[c] + 72 * (MyFlexGrid.Cols[c].Width == -1 // RHM20150429 - Table Scrunch ? MyFlexGrid.Cols.DefaultSize : MyFlexGrid.Cols[c].Width) / (float)MyFlexGrid.DPI; } #endregion @@ -134,9 +311,21 @@ namespace Volian.Print.Library public void ToPdf(iTextSharp.text.pdf.ColumnText myColumnText, float left, float top) { //ZoomGrid(myColumnText, left, top); - VlnSvgPageHelper myPageHelper = myColumnText.Canvas.PdfWriter.PageEvent as VlnSvgPageHelper; + if(ShowDetails) Console.WriteLine("vvvvvvToPdf============{0}===============", ItemID);// RHM20150525 - Table Scrunc + ShowRowTops("ToPDF1"); + PdfContentByte cb = myColumnText.Canvas; // RHM20150429 - Table Scrunch + VlnSvgPageHelper myPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper; + string myLPI = myPageHelper.YMultiplier == 1.0F ? ",6LPI" : ",7LPI"; + Rtf2Pdf.DrawPdfDebug(myColumnText.Canvas, left-2, top+1, left + Width, top-myPageHelper.YMultiplier *(Height+1), + DebugInfo+", Height= " + (myPageHelper.YMultiplier * Height).ToString() + myLPI, 0); + PdfLayer textLayer = myPageHelper == null ? null : myPageHelper.TextLayer; // RHM20150429 - Table Scrunch + if (textLayer != null) cb.BeginLayer(textLayer); myPageHelper.AddGap(top, top - Height, left, left + Width); MyCells.ToPdf(myColumnText, left, top); + DrawRuler(myColumnText.Canvas, left + Width, top, myPageHelper.YMultiplier * (Height + 1)); // RHM20150429 - Table Scrunch + if (textLayer != null) cb.EndLayer(); + ShowRowTops("ToPDF2"); + if (ShowDetails) Console.WriteLine("^^^^^^ToPdf============{0}===============", ItemID); } private void ZoomGrid(iTextSharp.text.pdf.ColumnText myColumnText, float left, float top) { @@ -145,7 +334,7 @@ namespace Volian.Print.Library } #endregion } - public class vlnCells : List + public partial class vlnCells : List // RHM20150429 - Table Scrunch { #region Properties private VlnFlexGrid _MyFlexGrid; @@ -160,6 +349,8 @@ namespace Volian.Print.Library get { return _MyTable; } set { _MyTable = value; } } + public bool ShowDetails// RHM20150525 - Table Scrunc + { get { return MyTable.ShowDetails; }} private iTextSharp.text.pdf.PdfContentByte _MyContentByte; public iTextSharp.text.pdf.PdfContentByte MyContentByte { @@ -195,6 +386,7 @@ namespace Volian.Print.Library // Walk through for (int r = 0; r < MyFlexGrid.Rows.Count; r++) { + float hMax = 12; // RHM20150429 - Table Scrunch for (int c = 0; c < MyFlexGrid.Cols.Count; c++) { CellRange cr = MyFlexGrid.GetMergedRange(r, c); @@ -212,7 +404,7 @@ namespace Volian.Print.Library str = dt.StartText; str = PreProcessRTF(w, str); iTextSharp.text.Paragraph myPara = RtfToParagraph(str); - myColumnText1.SetSimpleColumn(0, 0, w - 2, MyContentByte.PdfDocument.PageSize.Top); // Padding = 4 + myColumnText1.SetSimpleColumn(0, 0, w-2, MyContentByte.PdfDocument.PageSize.Top); // Padding = 4 if (str.Contains(@"\'05")) { // if there is a hanging indent, the iTextSharp paragraph properties must be set @@ -234,22 +426,78 @@ namespace Volian.Print.Library // once there is valid value for TotalLeading (from previous line), you can use it to // calculate a MultipliedLeading to give 6 LPI (12 points) myPara.MultipliedLeading = 12.0f / myPara.TotalLeading; - myPara.SpacingAfter = 8; // RHM 20120925 - Add a line to properly space text from lines. + if(Rtf2Pdf.GetTableScrunchingStatus(TableScrunching.Phase2)) // RHM20150429 - Table Scrunch + myPara.SpacingAfter = 0;// YAdjust_SpacingAfter; // RHM 20120925 - Add a line to properly space text from lines. FixHyphens(myPara, MyTable); + if (Rtf2Pdf.GetTableScrunchingStatus(TableScrunching.Phase3)) + TrimNewlines(myPara); // RHM20150429 - Table Scrunch myColumnText1.AddElement(myPara); //myColumnText1.Canvas.SetColorFill(PrintOverride.OverrideTextColor(System.Drawing.Color.Black)); float posBefore = myColumnText1.YLine; int status = myColumnText1.Go(true); float posAfter = myColumnText1.YLine; float hContent = 4 + posBefore - posAfter; + if (Rtf2Pdf.GetTableScrunchingStatus(TableScrunching.Phase4))// RHM20150525 - Table Scrunc + { + hContent = 0 + posBefore - posAfter;//YAdjust_HContent + posBefore - posAfter; + // if (myPara.Chunks.Count > 0 && myPara.Chunks[myPara.Chunks.Count - 1] == "\n") + // hContent -= 12; + } + //if(ShowDetails) Console.WriteLine("{0}\t{1}\t{2}",r,c, hContent/12); + if (cr.r1 == cr.r2) + hMax = Math.Max(hMax, hContent); + else + hMax = Math.Max(hMax, hContent - (cr.r2 - cr.r1) * _SixLinesPerInch); if (hContent > h) + { // RHM20150429 - Table Scrunch + //if (ShowDetails) Console.WriteLine("Less {0},{1},{2},{3},{4},{5}", r, c, posBefore, posAfter, hContent, hMax); MyTable.AdjustRowTop(cr.r1, cr.r2, hContent); - Add(new vlnCell(cr.r1, cr.c1, cr.r2, cr.c2, MyTable, myPara, hContent)); + } // RHM20150429 - Table Scrunch + if (Rtf2Pdf.GetTableScrunchingStatus(TableScrunching.Phase5)) + { + //if (ShowDetails) Console.WriteLine("Greater{0},{1},{2},{3},{4},{5}", r, c, posBefore, posAfter, hContent, hMax); + //if (c == MyFlexGrid.Cols.Count - 1) + //MyTable.AdjustRowTop(cr.r1, cr.r2, hMax + 6); + MyTable.HContents[cr.r2] = hMax+2; + } + Add(new vlnCell(cr.r1, cr.c1, cr.r2, cr.c2, MyTable, myPara,hContent)); } } } } + private void ShowChunks(System.Collections.ArrayList chunks) // RHM20150429 - Table Scrunch + { + StringBuilder sb = new StringBuilder(); + foreach (Chunk chk in chunks) + { + sb.Append(BuildChunks(chk.Content)); + } + //if (ShowDetails) Console.WriteLine("Chunks = '{0}'", sb.ToString()); + } + private string BuildChunks(string str) + { + StringBuilder sb = new StringBuilder(); + foreach(char c in str) + { + if (((int)c) < 0x20 || ((int)c) > 0x7F) + sb.Append(string.Format("<{0:X4}>",(int)c)); + else + sb.Append(c); + } + return "{" + sb.ToString() + "}"; + } + private void TrimNewlines(Paragraph myPara) + { + while (myPara.Chunks.Count > 0 && ParaEndsWithNewLine(myPara)) + myPara.RemoveAt(myPara.Chunks.Count - 1); + } + private bool ParaEndsWithNewLine(Paragraph myPara) + { + Chunk chk = myPara.Chunks[myPara.Chunks.Count - 1] as Chunk; + if (chk.Content == "\n") return true; + return false; + } public class VlnSplitCharacter : ISplitCharacter { public bool IsSplitCharacter(int start, int current, int end, char[] cc, PdfChunk[] ck) @@ -418,7 +666,7 @@ namespace Volian.Print.Library } #endregion } - public class vlnCell + public partial class vlnCell // RHM20150429 - Table Scrunch { #region Properties private vlnTable _MyTable; @@ -753,15 +1001,32 @@ namespace Volian.Print.Library float w = MyTable.ColLeft[c2 + 1] - x; float y = mult * MyTable.RowTop[r1]; float h = mult * MyTable.RowTop[r2 + 1] - y; + if (Rtf2Pdf.GetTableScrunchingStatus(TableScrunching.Phase6))// RHM20150525 - Table Scrunc + { + h = YAdjust_h + mult * MyTable.RowTop[r2 + 1] - y; + + } BordersToPdf(myColumnText, left, top, x, w, y, h ); - float hAdjust = VeritcalTextAlignment(h); + float hAdjust = VeritcalTextAlignment(h,_MyPageHelper.YMultiplier); iTextSharp.text.pdf.ColumnText myColumnText1 = new iTextSharp.text.pdf.ColumnText(myColumnText.Canvas); float adjustTextLocation = mult * 4; // RHM 20120925 Move text down about 1 half line from the border - myColumnText1.SetSimpleColumn(1 + left + x, top - y - h , left + x + w, 1 + top - y - hAdjust - adjustTextLocation); // 2 == Default Padding + if (Rtf2Pdf.GetTableScrunchingStatus(TableScrunching.Phase7))// RHM20150525 - Table Scrunc + { + adjustTextLocation = mult * 0; + if (mult != 1F) adjustTextLocation=1; + } + myColumnText1.SetSimpleColumn(1 + left + x, top - y - h , left + x + w - 2, 1 + top - y - hAdjust - adjustTextLocation); // 2 == Default Padding + if (ShowDetails) Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t\"{9}\"" + , r1, c1, hAdjust, adjustTextLocation, y, h, top, 1 + top - y - hAdjust - adjustTextLocation, + _MyPageHelper.YMultiplier, MyPara.Content.Substring(0, Math.Min(20, MyPara.Content.Length))); MyPara.MultipliedLeading *= _MyPageHelper.YMultiplier; vlnCells.FixHyphens(MyPara, MyTable); myColumnText1.AddElement(MyPara); + float posBefore = myColumnText1.YLine; // RHM20150429 - Table Scrunch myColumnText1.Go(); + float posAfter = myColumnText1.YLine; // RHM20150429 - Table Scrunch + if(ShowDetails)Console.WriteLine("ToPDF posBefore,posAfter,difference={0},{1},{2},{3}", + posBefore, posAfter, posBefore - posAfter,w); myColumnText.Canvas.RestoreState(); } private static float _SixLinesPerInch = 12; // twips @@ -790,7 +1055,7 @@ namespace Volian.Print.Library } #endregion #region Private Text Methods - private float VeritcalTextAlignment(float h) + private float VeritcalTextAlignment(float h, float mult) { float hAdjust = 0; //CellRange cr = MyTable.MyFlexGrid.GetCellRange(r1, c1, r2, c2); @@ -802,13 +1067,15 @@ namespace Volian.Print.Library case TextAlignEnum.GeneralBottom: case TextAlignEnum.LeftBottom: case TextAlignEnum.RightBottom: - hAdjust = h - HContent; + hAdjust = Math.Max(0,h - (mult * HContent) )-1; + Console.WriteLine("\"Bottom\",{0},{1},{2}", h, HContent, hAdjust); break; case TextAlignEnum.CenterCenter: case TextAlignEnum.GeneralCenter: case TextAlignEnum.LeftCenter: case TextAlignEnum.RightCenter: - hAdjust = (h - HContent) / 2; + hAdjust = Math.Max(0,(h - (mult * HContent)) / 2)-1; + Console.WriteLine("\"Middle\",{0},{1},{2}", h, HContent, hAdjust); break; default: break; diff --git a/PROMS/Volian.Print.Library/Pagination.cs b/PROMS/Volian.Print.Library/Pagination.cs index 176692e0..f00f65c4 100644 --- a/PROMS/Volian.Print.Library/Pagination.cs +++ b/PROMS/Volian.Print.Library/Pagination.cs @@ -403,7 +403,8 @@ namespace Volian.Print.Library KeepStepsOnPage = true; float mySize7LPI = mySize; // +SixLinesPerInch; if (_Match16BitPagination) mySize7LPI += SixLinesPerInch; - if (!KeepWithHeader && !KeepStepsOnPage && mySize - SixLinesPerInch + yEndMsg <= yPageSizeNextPage) // if the entire step can fit on one page, do a page break + float tableSpaceAvailable = TableSpaceAvailable;// RHM20150525 - Table Scrunch + if (!KeepWithHeader && !KeepStepsOnPage && mySize - SixLinesPerInch + yEndMsg - tableSpaceAvailable <= yPageSizeNextPage) // 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); @@ -422,7 +423,7 @@ namespace Volian.Print.Library // ySize7LPI includes a blank line after the step which we don't want to include in the page break test. else if (!KeepStepsOnPage && MyItemInfo.ActiveFormat.MyStepSectionLayoutData.CompressSteps - && (mySize7LPI - SixLinesPerInch + yEndMsg) < (yPageSizeNextPage * SixLinesPerInch / _SevenLinesPerInch)) + && (mySize7LPI - SixLinesPerInch + yEndMsg - tableSpaceAvailable) < (yPageSizeNextPage * SixLinesPerInch / _SevenLinesPerInch))// RHM20150525 - Table Scrunch { // ooooooooo ooooo ooooooooo. ooooo // d"""""""8' `888' `888 `Y88. `888' @@ -1316,6 +1317,19 @@ namespace Volian.Print.Library // DebugPagination.WriteLine("'StepLevel',{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", YVeryTop - yTopMost, YSize, YBottomMost - yTopMost, item.ItemID, item.DBSequence, item.StepLevel, item.MyContent.Type % 10000, // parent.MyContent.Type % 10000, item.HasCautionOrNote ? 1 : 0, parent.Cautions == null ? 0 : 1); //} + public float TableSpaceAvailable// RHM20150525 - Table Scrunch + { + get + { + float retval = 0; + if(_ChildrenBelow!= null) + foreach (vlnParagraph pgh in _ChildrenBelow) + retval += pgh.TableSpaceAvailable; + if (MyGrid != null) + retval += MyGrid.SpaceAvailable; + return retval; + } + } } public partial class VlnSvgPageHelper : SvgPageHelper { diff --git a/PROMS/Volian.Print.Library/Rtf2Pdf.cs b/PROMS/Volian.Print.Library/Rtf2Pdf.cs index 0344192c..e42c4aae 100644 --- a/PROMS/Volian.Print.Library/Rtf2Pdf.cs +++ b/PROMS/Volian.Print.Library/Rtf2Pdf.cs @@ -13,6 +13,21 @@ using System.IO; namespace Volian.Print.Library { + [Flags] + public enum TableScrunching:short // RHM20150507 Table Scrunch + { + None=0, + Phase1=1, + Phase2=2, + Phase3=4, + Phase4=8, + Phase5=16, + Phase6=32, + Phase7=64, + Phase8=128, + Phase9=256, + Phase10=512 + } public class Rtf2Pdf { private string _Rtf; @@ -99,6 +114,16 @@ namespace Volian.Print.Library return (c == ' '); } } + private static TableScrunching _AllowTableScrunching = TableScrunching.None; // RHM20150507 Table Scrunch + public static TableScrunching AllowTableScrunching + { + get { return Rtf2Pdf._AllowTableScrunching; } + set { Rtf2Pdf._AllowTableScrunching = value; } + } + public static bool GetTableScrunchingStatus(TableScrunching val) + { + return (val & _AllowTableScrunching) == val; + } public static VlnSplitCharacter mySplitter = new VlnSplitCharacter(); public static float TextAt(PdfContentByte cb, Paragraph iParagraph, float x, float y, float width, float height, string debugText, float yBottomMargin) { @@ -115,7 +140,7 @@ namespace Volian.Print.Library VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper; PdfLayer textLayer = _MyPageHelper == null ? null : _MyPageHelper.TextLayer; float left = x + Offset.X; - float top = y + Offset.Y; + float top = y + Offset.Y + _MyPageHelper.TableAdjustment;// RHM20150525 - Table Scrunch float right = left + width; float bottom = top - height; ColumnText myColumnText = new ColumnText(cb); @@ -188,20 +213,20 @@ namespace Volian.Print.Library } public static float GridAt(PdfContentByte cb, vlnTable myGrid, float x, float y, float width, float height, string debugText, float yBottomMargin, bool hasBorder) { - VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper; - PdfLayer textLayer = _MyPageHelper == null ? null : _MyPageHelper.TextLayer; + //VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper; // RHM20150507 Table Scrunch + //PdfLayer textLayer = _MyPageHelper == null ? null : _MyPageHelper.TextLayer; // RHM20150507 Table Scrunch float left = x + Offset.X; float top = y + Offset.Y; float right = left + width; float bottom = top - height; ColumnText myColumnText = new ColumnText(cb); myColumnText.SetSimpleColumn(left, top, left + width, yBottomMargin); - if (textLayer != null) cb.BeginLayer(textLayer); + //if (textLayer != null) cb.BeginLayer(textLayer); // RHM20150507 Table Scrunch myGrid.ToPdf(myColumnText, left, top + GridTopAdjust); - if (textLayer != null) cb.EndLayer(); + //if (textLayer != null) cb.EndLayer(); // RHM20150507 Table Scrunch return bottom; } - private static void DrawPdfDebug(PdfContentByte cb, float left, float top, float right, float bottom, string debugText, float yDescent) + internal static void DrawPdfDebug(PdfContentByte cb, float left, float top, float right, float bottom, string debugText, float yDescent) { VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper; PdfLayer debugLayer = _MyPageHelper == null ? null : _MyPageHelper.DebugLayer; diff --git a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs index 4fd5cdf6..9c217f9e 100644 --- a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs +++ b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs @@ -14,12 +14,31 @@ namespace Volian.Print.Library { public partial class VlnSvgPageHelper:SvgPageHelper { + private float _TableAdjustment = 0;// RHM20150525 - Table Scrunch + public float TableAdjustment + { + get { return _TableAdjustment; } + set { _TableAdjustment = value; } + } private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); private pkParagraphs _MyPlacekeepers = new pkParagraphs(); public pkParagraphs MyPlacekeepers { get { return _MyPlacekeepers; } } + private float? _BottomContent = null;// RHM20150525 - Table Scrunch + public float? BottomContent + { + get + { + return _BottomContent; + } + set + { + if(value == null || _BottomContent == null || _BottomContent > value) + _BottomContent = value; + } + } private PageBookmarks _PageBookmarks = new PageBookmarks(); public PageBookmarks PageBookmarks { @@ -201,6 +220,7 @@ namespace Volian.Print.Library //} public override void OnEndPage(PdfWriter writer, iTextSharp.text.Document document) { + TableAdjustment = 0;// RHM20150525 - Table Scrunch //string path = Volian.Base.Library.vlnStackTrace.StackToStringLocal(3, 1); //Console.WriteLine("End {0}",path); int profileDepth = ProfileTimer.Push(">>>> OnEndPage"); diff --git a/PROMS/Volian.Print.Library/vlnParagraph.cs b/PROMS/Volian.Print.Library/vlnParagraph.cs index d4c34246..b066ee7c 100644 --- a/PROMS/Volian.Print.Library/vlnParagraph.cs +++ b/PROMS/Volian.Print.Library/vlnParagraph.cs @@ -294,14 +294,14 @@ namespace Volian.Print.Library { if (childItemInfo is SectionInfo) formatInfo = (childItemInfo as SectionInfo).LocalFormat ?? formatInfo; if (rnoLevel < maxRNO && childItemInfo.RNOs != null) yoff = Math.Max(yoff, yoffRight); - if (childItemInfo.ActiveSection.ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.StepSectionPrintData.ContActBoxOnSubSteps && + if (childItemInfo.ActiveSection.ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.StepSectionPrintData.ContActBoxOnSubSteps && box != null && box.MyBox != null && bxIndx == null) // point beach boxed substeps { box.Height = yoff - box.YOffset - (1F * vlnPrintObject.SixLinesPerInch); box = null; yoff += 1 * vlnPrintObject.SixLinesPerInch; } - vlnParagraph para = new vlnParagraph(Parent, cb, childItemInfo, xoff, yoff, rnoLevel, maxRNO, formatInfo, null, null, yoffRight, true, pp); + vlnParagraph para = new vlnParagraph(Parent, cb, childItemInfo, xoff, yoff, rnoLevel, maxRNO, formatInfo, null, null, yoffRight,true, pp); // if doing the component list (FNP), keep track of the bottom most columns' data // so this can be returned after the row is done. @@ -331,7 +331,7 @@ namespace Volian.Print.Library else if (!para.UseTemplateKeepOnCurLine(childItemInfo)) yoff = para.YBottomMost; // don't adjust YBottomost until after yoff is set for the RNO Separator - para.YBottomMost += para.YBottomMostAdjust; + para.YBottomMost += para.YBottomMostAdjust; if (box != null && childItemInfo.FormatStepData != null && childItemInfo.FormatStepData.BoxIt) { box.Height = yoff - box.YOffset - (1.1F * vlnPrintObject.SixLinesPerInch); @@ -551,7 +551,8 @@ namespace Volian.Print.Library if (MyItemInfo.MyContent.MyGrid != null) { int profileDepth = ProfileTimer.Push(">>>> vlnParagraph.DrawDrid"); - retval = DrawGrid(cb, ref yPageStart, yTopMargin, yBottomMargin, ref yLocation); + // RHM20150507 Include Footer + retval = DrawGrid(cb, ref yPageStart, yTopMargin, yBottomMargin + (float) MyItemInfo.MyDocStyle.Layout.FooterLength, ref yLocation); // RHM20150429 - Table Scrunch ProfileTimer.Pop(profileDepth); } else @@ -828,11 +829,29 @@ namespace Volian.Print.Library { //DebugText.WriteLine("{0},'{1}','{2}','<>'", MyItemInfo.ItemID, MyItemInfo.ShortPath, FormattedText); if(DebugText.IsOpen)DebugText.WriteLine("{0},'{1}','{2}','<>',{3}", MyItemInfo.ItemID, MyItemInfo.ShortPath, MyItemInfo.MyContent.Text, XOffset); + //if (MyItemInfo.InList(11019,11024,111026)) // RHM20150507 Table Scrunch + // Console.WriteLine("here"); + float heightBefore = MyGrid.Height+4 * MyPageHelper.YMultiplier; + if (Rtf2Pdf.GetTableScrunchingStatus(TableScrunching.Phase1) && heightBefore > (yLocation - yBottomMargin)) + { + //MyGrid.TooBig = (MyItemInfo.MyDocStyle.Layout.FooterLength ?? 0) + SixLinesPerInch + MyGrid.Height - (yLocation - yBottomMargin); + MyGrid.TooBig = SixLinesPerInch + MyGrid.Height * MyPageHelper.YMultiplier - (yLocation - yBottomMargin); + float heightAfter = MyGrid.Height + 4 * MyPageHelper.YMultiplier; + MyPageHelper.TableAdjustment += (heightBefore - heightAfter); + if (heightAfter < (yLocation - yBottomMargin)) + { + _MyLog.ErrorFormat("<<< WARNING >>> Table is too big to fit on page, Vertical Padding adjusted to fit\r\n==>'Table Adjusted',{0},'{1}','{2}',{3},{4},{5}" + , MyItemInfo.ItemID, MyItemInfo.MyDocVersion.MyFolder.Name, MyItemInfo.ShortPath, heightBefore, MyGrid.Height, (yTopMargin - yBottomMargin)); + } + else + MyGrid.IsTooBig = true; + } + MyPageHelper.BottomContent=yLocation-(MyGrid.Height + 4 * MyPageHelper.YMultiplier); float retval = Rtf2Pdf.GridAt(cb, MyGrid, XOffset, yLocation, Width, 100, DebugInfo, yBottomMargin, !MyItemInfo.FormatStepData.Type.Contains("Borderless")); if (MyGrid.Height > (yTopMargin - yBottomMargin)) { - _MyLog.ErrorFormat("<<< ERROR >>> Table is too big to fit on page, expect pagination problems\r\n==>'Table Too Big',{0},'{1}','{2}',{3},{4}" - , MyItemInfo.ItemID, MyItemInfo.MyDocVersion.MyFolder.Name, MyItemInfo.ShortPath, MyGrid.Height, (yTopMargin - yBottomMargin)); + _MyLog.ErrorFormat("<<< ERROR >>> Table is too big to fit on page, expect pagination problems\r\n==>'Table Too Big',{0},'{1}','{2}',{3},{4},{5}" // RHM20150429 - Table Scrunch + , MyItemInfo.ItemID, MyItemInfo.MyDocVersion.MyFolder.Name, MyItemInfo.ShortPath, heightBefore, MyGrid.Height, (yTopMargin - yBottomMargin)); } return retval; } @@ -883,8 +902,42 @@ namespace Volian.Print.Library DebugPagination.WriteLine("Very Low {0},{1},{2},{3},{4},{5}", MyItemInfo.ShortPath, MyItemInfo.ItemID, yLocation, Height, yLocation - Height, yTopMargin - MyItemInfo.MyDocStyle.Layout.PageLength); } int profileDepth = ProfileTimer.Push(">>>> Rtf2Pdf.TextAt"); - retval = Rtf2Pdf.TextAt(cb, IParagraph, XOffset, yLocation, Width, 100, DebugInfo + string.Format(",YLines = {0}",YSize/SixLinesPerInch), yBottomMargin); - ProfileTimer.Pop(profileDepth); + // ooooooooo. oooooooooo. oooooooooooo ooooooooooooo o8o . o8o + // `888 `Y88. `888' `Y8b `888' `8 8' 888 `8 `"' .o8 `"' + // 888 .d88' 888 888 888 888 oooo d8b .oooo. ooo. .oo. .oooo.o oooo .o888oo oooo .ooooo. ooo. .oo. .oooo.o + // 888ooo88P' 888 888 888oooo8 888 `888""8P `P )88b `888P"Y88b d88( "8 `888 888 `888 d88' `88b `888P"Y88b d88( "8 + // 888 888 888 888 " 888 888 .oP"888 888 888 `"Y88b. 888 888 888 888 888 888 888 `"Y88b. + // 888 888 d88' 888 888 888 d8( 888 888 888 o. )88b 888 888 . 888 888 888 888 888 o. )88b + // o888o o888bood8P' o888o o888o d888b `Y888""8o o888o o888o 8""888P' o888o "888" o888o `Y8bod8P' o888o o888o 8""888P' + // + // Design Suggestion: + // During vlnParagraaph Constuctor Build an end point dictionary + // During toPdf check for end points before adding GoTos for Local + // Need to have a way to get to sections which do not have any output (header only) + // Need to have a way to identify procedures + // + //if (IParagraph.Chunks.Count > 0) + //{ + // Chunk chk1 = IParagraph.Chunks[0] as Chunk; + // chk1.SetLocalDestination(string.Format("ItemID={0}", MyItemInfo.ItemID)); // Destination + // if (MyItemInfo.MyContent.ContentTransitionCount > 0) + // { + // TransitionInfo ti = MyItemInfo.MyContent.ContentTransitions[0]; + // if (ti.MyItemToID.MyProcedure.ItemID == MyItemInfo.MyProcedure.ItemID) + // { // Local Go To + // if (ti.MyItemToID.MyContent.Type > 19999) + // foreach (Chunk chk in IParagraph.Chunks) + // chk.SetLocalGoto(string.Format("ItemID={0}", ti.ToID)); + // } + // else // Remote Go To + // foreach (Chunk chk in IParagraph.Chunks) + // chk.SetRemoteGoto(ti.MyItemToID.MyProcedure.DisplayNumber.Replace("/", "_") + ".pdf", string.Format("ItemID={0}", ti.ToID)); + // } + // MyPageHelper.BottomContent = yLocation - Height; + // if (MyItemInfo.InList(39048)) Console.WriteLine("Here"); + retval = Rtf2Pdf.TextAt(cb, IParagraph, XOffset, yLocation, Width, 100, DebugInfo + string.Format(",YLines = {0}", YSize / SixLinesPerInch), yBottomMargin); + ProfileTimer.Pop(profileDepth); + //} if (retval == 0) // problem occurred - paragraph was not able to be printed on page { // pagination logic needs to be fixed. // oooooooooooo ooooooooo. o8o . o8o @@ -2076,10 +2129,15 @@ namespace Volian.Print.Library { case E_ContBottomLoc.EndOfText: // place continue string at end of text msg_yLocation = msg_yLocation + yLocation - SixLinesPerInch; + float tableSpaceAvailable = TableSpaceAvailable;// RHM20150525 - Table Scrunch if (yBottomMargin + (docstyle.Layout.FooterLength ?? 0) > msg_yLocation) { // Adjusted Continue Message Y Offset //DebugPagination.WriteLine("====>> {0},'{1}'", msg_yLocation, MyItemInfo.ShortPath); - msg_yLocation = yBottomMargin + (docstyle.Layout.FooterLength ?? 0); + //msg_yLocation = (float) MyPageHelper.BottomContent - SixLinesPerInch; // Account for how low the lowest Item is on the page + msg_yLocation = Math.Min(yBottomMargin +(docstyle.Layout.FooterLength ?? 0),(float) MyPageHelper.BottomContent - SixLinesPerInch);// RHM20150525 - Table Scrunch + float msg_yLocationOld = yBottomMargin + (docstyle.Layout.FooterLength ?? 0); + if (msg_yLocationOld != msg_yLocation) + _MyLog.WarnFormat("Continue Message Moved from {0} to {1} for {2}", msg_yLocationOld, msg_yLocation, this);// RHM20150525 - Table Scrunch } break; case E_ContBottomLoc.BtwnTextAndBottom: // place continue string between end of text & bottom of page @@ -2109,6 +2167,7 @@ namespace Volian.Print.Library _MyLog.WarnFormat("**** BOTTOM CONTINUE MESSAGE NOT CODED FOR LOCATION {0}*****", docstyle.Continue.Bottom.Location); break; } + MyPageHelper.BottomContent = null;// RHM20150525 - Table Scrunch if (!PageBreakOnStep) { float xoffB = 0; @@ -2219,8 +2278,10 @@ namespace Volian.Print.Library { //if (!vPara.Processed && ((vPara.YOffset + vPara.Height) < YTopMost)) if (!vPara.Processed && ((vPara.YOffset) < YTopMost)) - if (MyItemInfo.ItemID != vPara.MyItemInfo.ItemID) + if (this.MyItemInfo.ItemID != vPara.MyItemInfo.ItemID) // RHM20150507 Table Scrunch process.Add(vPara); + else // RHM20150507 Table Scrunch + _MyLog.WarnFormat("Step Could Have Fit {0}, {1}",MyItemInfo.ItemID,MyItemInfo.ShortPath); } foreach (vlnParagraph vPara in process) { @@ -3788,14 +3849,14 @@ namespace Volian.Print.Library if (MyItemInfo.ActiveFormat.PlantFormat.FormatData.PrintData.SpecialCaseCalvertAlarm || (MyItemInfo.ActiveFormat.PlantFormat.FormatData.PrintData.SpecialCaseCalvert && MyItemInfo.IsStep && MyItemInfo.FormatStepData.StepLayoutData.STBoxindex != null)) { - if ((MyItemInfo.IsCaution || MyItemInfo.IsNote || MyItemInfo.MyParent.IsCaution || MyItemInfo.MyParent.IsNote) && !MyItemInfo.FormatStepData.SpaceIn - && (MyItemInfo.Steps == null || MyItemInfo.Steps.Count == 0) - && (MyItemInfo.NextItem == null || MyItemInfo.MyContent.Type != MyItemInfo.NextItem.MyContent.Type)) return 0; + if ((MyItemInfo.IsCaution || MyItemInfo.IsNote || MyItemInfo.MyParent.IsCaution || MyItemInfo.MyParent.IsNote) && !MyItemInfo.FormatStepData.SpaceIn + && (MyItemInfo.Steps == null || MyItemInfo.Steps.Count == 0) + && (MyItemInfo.NextItem == null || MyItemInfo.MyContent.Type != MyItemInfo.NextItem.MyContent.Type)) return 0; if (everyNLines == 99 && MyItemInfo.NextItem == null) - { - if (MyItemInfo.Steps != null && MyItemInfo.Steps.Count > 0 && MyItemInfo.Steps[0].MyContent.Type == MyItemInfo.MyContent.Type) return 0; - if (MyItemInfo.MyParent.NextItem != null && MyItemInfo.MyParent.NextItem.MyContent.Type == MyItemInfo.MyContent.Type) return 0; - } + { + if (MyItemInfo.Steps != null && MyItemInfo.Steps.Count > 0 && MyItemInfo.Steps[0].MyContent.Type == MyItemInfo.MyContent.Type) return 0; + if (MyItemInfo.MyParent.NextItem != null && MyItemInfo.MyParent.NextItem.MyContent.Type == MyItemInfo.MyContent.Type) return 0; + } } if (MyItemInfo.Ordinal % everyNLines == 0 || MyItemInfo.NextItem == null) return SixLinesPerInch; // Pagination issue to be used with yEndsWithBlankLine in Pagination code, but not checked in yet. @@ -4844,11 +4905,11 @@ namespace Volian.Print.Library XOffset += mycolT; // adjust caution/note text position if (PartsLeft != null && PartsLeft.Count > 0)// adjust tab position { - if (myTab != null && (itemInfo.IsNote || itemInfo.IsCaution)) + if(myTab!=null && (itemInfo.IsNote || itemInfo.IsCaution)) Width -= myTab.Width; foreach (vlnPrintObject vpo in PartsLeft) vpo.XOffset += mycolT; - } + } } else if (itemInfo.IsSection) { @@ -4885,10 +4946,10 @@ namespace Volian.Print.Library } else if (itemInfo.MyParent.IsCaution || itemInfo.MyParent.IsNote) { - if (itemInfo.ActiveFormat.MyStepSectionLayoutData.DevNoteOrCautionTabOffset != null) + if(itemInfo.ActiveFormat.MyStepSectionLayoutData.DevNoteOrCautionTabOffset != null) Width = MyParent.MyParent.Width - tabWidth + (myTab == null ? 0 : myTab.TabAlign); else - Width = MyParent.Width - tabWidth + (myTab == null ? 0 : myTab.TabAlign); + Width = MyParent.Width - tabWidth + (myTab == null ? 0 : myTab.TabAlign); Width -= 72 * (itemInfo.FormatStepData.CautionOrNoteSubstepIndent == null ? 0 : (float)itemInfo.FormatStepData.CautionOrNoteSubstepIndent / (float)itemInfo.FormatStepData.Font.CPI); } else @@ -4901,7 +4962,7 @@ namespace Volian.Print.Library else if (MyParent.WidthNoLimit != 0) Width = adjwidth + MyParent.WidthNoLimit - tabWidth + (myTab == null ? 0 : myTab.TabAlign); else if ((itemInfo.MyDocStyle.StructureStyle.Style & E_DocStructStyle.DSS_PageListSpBckgrnd) == E_DocStructStyle.DSS_PageListSpBckgrnd) - Width = adjwidth + MyParent.Width - (MyTab != null ? MyTab.Width : 0); + Width = adjwidth + MyParent.Width - (MyTab!=null?MyTab.Width:0); else Width = adjwidth + MyParent.Width - tabWidth + (myTab == null ? 0 : myTab.TabAlign); }