From 72b5b45ad2e303e02c1bfbb166df4e07b88d2798 Mon Sep 17 00:00:00 2001 From: Rich Date: Fri, 8 Jun 2018 17:55:42 +0000 Subject: [PATCH] B2018-085 -Table Scrunching Change - Make line-spacing match edit window more closely. Also, allow line-spacing to be adjusted to fit table on the current page if possible and if it is the last table of a step. --- PROMS/Volian.Print.Library/Grid2Pdf.cs | 50 +++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/PROMS/Volian.Print.Library/Grid2Pdf.cs b/PROMS/Volian.Print.Library/Grid2Pdf.cs index b79e3618..46c874f8 100644 --- a/PROMS/Volian.Print.Library/Grid2Pdf.cs +++ b/PROMS/Volian.Print.Library/Grid2Pdf.cs @@ -190,6 +190,10 @@ namespace Volian.Print.Library { get { return TotalContentHeight ==0 ? 0 : RowTop[RowTop.Length - 1] - TotalContentHeight; } } + public float LeadingSpaceAvailable// B2018-085 - Table Scrunch Fix + { + get { return TotalContentHeight == 0 ? 0 : TotalContentHeight * 1.5F/13.5F; } + } private float _TooBig;// RHM20150525 - Table Scrunc public float TooBig { @@ -200,9 +204,25 @@ namespace Volian.Print.Library //_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; + float extra = (_TooBig < SpaceAvailable) ? (SpaceAvailable - _TooBig) / HContents.Length : 0; + // B2018-085 Table Scrunch - Adjust Line Spacing + float leadingAdjust = 1.0F; + if (extra == 0) + { + // See if we can adjust Leading + float newLeading = Math.Max(12.0F, 13.5F - (_TooBig - SpaceAvailable) / LeadingSpaceAvailable); + leadingAdjust = newLeading / MyCells.MyLeading; + MyCells.MyLeading = newLeading; + foreach (vlnCell myCell in MyCells) + { + myCell.MyPara.SetLeading(MyCells.MyLeading, 0); + } + } for (int r = 0; r < RowTop.Length - 1; r++) + { + HContents[r] *= leadingAdjust; RowTop[r + 1] = RowTop[r] + HContents[r] + extra; + } //if(ShowDetails) Console.WriteLine("After RowTop={0}", RowTop[RowTop.Length-1] ); } } @@ -381,6 +401,12 @@ namespace Volian.Print.Library } } #endregion + private float _MyLeading=13.5F; // B2018-085 AEP and APP worked with 13.5 + public float MyLeading + { + get { return _MyLeading; } + set { _MyLeading = value; } + } #region Private Methods private void SetupCells() { @@ -415,7 +441,6 @@ namespace Volian.Print.Library DisplayText dt = new DisplayText(MyFlexGrid.GetMyItemInfo(), str, false); str = dt.StartText; str = PreProcessRTF(w, str); - // If the font is not proportional, pass the symbol font through to RtfToParagraph. It is needed // in underlying code to set the chunk's font if the first character of a cell is a hardspace. Without // this, pdfs were using the Helvetica font, which is a default itextsharp font. @@ -451,7 +476,7 @@ namespace Volian.Print.Library } // RHM 20120925 - Line spacing should be 6 lines per inch. // B2018-003 Change code to use absolute Leading rather than Multiplied based on Font size - myPara.SetLeading(12F, 0); + myPara.SetLeading(MyLeading, 0); 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. @@ -806,6 +831,23 @@ namespace Volian.Print.Library _StatRTB.SelectAll(); _StatRTB.SelectionColor = PrintOverride.OverrideTextColor(System.Drawing.Color.Black); str = _StatRTB.Rtf; + // RHM 20180607 The following lines calculated line spacing but it did not give consistent values + //System.Drawing.Point location0 = _StatRTB.GetPositionFromCharIndex(0); + //int ii = 1; + //System.Drawing.Point locnext = location0; + //while (ii < 1000 && (locnext = _StatRTB.GetPositionFromCharIndex(ii)).Y == location0.Y) + // ii++; + //if (ii < 1000) + //{ + // myLeading = (locnext.Y - location0.Y) * 72.0F / 96.0F; + // Console.WriteLine("{0} - {1}", _StatRTB.Font, myLeading); + //} + //else + // myLeading = 12.0F; + // myLeading = 13.5F; // RHM 20180607 This worked for AEP + // RHM 20180607 The following did not work + //RTBAPI.ParaFormatTwo pft = RTBAPI.GetParaFormat(_StatRTB); + //myLeading = Math.Max(12.0F, pft.dyLineSpacing); return str; } private iTextSharp.text.Paragraph RtfToParagraph(string rtf, iTextSharp.text.Font mySymFont,int r, int c) @@ -815,7 +857,7 @@ namespace Volian.Print.Library Rtf2iTextSharp rtf2IText = new Rtf2iTextSharp(rtfDoc); rtf2IText.DefaultFont = mySymFont; iTextSharp.text.Paragraph para = rtf2IText.Convert(); - para.SetLeading(_SixLinesPerInch , 0); + //para.SetLeading(MyLeading , 0);// RHM 20180607 Not Needed - performed in SetupCells return para; } // The text font used in FixRTFToPrint for grid