Print Library, Svg Library, Utils Library, XYPlots
This commit is contained in:
@@ -1,18 +1,10 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
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.Support;
|
||||
using Microsoft.Win32;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml;
|
||||
using System.IO;
|
||||
using Volian.Base.Library;
|
||||
|
||||
@@ -97,23 +89,14 @@ namespace Volian.Svg.Library
|
||||
{
|
||||
get { return _MyText; }
|
||||
}
|
||||
private SvgText _MySvgText;
|
||||
public SvgText MySvgText
|
||||
{
|
||||
get { return _MySvgText; }
|
||||
set { _MySvgText = value; }
|
||||
}
|
||||
private SvgScale _MySvgScale;
|
||||
public SvgScale MySvgScale
|
||||
{
|
||||
get { return _MySvgScale; }
|
||||
set { _MySvgScale = value; }
|
||||
}
|
||||
public SvgProcessTextArgs(string myText, SvgText mySvgText, SvgScale mySvgScale)
|
||||
|
||||
public SvgText MySvgText { get; set; }
|
||||
public SvgScale MySvgScale { get; set; }
|
||||
public SvgProcessTextArgs(string myText, SvgText mySvgText, SvgScale mySvgScale)
|
||||
{
|
||||
_MyText = myText;
|
||||
_MySvgText = mySvgText;
|
||||
_MySvgScale = mySvgScale;
|
||||
MySvgText = mySvgText;
|
||||
MySvgScale = mySvgScale;
|
||||
}
|
||||
}
|
||||
public partial class Svg : SvgGroup
|
||||
@@ -121,7 +104,7 @@ namespace Volian.Svg.Library
|
||||
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
public void DrawMacro(string macroDef, float x, float y, PdfContentByte cb)
|
||||
{
|
||||
_MyContentByte = cb;
|
||||
MyContentByte = cb;
|
||||
SvgMeasurement X = new SvgMeasurement(x, E_MeasurementUnits.PT);
|
||||
SvgMeasurement Y = new SvgMeasurement(Height.GetSizeInPoints(72) - y, E_MeasurementUnits.PT);
|
||||
if (!this.LookUp.ContainsKey(macroDef)) return; // AEP - DU1 (missing C22 macro for AEP)
|
||||
@@ -157,45 +140,31 @@ namespace Volian.Svg.Library
|
||||
top = (yll > yul ? (yll > top ? yll : top) : (yul > top ? yul : top));
|
||||
tmp.BoundingBox = new iTextSharp.text.Rectangle(xll, yll, xul, yul);
|
||||
}
|
||||
private PdfContentByte _MyContentByte;
|
||||
[XmlIgnore]
|
||||
public PdfContentByte MyContentByte
|
||||
{
|
||||
get { return _MyContentByte; }
|
||||
set { _MyContentByte = value; }
|
||||
}
|
||||
private float _LeftMargin = 0;
|
||||
public float LeftMargin
|
||||
{
|
||||
get { return _LeftMargin; }
|
||||
set { _LeftMargin = value; }
|
||||
}
|
||||
private float _TopMargin = 0;
|
||||
public float TopMargin
|
||||
{
|
||||
get { return _TopMargin; }
|
||||
set { _TopMargin = value; }
|
||||
}
|
||||
private SvgScale _MyScale;
|
||||
|
||||
[XmlIgnore]
|
||||
public PdfContentByte MyContentByte { get; set; }
|
||||
|
||||
public float LeftMargin { get; set; } = 0;
|
||||
|
||||
public float TopMargin { get; set; } = 0;
|
||||
private SvgScale _MyScale;
|
||||
public SvgScale MyScale
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_MyScale == null)
|
||||
{
|
||||
_MyScale = new SvgScale(72, new System.Drawing.RectangleF(0, 0, _MyContentByte.PdfWriter.PageSize.Width, _MyContentByte.PdfWriter.PageSize.Height), _Width, _Height, _ViewBox);
|
||||
_MyScale.XLowerLimit -= _LeftMargin;
|
||||
_MyScale.YLowerLimit -= _TopMargin;
|
||||
_MyScale = new SvgScale(72, new System.Drawing.RectangleF(0, 0, MyContentByte.PdfWriter.PageSize.Width, MyContentByte.PdfWriter.PageSize.Height), Width, Height, ViewBox);
|
||||
_MyScale.XLowerLimit -= LeftMargin;
|
||||
_MyScale.YLowerLimit -= TopMargin;
|
||||
}
|
||||
return _MyScale;
|
||||
}
|
||||
}
|
||||
public void Draw(PdfContentByte cb)
|
||||
{
|
||||
//myPdf.Clear();
|
||||
_MyContentByte = cb;
|
||||
MyContentByte = cb;
|
||||
_Templates = new Dictionary<string, PdfTemplate>();
|
||||
//RegisterFonts();
|
||||
SvgParts.Draw(cb, MyScale, this, this); //72 - Points
|
||||
}
|
||||
public static iTextSharp.text.Font GetFont(string fontName)
|
||||
@@ -214,36 +183,6 @@ namespace Volian.Svg.Library
|
||||
VlnItextFont.RegisterFont(fontName);
|
||||
return FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED, size, style, new iTextSharp.text.Color(color));
|
||||
}
|
||||
//private static string _FontFolder = null;
|
||||
//public static string FontFolder
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// if (_FontFolder == null)
|
||||
// {
|
||||
// _FontFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts);
|
||||
// if (_FontFolder == null) _FontFolder = (String)Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Explorer").OpenSubKey("Shell Folders").GetValue("Fontz");
|
||||
// _MyLog.WarnFormat("FontFolder set to {0}", _FontFolder);
|
||||
// }
|
||||
// return _FontFolder;
|
||||
// }
|
||||
//}
|
||||
private static int _StackTraceSkip = 1;
|
||||
private static DateTime _LastTime = DateTime.Now;
|
||||
private static DateTime _StartTime = DateTime.Now;
|
||||
public static void ResetWhen()
|
||||
{
|
||||
_StartTime = _LastTime = DateTime.Now;
|
||||
}
|
||||
public static void WhenAndWhere()
|
||||
{
|
||||
DateTime thisTime = DateTime.Now;
|
||||
System.Diagnostics.StackFrame sf = new System.Diagnostics.StackFrame(_StackTraceSkip, true);
|
||||
Console.WriteLine("{0:000000},{1:000000},'{2}',{3},'{4}'", TimeSpan.FromTicks(thisTime.Ticks - _StartTime.Ticks).TotalMilliseconds,
|
||||
TimeSpan.FromTicks(thisTime.Ticks - _LastTime.Ticks).TotalMilliseconds, sf.GetMethod().Name, sf.GetFileLineNumber()
|
||||
,sf.GetFileName());
|
||||
_LastTime = thisTime;
|
||||
}
|
||||
}
|
||||
public partial class SvgArc : SvgShapePart
|
||||
{
|
||||
@@ -326,18 +265,13 @@ namespace Volian.Svg.Library
|
||||
{
|
||||
// TODO: Could I try creating a template
|
||||
// Don't draw
|
||||
// SvgParts.Draw(cb, myScale, mySvg, myParent);
|
||||
PdfTemplate tmp = null;
|
||||
if (ID != "") tmp = mySvg.GetTemplate(ID, cb); // the size will be adjusted as items are added.
|
||||
SvgParts.Draw(tmp, myScale, mySvg, myParent);
|
||||
}
|
||||
public override void Draw(PdfTemplate tmp, SvgScale myScale, Svg mySvg, SvgPartInheritance myParent)
|
||||
{
|
||||
// TODO: Could I try creating a template
|
||||
// Don't draw
|
||||
// SvgParts.Draw(cb, myScale, mySvg, myParent);
|
||||
//PdfTemplate tmp2 = mySvg.GetTemplate(ID); // the size will be adjusted as items are added.
|
||||
//SvgParts.Draw(tmp2, myScale, mySvg, myParent);
|
||||
}
|
||||
}
|
||||
public partial class SvgUse : SvgPartInheritance
|
||||
@@ -348,24 +282,22 @@ namespace Volian.Svg.Library
|
||||
{
|
||||
// TODO: Could I use the template
|
||||
SetupInheritance(myParent.MyInheritedSettings);
|
||||
if (mySvg.LookUp.ContainsKey(_UseID))
|
||||
mySvg[_UseID].Draw(cb, scale.AdjustOrigin(X, Y), mySvg, this);
|
||||
if (mySvg.LookUp.ContainsKey(UseID))
|
||||
mySvg[UseID].Draw(cb, scale.AdjustOrigin(X, Y), mySvg, this);
|
||||
else
|
||||
{
|
||||
if (!_MissingMacros.Contains(_UseID))
|
||||
if (!_MissingMacros.Contains(UseID))
|
||||
{
|
||||
_MissingMacros.Add(_UseID);
|
||||
_MyLog.WarnFormat("Missing Macro '{0}'", _UseID);
|
||||
_MissingMacros.Add(UseID);
|
||||
_MyLog.WarnFormat("Missing Macro '{0}'", UseID);
|
||||
}
|
||||
}
|
||||
//cb.AddTemplate(mySvg.GetTemplate(_UseID.Substring(1),cb), scale.X(X), scale.Y(cb, Y));
|
||||
}
|
||||
public override void Draw(PdfTemplate tmp, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
|
||||
{
|
||||
// TODO: Could I use the template
|
||||
SetupInheritance(myParent.MyInheritedSettings);
|
||||
//mySvg[_UseID.Substring(1)].Draw(tmp, scale.AdjustOrigin(X, Y), mySvg, this);
|
||||
mySvg[_UseID].Draw(tmp, scale.AdjustOrigin(X, Y), mySvg, this);
|
||||
mySvg[UseID].Draw(tmp, scale.AdjustOrigin(X, Y), mySvg, this);
|
||||
}
|
||||
}
|
||||
public partial class SvgEllipse : SvgShapePart
|
||||
@@ -410,7 +342,7 @@ namespace Volian.Svg.Library
|
||||
public override void Draw(PdfContentByte cb, SvgScale myScale, Svg mySvg, SvgPartInheritance myParent)
|
||||
{
|
||||
SetupInheritance(myParent.MyInheritedSettings);
|
||||
_SvgParts.Draw(cb, myScale, mySvg, this);
|
||||
SvgParts.Draw(cb, myScale, mySvg, this);
|
||||
}
|
||||
public override void Draw(PdfTemplate tmp, SvgScale myScale, Svg mySvg, SvgPartInheritance myParent)
|
||||
{
|
||||
@@ -443,7 +375,8 @@ namespace Volian.Svg.Library
|
||||
{
|
||||
SetupInheritance(myParent.MyInheritedSettings);
|
||||
tmp.SaveState();
|
||||
try
|
||||
#pragma warning disable CS0168 // Variable is declared but never used - ex kept for debugging
|
||||
try
|
||||
{
|
||||
if (ImagePath != null)
|
||||
{
|
||||
@@ -457,7 +390,8 @@ namespace Volian.Svg.Library
|
||||
{
|
||||
//_MyLog.WarnFormat("SvgImage.Draw '{0}' {1} - {2}", ImagePath, ex.GetType().Name, ex.Message);
|
||||
}
|
||||
tmp.RestoreState();
|
||||
#pragma warning restore CS0168 // Variable is declared but never used
|
||||
tmp.RestoreState();
|
||||
}
|
||||
}
|
||||
public partial class SvgLine : SvgLinePart
|
||||
@@ -581,28 +515,19 @@ namespace Volian.Svg.Library
|
||||
{
|
||||
case SvgJustify.Left:
|
||||
return Element.ALIGN_LEFT;
|
||||
break;
|
||||
case SvgJustify.Center:
|
||||
return Element.ALIGN_CENTER;
|
||||
break;
|
||||
case SvgJustify.Right:
|
||||
return Element.ALIGN_RIGHT;
|
||||
break;
|
||||
}
|
||||
return Element.ALIGN_LEFT;
|
||||
}
|
||||
}
|
||||
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 bool IsSplitCharacter(int start, int current, int end, char[] cc, PdfChunk[] ck) => (cc[current] == ' ');
|
||||
public bool IsSplitCharacter(char c) => (c == ' ');
|
||||
}
|
||||
public static VlnSplitCharacter mySplitter = new VlnSplitCharacter();
|
||||
// Draw's using PdfContentByte are for drawing PageList items.
|
||||
public override void Draw(PdfContentByte cb, SvgScale scale, Svg mySvg, SvgPartInheritance myParent)
|
||||
@@ -654,9 +579,6 @@ namespace Volian.Svg.Library
|
||||
}
|
||||
switch (Justify)
|
||||
{
|
||||
//case SvgJustify.Left:
|
||||
// x = x;
|
||||
// break;
|
||||
case SvgJustify.Center:
|
||||
x-=w/2;
|
||||
break;
|
||||
@@ -687,12 +609,6 @@ namespace Volian.Svg.Library
|
||||
public static bool CompressPropSubSup = false;
|
||||
private Phrase BuildPhrase(string text, float fontSize, int fontStyle, iTextSharp.text.Font font)
|
||||
{
|
||||
//if (text == "Caution")
|
||||
//{
|
||||
// if (iTextSharp.text.FontFactory.IsRegistered("VolianScript"))
|
||||
// Console.WriteLine("Is Registered");
|
||||
// Console.WriteLine("stop");
|
||||
//}
|
||||
bool fontUnderline = false;
|
||||
float fontTextRise = 0;
|
||||
|
||||
@@ -700,8 +616,6 @@ namespace Volian.Svg.Library
|
||||
text = Regex.Replace(text, @"\\'[0-9a-fA-F][0-9a-fA-F]", new MatchEvaluator(ReplaceHexCharacter));
|
||||
text += " ";
|
||||
|
||||
//if (text.Contains("\\")) -- these 2 lines made \ul and \ulnone in page list text not get resolved and would then print
|
||||
//text = text.Replace("\\", ((char)9586).ToString()); // B2016-155 convert backslash char to the unicode symbol - to allow processing rtf commands \ul, \up, \dn, etc.
|
||||
// B2016-167: handle backslashes but don't do if the backslash is an underline rtf command
|
||||
int stindx = text.IndexOf("\\");
|
||||
while (stindx != -1)
|
||||
@@ -892,170 +806,38 @@ namespace Volian.Svg.Library
|
||||
tmp.RestoreState();
|
||||
}
|
||||
}
|
||||
public class SvgPageTotal
|
||||
{
|
||||
public SvgPageTotal(System.Drawing.Font myFont, PdfContentByte cb)
|
||||
{
|
||||
_MyFont = myFont;
|
||||
_MyTemplate = cb.CreateTemplate(100, 100);
|
||||
_MyTemplate.BoundingBox= new Rectangle(-20, -20, 100, 100);
|
||||
}
|
||||
private int _PageCount=1;
|
||||
private System.Drawing.Font _MyFont;
|
||||
private PdfTemplate _MyTemplate;
|
||||
public PdfTemplate MyTemplate
|
||||
{
|
||||
get { return _MyTemplate; }
|
||||
}
|
||||
public void Draw()
|
||||
{
|
||||
// Output Page Count
|
||||
_MyTemplate.BeginText();
|
||||
iTextSharp.text.Font font = Svg.GetFont(_MyFont.Name);
|
||||
BaseFont baseFont = font.BaseFont;
|
||||
_MyTemplate.SetFontAndSize(baseFont,_MyFont.Size);
|
||||
_MyTemplate.SetTextMatrix(0, 0);
|
||||
_MyTemplate.ShowText(_PageCount.ToString());
|
||||
_MyTemplate.EndText();
|
||||
}
|
||||
}
|
||||
public class SvgPageHelper : PdfPageEventHelper
|
||||
{
|
||||
private bool _SpecialCAS; // B2023-005: CAS page, rotate watermark
|
||||
public bool SpecialCAS
|
||||
public bool SpecialCAS { get; set; }
|
||||
public bool IsLandscape { get; set; }
|
||||
public bool IsWatermarkLandscape { get; set; }
|
||||
public Svg MySvg { get; set; }
|
||||
public PdfLayer PageListLayer { get; set; }
|
||||
public PdfLayer WatermarkLayer { get; set; }
|
||||
public string Watermark { get; set; } = string.Empty;
|
||||
public string WatermarkColor { get; set; } = "BLUE";
|
||||
public PdfLayer PROMSVersionLayer { get; set; }
|
||||
public string PROMSVersion { get; set; } = string.Empty;
|
||||
public bool DoZoomOMatic { get; set; } = false;
|
||||
public int CurrentPageNumber { get; set; } = 0;
|
||||
public int CurrentPageNumberNoFoldouts { get; set; } = 0;
|
||||
public int CurrentTOCPageNumber { get; set; } = 0;
|
||||
public bool OnFoldoutPage { get; set; } = false;
|
||||
public bool CreatingFoldoutPage { get; set; } = false;
|
||||
public bool CreatingSupInfoPage { get; set; } = false;
|
||||
public SvgPageHelper(Svg mySvg)
|
||||
{
|
||||
get { return _SpecialCAS; }
|
||||
set { _SpecialCAS = value; }
|
||||
}
|
||||
private bool _IsLandscape;
|
||||
public bool IsLandscape
|
||||
{
|
||||
get { return _IsLandscape; }
|
||||
set { _IsLandscape = value; }
|
||||
}
|
||||
// B2019-145: added the following property so that the code would know that an adjustment should be made to print the watermark
|
||||
// in landscape mode. Note that 'IsLandscape' could not be used because it also does the pagelist items.
|
||||
private bool _IsWatermarkLandscape;
|
||||
public bool IsWatermarkLandscape
|
||||
{
|
||||
get { return _IsWatermarkLandscape; }
|
||||
set { _IsWatermarkLandscape = value; }
|
||||
}
|
||||
// B2018-124 we no longer need is list was not hanling "Information Only" water mark
|
||||
//private List<string> _AllowedWatermarks = new List<string>();
|
||||
//public List<string> AllowedWatermarks
|
||||
//{
|
||||
// get { return _AllowedWatermarks; }
|
||||
// set { _AllowedWatermarks = value; }
|
||||
//}
|
||||
private Svg _MySvg;
|
||||
public Svg MySvg
|
||||
{
|
||||
get { return _MySvg; }
|
||||
set { _MySvg = value; }
|
||||
}
|
||||
private PdfLayer _PageListLayer;
|
||||
public PdfLayer PageListLayer
|
||||
{
|
||||
get { return _PageListLayer; }
|
||||
set { _PageListLayer = value; }
|
||||
}
|
||||
private PdfLayer _WatermarkLayer;
|
||||
public PdfLayer WatermarkLayer
|
||||
{
|
||||
get { return _WatermarkLayer; }
|
||||
set { _WatermarkLayer = value; }
|
||||
}
|
||||
private string _Watermark=string.Empty;
|
||||
public string Watermark
|
||||
{
|
||||
get { return _Watermark; }
|
||||
set { _Watermark = value; }
|
||||
}
|
||||
private string _WatermarkColor = "BLUE";
|
||||
public string WatermarkColor
|
||||
{
|
||||
get { return _WatermarkColor; }
|
||||
set { _WatermarkColor = value; }
|
||||
}
|
||||
private PdfLayer _PROMSVersionLayer; //C2018-009 print PROMS version
|
||||
public PdfLayer PROMSVersionLayer
|
||||
{
|
||||
get { return _PROMSVersionLayer; }
|
||||
set { _PROMSVersionLayer = value; }
|
||||
}
|
||||
private string _PROMSVersion = string.Empty;
|
||||
public string PROMSVersion
|
||||
{
|
||||
get { return _PROMSVersion; }
|
||||
set { _PROMSVersion = value; }
|
||||
}
|
||||
private bool _DoZoomOMatic = false;
|
||||
public bool DoZoomOMatic
|
||||
{
|
||||
get { return _DoZoomOMatic; }
|
||||
set { _DoZoomOMatic = value; }
|
||||
}
|
||||
private int _CurrentPageNumber = 0;
|
||||
public int CurrentPageNumber
|
||||
{
|
||||
get { return _CurrentPageNumber; }
|
||||
set { _CurrentPageNumber = value; }
|
||||
}
|
||||
private int _CurrentPageNumberNoFoldouts = 0;
|
||||
public int CurrentPageNumberNoFoldouts
|
||||
{
|
||||
get { return _CurrentPageNumberNoFoldouts; }
|
||||
set { _CurrentPageNumberNoFoldouts = value; }
|
||||
}
|
||||
private int _CurrentTOCPageNumber = 0;
|
||||
public int CurrentTOCPageNumber
|
||||
{
|
||||
get { return _CurrentTOCPageNumber; }
|
||||
set { _CurrentTOCPageNumber = value; }
|
||||
}
|
||||
private bool _OnFoldoutPage = false;
|
||||
public bool OnFoldoutPage
|
||||
{
|
||||
get { return _OnFoldoutPage; }
|
||||
set { _OnFoldoutPage = value; }
|
||||
}
|
||||
private bool _CreatingFoldoutPage = false;
|
||||
public bool CreatingFoldoutPage
|
||||
{
|
||||
get { return _CreatingFoldoutPage; }
|
||||
set { _CreatingFoldoutPage = value; }
|
||||
}
|
||||
private bool _CreatingSupInfoPage = false;
|
||||
public bool CreatingSupInfoPage
|
||||
{
|
||||
get { return _CreatingSupInfoPage; }
|
||||
set { _CreatingSupInfoPage = value; }
|
||||
}
|
||||
public SvgPageHelper(Svg mySvg)
|
||||
{
|
||||
_MySvg = mySvg;
|
||||
MySvg = mySvg;
|
||||
}
|
||||
public SvgPageHelper()
|
||||
{
|
||||
}
|
||||
private int _BGPageOffset = 0;
|
||||
public int BackgroundPageOffset
|
||||
{
|
||||
get { return _BGPageOffset; }
|
||||
set { _BGPageOffset = value; }
|
||||
}
|
||||
protected virtual string ReplacePageListToken(Match match)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public override void OnOpenDocument(PdfWriter writer, Document document)
|
||||
public int BackgroundPageOffset { get; set; } = 0;
|
||||
protected virtual string ReplacePageListToken(Match match) => string.Empty;
|
||||
|
||||
public override void OnOpenDocument(PdfWriter writer, Document document)
|
||||
{
|
||||
//base.OnOpenDocument(writer, document);
|
||||
//tmpTotal = writer.DirectContent.CreateTemplate(100, 100);
|
||||
//tmpTotal.BoundingBox = new Rectangle(-20, -20, 100, 100);
|
||||
//PdfContentByte cb = writer.DirectContent;
|
||||
}
|
||||
public override void OnEndPage(PdfWriter writer, Document document)
|
||||
{
|
||||
@@ -1093,8 +875,8 @@ namespace Volian.Svg.Library
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_BackgroundReader == null && _BackgroundFile != null && File.Exists(_BackgroundFile))
|
||||
_BackgroundReader = new PdfReader(_BackgroundFile);
|
||||
if (_BackgroundReader == null && BackgroundFile != null && File.Exists(BackgroundFile))
|
||||
_BackgroundReader = new PdfReader(BackgroundFile);
|
||||
return _BackgroundReader;
|
||||
}
|
||||
}
|
||||
@@ -1106,29 +888,17 @@ namespace Volian.Svg.Library
|
||||
return BackgroundReader.Info["Producer"].ToString().StartsWith("iTextSharp");
|
||||
}
|
||||
}
|
||||
private string _BackgroundFile = null;
|
||||
public string BackgroundFile
|
||||
{
|
||||
get { return _BackgroundFile; }
|
||||
set { _BackgroundFile = value; }
|
||||
}
|
||||
private PdfLayer _BackgroundLayer = null;
|
||||
public PdfLayer BackgroundLayer
|
||||
{
|
||||
get { return _BackgroundLayer; }
|
||||
set { _BackgroundLayer = value; }
|
||||
}
|
||||
private System.Drawing.PointF _BackgroundOffset = new System.Drawing.PointF(0, 0);
|
||||
|
||||
public string BackgroundFile { get; set; } = null;
|
||||
public PdfLayer BackgroundLayer { get; set; } = null;
|
||||
private System.Drawing.PointF _BackgroundOffset = new System.Drawing.PointF(0, 0);
|
||||
public System.Drawing.PointF BackgroundOffset
|
||||
{
|
||||
get { return _BackgroundOffset; }
|
||||
set { _BackgroundOffset = value; }
|
||||
}
|
||||
public int BackgroundPageCount
|
||||
{
|
||||
get { return BackgroundReader == null ? 0 : BackgroundReader.NumberOfPages; }
|
||||
}
|
||||
private PdfImportedPage GetBackgroundPage(PdfContentByte cb)
|
||||
public int BackgroundPageCount => BackgroundReader == null ? 0 : BackgroundReader.NumberOfPages;
|
||||
private PdfImportedPage GetBackgroundPage(PdfContentByte cb)
|
||||
{
|
||||
if (BackgroundReader == null) return null;
|
||||
int page = cb.PdfWriter.CurrentPageNumber + BackgroundPageOffset;
|
||||
@@ -1151,14 +921,10 @@ namespace Volian.Svg.Library
|
||||
ZoomOMatic(cb, 36);
|
||||
cb.RestoreState();
|
||||
}
|
||||
private bool _AllowAllWatermarks = false;
|
||||
public bool AllowAllWatermarks
|
||||
{
|
||||
get { return _AllowAllWatermarks; }
|
||||
set { _AllowAllWatermarks = value; }
|
||||
}
|
||||
//C2022-004 This will return the system drawing color from either the color name or ARGB values
|
||||
public System.Drawing.Color GetWatermarkColor(string colorDescription)
|
||||
|
||||
public bool AllowAllWatermarks { get; set; } = false;
|
||||
//C2022-004 This will return the system drawing color from either the color name or ARGB values
|
||||
public System.Drawing.Color GetWatermarkColor(string colorDescription)
|
||||
{
|
||||
System.Drawing.Color systemColor;
|
||||
if (colorDescription.StartsWith("[A=")) // if color is ARGB representation, parse out the values
|
||||
@@ -1192,9 +958,8 @@ namespace Volian.Svg.Library
|
||||
private void DrawWatermark(PdfContentByte cb)
|
||||
{
|
||||
if (Watermark == null || Watermark.ToLower().Contains("none") || Watermark == "") return;
|
||||
//if (!AllowAllWatermarks && !AllowedWatermarks.Contains(Watermark)) return; -- B2018-124 not needed anymore with above if statement - this does not hanle "Information Only"
|
||||
cb.SaveState();
|
||||
if (_WatermarkLayer != null) cb.BeginLayer(_WatermarkLayer);
|
||||
if (WatermarkLayer != null) cb.BeginLayer(WatermarkLayer);
|
||||
// B2023-005: Beaver Valley, second page of CAS page is a 'foldout' on large paper - need to rotate the
|
||||
// watermark
|
||||
if (SpecialCAS)
|
||||
@@ -1207,16 +972,13 @@ namespace Volian.Svg.Library
|
||||
else if (IsLandscape || IsWatermarkLandscape) // B2019-145: Added for printing landscape watermark on step section pages.
|
||||
{
|
||||
// The watermark needs to be rotated back for landscape pagelist - B2016-191
|
||||
//double a = -33 * (Math.PI / 180);
|
||||
//System.Drawing.Drawing2D.Matrix myMatrix = new System.Drawing.Drawing2D.Matrix((float)Math.Cos(a), (float)Math.Sin(a), (float)-Math.Sin(a), (float)Math.Cos(a), -60, 320);
|
||||
double a = -90 * (Math.PI / 180);
|
||||
System.Drawing.Drawing2D.Matrix myMatrix = new System.Drawing.Drawing2D.Matrix((float)Math.Cos(a), (float)Math.Sin(a), (float)-Math.Sin(a), (float)Math.Cos(a), 0, cb.PdfDocument.PageSize.Height);
|
||||
cb.Transform(myMatrix);
|
||||
}
|
||||
SvgWatermark myWatermark = new SvgWatermark(cb, Watermark, GetWatermarkColor(WatermarkColor), .15F);
|
||||
//myWatermark.SetSquareDotPattern(.7F);
|
||||
myWatermark.Draw();
|
||||
if (_WatermarkLayer != null) cb.EndLayer();
|
||||
if (WatermarkLayer != null) cb.EndLayer();
|
||||
cb.RestoreState();
|
||||
}
|
||||
//C2018-009 print PROMS version
|
||||
@@ -1226,32 +988,22 @@ namespace Volian.Svg.Library
|
||||
string text = PROMSVersion;
|
||||
float textBase =cb.PdfDocument.Top + 19;
|
||||
float textLeft = cb.PdfDocument.Right - 15;
|
||||
if (_PROMSVersionLayer != null) cb.BeginLayer(_PROMSVersionLayer);
|
||||
if (PROMSVersionLayer != null) cb.BeginLayer(PROMSVersionLayer);
|
||||
cb.BeginText();
|
||||
cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED), 6f);
|
||||
cb.SetTextMatrix(textLeft, textBase);
|
||||
cb.SetColorFill(new iTextSharp.text.Color(System.Drawing.Color.Indigo));
|
||||
cb.ShowText(text);
|
||||
cb.EndText();
|
||||
if (_PROMSVersionLayer != null) cb.EndLayer();
|
||||
if (PROMSVersionLayer != null) cb.EndLayer();
|
||||
cb.RestoreState();
|
||||
}
|
||||
private void DrawPageList(PdfContentByte cb)
|
||||
{
|
||||
if (_MySvg != null)
|
||||
if (MySvg != null)
|
||||
{
|
||||
cb.SaveState();
|
||||
if (_PageListLayer != null) cb.BeginLayer(_PageListLayer);
|
||||
// Do anything needed to finish off the page
|
||||
//System.Drawing.Drawing2D.Matrix myMatrix = new System.Drawing.Drawing2D.Matrix();
|
||||
//myMatrix.Rotate(90); // Rotate the Pagelist items by 90 Degrees.
|
||||
//// Translate by the Height of the page.
|
||||
//myMatrix.Translate(cb.PdfDocument.PageSize.Height, 0, System.Drawing.Drawing2D.MatrixOrder.Append);
|
||||
//// This was for fun
|
||||
//// myMatrix.Scale(.75F, .75F, System.Drawing.Drawing2D.MatrixOrder.Append);
|
||||
//cb.Transform(myMatrix);
|
||||
//// You can look at the value of the Matrix at this point, to create the matrix directly like I did below
|
||||
//OR
|
||||
if (PageListLayer != null) cb.BeginLayer(PageListLayer);
|
||||
// Rotate 90 Degrees and Translate by the Height of the Page
|
||||
|
||||
if (IsLandscape)
|
||||
@@ -1259,8 +1011,8 @@ namespace Volian.Svg.Library
|
||||
System.Drawing.Drawing2D.Matrix myMatrix = new System.Drawing.Drawing2D.Matrix(0, 1, -1, 0, cb.PdfDocument.PageSize.Height, 0);
|
||||
cb.Transform(myMatrix);
|
||||
}
|
||||
_MySvg.Draw(cb);
|
||||
if (_PageListLayer != null) cb.EndLayer();
|
||||
MySvg.Draw(cb);
|
||||
if (PageListLayer != null) cb.EndLayer();
|
||||
cb.RestoreState();
|
||||
}
|
||||
}
|
||||
@@ -1277,7 +1029,7 @@ namespace Volian.Svg.Library
|
||||
}
|
||||
public override void OnStartPage(PdfWriter writer, Document document)
|
||||
{
|
||||
//base.OnStartPage(writer, document);
|
||||
|
||||
}
|
||||
public override void OnCloseDocument(PdfWriter writer, Document document)
|
||||
{
|
||||
@@ -1289,137 +1041,24 @@ namespace Volian.Svg.Library
|
||||
private PdfContentByte _ContentByte;
|
||||
private string _Text;
|
||||
private System.Drawing.Color _Color;
|
||||
private PdfPatternPainter _PatternPainter;
|
||||
private BaseFont _Basefont;
|
||||
private float _Fontsize;
|
||||
private float _XOffset;
|
||||
private float _YOffset;
|
||||
private float _TextAngle;
|
||||
private float _Opacity;
|
||||
public SvgWatermark(PdfContentByte contentByte, string text, System.Drawing.Color color, float opacity)
|
||||
{
|
||||
_ContentByte = contentByte;
|
||||
_Text = text;
|
||||
//float radius = .5F;
|
||||
//float space = 3;
|
||||
// B2021-081: Blue was too intense with an alpha of 255 Read was too light with an alpha of 96
|
||||
if (color != System.Drawing.Color.Red)
|
||||
_Color = System.Drawing.Color.FromArgb(96, color);
|
||||
else
|
||||
_Color = color; // C2021-019: save color for color override
|
||||
_Opacity = opacity;
|
||||
//SetDotPattern(radius, space);
|
||||
//SetTextLayout();
|
||||
}
|
||||
#region commentedout
|
||||
//private void SetTextLayout()
|
||||
//{
|
||||
// Rectangle pageSize = _ContentByte.PdfWriter.PageSize; // Get page size
|
||||
// _Basefont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, Encoding.ASCII.EncodingName, BaseFont.EMBEDDED);
|
||||
// float hgtA = _Basefont.GetAscentPoint(_Text, 12);
|
||||
// //float hgtD = basefont.GetDescentPoint(text,20);
|
||||
// float wid = _Basefont.GetWidthPointKerned(_Text, 12);
|
||||
// //Console.WriteLine("{0} {1} {2}",hgtA,hgtD,wid);
|
||||
// float rho = wid / hgtA;
|
||||
// float x2 = (rho * pageSize.Height - pageSize.Width) / (rho * rho - 1);
|
||||
// float y1 = x2 * rho;
|
||||
// float y2 = pageSize.Height - y1;
|
||||
// float x1 = pageSize.Width - x2;
|
||||
// _XOffset = x2 + x1 / 2;
|
||||
// _YOffset = y1 / 2;
|
||||
// _TextAngle = CalcAngle(y1, x1);
|
||||
// _Fontsize = (float)(10 * Math.Sqrt(x2 * x2 + y2 * y2) / hgtA);
|
||||
//}
|
||||
//public void SetDotPattern(float radius, float space)
|
||||
//{
|
||||
// _PatternPainter = _ContentByte.CreatePattern(radius * 2, radius * 2, radius * 2 + space, radius * 2 + space);
|
||||
// PdfGState gState = new PdfGState();
|
||||
// gState.FillOpacity = _Opacity;
|
||||
// _PatternPainter.SetGState(gState);
|
||||
// _PatternPainter.SetColorFill(_Color);
|
||||
// _PatternPainter.Circle(radius, radius, radius);
|
||||
// _PatternPainter.Fill();
|
||||
//}
|
||||
//public void SetSquareDotPattern(float radius)
|
||||
//{
|
||||
// _PatternPainter = _ContentByte.CreatePattern(radius * 4, radius * 2, radius * 4, radius * 2);
|
||||
// PdfGState gState = new PdfGState();
|
||||
// gState.FillOpacity = .5f * _Opacity;
|
||||
// _PatternPainter.SetGState(gState);
|
||||
// _PatternPainter.SetColorFill(_Color);
|
||||
// _PatternPainter.Rectangle(0, 0, radius, radius);
|
||||
// _PatternPainter.Rectangle(radius * 2, radius, radius, radius);
|
||||
// _PatternPainter.Fill();
|
||||
//}
|
||||
//public void SetHashPattern(float thickness, float size)
|
||||
//{
|
||||
// _PatternPainter = _ContentByte.CreatePattern(size, size, size, size);
|
||||
// PdfGState gState = new PdfGState();
|
||||
// gState.FillOpacity = _Opacity;
|
||||
// gState.StrokeOpacity = _Opacity;
|
||||
// _PatternPainter.SetGState(gState);
|
||||
// _PatternPainter.SetLineWidth(.01F);
|
||||
// _PatternPainter.SetColorStroke(_Color); // Set color
|
||||
// _PatternPainter.MoveTo(0, 0);
|
||||
// _PatternPainter.LineTo(size, size);
|
||||
// _PatternPainter.MoveTo(size, 0);
|
||||
// _PatternPainter.LineTo(0, size);
|
||||
// _PatternPainter.Stroke();
|
||||
//}
|
||||
//public void SetTextPattern(float fontSize, float space)
|
||||
//{
|
||||
// float hgtA = _Basefont.GetAscentPoint(_Text, fontSize) + _Basefont.GetDescentPoint(_Text, fontSize);
|
||||
// float wid = _Basefont.GetWidthPointKerned(_Text, fontSize);
|
||||
// _PatternPainter = _ContentByte.CreatePattern(wid, hgtA, wid + space, hgtA + space);
|
||||
// _PatternPainter.SetFontAndSize(_Basefont, fontSize);
|
||||
// _PatternPainter.BoundingBox = new Rectangle(-20, -20, 100, 100);
|
||||
// _PatternPainter.BeginText();
|
||||
// PdfGState gs1 = new PdfGState();
|
||||
// gs1.FillOpacity = _Opacity;
|
||||
// _PatternPainter.SetGState(gs1);
|
||||
// _PatternPainter.SetColorFill(_Color); // Set color
|
||||
// _PatternPainter.ShowText(_Text);
|
||||
// _PatternPainter.EndText();
|
||||
//}
|
||||
//public void SetTextPattern2(float fontSize)
|
||||
//{
|
||||
// BaseFont _Basefont2 = BaseFont.CreateFont(BaseFont.HELVETICA, Encoding.ASCII.EncodingName, BaseFont.EMBEDDED);
|
||||
// float hgtA = _Basefont2.GetAscentPoint(_Text, fontSize);
|
||||
// float wid = _Basefont2.GetWidthPointKerned(_Text, fontSize);
|
||||
// _PatternPainter = _ContentByte.CreatePattern(wid * 2, hgtA * 2, wid * 2, hgtA * 2);
|
||||
// _PatternPainter.SetFontAndSize(_Basefont2, fontSize);
|
||||
// _PatternPainter.BoundingBox = new Rectangle(-20, -20, 100, 100);
|
||||
// _PatternPainter.BeginText();
|
||||
// PdfGState gs1 = new PdfGState();
|
||||
// gs1.FillOpacity = _Opacity;
|
||||
// _PatternPainter.SetGState(gs1);
|
||||
// _PatternPainter.SetColorFill(_Color); // Set color
|
||||
// _PatternPainter.ShowText(_Text);
|
||||
// _PatternPainter.ShowTextAligned(PdfContentByte.ALIGN_LEFT, _Text, wid, hgtA, 0);
|
||||
// _PatternPainter.EndText();
|
||||
//}
|
||||
#endregion
|
||||
public void Draw()
|
||||
{
|
||||
_ContentByte.SaveState();
|
||||
//_ContentByte.BeginText();
|
||||
//_ContentByte.SetPatternFill(_PatternPainter);
|
||||
//_ContentByte.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);
|
||||
//_ContentByte.SetLineWidth(.5F);
|
||||
//_ContentByte.SetFontAndSize(_Basefont, _Fontsize);// Set font and size
|
||||
//_ContentByte.SetColorStroke(_Color);
|
||||
//PdfGState gs2 = new PdfGState();
|
||||
//gs2.StrokeOpacity = _Opacity;
|
||||
//_ContentByte.SetGState(gs2);
|
||||
//_ContentByte.ShowTextAlignedKerned(PdfContentByte.ALIGN_CENTER, _Text, _XOffset, _YOffset, _TextAngle);// Draw the text
|
||||
//_ContentByte.EndText();
|
||||
_ContentByte.AddImage(WatermarkImage);
|
||||
_ContentByte.RestoreState();
|
||||
}
|
||||
//private float CalcAngle(float opposite, float adjacent)
|
||||
//{
|
||||
// return (float)(Math.Atan2(opposite, adjacent) * (180 / Math.PI));
|
||||
//}
|
||||
private Image _WatermarkImage;
|
||||
public Image WatermarkImage
|
||||
{
|
||||
@@ -1452,7 +1091,6 @@ namespace Volian.Svg.Library
|
||||
_Color, System.Drawing.Color.Transparent);
|
||||
g.FillPath(aHatchBrush, gp);
|
||||
g.DrawPath(new System.Drawing.Pen(_Color), gp);
|
||||
//g.DrawRectangle(System.Drawing.Pens.Cyan, 0, 0, bnds.Width, bnds.Height);
|
||||
}
|
||||
_WatermarkImage = iTextSharp.text.Image.GetInstance(bmp, System.Drawing.Imaging.ImageFormat.Png);
|
||||
_WatermarkImage.SetAbsolutePosition(72, 72);
|
||||
@@ -1481,11 +1119,4 @@ namespace Volian.Svg.Library
|
||||
}
|
||||
|
||||
}
|
||||
public enum SvgWatermarkFill
|
||||
{
|
||||
Dots = 1,
|
||||
Text1 = 2,
|
||||
Text2 = 3,
|
||||
Hash = 4
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user