C2021-004 logic to print shaded table cells

This commit is contained in:
John Jenko 2021-11-18 19:41:00 +00:00
parent 5118268906
commit 96fd567d92

View File

@ -120,6 +120,13 @@ namespace Volian.Print.Library
get { return _MyBorders; } get { return _MyBorders; }
set { _MyBorders = value; } set { _MyBorders = value; }
} }
// C2021-004 Table cell shading
private VlnGridCellShading _MyShading;
public VlnGridCellShading MyShading
{
get { return _MyShading; }
set { _MyShading = value; }
}
private iTextSharp.text.pdf.PdfContentByte _MyContentByte; private iTextSharp.text.pdf.PdfContentByte _MyContentByte;
public iTextSharp.text.pdf.PdfContentByte MyContentByte public iTextSharp.text.pdf.PdfContentByte MyContentByte
{ {
@ -403,6 +410,7 @@ public string Path
SetupCells(); SetupCells();
foreach(vlnCell cell in this) foreach(vlnCell cell in this)
{ {
myTable.MyShading = VlnGridCellShading.Get(myFlexGrid.MyShading.ConvertToString()); // C2021-004 Table Cell Shading
myTable.MyBorders = VlnBorders.Get(myFlexGrid.MyBorders.ConvertToString()); myTable.MyBorders = VlnBorders.Get(myFlexGrid.MyBorders.ConvertToString());
GridLinePattern glp = cell.AboveLeftSide; GridLinePattern glp = cell.AboveLeftSide;
glp = cell.AboveRightSide; glp = cell.AboveRightSide;
@ -1114,6 +1122,10 @@ public string Path
get { return _HContent; } get { return _HContent; }
set { _HContent = value; } set { _HContent = value; }
} }
public VlnGridCellShading MyShading
{
get { return _MyTable.MyShading; }
}
#endregion #endregion
#region Line Pattern Diagram #region Line Pattern Diagram
/* /*
@ -1441,8 +1453,8 @@ public string Path
if (Rtf2Pdf.GetTableScrunchingStatus(TableScrunching.Phase6))// RHM20150525 - Table Scrunc if (Rtf2Pdf.GetTableScrunchingStatus(TableScrunching.Phase6))// RHM20150525 - Table Scrunc
{ {
h = YAdjust_h + mult * MyTable.RowTop[r2 + 1] - y; h = YAdjust_h + mult * MyTable.RowTop[r2 + 1] - y;
} }
ShadingToPdf(myColumnText, left, top, x, w, y, h); // C2021-004 Table Cell Shading
BordersToPdf(myColumnText, left, top, x, w, y, h ); BordersToPdf(myColumnText, left, top, x, w, y, h );
float hAdjust = VeritcalTextAlignment(h,_MyPageHelper.YMultiplier); float hAdjust = VeritcalTextAlignment(h,_MyPageHelper.YMultiplier);
iTextSharp.text.pdf.ColumnText myColumnText1 = new iTextSharp.text.pdf.ColumnText(myColumnText.Canvas); iTextSharp.text.pdf.ColumnText myColumnText1 = new iTextSharp.text.pdf.ColumnText(myColumnText.Canvas);
@ -1606,9 +1618,6 @@ public string Path
float yTop = top - y + YOffset; float yTop = top - y + YOffset;
float xRight = left + x + w + XOffset; float xRight = left + x + w + XOffset;
float yBottom = top - y - h + YOffset; float yBottom = top - y - h + YOffset;
// PIP TESTING SHADING CELLS
//FillRectangle(cb, xLeft, xRight, yTop-2, yBottom, Color.GREEN, Color.MAGENTA);
// ZoomToCell(myColumnText, xLeft, yTop, xRight, yBottom); // ZoomToCell(myColumnText, xLeft, yTop, xRight, yBottom);
// Draw Top Side for the first row // Draw Top Side for the first row
if (r1 == 0) if (r1 == 0)
@ -1621,26 +1630,30 @@ public string Path
// Draw Right Side // Draw Right Side
DrawLineVertical(cb, "Right", xRight, yBottom, yTop, RightSide, RightOfBottomSide, BottomSide, BelowRightSide, TopSide, RightOfTopSide, AboveRightSide); DrawLineVertical(cb, "Right", xRight, yBottom, yTop, RightSide, RightOfBottomSide, BottomSide, BelowRightSide, TopSide, RightOfTopSide, AboveRightSide);
cb.RestoreState(); cb.RestoreState();
}
// PIP TESTING SHADING CELLS // C2021-004 Set the cell background shading color
//FillRectangle(cb, xLeft, xRight, yTop, yBottom, Color.GREEN, Color.MAGENTA); private void ShadingToPdf(iTextSharp.text.pdf.ColumnText myColumnText, float left, float top, float x, float w, float y, float h)
{
PdfContentByte cb = myColumnText.Canvas;
cb.SaveState();// Save state before shading
float xLeft = left + x + XOffset;
float yTop = top - y + YOffset;
float xRight = left + x + w + XOffset;
float yBottom = top - y - h + YOffset;
//Console.WriteLine("Color {0}", MyShading.TableShadingInfo[r1, c1]);
FillRectangle(cb, xLeft, xRight, yTop, yBottom, new Color(MyShading.GetColor(r1, c1)), new Color(MyShading.GetColor(r1, c1)));
cb.RestoreState();
} }
// PIP TESTING SHADING CELLS // PIP TESTING SHADING CELLS
private void FillRectangle(PdfContentByte cb, float xLeft, float xRight, float yTop, float yBottom, Color FillColor, Color OutlineColor) private void FillRectangle(PdfContentByte cb, float xLeft, float xRight, float yTop, float yBottom, Color FillColor, Color OutlineColor)
{ {
cb.SaveState(); cb.SaveState();
//bool fill = FillColor != System.Drawing.Color.Transparent; cb.SetColorFill(FillColor);
//bool stroke = OutlineWidth.Value != 0F && OutlineColor != System.Drawing.Color.Empty; cb.SetLineWidth(.5f);
//if (fill) cb.SetColorStroke(OutlineColor);
cb.SetColorFill(FillColor); cb.RoundRectangle(xLeft, yBottom, xRight-xLeft, yTop-yBottom, .005F);
//if (stroke) cb.Fill();
//{
cb.SetLineWidth(.5f);//scale.M(OutlineWidth));
cb.SetColorStroke(OutlineColor);
//}
cb.RoundRectangle(xLeft, yBottom, xRight-xLeft, yTop-yBottom, .005F);
cb.Fill();//.FillStroke();
cb.RestoreState(); cb.RestoreState();
} }