Print Library, Svg Library, Utils Library, XYPlots
This commit is contained in:
@@ -1,18 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.pdf;
|
||||
using iTextSharp.text.factories;
|
||||
using Itenso.Rtf;
|
||||
using Itenso.Rtf.Parser;
|
||||
using Itenso.Rtf.Interpreter;
|
||||
//using Itenso.Rtf.Model;
|
||||
using Itenso.Rtf.Support;
|
||||
using Microsoft.Win32;
|
||||
using Volian.Base.Library;
|
||||
using System.Text.RegularExpressions;
|
||||
using VEPROMS.CSLA.Library;
|
||||
using System.Linq;
|
||||
|
||||
namespace Volian.Print.Library
|
||||
{
|
||||
@@ -21,17 +16,13 @@ namespace Volian.Print.Library
|
||||
public static bool CompressSub = false;
|
||||
public static bool CompressSuper = false;
|
||||
public static bool CompressPropSubSup = false;
|
||||
private static System.Drawing.Color _TextColor = System.Drawing.Color.Empty;
|
||||
public static System.Drawing.Color TextColor
|
||||
|
||||
public static System.Drawing.Color TextColor { get; set; } = System.Drawing.Color.Empty;
|
||||
public static System.Drawing.Color OverrideTextColor(System.Drawing.Color color)
|
||||
{
|
||||
get { return _TextColor; }
|
||||
set { _TextColor = value; }
|
||||
}
|
||||
public static System.Drawing.Color OverrideTextColor(System.Drawing.Color color)
|
||||
{
|
||||
if (_TextColor == System.Drawing.Color.Empty)
|
||||
if (TextColor == System.Drawing.Color.Empty)
|
||||
return color;
|
||||
return _TextColor;
|
||||
return TextColor;
|
||||
}
|
||||
private static System.Drawing.Color _SvgColor = System.Drawing.Color.Empty;
|
||||
public static System.Drawing.Color SvgColor
|
||||
@@ -45,29 +36,21 @@ namespace Volian.Print.Library
|
||||
return color;
|
||||
return _SvgColor;
|
||||
}
|
||||
private static System.Drawing.Color _BoxColor = System.Drawing.Color.Empty;
|
||||
public static System.Drawing.Color BoxColor
|
||||
|
||||
public static System.Drawing.Color BoxColor { get; set; } = System.Drawing.Color.Empty;
|
||||
public static System.Drawing.Color OverrideBoxColor(System.Drawing.Color color)
|
||||
{
|
||||
get { return _BoxColor; }
|
||||
set { _BoxColor = value; }
|
||||
}
|
||||
public static System.Drawing.Color OverrideBoxColor(System.Drawing.Color color)
|
||||
{
|
||||
if (_BoxColor == System.Drawing.Color.Empty)
|
||||
if (BoxColor == System.Drawing.Color.Empty)
|
||||
return color;
|
||||
return _BoxColor;
|
||||
return BoxColor;
|
||||
}
|
||||
private static System.Drawing.Color _ChangeBarColor = System.Drawing.Color.Empty;
|
||||
public static System.Drawing.Color ChangeBarColor
|
||||
|
||||
public static System.Drawing.Color ChangeBarColor { get; set; } = System.Drawing.Color.Empty;
|
||||
public static System.Drawing.Color OverrideChangeBarColor(System.Drawing.Color color)
|
||||
{
|
||||
get { return _ChangeBarColor; }
|
||||
set { _ChangeBarColor = value; }
|
||||
}
|
||||
public static System.Drawing.Color OverrideChangeBarColor(System.Drawing.Color color)
|
||||
{
|
||||
if (_ChangeBarColor == System.Drawing.Color.Empty)
|
||||
if (ChangeBarColor == System.Drawing.Color.Empty)
|
||||
return color;
|
||||
return _ChangeBarColor;
|
||||
return ChangeBarColor;
|
||||
}
|
||||
private static System.Drawing.Color _DebugColor = System.Drawing.Color.Empty;
|
||||
public static System.Drawing.Color DebugColor
|
||||
@@ -93,43 +76,17 @@ namespace Volian.Print.Library
|
||||
public class Rtf2iTextSharp : RtfVisualVisitorBase
|
||||
{
|
||||
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
private bool _HasIndent = false;
|
||||
public bool HasIndent
|
||||
{
|
||||
get { return _HasIndent; }
|
||||
set { _HasIndent = value; }
|
||||
}
|
||||
private IRtfDocument _RtfDoc;
|
||||
private Paragraph _MyParagraph = new Paragraph();
|
||||
|
||||
public bool HasIndent { get; set; } = false;
|
||||
private readonly IRtfDocument _RtfDoc;
|
||||
private readonly Paragraph _MyParagraph = new Paragraph();
|
||||
private iTextSharp.text.Font _MyFont;
|
||||
|
||||
// Allow for definition of a default font: if the font is not proportional, this gets set.
|
||||
// It is needed to set the chunk's font if the first character of a cell is a hardspace (or various
|
||||
// other special cases (see its use below). Without this, pdfs were using the Helvetica font,
|
||||
// which is a default itextsharp font (this was causing a problem for HLP, their pdfs could not
|
||||
// contain a Helvetica font when putting them in their production environment).
|
||||
private iTextSharp.text.Font _DefaultFont;
|
||||
public iTextSharp.text.Font DefaultFont
|
||||
{
|
||||
get { return _DefaultFont; }
|
||||
set { _DefaultFont = value; }
|
||||
}
|
||||
private string _MyDebugID = null;
|
||||
public string MyDebugID
|
||||
{
|
||||
get { return _MyDebugID; }
|
||||
set { _MyDebugID = value; }
|
||||
}
|
||||
public bool DoPdfLinks = false;
|
||||
// public Rtf2iTextSharp(IRtfDocument rtfDoc, Document doc, PdfWriter writer)
|
||||
public Rtf2iTextSharp(IRtfDocument rtfDoc)
|
||||
{
|
||||
if (rtfDoc == null)
|
||||
throw new ArgumentNullException("rtfDoc");
|
||||
|
||||
_RtfDoc = rtfDoc;
|
||||
}
|
||||
public Paragraph Convert()
|
||||
public iTextSharp.text.Font DefaultFont { get; set; }
|
||||
public string MyDebugID { get; set; } = null;
|
||||
public bool DoPdfLinks = false;
|
||||
public Rtf2iTextSharp(IRtfDocument rtfDoc) => _RtfDoc = rtfDoc ?? throw new ArgumentNullException("rtfDoc");
|
||||
public Paragraph Convert()
|
||||
{
|
||||
int profileDepth = ProfileTimer.Push(">>>> Rtf2ITextSharp.Convert");
|
||||
_MyParagraph.Clear();
|
||||
@@ -138,7 +95,6 @@ namespace Volian.Print.Library
|
||||
{
|
||||
visual.Visit(this);
|
||||
}
|
||||
//_MyParagraph.SetLeading(0, 1);
|
||||
ProfileTimer.Pop(profileDepth);
|
||||
return _MyParagraph;
|
||||
}
|
||||
@@ -177,6 +133,7 @@ namespace Volian.Print.Library
|
||||
_lastWasLineBreak = 0; // B2017-191 reset hard return count
|
||||
break;
|
||||
}
|
||||
//For Debugging:
|
||||
//_MyParagraph.Add(string.Format("<{0}>", visualBreak.BreakKind.ToString()));
|
||||
}
|
||||
private void AddChunk(string str, iTextSharp.text.Font font)
|
||||
@@ -188,8 +145,9 @@ namespace Volian.Print.Library
|
||||
}
|
||||
protected override void DoVisitSpecial(IRtfVisualSpecialChar visualSpecialChar)
|
||||
{
|
||||
//_MyParagraph.Add(string.Format("<special {0}>", visualSpecialChar.CharKind.ToString()));
|
||||
iTextSharp.text.Font activeFont = _MyFont ?? DefaultFont;
|
||||
//For Debugging:
|
||||
//_MyParagraph.Add(string.Format("<special {0}>", visualSpecialChar.CharKind.ToString()));
|
||||
iTextSharp.text.Font activeFont = _MyFont ?? DefaultFont;
|
||||
switch (visualSpecialChar.CharKind)
|
||||
{
|
||||
case RtfVisualSpecialCharKind.Bullet:
|
||||
@@ -248,23 +206,15 @@ namespace Volian.Print.Library
|
||||
if (c <= '\x7F') return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//For Debugging:
|
||||
private bool ContainsAnySymbols(string p)
|
||||
{
|
||||
foreach (char c in p)
|
||||
if (c > '\x7F' && c != '\xA0' && c != '\xB0') return true;
|
||||
return false;
|
||||
}
|
||||
// The funcction below was used for the first few lines of DoVisitText which have been commented-out
|
||||
//private object FixText(string str)
|
||||
//{
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// foreach (char c in str)
|
||||
// if (c < ' ' || c > '\xFF')
|
||||
// sb.Append(string.Format("[{0}]", (int)c));
|
||||
// else
|
||||
// sb.Append(c);
|
||||
// return sb.ToString();
|
||||
//}
|
||||
|
||||
// ParseLink & GetDefaultItemInfo (which used to be in vlnParagraph) support coding that was added to DoVisitText for
|
||||
// doing pdflink for each transition/ro in a step, see bug B2019-052
|
||||
private RoUsageInfo _Roui = null;
|
||||
@@ -278,8 +228,9 @@ namespace Volian.Print.Library
|
||||
if (_LinkInfoText.Contains(@"\v"))
|
||||
throw new Exception("LinkText.ParseLink found RTF token");
|
||||
Match m = Regex.Match(_LinkInfoText, @"[#]Link:([A-Za-z]*):(.*)");
|
||||
string _MyValue = m.Groups[1].Value;
|
||||
string _MyLink = "#Link:" + m.Groups[2].Value + ":" + m.Groups[3].Value;
|
||||
//For Debugging:
|
||||
//string _MyValue = m.Groups[1].Value;
|
||||
//string _MyLink = "#Link:" + m.Groups[2].Value + ":" + m.Groups[3].Value;
|
||||
switch (m.Groups[1].Value)
|
||||
{
|
||||
case "ReferencedObject":
|
||||
@@ -319,7 +270,7 @@ namespace Volian.Print.Library
|
||||
if (myItemInfo.IsProcedure && myItemInfo.Sections != null)
|
||||
{
|
||||
SectionInfo siProcedureSteps = null;
|
||||
foreach (SectionInfo si in myItemInfo.Sections)
|
||||
foreach (SectionInfo si in myItemInfo.Sections.OfType<SectionInfo>())
|
||||
{
|
||||
if (si.IsDefaultSection)
|
||||
{
|
||||
@@ -347,7 +298,7 @@ namespace Volian.Print.Library
|
||||
private static int chkStart = -1;
|
||||
protected override void DoVisitText(IRtfVisualText visualText)
|
||||
{
|
||||
//Code to find text (non-symbol) being output with a symbol font
|
||||
//Debugging Code to find text (non-symbol) being output with a symbol font
|
||||
//if(visualText.Format.Font.Name=="VESymbFix" && visualText.Text.Length > 1)
|
||||
//{
|
||||
// string s = visualText.Text;
|
||||
@@ -375,44 +326,43 @@ namespace Volian.Print.Library
|
||||
{
|
||||
try
|
||||
{
|
||||
Chunk chk = _MyParagraph.Chunks[i] as Chunk;
|
||||
if (chk != null)
|
||||
{
|
||||
if (_linkType == 2 && _Ti != null) // transition
|
||||
{
|
||||
ItemInfo tiDefault = GetDefaultItemInfo(_Ti.MyItemToID);
|
||||
ItemInfo from = _Ti.MyContent.ContentItems[0];
|
||||
if (_Ti.MyItemToID.MyProcedure.ItemID == from.MyProcedure.ItemID &&
|
||||
!((from.ActiveSection.MyConfig as SectionConfig).Section_IsFoldout == "Y")) //C2019-042 Section_IsFoldout checks Section Number, Section Title, and use of check box
|
||||
{ // Local Go To
|
||||
// B2020-028, 029 and 030: all were related to print of supplemental information when printing with
|
||||
// pdf links. The pdf links in the temporary supinfo pdf caused a crash on save of file because they didn't exist.
|
||||
if (_Ti.MyItemToID.MyContent.Type > 9999 && !from.IsInSupInfo) // internal to this file
|
||||
{
|
||||
chk.SetLocalGoto(string.Format("ItemID={0}", tiDefault.ItemID));
|
||||
chk.SetBackground(Color.CYAN);
|
||||
chk.SetBackground(new Color(System.Drawing.Color.LightCyan));
|
||||
}
|
||||
}
|
||||
else if (_Ti != null && !from.IsInSupInfo) // Remote Go To. Added SupInfo check for B2020 bugs (see above)
|
||||
{
|
||||
// C2024-009 add PDF file prefix and suffix if available to the PDF file name in the transition reference.
|
||||
DocVersionConfig dvc = _Ti.MyItemToID.MyProcedure.MyDocVersion.DocVersionConfig;
|
||||
string remotePDFName = dvc.Print_PDFFilePrefix + _Ti.MyItemToID.MyProcedure.DisplayNumber.Replace("/", "_") + dvc.Print_PDFFileSuffix + ".pdf";
|
||||
chk.SetRemoteGoto(remotePDFName, string.Format("ItemID={0}", tiDefault.ItemID));
|
||||
chk.SetBackground(new Color(System.Drawing.Color.PeachPuff));
|
||||
}
|
||||
}
|
||||
else if (_linkType == 1 && _Roui != null && !_Roui.MyContent.ContentItems[0].IsInSupInfo) // referenced object. Added SupInfo check for B2020 bugs (see above)
|
||||
{
|
||||
if (_Roui.ROID.Substring(0, 4) != "FFFF")
|
||||
{
|
||||
chk.SetRemoteGoto("completeroreport.pdf", string.Format("ROID={0}", _Roui.ROID.Substring(0, 12).ToUpper()));
|
||||
chk.SetBackground(new Color(System.Drawing.Color.LightGreen));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_MyParagraph.Chunks[i] is Chunk chk)
|
||||
{
|
||||
if (_linkType == 2 && _Ti != null) // transition
|
||||
{
|
||||
ItemInfo tiDefault = GetDefaultItemInfo(_Ti.MyItemToID);
|
||||
ItemInfo from = _Ti.MyContent.ContentItems[0];
|
||||
if (_Ti.MyItemToID.MyProcedure.ItemID == from.MyProcedure.ItemID &&
|
||||
!((from.ActiveSection.MyConfig as SectionConfig).Section_IsFoldout == "Y")) //C2019-042 Section_IsFoldout checks Section Number, Section Title, and use of check box
|
||||
{ // Local Go To
|
||||
// B2020-028, 029 and 030: all were related to print of supplemental information when printing with
|
||||
// pdf links. The pdf links in the temporary supinfo pdf caused a crash on save of file because they didn't exist.
|
||||
if (_Ti.MyItemToID.MyContent.Type > 9999 && !from.IsInSupInfo) // internal to this file
|
||||
{
|
||||
chk.SetLocalGoto(string.Format("ItemID={0}", tiDefault.ItemID));
|
||||
chk.SetBackground(Color.CYAN);
|
||||
chk.SetBackground(new Color(System.Drawing.Color.LightCyan));
|
||||
}
|
||||
}
|
||||
else if (_Ti != null && !from.IsInSupInfo) // Remote Go To. Added SupInfo check for B2020 bugs (see above)
|
||||
{
|
||||
// C2024-009 add PDF file prefix and suffix if available to the PDF file name in the transition reference.
|
||||
DocVersionConfig dvc = _Ti.MyItemToID.MyProcedure.MyDocVersion.DocVersionConfig;
|
||||
string remotePDFName = $"{dvc.Print_PDFFilePrefix}{_Ti.MyItemToID.MyProcedure.DisplayNumber.Replace("/", "_")}{dvc.Print_PDFFileSuffix}.pdf";
|
||||
chk.SetRemoteGoto(remotePDFName, string.Format("ItemID={0}", tiDefault.ItemID));
|
||||
chk.SetBackground(new Color(System.Drawing.Color.PeachPuff));
|
||||
}
|
||||
}
|
||||
else if (_linkType == 1 && _Roui != null && !_Roui.MyContent.ContentItems[0].IsInSupInfo) // referenced object. Added SupInfo check for B2020 bugs (see above)
|
||||
{
|
||||
if (_Roui.ROID.Substring(0, 4) != "FFFF")
|
||||
{
|
||||
chk.SetRemoteGoto("completeroreport.pdf", string.Format("ROID={0}", _Roui.ROID.Substring(0, 12).ToUpper()));
|
||||
chk.SetBackground(new Color(System.Drawing.Color.LightGreen));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_MyLog.ErrorFormat("Error creating pdf links {0}", ex.Message);
|
||||
@@ -630,6 +580,7 @@ namespace Volian.Print.Library
|
||||
}
|
||||
}
|
||||
|
||||
//For Debugging:
|
||||
private string ShowSpecialCharacters(string p)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@@ -642,31 +593,23 @@ namespace Volian.Print.Library
|
||||
sb.Append(c);
|
||||
}
|
||||
return sb.ToString();
|
||||
}// DoVisitText
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
protected override void DoVisitImage(IRtfVisualImage visualImage)
|
||||
{
|
||||
//_MyParagraph.Add(new Chunk("<Image>"));
|
||||
//DateTime dt1 = DateTime.Now;
|
||||
//System.Drawing.Image img2 = visualImage.ImageForDrawing;
|
||||
//Console.WriteLine("1 Time Span {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - dt1.Ticks).TotalMilliseconds);
|
||||
//img2.Save(@"c:\datacvrt\x.png");
|
||||
System.IO.MemoryStream ms = new System.IO.MemoryStream();
|
||||
{
|
||||
|
||||
//Console.WriteLine("2 Time Span {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - dt1.Ticks).TotalMilliseconds);
|
||||
//Console.WriteLine("Size {0}", visualImage.ImageForDrawing.Size);
|
||||
visualImage.ImageForDrawing.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||
//Console.WriteLine("3 Time Span {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - dt1.Ticks).TotalMilliseconds);
|
||||
ms.Seek(0, System.IO.SeekOrigin.Begin);
|
||||
//Console.WriteLine("4 Time Span {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - dt1.Ticks).TotalMilliseconds);
|
||||
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(ms);
|
||||
//Console.WriteLine("5 Time Span {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - dt1.Ticks).TotalMilliseconds);
|
||||
_MyParagraph.Add(img);
|
||||
//Console.WriteLine("6 Time Span {0}", TimeSpan.FromTicks(DateTime.Now.Ticks - dt1.Ticks).TotalMilliseconds);
|
||||
_lastWasLineBreak = 0; // B2017-191 reset hard return count
|
||||
} // DoVisitImage
|
||||
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
|
||||
{
|
||||
visualImage.ImageForDrawing.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||
ms.Seek(0, System.IO.SeekOrigin.Begin);
|
||||
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(ms);
|
||||
_MyParagraph.Add(img);
|
||||
}
|
||||
|
||||
}
|
||||
_lastWasLineBreak = 0; // B2017-191 reset hard return count
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user