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
+81 -115
View File
@@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Text;
using System.Drawing;
using iTextSharp.text.pdf;
using iTextSharp.text;
using VEPROMS.CSLA.Library;
@@ -12,23 +11,11 @@ namespace Volian.Print.Library
public partial class vlnBox : vlnPrintObject
{
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private int _LineType; /* how to represent?? */
private System.Drawing.Color _Color;
public System.Drawing.Color Color
{
get { return _Color; }
set { _Color = value; }
}
private Box _MyBox;
public Box MyBox
{
get { return _MyBox; }
set { _MyBox = value; }
}
// the following two fields are used if 'boxed' step, thus
// no 'Box' was defined in format file.
public override float Height
public Box MyBox { get; set; }
// the following two fields are used if 'boxed' step, thus
// no 'Box' was defined in format file.
public override float Height
{
get
{
@@ -41,26 +28,13 @@ namespace Volian.Print.Library
public string DefBox = null;
public float DefEnd = 0;
private bool _ContainsPageBreak = false;
public bool ContainsPageBreak
{
get { return _ContainsPageBreak; }
set { _ContainsPageBreak = value; }
}
private bool _DoubleBoxHls = false; // BGE double lined box around HLS
public bool DoubleBoxHls
{
get { return _DoubleBoxHls; }
set { _DoubleBoxHls = value; }
}
public const string DOUBLEboxHLS = "DoubleBox";
public bool ContainsPageBreak { get; set; } = false;
public bool DoubleBoxHls { get; set; } = false;
public const string DOUBLEboxHLS = "DoubleBox";
//private bool _DoBottom = true;
public vlnBox()
{
}
public vlnBox(vlnParagraph paragraph)
{
}
public const string BoxThin = "\x2510.\x2500.\x250c.\x2502. . .\x2518.\x2514. .\x2500. . ";
const string BoxThick = "\x2584.\x2584.\x2584.\x2588. . .\x2580.\x2580. .\x2580. . ";
const string BoxDouble = "\x2557.\x2550.\x2554.\x2551. . .\x255D.\x255A. .\x2550. . ";
@@ -95,10 +69,9 @@ namespace Volian.Print.Library
if (MyBox == null) return yPageStart;
cb.SaveState();
VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper;
PdfLayer textLayer = _MyPageHelper == null ? null : _MyPageHelper.TextLayer;
PdfLayer textLayer = _MyPageHelper?.TextLayer;
if (textLayer != null) cb.BeginLayer(textLayer);
MyContentByte = cb;
//Console.WriteLine("'{0}','{1}'", CharToAsc(MyBox.BoxStyle), MyParent.MyItemInfo.ShortPath);
float top = CalculateYOffset(yPageStart, yTopMargin) - (7*MyPageHelper.YMultiplier);
float bottom = top - (Height * MyPageHelper.YMultiplier);
float left = (float)((MyBox.Start ?? 0) + MyParent.MyItemInfo.MyDocStyle.Layout.LeftMargin);
@@ -157,7 +130,7 @@ namespace Volian.Print.Library
else
{
const float llxOffset = 3;
float lineThickness = 0;
float lineThickness;
switch (MyBox.BoxStyle)
{
case BoxThin:
@@ -331,23 +304,23 @@ namespace Volian.Print.Library
// create a new font without any styles such as underline.
E_Style es = ((vef.Style & E_Style.Bold) == E_Style.Bold) ? E_Style.Bold : E_Style.None;
// if the box has a font, use it - otherwise use this item info's font
VE_Font vf = null;
bool UseBoxFont = false;
try
bool UseBoxFont = false;
try
{
UseBoxFont = MyParent.MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.StepSectionPrintData.DiffContActBox;
}
catch // done this way in case one of the format properties is null in the previous statement, UseBoxFont will be false.
{
}
if (UseBoxFont)
vf = new VE_Font(vef.Family, (int)vef.Size, es, (float)MyParent.MyItemInfo.FormatStepData.Font.CPI);
else
vf = new VE_Font(MyParent.MyItemInfo.FormatStepData.Font.Family, (int)MyParent.MyItemInfo.FormatStepData.Font.Size, es, (float)MyParent.MyItemInfo.FormatStepData.Font.CPI);
// if the box has a font, use it - otherwise use this item info's font
VE_Font vf;
if (UseBoxFont)
vf = new VE_Font(vef.Family, (int)vef.Size, es, (float)MyParent.MyItemInfo.FormatStepData.Font.CPI);
else
vf = new VE_Font(MyParent.MyItemInfo.FormatStepData.Font.Family, (int)MyParent.MyItemInfo.FormatStepData.Font.Size, es, (float)MyParent.MyItemInfo.FormatStepData.Font.CPI);
// To find the length of the line, account for the length of the upper right corner also (BXURC)
int urcLen = MyBox.BXHorz[MyBox.BXHorz.Length - 1] == ' ' && MyBox.BXURC[0] == ' ' ? 1 : MyBox.BXURC.Length;
// To find the length of the line, account for the length of the upper right corner also (BXURC)
int urcLen = MyBox.BXHorz[MyBox.BXHorz.Length - 1] == ' ' && MyBox.BXURC[0] == ' ' ? 1 : MyBox.BXURC.Length;
float endHorz = (float)MyBox.End - (float)MyBox.Start - (float)(urcLen * (72 / vf.CPI));
float bxHorzTextWidth = GetTextWidth(vf, MyBox.BXHorz); // get the width of the BXHorz string
@@ -355,21 +328,21 @@ namespace Volian.Print.Library
StringBuilder sb = new StringBuilder();
sb.Append(MyBox.BXULC);
float size = GetTextWidth(vf, MyBox.BXULC); //(float)(MyBox.BXULC.Length * (72 / vf.CPI));
string bxstr = null;
if (!ContainsPageBreak) // Only do top line if there is no page break.
string bxstr;
if (!ContainsPageBreak) // Only do top line if there is no page break.
{
while (size < endHorz)
{
sb.Append(MyBox.BXHorz);
size = size + bxHorzTextWidth; //(float)(MyBox.BXHorz.Length * (72 / vf.CPI));
size += bxHorzTextWidth; //(float)(MyBox.BXHorz.Length * (72 / vf.CPI));
}
// Tack on the right upper corner. For some formats, the upper right corner in the
// had the first character as a space, this would put two spaces in a row at the
// end of the string, so remove the space before tacking on the upper right corner:
bxstr = sb.ToString();
if (bxstr[bxstr.Length - 1] == ' ' && MyBox.BXURC[0] == ' ') bxstr = bxstr.TrimEnd();
bxstr = bxstr + MyBox.BXURC;
size = size + GetTextWidth(vf, MyBox.BXURC);//(float)((MyBox.BXURC.Length) * (72 / vf.CPI));
bxstr += MyBox.BXURC;
size += GetTextWidth(vf, MyBox.BXURC);//(float)((MyBox.BXURC.Length) * (72 / vf.CPI));
Rtf = GetRtf(bxstr, vf);
IParagraph = null; // set to null so that next access of IParagraph sets the Rtf.
Rtf2Pdf.TextAt(cb, IParagraph, left, top, size + 10, 100, "", yBottomMargin);
@@ -384,15 +357,15 @@ namespace Volian.Print.Library
while (size < endHorz)
{
sb.Append(MyBox.BXHorz);
size = size + bxHorzTextWidth;//(float)(MyBox.BXHorz.Length * (72 / vf.CPI));
size += bxHorzTextWidth;//(float)(MyBox.BXHorz.Length * (72 / vf.CPI));
}
bxstr = sb.ToString().TrimEnd() + MyBox.BXLRC;
size = size + GetTextWidth(vf, MyBox.BXLRC); //(float)((MyBox.BXLRC.Length) * (72 / vf.CPI));
size += GetTextWidth(vf, MyBox.BXLRC); //(float)((MyBox.BXLRC.Length) * (72 / vf.CPI));
Rtf = GetRtf(bxstr, vf);
IParagraph = null; // set to null so that next access of IParagraph sets the Rtf.
Rtf2Pdf.TextAt(cb, IParagraph, left, bottom, size + 10, 100, "", yBottomMargin);
}
private string symblsStr = "\u25CF\u0394"; // string of possible symbol character in a tab
private readonly string symblsStr = "\u25CF\u0394"; // string of possible symbol character in a tab
// add symbol characters as needed
// "\u25CF" - solid bullet
// \x0394 - delta
@@ -409,8 +382,6 @@ namespace Volian.Print.Library
// 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
//System.Drawing.Font font = new System.Drawing.Font(vefont.Family, (float)vefont.Size, GetSysFontStyle(vefont));
//System.Drawing.Font symbFont = new System.Drawing.Font(symblFontName, (float)vefont.Size);
System.Drawing.Font font = VE_Font.GetWinSysFont(vefont.Family, (float)vefont.Size, GetSysFontStyle(vefont));
System.Drawing.Font symbFont = VE_Font.GetWinSysFont(symblFontName, (float)vefont.Size);
iTextSharp.text.Font iFont = Volian.Svg.Library.VolianPdf.GetFont(font);
@@ -424,10 +395,10 @@ namespace Volian.Print.Library
else
w += iFont.BaseFont.GetWidthPointKerned(c.ToString(), (float)vefont.Size);
}
//float w = iFont.BaseFont.GetWidthPointKerned(Text.Replace("\u25CF","@"), (float)vefont.Size);
return w;
}
private void DrawAsteriskSide(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin, float top, float bottom, float left, float right, VE_Font vef)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "top and bottom kept for debugging")]
private void DrawAsteriskSide(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin, float top, float bottom, float left, float right, VE_Font vef)
{
// set the top & bottom of sides. If there is a page break in the middle of box, adjust these.
// The vlnBox property, ContainsPageBreak, flags that a break occurred.
@@ -453,23 +424,23 @@ namespace Volian.Print.Library
// create a new font without any styles such as underline.
E_Style es = ((vef.Style & E_Style.Bold) == E_Style.Bold) ? E_Style.Bold : E_Style.None;
// if the box has a font, use it - otherwise use this item info's font
VE_Font vf = null;
bool UseBoxFont = false;
try
bool UseBoxFont = false;
try
{
UseBoxFont = MyParent.MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.StepSectionPrintData.DiffContActBox;
}
catch // done this way in case one of the format properties is null in the previous statement, UseBoxFont will be false.
{
}
if (UseBoxFont)
vf = new VE_Font(vef.Family, (int)vef.Size, es, (float)MyParent.MyItemInfo.FormatStepData.Font.CPI);
else
vf = new VE_Font(MyParent.MyItemInfo.FormatStepData.Font.Family, (int)MyParent.MyItemInfo.FormatStepData.Font.Size, es, (float)MyParent.MyItemInfo.FormatStepData.Font.CPI);
// if the box has a font, use it - otherwise use this item info's font
VE_Font vf;
if (UseBoxFont)
vf = new VE_Font(vef.Family, (int)vef.Size, es, (float)MyParent.MyItemInfo.FormatStepData.Font.CPI);
else
vf = new VE_Font(MyParent.MyItemInfo.FormatStepData.Font.Family, (int)MyParent.MyItemInfo.FormatStepData.Font.Size, es, (float)MyParent.MyItemInfo.FormatStepData.Font.CPI);
// Left side first:
Rtf = GetRtf(MyBox.BXVert, vf);
// Left side first:
Rtf = GetRtf(MyBox.BXVert, vf);
IParagraph = null; // set to null so that next access of IParagraph sets the Rtf.
// start down one line because the top/bottom code draws the corner
float vertDiff = top - (SixLinesPerInch * MyPageHelper.YMultiplier);
@@ -503,17 +474,8 @@ namespace Volian.Print.Library
}
return sb.ToString();
}
private static List<string> _UnimplementedBoxStyles = new List<string>();
private string CharToAsc(string p)
{
StringBuilder sb = new StringBuilder();
foreach (char c in p)
{
if (c >= ' ' && c < 127) sb.Append(c);
else sb.Append(string.Format("\\x{0:x}", (int)c));
}
return sb.ToString();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static List<string> _UnimplementedBoxStyles = new List<string>();
private void DrawAsteriskTopBottomHLS(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin, ref float top, ref float bottom, float left, VE_Font vef)
{
// this box is not drawn, it is a series of asterisks drawn above and below text.
@@ -527,45 +489,45 @@ namespace Volian.Print.Library
bottom = ytmpbottom1;
// create a new font without any styles such as underline.
E_Style es = ((vef.Style & E_Style.Bold) == E_Style.Bold) ? E_Style.Bold : E_Style.None;
// if the box has a font, use it - otherwise use this item info's font
VE_Font vf = null;
bool UseBoxFont = false;
try
bool UseBoxFont = false;
try
{
UseBoxFont = MyParent.MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.StepSectionPrintData.DiffContActBox;
}
catch // done this way in case one of the format properties is null in the previous statement, UseBoxFont will be false.
{
}
if (UseBoxFont)
vf = new VE_Font(vef.Family, (int)vef.Size, es, (float)MyParent.MyItemInfo.FormatStepData.Font.CPI);
else
vf = new VE_Font(MyParent.MyItemInfo.FormatStepData.Font.Family, (int)MyParent.MyItemInfo.FormatStepData.Font.Size, es, (float)MyParent.MyItemInfo.FormatStepData.Font.CPI);
// if the box has a font, use it - otherwise use this item info's font
VE_Font vf;
if (UseBoxFont)
vf = new VE_Font(vef.Family, (int)vef.Size, es, (float)MyParent.MyItemInfo.FormatStepData.Font.CPI);
else
vf = new VE_Font(MyParent.MyItemInfo.FormatStepData.Font.Family, (int)MyParent.MyItemInfo.FormatStepData.Font.Size, es, (float)MyParent.MyItemInfo.FormatStepData.Font.CPI);
// To find the length of the line, account for the length of the upper right corner also (BXURC)
int urcLen = MyBox.BXHorz[MyBox.BXHorz.Length - 1] == ' ' && MyBox.BXURC[0] == ' ' ? 1 : MyBox.BXURC.Length;
// To find the length of the line, account for the length of the upper right corner also (BXURC)
int urcLen = MyBox.BXHorz[MyBox.BXHorz.Length - 1] == ' ' && MyBox.BXURC[0] == ' ' ? 1 : MyBox.BXURC.Length;
float endHorz = (float)MyBox.End - (float)MyBox.Start - (float)(urcLen * (72 / vf.CPI));
float bxHorzTextWidth = GetTextWidth(vf, MyBox.BXHorz); // get the width of the BXHorz string
// Do the top line first:
StringBuilder sb = new StringBuilder();
sb.Append(MyBox.BXULC);
float size = GetTextWidth(vf, MyBox.BXULC); //(float)(MyBox.BXULC.Length * (72 / vf.CPI));
string bxstr = null;
if (!ContainsPageBreak) // Only do top line if there is no page break.
float size = GetTextWidth(vf, MyBox.BXULC);
string bxstr;
if (!ContainsPageBreak) // Only do top line if there is no page break.
{
while (size < endHorz)
{
sb.Append(MyBox.BXHorz);
size = size + bxHorzTextWidth; //(float)(MyBox.BXHorz.Length * (72 / vf.CPI));
size += bxHorzTextWidth;
}
// Tack on the right upper corner. For some formats, the upper right corner in the
// had the first character as a space, this would put two spaces in a row at the
// end of the string, so remove the space before tacking on the upper right corner:
bxstr = sb.ToString();
if (bxstr[bxstr.Length - 1] == ' ' && MyBox.BXURC[0] == ' ') bxstr = bxstr.TrimEnd();
bxstr = bxstr + MyBox.BXURC;
size = size + GetTextWidth(vf, MyBox.BXURC);//(float)((MyBox.BXURC.Length) * (72 / vf.CPI));
bxstr += MyBox.BXURC;
size += GetTextWidth(vf, MyBox.BXURC);//(float)((MyBox.BXURC.Length) * (72 / vf.CPI));
Rtf = GetRtf(bxstr, vf);
IParagraph = null; // set to null so that next access of IParagraph sets the Rtf.
Rtf2Pdf.TextAt(cb, IParagraph, left, top, size + 10, 100, "", yBottomMargin);
@@ -576,24 +538,25 @@ namespace Volian.Print.Library
sb.Remove(0, sb.Length);
sb.Append(MyBox.BXLLC);
size = GetTextWidth(vf, MyBox.BXLLC); //(float)(MyBox.BXLLC.Length * (72 / vf.CPI));
size = GetTextWidth(vf, MyBox.BXLLC);
while (size < endHorz)
{
sb.Append(MyBox.BXHorz);
size = size + bxHorzTextWidth;//(float)(MyBox.BXHorz.Length * (72 / vf.CPI));
size += bxHorzTextWidth;
}
bxstr = sb.ToString().TrimEnd() + MyBox.BXLRC;
size = size + GetTextWidth(vf, MyBox.BXLRC); //(float)((MyBox.BXLRC.Length) * (72 / vf.CPI));
size += GetTextWidth(vf, MyBox.BXLRC);
Rtf = GetRtf(bxstr, vf);
IParagraph = null; // set to null so that next access of IParagraph sets the Rtf.
Rtf2Pdf.TextAt(cb, IParagraph, left, bottom, size + 10, 100, "", yBottomMargin);
}
private void DrawAsteriskSideHLS(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin, float top, float bottom, float left, float right, VE_Font vef)
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "top and bottom kept for debugging")]
private void DrawAsteriskSideHLS(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin, float top, float bottom, float left, float right, VE_Font vef)
{
// set the top & bottom of sides. If there is a page break in the middle of box, adjust these.
// The vlnBox property, ContainsPageBreak, flags that a break occurred.
float yOffBreak = 0;
if (!ContainsPageBreak)
// set the top & bottom of sides. If there is a page break in the middle of box, adjust these.
// The vlnBox property, ContainsPageBreak, flags that a break occurred.
float yOffBreak;
if (!ContainsPageBreak)
{
top = CalculateYOffset(yPageStart, yTopMargin);
if (MyPageHelper.YMultiplier != 1) top += 2;
@@ -613,8 +576,11 @@ namespace Volian.Print.Library
}
else
{
top = CalculateYOffset(yPageStart, yTopMargin);
yOffBreak = MyPageHelper.ParaBreaks.Count > 0 ? MyPageHelper.ParaBreaks[0].YOffset : 0;
#pragma warning disable IDE0059 // Unnecessary assignment of a value - Keeping top for Debugging
top = CalculateYOffset(yPageStart, yTopMargin);
#pragma warning restore IDE0059 // Unnecessary assignment of a value
yOffBreak = MyPageHelper.ParaBreaks.Count > 0 ? MyPageHelper.ParaBreaks[0].YOffset : 0;
if (yOffBreak > 0)
bottom = (yPageStart - yOffBreak) * MyPageHelper.YMultiplier;
else
@@ -636,23 +602,23 @@ namespace Volian.Print.Library
// create a new font without any styles such as underline.
E_Style es = ((vef.Style & E_Style.Bold) == E_Style.Bold) ? E_Style.Bold : E_Style.None;
// if the box has a font, use it - otherwise use this item info's font
VE_Font vf = null;
bool UseBoxFont = false;
try
bool UseBoxFont = false;
try
{
UseBoxFont = MyParent.MyItemInfo.ActiveFormat.PlantFormat.FormatData.SectData.StepSectionData.StepSectionPrintData.DiffContActBox;
}
catch // done this way in case one of the format properties is null in the previous statement, UseBoxFont will be false.
{
}
if (UseBoxFont)
vf = new VE_Font(vef.Family, (int)vef.Size, es, (float)MyParent.MyItemInfo.FormatStepData.Font.CPI);
else
vf = new VE_Font(MyParent.MyItemInfo.FormatStepData.Font.Family, (int)MyParent.MyItemInfo.FormatStepData.Font.Size, es, (float)MyParent.MyItemInfo.FormatStepData.Font.CPI);
// if the box has a font, use it - otherwise use this item info's font
VE_Font vf;
if (UseBoxFont)
vf = new VE_Font(vef.Family, (int)vef.Size, es, (float)MyParent.MyItemInfo.FormatStepData.Font.CPI);
else
vf = new VE_Font(MyParent.MyItemInfo.FormatStepData.Font.Family, (int)MyParent.MyItemInfo.FormatStepData.Font.Size, es, (float)MyParent.MyItemInfo.FormatStepData.Font.CPI);
// Left side first:
Rtf = GetRtf(MyBox.BXVert, vf);
// Left side first:
Rtf = GetRtf(MyBox.BXVert, vf);
IParagraph = null; // set to null so that next access of IParagraph sets the Rtf.
// start down one line because the top/bottom code draws the corner
float vertDiff = top - (SixLinesPerInch * MyPageHelper.YMultiplier);