Print Library, Svg Library, Utils Library, XYPlots

This commit is contained in:
2026-07-24 13:36:46 -04:00
parent 06c3136566
commit f67d37801a
68 changed files with 12173 additions and 16618 deletions
+150 -583
View File
@@ -2,12 +2,8 @@ using System;
using System.Collections.Generic;
using System.Text;
using C1.Win.C1FlexGrid;
using System.IO;
using Itenso.Rtf;
using Itenso.Rtf.Parser;
using Itenso.Rtf.Interpreter;
using Itenso.Rtf.Support;
using Volian.Print.Library;
using Volian.Controls.Library;
using iTextSharp.text;
using iTextSharp.text.pdf;
@@ -19,139 +15,37 @@ namespace Volian.Print.Library
#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 string DebugInfo { get; set; } = null;
public int ItemID { get; set; } = 0;
public bool ShowDetails { get; set; } = false;
public bool IsTooBig { get; set; } = false;
}
public partial class vlnCell
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
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 bool ShowDetails => MyTable.ShowDetails;
private static readonly float YAdjust_h = 0;
}
#endregion
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
{
get { return _HContents; }
set { _HContents = value; }
}
private float[] _RowTop;
public float[] RowTop
{
get { return _RowTop; }
set { _RowTop = value; }
}
private float[] _ColLeft;
public float[] ColLeft
{
get { return _ColLeft; }
set { _ColLeft = value; }
}
private VlnFlexGrid _MyFlexGrid;
public VlnFlexGrid MyFlexGrid
{
get { return _MyFlexGrid; }
set { _MyFlexGrid = value; }
}
private VlnBorders _MyBorders;
public VlnBorders MyBorders
{
get { return _MyBorders; }
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;
public iTextSharp.text.pdf.PdfContentByte MyContentByte
{
get { return _MyContentByte; }
set { _MyContentByte = value; }
}
private vlnCells _MyCells;
public vlnCells MyCells
{
get { return _MyCells; }
set { _MyCells = value; }
}
public float Height
{ get
{
return RowTop[RowTop.Length - 1];
} }
public float Width
{ get
{
return ColLeft[ColLeft.Length - 1];
} }
#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
public float[] HContents { get; set; }
public float[] RowTop { get; set; }
public float[] ColLeft { get; set; }
public VlnFlexGrid MyFlexGrid { get; set; }
public VlnBorders MyBorders { get; set; }
public VlnGridCellShading MyShading { get; set; }
public iTextSharp.text.pdf.PdfContentByte MyContentByte { get; set; }
public vlnCells MyCells { get; set; }
public float Height => RowTop[RowTop.Length - 1];
public float Width => ColLeft[ColLeft.Length - 1];
private static float _XOffset = -1; // This moves the borders with respect to the text
private static float _XOffset = -1; // This moves the borders with respect to the text
public static float XOffset
{
get { return vlnTable._XOffset; }
@@ -186,7 +80,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,29 +93,28 @@ namespace Volian.Print.Library
return _TotalContentHeight;
}
}
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:
{
// 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
// 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)
public float SpaceAvailable => TotalContentHeight == 0 ? 0 : RowTop[RowTop.Length - 1] - TotalContentHeight;
// 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.
public float LeadingSpaceAvailable => 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
{
get { return _TooBig; }
set
{
_TooBig = value;
//Debugging
//_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] );
@@ -252,21 +145,10 @@ namespace Volian.Print.Library
//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
public float Adjustment { get; set; } = 0;
public float YAdjust_RowTop => 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)
@@ -290,8 +172,8 @@ namespace Volian.Print.Library
cb.LineTo(x, y);
cb.Stroke();
}
i = 0;
cb.Stroke();
cb.Stroke();
cb.RestoreState();
cb.EndLayer();
}
@@ -320,17 +202,12 @@ namespace Volian.Print.Library
0, myItemInfo.ItemID, myItemInfo.FormatStepType, myItemInfo.FormatStepData == null ? "NoStepData" : myItemInfo.FormatStepData.Type,
myItemInfo.StepLevel, myItemInfo.ShortPath, Width, XOffset, YOffset);
}
#endregion
private string _Path;
#endregion
public string Path
{
get { return _Path; }
set { _Path = value; }
}
public string Path { get; set; }
#region Constructors
public vlnTable(VlnFlexGrid myFlexGrid, iTextSharp.text.pdf.PdfContentByte myContentByte)
#region Constructors
public vlnTable(VlnFlexGrid myFlexGrid, iTextSharp.text.pdf.PdfContentByte myContentByte)
{
MyFlexGrid = myFlexGrid;
MyContentByte = myContentByte;
@@ -374,7 +251,7 @@ public string Path
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
PdfLayer textLayer = myPageHelper?.TextLayer; // RHM20150429 - Table Scrunch
if (textLayer != null) cb.BeginLayer(textLayer);
myPageHelper.AddGap(top, top - Height, left, left + Width);
MyCells.ToPdf(myColumnText, left, top);
@@ -383,6 +260,7 @@ public string Path
ShowRowTops("ToPDF2");
if (ShowDetails) Console.WriteLine("^^^^^^ToPdf============{0}===============", ItemID);
}
//For Debugging
private void ZoomGrid(iTextSharp.text.pdf.ColumnText myColumnText, float left, float top)
{
PdfDestination dest = new PdfDestination(PdfDestination.FITR, left - 4, top - Height - 4, left + Width, top + 4);
@@ -394,58 +272,29 @@ public string Path
{
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Properties
private VlnFlexGrid _MyFlexGrid;
public VlnFlexGrid MyFlexGrid
{
get { return _MyFlexGrid; }
set { _MyFlexGrid = value; }
}
private vlnTable _MyTable;
public vlnTable MyTable
{
get { return _MyTable; }
set { _MyTable = value; }
}
public bool ShowDetails// RHM20150525 - Table Scrunc
#endregion
#region Properties
public VlnFlexGrid MyFlexGrid { get; set; }
public vlnTable MyTable { get; set; }
public bool ShowDetails// RHM20150525 - Table Scrunc
{ get { return MyTable.ShowDetails; }}
private iTextSharp.text.pdf.PdfContentByte _MyContentByte;
public iTextSharp.text.pdf.PdfContentByte MyContentByte
{
get { return _MyContentByte; }
set { _MyContentByte = value; }
}
#endregion
#region Constructors
public vlnCells(vlnTable myTable, VlnFlexGrid myFlexGrid, iTextSharp.text.pdf.PdfContentByte myContentByte)
public iTextSharp.text.pdf.PdfContentByte MyContentByte { get; set; }
#endregion
#region Constructors
public vlnCells(vlnTable myTable, VlnFlexGrid myFlexGrid, iTextSharp.text.pdf.PdfContentByte myContentByte)
{
MyTable = myTable;
MyFlexGrid = myFlexGrid;
MyContentByte = myContentByte;
SetupCells();
foreach(vlnCell cell in this)
{
myTable.MyShading = VlnGridCellShading.Get(myFlexGrid.MyShading.ConvertToString()); // C2021-004 Table Cell Shading
myTable.MyBorders = VlnBorders.Get(myFlexGrid.MyBorders.ConvertToString());
GridLinePattern glp = cell.AboveLeftSide;
glp = cell.AboveRightSide;
glp = cell.BelowLeftSide;
glp = cell.BelowRightSide;
glp = cell.RightOfBottomSide;
glp = cell.RightOfTopSide;
object ta = cell.TextAlign;
}
myTable.MyShading = VlnGridCellShading.Get(myFlexGrid.MyShading.ConvertToString()); // C2021-004 Table Cell Shading
myTable.MyBorders = VlnBorders.Get(myFlexGrid.MyBorders.ConvertToString());
}
#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()
#endregion
public float MyLeading { get; set; } = 13.5F;
#region Private Methods
private void SetupCells()
{
// Create a ColumnText to determine the cell heights
iTextSharp.text.pdf.ColumnText myColumnText1 = new iTextSharp.text.pdf.ColumnText(MyContentByte);
@@ -526,9 +375,9 @@ public string Path
TrimNewlines(myPara); // RHM20150429 - Table Scrunch
myColumnText1.AddElement(myPara);
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; // position is y of top of paragraph since paragraph was just added
_ = 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 hContent = 4 + posBefore - posAfter;
// TableScrunch Phase 4: sets content height, uses the size derived from iTextsharp putting out text
@@ -566,6 +415,7 @@ public string Path
}
}
}
//For Debugging:
// This summarizes the Content heights per row
//int i=0;
//foreach (float h in MyTable.HContents)
@@ -580,41 +430,6 @@ public string Path
return total;
}
// B2017-105 if a symbol character was set to a bigger font size, then the positioning of the larger symbol character was printing too high on the line
// found with Wolf Creek use of the empty box symbol
//private float BiggestFontSize(Paragraph myPara)
//{
// float fontSize = 12;
// foreach (Chunk ck in myPara.Chunks)
// {
// fontSize = Math.Max(fontSize, ck.Font.Size);
// if (ck.Font.Size > 12)
// {
// ck.SetTextRise(-2f);
// //_MyLog.WarnFormat("set text rise");
// }
// }
// return fontSize;
//}
// B2017-233, B2017-234 needed to get the smallest font size to help decide if a vertical adjustment of the text is needed in a table cell
//private float SmallestFontSize(Paragraph myPara)
//{
// float fontSize = 30;
// foreach (Chunk ck in myPara.Chunks)
// {
// fontSize = Math.Min(fontSize, ck.Font.Size);
// }
// return fontSize;
//}
//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();
@@ -625,44 +440,25 @@ public string Path
else
sb.Append(c);
}
return "{" + sb.ToString() + "}";
return $"{{{sb}}}";
}
private void TrimNewlines(Paragraph myPara)
{
while (myPara.Count > 0 && ParaEndsWithNewLine(myPara))
myPara.RemoveAt(myPara.Count - 1);
}
private bool ParaEndsWithNewLine(Paragraph myPara)
{
Chunk chk = myPara[myPara.Count - 1] as Chunk;
if (chk == null) return false;
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)
{
return (cc[current] == ' ');
}
public bool IsSplitCharacter(char c)
{
return (c == ' ');
}
}
public static VlnSplitCharacter mySplitter = new VlnSplitCharacter();
internal static void FixHyphens(Paragraph myPara, vlnTable myTable)
private bool ParaEndsWithNewLine(Paragraph myPara) => myPara[myPara.Count - 1] is Chunk chk && chk.Content == "\n";
internal static void FixHyphens(Paragraph myPara, vlnTable myTable)
{
// Find chunk with hardhyphen
// If a hard hyphen is found, the remove it and add a dash (keyboard minus sign) to the beginning
// of the text that follows it.
int hype=-1;
Font fnt = null;
while ((hype = GetHyphen(myPara)) > -1)
while ((hype = GetHyphen(myPara)) > -1)
{
fnt = null;
if (hype > 0)
Font fnt = null;
if (hype > 0)
{
Chunk chk1 = (Chunk)myPara[hype - 1];
if (hype > 1 && chk1.Content.Equals("\n"))
@@ -755,11 +551,10 @@ public string Path
// If a backslash symbold is found, the remove it and add a backslash (keyboard char) to the beginning
// of the text that follows it.
int bckSlsh = -1;
Font fnt = null;
while ((bckSlsh = GetBackslash(myPara)) > -1)
while ((bckSlsh = GetBackslash(myPara)) > -1)
{
fnt = null;
if (bckSlsh > 0)
Font fnt = null;
if (bckSlsh > 0)
{
Chunk chk1 = (Chunk)myPara[bckSlsh - 1];
if (bckSlsh > 1 && chk1.Content.Equals("\n"))
@@ -842,23 +637,17 @@ public string Path
public static float CalculateHangingIndent(string rtf)
{
float chkW = 0;
// **** This is intened to be a temporary fix for V.C.Summer ****
// Two procedures would not print: A-2 SAG in Summer's SAMG set, and SAG-3 in Summer's PWOG DAMG set.
// These procedures have tables with hanging indents and use the Letter Gothic Tall font.
// It appears that the font information for the hanging indent character is not included in the RTF
// for those table cells.
// This piece of code checks for the existance of a font definition of \f1 which is need for the \u9999? indent character
// If the a font definition of \f1 is not found then the indent character is removed. This will allow the procedure to print
// but the text in that table cell will not be indented. - jsj 10/10/2014
//IRtfDocument rtfDoc2 = RtfInterpreterTool.BuildDoc(rtf.Replace(@"\'05", @"\f1 \u9999? \f0 "));
IRtfDocument rtfDoc2 = null;
//if (rtf.Contains(@"\f1\fnil\fcharset0 "))
// rtfDoc2 = RtfInterpreterTool.BuildDoc(rtf.Replace(@"\'05", @"\f1 \u9999? \f0 "));
//else
//{
// first add the symbol font and then surround the indent as above.
rtfDoc2 = RtfInterpreterTool.BuildDoc(rtf.Replace(@"\'05", @"\par\u9999?\par"));
//}
// **** This is intened to be a temporary fix for V.C.Summer ****
// Two procedures would not print: A-2 SAG in Summer's SAMG set, and SAG-3 in Summer's PWOG DAMG set.
// These procedures have tables with hanging indents and use the Letter Gothic Tall font.
// It appears that the font information for the hanging indent character is not included in the RTF
// for those table cells.
// This piece of code checks for the existance of a font definition of \f1 which is need for the \u9999? indent character
// If the a font definition of \f1 is not found then the indent character is removed. This will allow the procedure to print
// but the text in that table cell will not be indented. - jsj 10/10/2014
// add the symbol font and then surround the indent.
//IRtfDocument rtfDoc2 = RtfInterpreterTool.BuildDoc(rtf.Replace(@"\'05", @"\f1 \u9999? \f0 "));
IRtfDocument rtfDoc2 = RtfInterpreterTool.BuildDoc(rtf.Replace(@"\'05", @"\par\u9999?\par"));
Rtf2iTextSharp rtf2IText2 = new Rtf2iTextSharp(rtfDoc2);
iTextSharp.text.Paragraph para2 = rtf2IText2.Convert();
@@ -883,7 +672,7 @@ public string Path
return chkW;
}
private static StepRTB _StatRTB = new StepRTB();
private static readonly StepRTB _StatRTB = new StepRTB();
private string PreProcessRTF(float w, string str)
{
_StatRTB.Text = string.Empty;
@@ -912,25 +701,7 @@ public string Path
_StatRTB.Text = str;
_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;
return _StatRTB.Rtf;
}
private iTextSharp.text.Paragraph RtfToParagraph(string rtf, iTextSharp.text.Font mySymFont,int r, int c)
{
@@ -940,10 +711,11 @@ public string Path
rtf = rtf.Replace(@"\_", "-").Replace(@"\u8209?", "-");
rtf = FixRTFToPrint(rtf, r, c);
IRtfDocument rtfDoc = RtfInterpreterTool.BuildDoc(rtf);
Rtf2iTextSharp rtf2IText = new Rtf2iTextSharp(rtfDoc);
rtf2IText.DefaultFont = mySymFont;
iTextSharp.text.Paragraph para = rtf2IText.Convert();
//para.SetLeading(MyLeading , 0);// RHM 20180607 Not Needed - performed in SetupCells
Rtf2iTextSharp rtf2IText = new Rtf2iTextSharp(rtfDoc)
{
DefaultFont = mySymFont
};
iTextSharp.text.Paragraph para = rtf2IText.Convert();
return para;
}
// The text font used in FixRTFToPrint for grid
@@ -1011,7 +783,6 @@ public string Path
// follow through in fixing an Out of Window Handles bug, use new function to see if
// we can retrieve the font from a dictionary instead a doing a New and using another
// window handle B2017-117
//rtb.SelectionFont = new System.Drawing.Font(DefaultFont, fnt.Style);
rtb.SelectionFont = VE_Font.GetWinSysFont(DefaultFont, fnt.Style);
changed = true;
}
@@ -1027,8 +798,7 @@ public string Path
{
//use bolding underline italics from local font
System.Drawing.Font fnt = rtb.SelectionFont;
//System.Drawing.Font fntw = new System.Drawing.Font((rc.Family != null) ? rc.Family : fnt.FontFamily.Name, (rc.Size != null) ? (float)rc.Size : fnt.Size, (rc.Style != null) ? (System.Drawing.FontStyle)rc.Style : fnt.Style);
System.Drawing.Font fntw = VE_Font.GetWinSysFont((rc.Family != null) ? rc.Family : fnt.FontFamily.Name, (rc.Size != null) ? (float)rc.Size : fnt.Size, (rc.Style != null) ? (System.Drawing.FontStyle)rc.Style : fnt.Style);
System.Drawing.Font fntw = VE_Font.GetWinSysFont(rc.Family ?? fnt.FontFamily.Name, (rc.Size != null) ? (float)rc.Size : fnt.Size, (rc.Style != null) ? (System.Drawing.FontStyle)rc.Style : fnt.Style);
rtb.SelectionFont = fntw;
if (rc.Replace != null)
{
@@ -1047,7 +817,6 @@ public string Path
}
return rtf;
}
private static float _SixLinesPerInch = 12; // twips
#endregion
#region Public Methods
// C2021-005 Get the largest font size being used.
@@ -1116,60 +885,20 @@ public string Path
}
public partial class vlnCell // RHM20150429 - Table Scrunch
{
#region Properties
private vlnTable _MyTable;
public vlnTable MyTable
{
get { return _MyTable; }
set { _MyTable = value; }
}
public VlnBorders MyBorders
{
get { return _MyTable.MyBorders; }
}
private int _r1;
public int r1
{
get { return _r1; }
set { _r1 = value; }
}
private int _c1;
public int c1
{
get { return _c1; }
set { _c1 = value; }
}
private int _r2;
public int r2
{
get { return _r2; }
set { _r2 = value; }
}
private int _c2;
public int c2
{
get { return _c2; }
set { _c2 = value; }
}
private iTextSharp.text.Paragraph _MyPara;
public iTextSharp.text.Paragraph MyPara
{
get { return _MyPara; }
set { _MyPara = value; }
}
private float _HContent;
public float HContent
{
get { return _HContent; }
set { _HContent = value; }
}
public VlnGridCellShading MyShading
{
get { return _MyTable.MyShading; }
}
#endregion
#region Line Pattern Diagram
/*
#region Properties
public vlnTable MyTable { get; set; }
public VlnBorders MyBorders => MyTable.MyBorders;
public int r1 { get; set; }
public int c1 { get; set; }
public int r2 { get; set; }
public int c2 { get; set; }
public iTextSharp.text.Paragraph MyPara { get; set; }
public float HContent { get; set; }
public VlnGridCellShading MyShading => MyTable.MyShading;
#endregion
#region Line Pattern Diagram
/*
The diagram below identifies the various border names for the cell in the center
|-AboveLeftSide |-AboveRightSide
@@ -1192,9 +921,9 @@ public string Path
|-BelowLeftSide |-BelowRightSide
*/
#endregion
#region Horizontal Line Patterns
private GridLinePattern _TopSide = GridLinePattern.Unknown;
#endregion
#region Horizontal Line Patterns
private GridLinePattern _TopSide = GridLinePattern.Unknown;
public GridLinePattern TopSide
{
get
@@ -1408,27 +1137,27 @@ public string Path
return _AboveLeftSide;
}
}
#endregion
#region Static Properties
private static float XOffset { get { return vlnTable.XOffset; } }
private static float YOffset { get { return vlnTable.YOffset; } }
private static float LineThicknessForThin { get { return vlnTable.LineThicknessForThin; } }
private static float LineThicknessForThick { get { return vlnTable.LineThicknessForThick; } }
private static float LineThicknessForDouble { get { return vlnTable.LineThicknessForDouble; } }
private static float DoubleLineOffset { get { return vlnTable.DoubleLineOffset; } }
#endregion
#region Static Properties
private static float XOffset => vlnTable.XOffset;
private static float YOffset => vlnTable.YOffset;
private static float LineThicknessForThin => vlnTable.LineThicknessForThin;
private static float LineThicknessForThick => vlnTable.LineThicknessForThick;
private static float LineThicknessForDouble => vlnTable.LineThicknessForDouble;
private static float DoubleLineOffset => vlnTable.DoubleLineOffset;
// adjustments for line intersections:
private static float ThickOverDouble { get { return ((2 * DoubleLineOffset) + LineThicknessForDouble - LineThicknessForThick) / 2; } }
private static float ThickUnderDouble { get { return DoubleLineOffset + (LineThicknessForThick - LineThicknessForDouble) / 2; } }
private static float ThickOverThin { get { return (LineThicknessForThin - LineThicknessForThick) / 2; } }
private static float ThinOverThick { get { return (LineThicknessForThick - LineThicknessForThin) / 2; } }
private static float ThinUnderDouble { get { return DoubleLineOffset + (LineThicknessForThin - LineThicknessForDouble) / 2; } }
private static float ThinOverDouble { get { return (DoubleLineOffset + LineThicknessForThin - LineThicknessForDouble) / 2; } }
private static float DoubleUnderThin { get { return (LineThicknessForThin - LineThicknessForDouble) / 2; } }
private static float DoubleUnderThick { get { return (LineThicknessForThick - LineThicknessForDouble) / 2; } }
#endregion
#region Constructors
public vlnCell(int r1, int c1, int r2, int c2, vlnTable myTable, iTextSharp.text.Paragraph myPara, float hContent)
// adjustments for line intersections:
private static float ThickOverDouble => ((2 * DoubleLineOffset) + LineThicknessForDouble - LineThicknessForThick) / 2;
private static float ThickUnderDouble => DoubleLineOffset + (LineThicknessForThick - LineThicknessForDouble) / 2;
private static float ThickOverThin => (LineThicknessForThin - LineThicknessForThick) / 2;
private static float ThinOverThick => (LineThicknessForThick - LineThicknessForThin) / 2;
private static float ThinUnderDouble => DoubleLineOffset + (LineThicknessForThin - LineThicknessForDouble) / 2;
private static float ThinOverDouble => (DoubleLineOffset + LineThicknessForThin - LineThicknessForDouble) / 2;
private static float DoubleUnderThin => (LineThicknessForThin - LineThicknessForDouble) / 2;
private static float DoubleUnderThick => (LineThicknessForThick - LineThicknessForDouble) / 2;
#endregion
#region Constructors
public vlnCell(int r1, int c1, int r2, int c2, vlnTable myTable, iTextSharp.text.Paragraph myPara, float hContent)
{
this.r1 = r1;
this.c1 = c1;
@@ -1438,19 +1167,14 @@ public string Path
MyPara = myPara;
HContent = hContent;
}
#endregion
#region Public Methods
public override string ToString()
{
return string.Format("{0}:{1}", r1, c1);
}
// B2018-003 - RHM 20180319 Add
public void PdfDebug(iTextSharp.text.pdf.ColumnText myColumnText, float x, float bottom, float right, float y, string debugText, float yDescent)
#endregion
#region Public Methods
public override string ToString() => string.Format("{0}:{1}", r1, c1);
public void PdfDebug(iTextSharp.text.pdf.ColumnText myColumnText, float x, float bottom, float right, float y, string debugText, float yDescent)
{
PdfContentByte cb = myColumnText.Canvas;
VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper;
PdfLayer debugLayer = _MyPageHelper == null ? null : _MyPageHelper.DebugLayer;
if (debugLayer == null) return;
PdfLayer debugLayer = !(cb.PdfWriter.PageEvent is VlnSvgPageHelper _MyPageHelper) ? null : _MyPageHelper.DebugLayer;
if (debugLayer == null) return;
System.Drawing.Color sysColor = PrintOverride.OverrideDebugColor(System.Drawing.Color.Gray);
cb.SaveState();
cb.BeginLayer(debugLayer);
@@ -1481,7 +1205,6 @@ public string Path
cb.EndLayer();
cb.RestoreState();
}
//RHM 20180319 End of Add
// B2021-137 Added doShading parameter
// We call this twice. The first time to print the shading the second time to print the borders and text
public void ToPdf(iTextSharp.text.pdf.ColumnText myColumnText, float left, float top, int topPlacementAdjust, bool doShading)
@@ -1518,7 +1241,6 @@ public string Path
// 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)
// this will have the cell text print a little more toward the top of the cell
//myColumnText1.SetSimpleColumn(1 + left + x, top - y - h, left + x + w - 2, 3 + top - y - hAdjust - adjustTextLocation); // 2 == Default Padding
// B2019-109 Adjusted width of cell to match edit cell
// B2020-034 - use the passed in topPlacementAdjust value which is set based on the font size.
myColumnText1.SetSimpleColumn(.5F + left + x, top - y - h, left + x + w - 1.5F, topPlacementAdjust + top - y - hAdjust - adjustTextLocation); // 2 == Default Padding
@@ -1566,7 +1288,6 @@ public string Path
int cellStatus = myColumnText1.Go(); // B2019-109 Add to Error Log if cell too small
if (cellStatus != 1)
{
//System.Windows.Forms.MessageBox.Show("Cell width too narrow \r\n" + MyTable.Path, "Narrow Cell", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
_MyLog.WarnFormat("\r\n=-=-=-= Cell Width too narrow, text is wrapping ItemID={0} Location={1}, Row={2}, Col={3}, Status={4}",MyTable.ItemID, MyTable.Path, r1, c1, cellStatus);
}
float posAfter = myColumnText1.YLine; // RHM20150429 - Table Scrunch
@@ -1606,7 +1327,6 @@ public string Path
}
return sb.ToString();
}
private static float _SixLinesPerInch = 12; // twips
public bool IsRangeStyleNull = false;
private TextAlignEnum? _TextAlign = null;
public TextAlignEnum? TextAlign
@@ -1635,7 +1355,6 @@ public string Path
private float VeritcalTextAlignment(float h, float mult)
{
float hAdjust = 0;
//CellRange cr = MyTable.MyFlexGrid.GetCellRange(r1, c1, r2, c2);
if (!IsRangeStyleNull)
{
switch (TextAlign)
@@ -1913,28 +1632,10 @@ public string Path
else if (linePattern == GridLinePattern.Dashed)
cb.SetLineDash(4, 4, 0);
}
private static void SetLineColor(PdfContentByte cb, int row, int col, string side)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Keeping row and col for Debugging")]
private static void SetLineColor(PdfContentByte cb, int row, int col, string side)
{
iTextSharp.text.Color lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Black));
//switch (side)
//{
// case "Top":
// if (col == 0) lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Blue));
// else lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Cyan));
// break;
// case "Left":
// if (row == 0) lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Red));
// else lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Magenta));
// break;
// case "Bottom":
// if (col == 0) lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Green));
// else lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Cyan));
// break;
// case "Right":
// if (row == 0) lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Orange));
// else lineColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Magenta));
// break;
//}
cb.SetColorStroke(lineColor);
}
private static void InitializeLineStyle(PdfContentByte cb)
@@ -1946,9 +1647,11 @@ public string Path
#region Debug Methods
private static void SetOpacity(PdfContentByte cb, float opacity)
{
PdfGState gs = new PdfGState();
gs.StrokeOpacity = opacity;
cb.SetGState(gs);
PdfGState gs = new PdfGState
{
StrokeOpacity = opacity
};
cb.SetGState(gs);
}
private static void ZoomToCell(iTextSharp.text.pdf.ColumnText myColumnText, float xLeft, float yTop, float xRight, float yBottom)
{
@@ -1956,141 +1659,5 @@ public string Path
myColumnText.Canvas.SetAction(PdfAction.GotoLocalPage(myColumnText.Canvas.PdfWriter.CurrentPageNumber, dest, myColumnText.Canvas.PdfWriter), xLeft, yBottom, xRight, yTop);
}
#endregion
#region Old Border Methods
//private void DrawLeftLine(PdfContentByte cb, float xLeft, float yTop, float yBottom)
//{
// if (c1 == 0 && LineLeft != GridLinePattern.None)
// {
// InitializeLineStyle(cb);
// SetLineColor(cb, r1, c1, "Left");
// if (LineLeft == GridLinePattern.Double)
// {
// //Left Line
// float dyTop = DoubleIntersectionLeft(LineTopLeft, LineTop, LineLeftAbove);
// float dyBottom = -DoubleIntersectionRight(LineBottom, LineBottomLeft, LineLeftBelow);
// DrawLine(cb, LineThicknessForDouble, xLeft - DoubleLineOffset, yTop + dyTop, xLeft - DoubleLineOffset, yBottom + dyBottom);
// //Right Line
// dyTop = DoubleIntersectionRight(LineTopLeft, LineTop, LineLeftAbove);
// dyBottom = -DoubleIntersectionLeft(LineBottom, LineBottomLeft, LineLeftBelow);
// DrawLine(cb, LineThicknessForDouble, xLeft + DoubleLineOffset, yTop + dyTop, xLeft + DoubleLineOffset, yBottom + dyBottom);
// }
// else if (LineLeft != GridLinePattern.Thick)
// {
// SetLinePattern(cb, LineLeft);
// float dyTop = ThinIntersection(LineTopLeft, LineTop, LineLeftAbove);
// float dyBottom = -ThinIntersection(LineBottom, LineBottomLeft, LineLeftBelow);
// DrawLine(cb, LineThicknessForThin, xLeft, yTop + dyTop, xLeft, yBottom + dyBottom);
// }
// else
// {
// float dyTop = ThickIntersection(LineTopLeft, LineTop, LineLeftAbove);
// float dyBottom = -ThickIntersection(LineBottom, LineBottomLeft, LineLeftBelow);
// DrawLine(cb, LineThicknessForThick, xLeft, yTop + dyTop, xLeft, yBottom + dyBottom);
// }
// cb.Stroke();
// }
//}
//private void DrawRightLine(PdfContentByte cb, float xRight, float yTop, float yBottom)
//{
// if (LineRight != GridLinePattern.None)
// {
// InitializeLineStyle(cb);
// SetLineColor(cb, r1, c1, "Right");
// if (LineRight == GridLinePattern.Double)
// {
// //Left Line
// float dyTop = DoubleIntersectionLeft(LineTop, LineTopRight, LineRightAbove);
// float dyBottom = -DoubleIntersectionRight(LineBottomRight, LineBottom, LineRightBelow);
// DrawLine(cb, LineThicknessForDouble, xRight - DoubleLineOffset, yTop + dyTop, xRight - DoubleLineOffset, yBottom + dyBottom);
// //Right Line
// dyTop = DoubleIntersectionRight(LineTop, LineTopRight, LineRightAbove);
// dyBottom = -DoubleIntersectionLeft(LineBottomRight, LineBottom, LineRightBelow);
// DrawLine(cb, LineThicknessForDouble, xRight + DoubleLineOffset, yTop + dyTop, xRight + DoubleLineOffset, yBottom + dyBottom);
// }
// else if (LineRight != GridLinePattern.Thick)
// {
// float dyTop = ThinIntersection(LineTop, LineTopRight, LineRightAbove);
// float dyBottom = -ThinIntersection(LineBottomRight, LineBottom, LineRightBelow);
// SetLinePattern(cb, LineRight);
// DrawLine(cb, LineThicknessForThin, xRight, yTop + dyTop, xRight, yBottom + dyBottom);
// }
// else
// {
// float dyTop = ThickIntersection(LineTop, LineTopRight, LineRightAbove);
// float dyBottom = -ThickIntersection(LineBottomRight, LineBottom, LineRightBelow);
// DrawLine(cb, LineThicknessForThick, xRight, yTop + dyTop, xRight, yBottom + dyBottom);
// }
// cb.Stroke();
// }
//}
//private void DrawTopLine(PdfContentByte cb, float xLeft, float xRight, float yTop)
//{
// if (r1 == 0 && TopSide != GridLinePattern.None)
// {
// InitializeLineStyle(cb);
// SetLineColor(cb, r1, c1, "Top");
// if (TopSide == GridLinePattern.Double)
// {
// // Top Line
// float dxLeft = -DoubleIntersectionRight(LeftSide, AboveLeftSide, LeftOfTopSide);
// float dxRight = DoubleIntersectionLeft(AboveRightSide, RightSide, RightOfTopSide);
// DrawLine(cb, LineThicknessForDouble, xLeft + dxLeft, yTop + DoubleLineOffset, xRight + dxRight, yTop + DoubleLineOffset);
// // Bottom Line
// dxLeft = -DoubleIntersectionLeft(LeftSide, AboveLeftSide, LeftOfTopSide);
// dxRight = DoubleIntersectionRight(AboveRightSide, RightSide, RightOfTopSide);
// DrawLine(cb, LineThicknessForDouble, xLeft + dxLeft, yTop - DoubleLineOffset, xRight + dxRight, yTop - DoubleLineOffset);
// }
// else if (TopSide != GridLinePattern.Thick)
// {
// SetLinePattern(cb, TopSide);
// float dxLeft = -ThinIntersection(LeftSide, AboveLeftSide, LeftOfTopSide);
// float dxRight = ThinIntersection(AboveRightSide, RightSide, RightOfTopSide);
// DrawLine(cb, LineThicknessForThin, xLeft + dxLeft, yTop, xRight + dxRight, yTop);
// }
// else
// {
// float dxLeft = -ThickIntersection(LeftSide, AboveLeftSide, LeftOfTopSide);
// float dxRight = ThickIntersection(AboveRightSide, RightSide, RightOfTopSide);
// if (c1 == 0)
// Console.WriteLine("'{0}','{1}','{2}',{3},{4}", LeftSide, AboveLeftSide, LeftOfTopSide, dxLeft, ThickOverThin);
// DrawLine(cb, LineThicknessForThick, xLeft + dxLeft, yTop, xRight + dxRight, yTop);
// }
// cb.Stroke();
// }
//}
//private void DrawBottomLine(PdfContentByte cb, float xLeft, float xRight, float yBottom)
//{
// if (BottomSide != GridLinePattern.None)
// {
// InitializeLineStyle(cb);
// SetLineColor(cb, r1, c1, "Bottom");
// if (BottomSide == GridLinePattern.Double)
// {
// // Top Line
// float dxLeft = -DoubleIntersectionRight(BelowLeftSide, LeftSide, LeftOfBottomSide);
// float dxRight = DoubleIntersectionLeft(RightSide, BelowRightSide, RightOfBottomSide);
// DrawLine(cb, LineThicknessForDouble, xLeft + dxLeft, yBottom + DoubleLineOffset, xRight + dxRight, yBottom + DoubleLineOffset);// Top Line
// // Bottom Line
// dxLeft = -DoubleIntersectionLeft(BelowLeftSide, LeftSide, LeftOfBottomSide);
// dxRight = DoubleIntersectionRight(RightSide, BelowRightSide, RightOfBottomSide);
// DrawLine(cb, LineThicknessForDouble, xLeft + dxLeft, yBottom - DoubleLineOffset, xRight + dxRight, yBottom - DoubleLineOffset);//Bottom Line
// }
// else if (BottomSide != GridLinePattern.Thick) // Bottom line is thin. Determine if intersecting with double:
// {
// SetLinePattern(cb, BottomSide);
// float dxLeft = -ThinIntersection(BelowLeftSide, LeftSide, LeftOfBottomSide);
// float dxRight = ThinIntersection(RightSide, BelowRightSide, RightOfBottomSide);
// DrawLine(cb, LineThicknessForThin, xLeft + dxLeft, yBottom, xRight + dxRight, yBottom);
// }
// else
// {
// float dxLeft = -ThickIntersection(BelowLeftSide, LeftSide, LeftOfBottomSide);
// float dxRight = ThickIntersection(RightSide, BelowRightSide, RightOfBottomSide);
// DrawLine(cb, LineThicknessForThick, xLeft + dxLeft, yBottom, xRight + dxRight, yBottom);
// }
// cb.Stroke();
// }
//}
#endregion
}
}