Print Library, Svg Library, Utils Library, XYPlots
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using iTextSharp.text.pdf;
|
||||
using iTextSharp.text;
|
||||
using Itenso.Rtf;
|
||||
using Itenso.Rtf.Parser;
|
||||
using Itenso.Rtf.Interpreter;
|
||||
using Itenso.Rtf.Support;
|
||||
using Volian.Controls.Library;
|
||||
using VEPROMS.CSLA.Library;
|
||||
using Volian.Base.Library;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -24,22 +20,14 @@ namespace Volian.Print.Library
|
||||
get { return _UniqueDebugId++; }
|
||||
set { _UniqueDebugId = value; }
|
||||
}
|
||||
private int _DebugId = UniqueDebugId;
|
||||
public int DebugId
|
||||
{
|
||||
get { return _DebugId; }
|
||||
set { _DebugId = value; }
|
||||
}
|
||||
|
||||
protected static float _WidthAdjust = 1; // 1 Point - adjusted to match 16-bit line wrapping. For editting it's 3.
|
||||
public int DebugId { get; set; } = UniqueDebugId;
|
||||
|
||||
protected static float _WidthAdjust = 1; // 1 Point - adjusted to match 16-bit line wrapping. For editting it's 3.
|
||||
protected static float _WidthAdjustBox = 6;
|
||||
private static float _SixLinesPerInch = 12; // twips
|
||||
public static float SixLinesPerInch
|
||||
{
|
||||
get { return vlnPrintObject._SixLinesPerInch; }
|
||||
set { vlnPrintObject._SixLinesPerInch = value; }
|
||||
}
|
||||
protected static float _SevenLinesPerInch = 10.1F;//72F / 7F;
|
||||
|
||||
public static float SixLinesPerInch { get; set; } = 12;
|
||||
protected static float _SevenLinesPerInch = 10.1F;//72F / 7F;
|
||||
|
||||
protected float _XOffset;
|
||||
public float XOffset
|
||||
@@ -64,31 +52,13 @@ namespace Volian.Print.Library
|
||||
set
|
||||
{
|
||||
_MyParent = value;
|
||||
if (_MyParent != null)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
private bool _HasIndent = false;
|
||||
public bool HasIndent
|
||||
{
|
||||
get { return _HasIndent; }
|
||||
set { _HasIndent = value; }
|
||||
}
|
||||
private bool _IsCompressed = false;
|
||||
public bool IsCompressed
|
||||
{
|
||||
get { return _IsCompressed; }
|
||||
set { _IsCompressed = value; }
|
||||
}
|
||||
private string _ImageText; // ro definition, value part of #Link in case of image/figure
|
||||
public string ImageText
|
||||
{
|
||||
get { return _ImageText; }
|
||||
set { _ImageText = value; }
|
||||
}
|
||||
protected string _Rtf; // may become iTextSharp paragraph
|
||||
|
||||
public bool HasIndent { get; set; } = false;
|
||||
public bool IsCompressed { get; set; } = false;
|
||||
public string ImageText { get; set; }
|
||||
protected string _Rtf; // may become iTextSharp paragraph
|
||||
public virtual string Rtf
|
||||
{
|
||||
get { return _Rtf; }
|
||||
@@ -96,15 +66,9 @@ namespace Volian.Print.Library
|
||||
}
|
||||
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();
|
||||
// B2018-034 Attributes were being lost when the IsCompressed flag was true.
|
||||
// The following variable was changed to a public so that it could be used
|
||||
@@ -114,6 +78,7 @@ namespace Volian.Print.Library
|
||||
{
|
||||
get
|
||||
{
|
||||
//For Debugging:
|
||||
// If the paragraph iscompressed, it may have been created as not compressed since compression
|
||||
// is not set when paragraph is initially created, it is set during pagination tests.
|
||||
//if (_IParagraph == null || IsCompressed)
|
||||
@@ -186,49 +151,10 @@ namespace Volian.Print.Library
|
||||
}
|
||||
set { _Height = value; }
|
||||
}
|
||||
public float GetParagraphHeight(PdfContentByte cb, Paragraph iParagraph, string suffix, float width)
|
||||
{
|
||||
return GetParagraphHeight(cb, iParagraph, suffix, width, true);
|
||||
}
|
||||
public float GetParagraphHeight(PdfContentByte cb, Paragraph iParagraph, string suffix, float width, bool throwException)
|
||||
{
|
||||
float heightAll = GetHeight(cb, iParagraph, suffix, width, throwException);
|
||||
return heightAll;
|
||||
}
|
||||
private static void RestoreLastCharacter(Paragraph iParagraph, Chunk chk)
|
||||
{
|
||||
iParagraph.RemoveAt(iParagraph.Count - 1);
|
||||
iParagraph.Add(chk);
|
||||
}
|
||||
private static Chunk RemoveLastCharacter(Paragraph iParagraph)
|
||||
{
|
||||
if (iParagraph.Count == 0)
|
||||
return null;
|
||||
object obj = iParagraph[iParagraph.Count-1];
|
||||
Chunk chk = obj as Chunk;
|
||||
if (chk == null)
|
||||
return null;
|
||||
string s = chk.Content;
|
||||
if (s.Length > 1 || iParagraph.Count > 1) // don't remove last character if it's the only one
|
||||
{
|
||||
iParagraph.RemoveAt(iParagraph.Count - 1);
|
||||
if (s.Length > 0)
|
||||
{
|
||||
if (s == "\xA0") // If this is a space at the end put it back
|
||||
{
|
||||
iParagraph.Add(chk);
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
s = s.Substring(0, s.Length - 1);
|
||||
iParagraph.Add(new Chunk(s, chk.Font));
|
||||
}
|
||||
}
|
||||
}
|
||||
return chk;
|
||||
}
|
||||
public static float GetHeight(PdfContentByte cb, Paragraph iParagraph, string suffix, float width, bool throwException)
|
||||
public float GetParagraphHeight(PdfContentByte cb, Paragraph iParagraph, string suffix, float width) => GetParagraphHeight(cb, iParagraph, suffix, width, true);
|
||||
public float GetParagraphHeight(PdfContentByte cb, Paragraph iParagraph, string suffix, float width, bool throwException) => (float)GetHeight(cb, iParagraph, suffix, width, throwException);
|
||||
|
||||
public static float GetHeight(PdfContentByte cb, Paragraph iParagraph, string suffix, float width, bool throwException)
|
||||
{
|
||||
ColumnText myColumnText = new ColumnText(cb);
|
||||
float pgHeight = cb.PdfDocument.PageSize.Height; // C2020-002 paper size is now set in the format files
|
||||
@@ -243,7 +169,6 @@ namespace Volian.Print.Library
|
||||
{
|
||||
myColumnText.AddElement(iParagraph);
|
||||
}
|
||||
//myColumnText.UseAscender = true;// Adjusts to the top of the text box.
|
||||
int status = myColumnText.Go(true); // Check to see if it will fit on the page.
|
||||
if (ColumnText.HasMoreText(status) && throwException)
|
||||
{
|
||||
@@ -255,7 +180,6 @@ namespace Volian.Print.Library
|
||||
iParagraph.IndentationLeft = 0;
|
||||
return GetHeight(cb, iParagraph, suffix, width, throwException);
|
||||
}
|
||||
//throw (new Exception("Paragraph longer than a page"));
|
||||
Console.WriteLine("Paragraph longer than a page");
|
||||
}
|
||||
return pgHeight - myColumnText.YLine; // This gives the height of the Paragraph // C2020-002 paper size is now set in the format files
|
||||
@@ -266,23 +190,19 @@ namespace Volian.Print.Library
|
||||
float h = GetParagraphHeight(cb, iParagraph, string.Empty, iWidth);
|
||||
int iWidthMax = iWidth; // maximum width in Characters
|
||||
int iDelta = iWidth / 2;
|
||||
iWidth = iWidth / 2;
|
||||
iWidth /= 2;
|
||||
while (iDelta > 0)
|
||||
{
|
||||
float h2 = GetParagraphHeight(cb, iParagraph, string.Empty, iWidth,false);
|
||||
iDelta = iDelta / 2;
|
||||
iDelta /= 2;
|
||||
if (h2 == h) iWidthMax = iWidth;
|
||||
iWidth += (h2>h ? 1: -1) * iDelta;
|
||||
}
|
||||
return (float) iWidthMax;
|
||||
}
|
||||
private PdfContentByte _MyContentByte;
|
||||
public PdfContentByte MyContentByte
|
||||
{
|
||||
get { return _MyContentByte; }
|
||||
set { _MyContentByte = value; }
|
||||
}
|
||||
private VlnSvgPageHelper _MyPageHelper;
|
||||
|
||||
public PdfContentByte MyContentByte { get; set; }
|
||||
private VlnSvgPageHelper _MyPageHelper;
|
||||
public VlnSvgPageHelper MyPageHelper
|
||||
{
|
||||
get
|
||||
@@ -296,50 +216,34 @@ namespace Volian.Print.Library
|
||||
public vlnPrintObject()
|
||||
{
|
||||
}
|
||||
/// <summary>
|
||||
/// No conversion necessary: twips -> twips
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static int ToInt(int value)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
/// <summary>
|
||||
/// No conversion necessary: int? twips -> int twips
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static int ToInt(int? value)
|
||||
{
|
||||
return ToInt((int)value);
|
||||
}
|
||||
/// <summary>
|
||||
/// No conversion necessary: string twips -> int twips
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static int ToInt(string value)
|
||||
{
|
||||
return ToInt((int)Convert.ToSingle(value));
|
||||
}
|
||||
/// <summary>
|
||||
/// No conversion necessary: value from a list in a string, twips -> int twips
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static int ToInt(string value, int i)
|
||||
{
|
||||
string s = (value.Contains(",")) ? value.Split(",".ToCharArray())[i] : value;
|
||||
return ToInt(s);
|
||||
}
|
||||
public static string GetRtf(string text, VE_Font vFont)
|
||||
/// <summary>
|
||||
/// No conversion necessary: twips -> twips
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static int ToInt(int value) => value;
|
||||
/// <summary>
|
||||
/// No conversion necessary: int? twips -> int twips
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static int ToInt(int? value) => ToInt((int)value);
|
||||
/// <summary>
|
||||
/// No conversion necessary: string twips -> int twips
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static int ToInt(string value) => ToInt((int)Convert.ToSingle(value));
|
||||
/// <summary>
|
||||
/// No conversion necessary: value from a list in a string, twips -> int twips
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static int ToInt(string value, int i) => ToInt((value.Contains(",")) ? value.Split(",".ToCharArray())[i] : value);
|
||||
public static string GetRtf(string text, VE_Font vFont)
|
||||
{
|
||||
StringBuilder rtfSB = new StringBuilder();
|
||||
//DisplayText vlntxt = new DisplayText(text.TrimStart(" ".ToCharArray()), vFont, false);
|
||||
DisplayText vlntxt = new DisplayText(text, vFont, false);
|
||||
//rtfSB.Append(AddFontTable(vlntxt.TextFont.WindowsFont));
|
||||
//rtfSB.Append(AddFontTable(vFont.WindowsFont));
|
||||
rtfSB.Append(AddFontTable(vFont));
|
||||
rtfSB.Append(vlntxt.StartText);
|
||||
rtfSB.Append("}");
|
||||
@@ -413,11 +317,8 @@ namespace Volian.Print.Library
|
||||
float fE = iFont.BaseFont.GetWidthPointKerned("!", 12);
|
||||
return fW == fE;
|
||||
}
|
||||
public static iTextSharp.text.Paragraph RtfToParagraph(string rtf)
|
||||
{
|
||||
return RtfToParagraph(rtf, false, false);
|
||||
}
|
||||
public static iTextSharp.text.Paragraph RtfToParagraph(string rtf, bool hasIndent, bool doPdfLinks)
|
||||
public static iTextSharp.text.Paragraph RtfToParagraph(string rtf) => RtfToParagraph(rtf, false, false);
|
||||
public static iTextSharp.text.Paragraph RtfToParagraph(string rtf, bool hasIndent, bool doPdfLinks)
|
||||
{
|
||||
if (hasIndent)
|
||||
{
|
||||
@@ -427,11 +328,13 @@ namespace Volian.Print.Library
|
||||
}
|
||||
|
||||
IRtfDocument rtfDoc = RtfInterpreterTool.BuildDoc(rtf);
|
||||
Rtf2iTextSharp rtf2IText = new Rtf2iTextSharp(rtfDoc);
|
||||
rtf2IText.DoPdfLinks = doPdfLinks;
|
||||
rtf2IText.HasIndent = hasIndent;
|
||||
iTextSharp.text.Paragraph para = rtf2IText.Convert();
|
||||
para.SetLeading(_SixLinesPerInch, 0);
|
||||
Rtf2iTextSharp rtf2IText = new Rtf2iTextSharp(rtfDoc)
|
||||
{
|
||||
DoPdfLinks = doPdfLinks,
|
||||
HasIndent = hasIndent
|
||||
};
|
||||
iTextSharp.text.Paragraph para = rtf2IText.Convert();
|
||||
para.SetLeading(SixLinesPerInch, 0);
|
||||
if (rtf.Contains("\x05")) // note that this is for existing customer data as of August 2015.
|
||||
{
|
||||
// if there is a hanging indent, the iTextSharp paragraph properties must be set
|
||||
@@ -459,22 +362,17 @@ namespace Volian.Print.Library
|
||||
// Change the chunks to only split on spaces rather than spaces and hyphens
|
||||
foreach (object obj in para)//Fix the code to check for chunks before assuming chunks
|
||||
{
|
||||
Chunk chk = obj as Chunk;
|
||||
if (chk != null && (chk.Attributes==null || !chk.Attributes.ContainsKey("NoSplit")))
|
||||
{
|
||||
if (chk.Attributes == null) chk.Attributes = new System.Collections.Hashtable();
|
||||
chk.SetSplitCharacter(mySplitter);
|
||||
chk.Attributes.Add("NoSplit", false);
|
||||
}
|
||||
}
|
||||
if (obj is Chunk chk && (chk.Attributes == null || !chk.Attributes.ContainsKey("NoSplit")))
|
||||
{
|
||||
if (chk.Attributes == null) chk.Attributes = new System.Collections.Hashtable();
|
||||
chk.SetSplitCharacter(mySplitter);
|
||||
chk.Attributes.Add("NoSplit", false);
|
||||
}
|
||||
}
|
||||
return para;
|
||||
}
|
||||
private static string FixNumber(string num)
|
||||
{
|
||||
if (num == "") return ("0");
|
||||
return num;
|
||||
}
|
||||
public static float CalculateHangingIndent(string rtf)
|
||||
private static string FixNumber(string num) => num == "" ? "0" : num;
|
||||
public static float CalculateHangingIndent(string rtf)
|
||||
{
|
||||
float chkW=0;
|
||||
IRtfDocument rtfDoc2 = RtfInterpreterTool.BuildDoc(rtf.Replace("\x05", @"\f1 \u9999? \f0 "));
|
||||
@@ -515,9 +413,8 @@ namespace Volian.Print.Library
|
||||
}
|
||||
public void DebugPdf(PdfContentByte cb, float left, float top)
|
||||
{
|
||||
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;
|
||||
cb.SaveState();
|
||||
cb.BeginLayer(debugLayer);
|
||||
ColumnText ct = new ColumnText(cb);
|
||||
@@ -531,9 +428,8 @@ namespace Volian.Print.Library
|
||||
cb.EndLayer();
|
||||
cb.RestoreState();
|
||||
}
|
||||
public virtual float YBottom
|
||||
{ get { return YOffset + Height;} }
|
||||
}
|
||||
public virtual float YBottom => YOffset + Height;
|
||||
}
|
||||
public partial class vlnPrintObjects : List<vlnPrintObject>
|
||||
{
|
||||
public float ToPdf(PdfContentByte cb, float yPageStart, ref float yTopMargin, ref float yBottomMargin)
|
||||
|
||||
Reference in New Issue
Block a user