Internal only – commenting Table Scrunch code

This commit is contained in:
Kathy Ruffing 2022-06-29 10:28:25 +00:00
parent cac64aee18
commit 0cf054ea05
4 changed files with 71 additions and 43 deletions

View File

@ -90,6 +90,8 @@ namespace Volian.Print.Library
public partial class vlnTable
{
#region Properties
// HContents: For each row, contains the largest height for all columns in that row.
// Merged cells are accounted for. This is done in vlnCells:SetupCells
private float[] _HContents;// RHM20150525 - Table Scrunch
public float[] HContents
{
@ -185,6 +187,7 @@ namespace Volian.Print.Library
get { return (LineThicknessForThick - LineThicknessForDouble) / 2; }//LineThicknessForThick - 2 * LineThicknessForDouble; }
}
private float _TotalContentHeight = 0;// RHM20150525 - Table Scrunc
// TotalContentHeight - height of just the content of all rows in the table.
public float TotalContentHeight
{
get
@ -199,12 +202,20 @@ namespace Volian.Print.Library
}
public float SpaceAvailable// RHM20150525 - Table Scrunc
{
// SpaceAvailable is the amount of white space there is to work with. It uses the bottom location
// of the table and subtracts how much height the actual contents take, TotalContentHeight. TotalContentHeight
// includes size/height (font size - assumes 12, 6LPI) of text & leading (space between lines)
get { return TotalContentHeight ==0 ? 0 : RowTop[RowTop.Length - 1] - TotalContentHeight; }
}
public float LeadingSpaceAvailable// B2018-085 - Table Scrunch Fix
public float LeadingSpaceAvailable// B2018-085 - Table Scrunch Fix:
{
// LeadingSpaceAvailable is the amount of 'blank' space between lines, this is included in TotalContentHeight.
// 1.5 is difference between 12 and 13.5, 12 is the standard font size, i.e. 6LPI. 13.5 is line leading.
// 1.5/13.5 is amount of space used by leading.
get { return TotalContentHeight == 0 ? 0 : TotalContentHeight * 1.5F/13.5F; }
}
// TooBig is the amount that the grid is over the amount of space on the page. To start (value in TooBig), it is set to
// (height of grid w/ compressed setting if needed + line) - (how much room on page), i.e. negative number if it can fit
private float _TooBig;// RHM20150525 - Table Scrunc
public float TooBig
{
@ -215,9 +226,13 @@ 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] );
// SpaceAvailable - amount of white space that can be removed. if the amount of the table that is too big to fit
// is less than the amount of white space that can be removed, then set extra to this amount divided by the
// number of cells, otherwise it is 0.
float extra = (_TooBig < SpaceAvailable) ? (SpaceAvailable - _TooBig) / HContents.Length : 0;
// B2018-085 Table Scrunch - Adjust Line Spacing
float leadingAdjust = 1.0F;
// if removing white space doesn't make table scrunch enough, see if adjusting leading will help
if (extra == 0)
{
// See if we can adjust Leading
@ -229,6 +244,7 @@ namespace Volian.Print.Library
myCell.MyPara.SetLeading(MyCells.MyLeading, 0);
}
}
// The following resets the height of all rows in the table
for (int r = 0; r < RowTop.Length - 1; r++)
{
HContents[r] *= leadingAdjust;
@ -344,6 +360,7 @@ public string Path
#region Public Methods
public void AdjustRowTop(int row1, int row2, float hNew)
{
// shift the row top of next row down by the adjustment, i.e. if the content needs more space
float hAdjust = hNew - (RowTop[row2 + 1] - RowTop[row1]);
for (int r = row2; r < MyFlexGrid.Rows.Count; r++)
RowTop[r + 1] += hAdjust;
@ -422,7 +439,7 @@ public string Path
}
}
#endregion
private float _MyLeading=13.5F; // B2018-085 AEP and APP worked with 13.5
private float _MyLeading = 13.5F; // B2018-085 AEP and APP worked with 13.5
public float MyLeading
{
get { return _MyLeading; }
@ -433,7 +450,7 @@ public string Path
{
// Create a ColumnText to determine the cell heights
iTextSharp.text.pdf.ColumnText myColumnText1 = new iTextSharp.text.pdf.ColumnText(MyContentByte);
// Walk through
// Walk through all the rows
for (int r = 0; r < MyFlexGrid.Rows.Count; r++)
{
float hMax = 12; // RHM20150429 - Table Scrunch
@ -495,55 +512,56 @@ public string Path
myPara.IndentationLeft = li;
myPara.FirstLineIndent = fi;
}
// RHM 20120925 - Line spacing should be 6 lines per inch.
// RHM 20120925 - Line spacing should default to 6 lines per inch.
// B2018-003 Change code to use absolute Leading rather than Multiplied based on Font size
myPara.SetLeading(MyLeading, 0);
// TableScrunch Phase 2: SpacingAfter is the space after the bottom line of text.
// Setting to 0 removes blank space between bottom of text & line
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.
myPara.SpacingAfter = 0;
FixHyphens(myPara, MyTable);
FixBackslashes(myPara, MyTable);
// TableScrunch Phase 3: Remove new lines at end of text
if (Rtf2Pdf.GetTableScrunchingStatus(TableScrunching.Phase3))
TrimNewlines(myPara); // RHM20150429 - Table Scrunch
myColumnText1.AddElement(myPara);
//myColumnText1.Canvas.SetColorFill(PrintOverride.OverrideTextColor(System.Drawing.Color.Black));
// PIP TEST CODE FOR TABLE SHADING
//myColumnText1.Canvas.SetColorFill(new iTextSharp.text.Color(System.Drawing.Color.Red));
float posBefore = myColumnText1.YLine; // position is y of top of paragraph since paragraph was just added
int status = myColumnText1.Go(true); // 'puts out' text for info only
float posAfter = myColumnText1.YLine; // posAfter is y of bottom of paragraph, really y top of line below this
float posBefore = myColumnText1.YLine;
int status = myColumnText1.Go(true);
float posAfter = myColumnText1.YLine;
float hContent = 4 + posBefore - posAfter;
// TableScrunch Phase 4: sets content height, uses the size derived from iTextsharp putting out text
// y loc before text is put out - y loc after text is put out
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;
hContent = 0 + posBefore - posAfter;
}
//if(ShowDetails) Console.WriteLine("{0}\t{1}\t{2}",r,c, hContent/12);
if (cr.r1 == cr.r2)
// hMax is maximum height of row taking into account merged cells
if (cr.r1 == cr.r2) // not merged:
hMax = Math.Max(hMax, hContent);
// B2018-033 VCS SAG-6 Steps 3 and 9 and SACRG1 Step 13
// Tables not being scrunched properly
// Merged cells should be adjusted based upon the bottom most cell of the range
else if(cr.r2 == r) // Adjust for Previous rows within merged cells
hMax = Math.Max(hMax, hContent- SumContents(cr.r1,cr.r2));
//else
// hMax = Math.Max(hMax, hContent - (cr.r2 - cr.r1) * _SixLinesPerInch);
// h is row height defined in table, if height of content is > height of row, adjust.
// if the content's height is larger than the height of cell, shift row below down using AdjustRowTop.
if (hContent > h)
{ // RHM20150429 - Table Scrunch
// B2018-003 modified debug to add h
{
//if (ShowDetails) Console.WriteLine("Less {0},{1},{2},{3},{4},{5},{6}", r, c, posBefore, posAfter, h, hContent, hMax);
MyTable.AdjustRowTop(cr.r1, cr.r2, hContent);
} // RHM20150429 - Table Scrunch
}
// TableScrunch Phase 5: stores max height for row content
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);
//B2018-033 - Adjuust current row
MyTable.HContents[r] = hMax+2;
// For each row, hMax is te largest height for all columns.
MyTable.HContents[r] = hMax+2; // make contents of the row a little bigger than max (max may be for merged cells)
}
Add(new vlnCell(cr.r1, cr.c1, cr.r2, cr.c2, MyTable, myPara,hContent));
}
@ -1472,10 +1490,13 @@ public string Path
float mult = _MyPageHelper.YMultiplier;
float x = MyTable.ColLeft[c1];
float w = MyTable.ColLeft[c2 + 1] - x;
float y = mult * MyTable.RowTop[r1];
float h = mult * MyTable.RowTop[r2 + 1] - y;
float y = mult * MyTable.RowTop[r1]; // r1 - top row of cell or top of merged cells
float h = mult * MyTable.RowTop[r2 + 1] - y; // r2 - top of last merged cell. r2+1 - top row of next cell, if merging
// Phase 6 has no affect - YAdjust_h is set to 0. May have been used for testing/trying options.
if (Rtf2Pdf.GetTableScrunchingStatus(TableScrunching.Phase6))// RHM20150525 - Table Scrunc
{
// get height of row,
h = YAdjust_h + mult * MyTable.RowTop[r2 + 1] - y;
}
if (doShading)
@ -1491,7 +1512,7 @@ public string Path
if (Rtf2Pdf.GetTableScrunchingStatus(TableScrunching.Phase7))// RHM20150525 - Table Scrunc
{
adjustTextLocation = mult * 0;
if (mult != 1F) adjustTextLocation=1;
if (mult != 1F) adjustTextLocation=1; // 1 Point: move down a slight bit if printing 7LPI
}
// B2019-093 missing table cell text when printing South Texas FSG-20 step 1
// Added two more to the last parameter of SetSimplColun (it's the ury value - upper y value)
@ -1506,8 +1527,8 @@ public string Path
// Added Header to debug output
if (ShowDetails)
{
if(FirstTime)
Console.WriteLine("\"r1\"\t\"c1\"\t\"hAdjust\"\t\"adjustTextLocation\"\t\"y\"\t\"h\"\t\"top\"\t\"1 + top - y - hAdjust - adjustTextLocation\"\t\""+
if (FirstTime)
Console.WriteLine("\"r1\"\t\"c1\"\t\"hAdjust\"\t\"adjustTextLocation\"\t\"y\"\t\"h\"\t\"top\"\t\"1 + top - y - hAdjust - adjustTextLocation\"\t\"" +
"_MyPageHelper.YMultiplier\"\t\"Text\"");
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,

View File

@ -1898,6 +1898,8 @@ namespace Volian.Print.Library
vlnParagraph pLast = ChildrenBelow[ChildrenBelow.Count - 1];
btm = pLast.YBottomPagination;
}
// TableSpaceAvailable is SpaceAvailable (Amount of white space there is to work with in table) +
// LeadingSpaceAvailable (Amount of space taken up by space between lines, leading - fontsize)
if (MyGrid != null)
tsa = MyGrid.SpaceAvailable + MyGrid.LeadingSpaceAvailable;
if (btmRight != 0)

View File

@ -15,20 +15,22 @@ using VEPROMS.CSLA.Library;
namespace Volian.Print.Library
{
[Flags]
// TableScrunching is used to allow for turning off/on various parts of the table scrunch test & data manipulation
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,
AllPhases=1+2+4+8+16+32+64+128+256+512
Phase1=1, // Checks if height of table greater than what will fit on current page. (in setup)
Phase2=2, // Remove any blank space between bottom of text & line in a table cell. (in setup)
Phase3=4, // Removes new lines at end of text. (in setup)
Phase4=8, // Determines height of content, i.e. text in cell, uses leading (height of line). (in setup)
Phase5=16, // Make contents of the row a little bigger than max (max may be for merged cells). (in setup)
Phase6=32, // Has no affect - YAdjust_h is set to 0. May have been used for testing/trying options. (in ToPdf)
Phase7 =64, // Adjust y location of text: by 0 or by 1 if printing 7LPI
Phase8=128, // not used
Phase9=256, // not used
Phase10=512, // not used
AllPhases=1+2+4+8+16+32+64+128+256+512 // The default, and always used unless printing from UI list of items
}
public class Rtf2Pdf
{

View File

@ -949,9 +949,12 @@ namespace Volian.Print.Library
float ySizeBtmCtnMess = GetBottomContinueMessageSize(MyItemInfo.MyDocStyle);
// B2018-085 Ignore the bottom continue message if the Table is the last part of the step.
if(ySizeBtmCtnMess > 0 && MyParent.MyItemInfo.IsHigh && YBottomMost == MyParent.YBottomMost) ySizeBtmCtnMess = 0;
// TableScrunch Phase 1: Is height of table greater than what will fit on current page.
if (Rtf2Pdf.GetTableScrunchingStatus(TableScrunching.Phase1) && heightBefore > (yLocation - (yBottomMargin + ySizeBtmCtnMess)))
{
//MyGrid.TooBig = (MyItemInfo.MyDocStyle.Layout.FooterLength ?? 0) + SixLinesPerInch + MyGrid.Height - (yLocation - yBottomMargin);
// TooBig is the amount of height that the grid is larger than the amount of space on the page. It is set to
// (height of grid w/ compressed setting if needed + line) - (how much room on page)
// NOTE TooBig actually will do the adjustments of the row heights by eliminating the blank space!
MyGrid.TooBig = SixLinesPerInch + MyGrid.Height * MyPageHelper.YMultiplier - (yLocation - yBottomMargin - ySizeBtmCtnMess);
float heightAfter = (MyGrid.Height + 4) * MyPageHelper.YMultiplier; // B2020-014 added parenthesis was calculating wrong for 7lpi Callaway FSG-7 Attachment 7
MyPageHelper.TableAdjustment += (heightBefore - heightAfter);