diff --git a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs index 28266eb6..42eeefee 100644 --- a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs +++ b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs @@ -11,14 +11,54 @@ using VEPROMS.CSLA.Library; namespace Volian.Print.Library { + public class VlnSvgPageHelper:SvgPageHelper { + //vlnParagraphs _MyParagraphs = new vlnParagraphs(null); + //public vlnParagraphs MyParagraphs + //{ + // get { return _MyParagraphs; } + // set { _MyParagraphs = value; } + //} + Dictionary _MyParagraphs = new Dictionary(); + public Dictionary MyParagraphs + { + get { return _MyParagraphs; } + set { _MyParagraphs = value; } + } + float _YMultiplier = 1; + public float YMultiplier + { + get { return _YMultiplier; } + set { _YMultiplier = value; } + } + public override void OnEndPage(PdfWriter writer, iTextSharp.text.Document document) + { + base.OnEndPage(writer, document); + DrawChangeBars(writer.DirectContent); + //DrawBackground(writer.DirectContentUnder); + //DrawPageList(writer.DirectContent); + //DrawWatermark(writer.DirectContentUnder); + //DrawZoomOMatic(writer.DirectContent); + //CurrentPageNumber++; + } + private void DrawChangeBars(PdfContentByte cb) + { + foreach (vlnChangeBar vcb in MyChangeBars) + { + // TODO: Pass in zeroes because topdf is inherited. + vcb.ToPdf(cb, 0, 0, 0); + } + _MyChangeBars = new List(); + } + #region SectionLevelData private ChangeBarDefinition _ChangeBarDefinition; - public ChangeBarDefinition ChangeBarDefinition + public ChangeBarDefinition ChangeBarDefinition { get { return _ChangeBarDefinition; } set { _ChangeBarDefinition = value; } } + #endregion private PdfLayer _TextLayer; public PdfLayer TextLayer { @@ -41,6 +81,15 @@ namespace Volian.Print.Library MySvg = BuildSvg(_MySection); } } + private int _MaxRNO; + public int MaxRNO + { + get + { + if (_MaxRNO == 0) _MaxRNO = _MySection.ColumnMode; + return _MaxRNO; + } + } private int _CurrentPageOf = 0; public int CurrentPageOf { @@ -59,6 +108,105 @@ namespace Volian.Print.Library get { return _RevDate; } set { _RevDate = value; } } + private List _MyChangeBars = new List(); + public List MyChangeBars + { + get { return _MyChangeBars; } + set { _MyChangeBars = value; } + } + public void AddChangeBar(vlnChangeBar vcb, string cbmess) + { + vlnChangeBar prevCB = null; + foreach (vlnChangeBar cb in MyChangeBars) + { + // only look at changebars in same column + if (cb.XOffset == vcb.XOffset) + { + // if the two change bars end at same location, set prevCB which will + // adjust the length (top position) of the change bar. This condition + // also flags that the change bar texts overlap. + if (cb.YChangeBarBottom == vcb.YChangeBarBottom) prevCB = cb; + + // continuous case, if changes bars overlap, adjust size and don't add new one to + // the MyChangeBars list. + if (MySection.ActiveFormat.PlantFormat.FormatData.ProcData.ChangeBarData.ContinuousChangeBars) + { + if (OverlapOrSpan(cb, vcb)) + { + if (prevCB == null) prevCB = cb; + else if (prevCB.YChangeBarBottom > cb.YChangeBarBottom) prevCB = cb; + } + } + } + } + // if this and the prevCB overlap, adjust yoffset/height/ybottom in the prevCB so that both change bars are + // included in this Dictionary item. A new vlnChangeBar is not added to the MyChangeBars list, the current + // one that overlaps with the new is adjusted. + if (prevCB != null) + { + // Bottom for both change bars is same, adjust top (YOffset) and height. + if (prevCB.YChangeBarBottom == vcb.YChangeBarBottom) + { + prevCB.YOffset = Math.Max(prevCB.YOffset, vcb.YOffset); + float yChangeBarBottomExtend = prevCB.YChangeBarBottomExtend; + prevCB.Height = Math.Max(prevCB.Height, vcb.Height); + prevCB.YExtendLine = prevCB.YChangeBarBottom - Math.Min(yChangeBarBottomExtend, vcb.YChangeBarBottomExtend); //Math.Max(prevCB.YExtendLine, vcb.YExtendLine); + // if a change bar message at this ychangebarbottom exists, see which message is used + if (cbmess != null && prevCB.Messages.ContainsKey(prevCB.YChangeBarBottom)) UpdateCbMessage(cbmess, prevCB, vcb.XOffset); + return; + } + // Bottom locations are not the same, but another change bar is not added, i.e. the + // length of the line is adjusted. + prevCB.YOffset = Math.Max(prevCB.YOffset, vcb.YOffset); + float yChangeBarBottomExtend1 = prevCB.YChangeBarBottomExtend; + prevCB.YChangeBarBottom = Math.Min(prevCB.YChangeBarBottom, vcb.YChangeBarBottom); + prevCB.YExtendLine = prevCB.YChangeBarBottom - Math.Min(yChangeBarBottomExtend1, vcb.YChangeBarBottomExtend); //Math.Max(prevCB.YExtendLine, vcb.YExtendLine); + // Two messages at this location, determine which one to use + if (cbmess != null && prevCB.Messages.ContainsKey(prevCB.YChangeBarBottom)) UpdateCbMessage(cbmess, prevCB, vcb.XOffset); + + // no message at this location, just add it. + else if (cbmess != null) + prevCB.Messages.Add(vcb.YChangeBarBottom, new vlnChangeBarMessage(vcb.MyParent.XOffset, cbmess)); + return; + } + + // There was no overlap, add a message if it exists, and then add the change bar to the MyChangeBars list. + if (cbmess != null) vcb.Messages.Add(vcb.YChangeBarBottom, new vlnChangeBarMessage(vcb.MyParent.XOffset, cbmess)); + MyChangeBars.Add(vcb); + } + + private static void UpdateCbMessage(string cbmess, vlnChangeBar prevCB, float xoff) + { + // If there are two messages at the same location, for example an AER change bar & and RNO + // change bar, and the messages have different text, see which change bar message should be + // added, i.e. use the one in 'rno', the greatest x value. + vlnChangeBarMessage tmp = prevCB.Messages[prevCB.YChangeBarBottom]; + if (cbmess != tmp.Message) + { + if (xoff > tmp.ParentX) + { + prevCB.Messages.Remove(prevCB.YChangeBarBottom); + prevCB.Messages.Add(prevCB.YChangeBarBottom, new vlnChangeBarMessage(xoff, cbmess)); + } + } + } + private bool OverlapOrSpan(vlnChangeBar cb, vlnChangeBar vcb) + { + if (cb.MyParent.MyItemInfo.MyHLS.ItemID != vcb.MyParent.MyItemInfo.MyHLS.ItemID) return false; + // cb.Yoffset is within range of vcb: + if (cb.YOffset <= vcb.YOffset && + cb.YOffset >= (vcb.YChangeBarBottomExtend - vlnPrintObject._SixLinesPerInch)) return true; + // cb.YChangeBarBottom is within range of vcb: + if ((cb.YChangeBarBottomExtend-vlnPrintObject._SixLinesPerInch) <= vcb.YOffset && + cb.YChangeBarBottomExtend >= (vcb.YChangeBarBottomExtend - vlnPrintObject._SixLinesPerInch)) return true; + // vcb.Yoffset is within range of cb: + if (vcb.YOffset <= cb.YOffset && + vcb.YOffset >= (cb.YChangeBarBottomExtend - vlnPrintObject._SixLinesPerInch)) return true; + // vcb.YChangeBarBottom is within range of cb: + if ((vcb.YChangeBarBottomExtend - vlnPrintObject._SixLinesPerInch) <= cb.YOffset && + vcb.YChangeBarBottomExtend >= (cb.YChangeBarBottomExtend - vlnPrintObject._SixLinesPerInch)) return true; + return false; + } public VlnSvgPageHelper(VEPROMS.CSLA.Library.SectionInfo mySection) { MySection = mySection; @@ -286,7 +434,7 @@ namespace Volian.Print.Library return ""; } } - public class ChangeBarDefinition + public class ChangeBarDefinition // anything that is section level should go in here. { private DocVersionConfig.PrintChangeBar _MyChangeBarType; public DocVersionConfig.PrintChangeBar MyChangeBarType @@ -306,18 +454,21 @@ namespace Volian.Print.Library get { return _MyChangeBarText; } set { _MyChangeBarText = value; } } - private string _MyChangeBarMessage; + private string _MyChangeBarMessage; // user defined change bar message from docconfig public string MyChangeBarMessage { get { return _MyChangeBarMessage; } set { _MyChangeBarMessage = value; } } - private int _MyChangeBarColumn; //TODO Should this be two dimensional array + private int _MyChangeBarColumn; // two dimensional array, if both on same side, values are = public int MyChangeBarColumn { get { return _MyChangeBarColumn; } set { _MyChangeBarColumn = value; } } + /* + * could have line thickness (set default from 16-bit), line color (set default as black), line style + */ public ChangeBarDefinition() { } @@ -326,7 +477,42 @@ namespace Volian.Print.Library _MyChangeBarType = myCBT; _MyChangeBarLoc = myCBL; _MyChangeBarText = myCBTxt; - _MyChangeBarMessage = myCBMsg; + } + public ChangeBarDefinition(DocVersionConfig docverConfig, FormatInfo formatInfo) + { + // if there is not overridden data on the docversion, prompt user... + ChangeBarData changeBarData = formatInfo.PlantFormat.FormatData.ProcData.ChangeBarData; + if (docverConfig == null || docverConfig.Print_ChangeBar == DocVersionConfig.PrintChangeBar.SelectBeforePrinting) + { + // use these for now, i.e. this is what user would have selected from dialog. + _MyChangeBarType = DocVersionConfig.PrintChangeBar.WithDefault; + _MyChangeBarLoc = DocVersionConfig.PrintChangeBarLoc.OutsideBox; + _MyChangeBarText = DocVersionConfig.PrintChangeBarText.None; + } + else + { + _MyChangeBarType = docverConfig.Print_ChangeBar; + _MyChangeBarLoc = docverConfig.Print_ChangeBarLoc; + _MyChangeBarText = docverConfig.Print_ChangeBarText; + } + if (_MyChangeBarType == DocVersionConfig.PrintChangeBar.WithDefault) // get data from format + { + _MyChangeBarText = changeBarData.ChangeBarMessage == "ChgID" ? DocVersionConfig.PrintChangeBarText.ChgID : + changeBarData.ChangeBarMessage == "DateAndChgID" ? DocVersionConfig.PrintChangeBarText.DateChgID : + changeBarData.ChangeBarMessage == "None" ? DocVersionConfig.PrintChangeBarText.None : + changeBarData.ChangeBarMessage == "RevNum" ? DocVersionConfig.PrintChangeBarText.RevNum : DocVersionConfig.PrintChangeBarText.UserDef; + } + if (_MyChangeBarType != DocVersionConfig.PrintChangeBar.Without) + { + // if the format has the absolutefixedchangecolumn format flag, then always use the fixedchangecolumn from the + // format, otherwise, use the default column based on the selected location, stored in the base format. + _MyChangeBarColumn = (changeBarData.AbsoluteFixedChangeColumn) ? + (int)changeBarData.FixedChangeColumn : + System.Convert.ToInt32(changeBarData.DefaultCBLoc.Split(" ".ToCharArray())[System.Convert.ToInt32(_MyChangeBarLoc)]); + if (_MyChangeBarText == DocVersionConfig.PrintChangeBarText.UserDef) + _MyChangeBarMessage = docverConfig.Print_UserCBMess1 + @"\n" + docverConfig.Print_UserCBMess2; + + } } } } diff --git a/PROMS/Volian.Print.Library/vlnBox.cs b/PROMS/Volian.Print.Library/vlnBox.cs new file mode 100644 index 00000000..48a22ce6 --- /dev/null +++ b/PROMS/Volian.Print.Library/vlnBox.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Drawing; +using iTextSharp.text.pdf; +using iTextSharp.text; +using VEPROMS.CSLA.Library; + + +namespace Volian.Print.Library +{ + public partial class vlnBox : vlnPrintObject + { + private int _LineType; /* how to represent?? */ + private System.Drawing.Color _Color; + public System.Drawing.Color Color + { + get { return _Color; } + set { _Color = value; } + } + public vlnBox(vlnParagraph paragraph/*, FormatBox box*/) + { + } + public override float ToPdf(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin) + { + return yPageStart; + } + } +} diff --git a/PROMS/Volian.Print.Library/vlnChangeBar.cs b/PROMS/Volian.Print.Library/vlnChangeBar.cs new file mode 100644 index 00000000..7ed8f414 --- /dev/null +++ b/PROMS/Volian.Print.Library/vlnChangeBar.cs @@ -0,0 +1,179 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Drawing; +using iTextSharp.text.pdf; +using iTextSharp.text; +using VEPROMS.CSLA.Library; + +namespace Volian.Print.Library +{ + public class vlnChangeBarMessage + { + private float _ParentX; + public float ParentX + { + get { return _ParentX; } + set { _ParentX = value; } + } + private string _Message; + public string Message + { + get { return _Message; } + set { _Message = value; } + } + private static int _UniqueMessageId = 0; + public static int UniqueMessageId + { + get { return vlnChangeBarMessage._UniqueMessageId++; } + set { vlnChangeBarMessage._UniqueMessageId = value; } + } + private int _MessageId = UniqueMessageId; + public int MessageId + { + get { return _MessageId; } + set { _MessageId = value; } + } + public vlnChangeBarMessage(float parentx, string msg) + { + _ParentX = parentx; + _Message = msg; + } + } + public partial class vlnChangeBar : vlnPrintObject + { + private bool _HasChangeBar; + public bool HasChangeBar + { + get { return _HasChangeBar; } + set { _HasChangeBar = value; } + } + protected float _YChangeBarBottom; + public float YChangeBarBottom + { + get + { + if (_YChangeBarBottom == 0F) _YChangeBarBottom = _YOffset - _Height; + return _YChangeBarBottom; + } + set + { + _YChangeBarBottom = value; + _Height = _YOffset - _YChangeBarBottom; + } + } + private SortedDictionary _Messages; + public SortedDictionary Messages + { + get { return _Messages; } + set { _Messages = value; } + } + private int _MessageAlignment; + public int MessageAlignment + { + get { return _MessageAlignment; } + set { _MessageAlignment = value; } + } + private float _YExtendLine = 0; + public float YExtendLine + { + get { return _YExtendLine; } + set {_YExtendLine = value; } + } + public float YChangeBarBottomExtend + { + get {return YChangeBarBottom - YExtendLine; } + } + public vlnChangeBar(PdfContentByte cb, vlnParagraph parent, float xoff, float yoff, int msgAlignment) + { + MyContentByte = cb; + _XOffset = xoff; + _YOffset = yoff; + _MyParent = parent; + _Messages = new SortedDictionary(); + // if there is an RNO separator, add the separator's height in too. + _Height = parent.Height * MyPageHelper.YMultiplier; + foreach (vlnPrintObject vpo in parent.PartsBelow) + { + if (vpo is vlnRNOSeparator) _YExtendLine = (vpo.Height + vpo.YOffset - (parent.Height + parent.YOffset)) * MyPageHelper.YMultiplier; + } + foreach (vlnPrintObject vph in parent.PartsAbove) + { + if (vph is vlnHeader) + { + string sep = parent.MyItemInfo.MyHeader.CleanText; + vlnHeader tmp = vph as vlnHeader; + // the separator must exist and the previous must have a change bar. + + if ((sep != "") && (tmp.HeaderText == sep) && parent.MyItemInfo.MyPrevious.HasChangeBar()) + { + vlnParagraph prev = MyPageHelper.MyParagraphs[parent.MyItemInfo.MyPrevious.ItemID]; + float delta = parent.YOffset - prev.YOffset; + _YOffset += delta; + _Height += delta; + } + + } + } + _MessageAlignment = msgAlignment; + } + public override string ToString() + { + return string.Format("vlnChangeBar: X={0} Y={1} H={2} B={3} ID={4}", XOffset, YOffset, Height, YChangeBarBottom, MyParent.MyItemInfo.ItemID); + } + public override float ToPdf(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin) + { + cb.SaveState(); + VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper; + PdfLayer textLayer = _MyPageHelper == null ? null : _MyPageHelper.TextLayer; + if (textLayer != null) cb.BeginLayer(textLayer); + float yAdj = 0.5F; + float xAdj = 3F; + //cb.SetColorStroke(Color.GREEN); + // TODO: Should default to black + iTextSharp.text.Color changeBarColor = new iTextSharp.text.Color(PrintOverride.OverrideTextColor(System.Drawing.Color.Green)); + cb.SetColorStroke(changeBarColor); + cb.SetLineWidth(.5F); + cb.MoveTo(XOffset + xAdj, YOffset - yAdj); // combination yStart and YOffset + cb.LineTo(XOffset + xAdj, YChangeBarBottomExtend - yAdj - 1); + cb.Stroke(); + DebugPdf(cb, XOffset + 5, YChangeBarBottomExtend - yAdj - 1); + DebugPdf(cb, XOffset + 5, YOffset - yAdj); + if (Messages != null) + { + // Loop through messages for this change bar. The first message is the bottom-most, which is always put out. + // Working up, if the current message is the same as the one below it, don't put it out. + string lastMsg = null; + foreach (KeyValuePair kvp in Messages) + { + float yBottom = (float)System.Convert.ToDouble(kvp.Key); + vlnChangeBarMessage vcbm = (vlnChangeBarMessage)kvp.Value; + if (lastMsg != vcbm.Message) + { + //If change bar is on left side, subtract off size of text & some constant number + // y is yoffset - size of paragraph + iTextSharp.text.Font iFont = Rtf2iTextSharp.GetFont(new System.Drawing.Font("Letter Gothic", 5.5F)); + + Chunk chk = new Chunk(vcbm.Message.IndexOf(@"\n") > -1 ? vcbm.Message.Substring(0, vcbm.Message.IndexOf(@"\n")) : vcbm.Message, iFont); + Paragraph myparagraph = new Paragraph(chk); + if (vcbm.Message.IndexOf(@"\n") > -1) + { + myparagraph.Add(Chunk.NEWLINE); + myparagraph.Add(new Chunk(vcbm.Message.Substring(vcbm.Message.IndexOf(@"\n") + 2, vcbm.Message.Length - vcbm.Message.IndexOf(@"\n") - 2), iFont)); + } + myparagraph.Alignment = MessageAlignment; + myparagraph.Leading = iFont.Size; + float w = vlnPrintObject.GetTableWidth(cb, myparagraph); + float h = vlnPrintObject.GetParagraphHeight(cb, myparagraph, w); + cb.SetColorFill(changeBarColor); + Rtf2Pdf.TextAt(cb, myparagraph, XOffset + xAdj - Rtf2Pdf.Offset.X + 3, yBottom + h - Rtf2Pdf.Offset.Y + 2.7F, w, h, ""); + lastMsg = vcbm.Message; + } + } + } + if (textLayer != null) cb.EndLayer(); + cb.RestoreState(); + return yPageStart; + } + } +} diff --git a/PROMS/Volian.Print.Library/vlnHeader.cs b/PROMS/Volian.Print.Library/vlnHeader.cs new file mode 100644 index 00000000..54154cda --- /dev/null +++ b/PROMS/Volian.Print.Library/vlnHeader.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Drawing; +using iTextSharp.text.pdf; +using iTextSharp.text; +using VEPROMS.CSLA.Library; + +namespace Volian.Print.Library +{ + public partial class vlnHeader : vlnPrintObject + { + public float HeaderWidth + { + get { return _WidthAdjust + (_CharsToTwips * HeaderText.Length); } + } + private string _HeaderText; + public string HeaderText + { + get { return _HeaderText; } + set { _HeaderText = value; } + } + private VE_Font _MyFont; + public VE_Font MyFont + { + get { return _MyFont; } + set { _MyFont = value; } + } + private ContentAlignment _ContentAlignment; + public ContentAlignment ContentAlignment + { + get { return _ContentAlignment; } + set { _ContentAlignment = value; } + } + public vlnHeader(vlnParagraph myParent, PdfContentByte cb, string origStr, string cleanStr, float xoffset, float yoffset, VE_Font vFont, System.Drawing.ContentAlignment ca) + { + MyParent = myParent; + MyContentByte = cb; + YOffset = yoffset; + Width = MyParent.Width; + HeaderText = cleanStr; + Rtf = GetRtf(origStr, vFont); + XOffset = xoffset; + MyFont = vFont; + ContentAlignment = ca; + } + public override float ToPdf(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin) + { + float yLocation = CalculateYOffset(yPageStart, yTopMargin); + Rtf2Pdf.TextAt(cb, IParagraph, XOffset, yLocation, HeaderWidth, 100, ""); + return yPageStart; + } + } +} diff --git a/PROMS/Volian.Print.Library/vlnMacro.cs b/PROMS/Volian.Print.Library/vlnMacro.cs new file mode 100644 index 00000000..ab53adbf --- /dev/null +++ b/PROMS/Volian.Print.Library/vlnMacro.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Drawing; +using iTextSharp.text.pdf; +using iTextSharp.text; +using VEPROMS.CSLA.Library; + +namespace Volian.Print.Library +{ + public partial class vlnMacro : vlnPrintObject + { + private string _MacroDef; + public string MacroDef + { + get { return _MacroDef; } + set { _MacroDef = value; } + } + public vlnMacro(float xoffset, float yoffset, string macroDef) + { + YOffset = yoffset; + XOffset = xoffset; + MacroDef = macroDef; + } + public override float ToPdf(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin) + { + MyContentByte = cb; + float yLocation = CalculateYOffset(yPageStart, yTopMargin); + // Adjust the starting point for the Macro if the LPI is 7 + if (MyPageHelper.YMultiplier != 1) yLocation += _SixLinesPerInch - _SevenLinesPerInch; + VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper; + PdfLayer textLayer = _MyPageHelper == null ? null : _MyPageHelper.TextLayer; + if (textLayer != null) cb.BeginLayer(textLayer); + MyContentByte = cb; + System.Drawing.Color push = PrintOverride.SvgColor; + PrintOverride.SvgColor = PrintOverride.TextColor == System.Drawing.Color.Empty ? System.Drawing.Color.Black : PrintOverride.TextColor; + if (MyPageHelper != null && MyPageHelper.MySvg != null) + MyPageHelper.MySvg.DrawMacro(MacroDef, XOffset, yLocation, cb); + PrintOverride.SvgColor = push; + if (textLayer != null) cb.EndLayer(); + return yPageStart; + } + } +} diff --git a/PROMS/Volian.Print.Library/vlnParagraph.cs b/PROMS/Volian.Print.Library/vlnParagraph.cs new file mode 100644 index 00000000..d413286b --- /dev/null +++ b/PROMS/Volian.Print.Library/vlnParagraph.cs @@ -0,0 +1,707 @@ +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; + +namespace Volian.Print.Library +{ + public partial class vlnParagraphs : List + { + private vlnParagraph _Parent; + public vlnParagraph Parent + { + get { return _Parent; } + set { _Parent = value; } + } + public vlnParagraphs(vlnParagraph parent) + { + _Parent = parent; + } + public float Add(PdfContentByte cb, ItemInfoList itemInfoList, float xoff, float yoff, float yoffRight, int rnoLevel, int maxRNO, FormatInfo formatInfo) + { + int? bxIndex = null; + foreach (ItemInfo childItemInfo in itemInfoList) + { + int? bxIndx = childItemInfo.FormatStepData.StepLayoutData.STBoxindex; + if (bxIndex != bxIndx) + { + if (bxIndex == null) // First boxed step + yoff += 2 * vlnPrintObject._SixLinesPerInch; + else // Change Box Style + yoff += 2 * vlnPrintObject._SixLinesPerInch; + bxIndex = bxIndx; + } + if (childItemInfo is SectionInfo) formatInfo = (childItemInfo as SectionInfo).LocalFormat ?? formatInfo; + if (rnoLevel < maxRNO && childItemInfo.RNOs != null) yoff = Math.Max(yoff, yoffRight); + vlnParagraph para = new vlnParagraph(Parent, cb, childItemInfo, xoff, yoff, rnoLevel, maxRNO, formatInfo); + Add(para); + yoff = para.YBottomMost; + } + if (bxIndex != null) // End Box Style + yoff += 2 * vlnPrintObject._SixLinesPerInch; + return yoff; + } + public float ToPdf(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin) + { + foreach (vlnParagraph child in this) + { + yPageStart = child.ToPdf(cb, yPageStart, yTopMargin, yBottomMargin); + } + return yPageStart; + } + } + public partial class vlnParagraph : vlnPrintObject + { + public float ParagraphToPdf(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin) + { + if (Processed) return yPageStart; + //if (!MyPageHelper.MyParagraphs.ContainsValue(this)) return yPageStart; + Processed = true; + //MyPageHelper.MyParagraphs.Remove(this.MyItemInfo.ItemID); + //Console.WriteLine("'{0}',{1},{2},{3},{4},{5},{6},{7},{8}", MyItemInfo.Path.Substring(_Prefix.Length).Trim(), + // cb.PdfWriter.CurrentPageNumber, yStart, YTop, yStart + YTop, yStart + YTop - _LastY, YTopMost, YSize, yPageStart); + //_LastY = yStart + YTop; + // 72 points per inchs. 504 is 7 inches wide. 3 1/2 inches wide: 252, 100); + if (_PartsAbove != null && _PartsAbove.Count > 0) yPageStart = PartsAbove.ToPdf(cb, yPageStart, yTopMargin, yBottomMargin); + float yLocation = CalculateYOffset(yPageStart, yTopMargin); + if (MyItemInfo.HasChangeBar()) MyPageHelper.AddChangeBar(DoChangeBar(cb, MyItemInfo, MyPageHelper, XOffset, yLocation, MyPageHelper.MaxRNO, MyItemInfo.ActiveFormat), cbMess); + + float retval = yLocation; + if (!MyItemInfo.IsStepSection) // Don't ouput the Step Section title + { + retval = Rtf2Pdf.TextAt(cb, IParagraph, XOffset, yLocation, Width, 100, PdfDebugText); + if (retval == 0) + { + cb.PdfDocument.NewPage(); + yPageStart = yTopMargin + YTop; + yLocation = yPageStart - YOffset; + //MyItemInfo.ItemID, YSize, yPageSize, yLocation + Console.WriteLine("-1,'Yes','Forced Pagination',{0},{1},,{3},'{4}'", MyItemInfo.ItemID, YSize, 0, yLocation, MyItemInfo.ShortPath); + retval = Rtf2Pdf.TextAt(cb, IParagraph, XOffset, yLocation, Width, 100, PdfDebugText); + } + } + //Height = yLocation - retval; + if (_PartsLeft != null && _PartsLeft.Count > 0) yPageStart = PartsLeft.ToPdf(cb, yPageStart, yTopMargin, yBottomMargin); + if (_PartsRight != null && _PartsRight.Count > 0) yPageStart = PartsRight.ToPdf(cb, yPageStart, yTopMargin, yBottomMargin); + if (_PartsBelow != null && _PartsBelow.Count > 0) yPageStart = PartsBelow.ToPdf(cb, yPageStart, yTopMargin, yBottomMargin); + if (_PartsContainer != null && _PartsContainer.Count > 0) yPageStart = PartsContainer.ToPdf(cb, yPageStart, yTopMargin, yBottomMargin); + return yPageStart; + } + private string PdfDebugText + { + get + { + return string.Format("DebugID = {0}, ID={1} Type={2} TypeName='{3}' EveryNLines= {4}", DebugId, MyItemInfo.ItemID, MyItemInfo.FormatStepType, MyItemInfo.FormatStepData.Type, MyItemInfo.FormatStepData.StepLayoutData.EveryNLines); + } + } + public override float ToPdf(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin) + { + //if (!MyPageHelper.MyParagraphs.Contains(this)) return yPageStart; + //MyPageHelper.MyParagraphs.Remove(this); + float yLocation = yPageStart - YTopMost; + int paginate = Paginate(yLocation, yTopMargin, yBottomMargin); + switch (paginate) + { + case 1: // Break on High Level Step + OutputOtherPageSteps(cb, YTopMost, yPageStart, yTopMargin, yBottomMargin); + cb.PdfDocument.NewPage(); + yPageStart = yTopMargin + YTopMost; + MyPageHelper.YMultiplier = 1; + break; + case 2: // Break within a Step + OutputOtherPageSteps(cb, YTopMost, yPageStart, yTopMargin, yBottomMargin); + cb.PdfDocument.NewPage(); + yPageStart = yTopMargin + YTopMost - 2 * _SixLinesPerInch; + MyPageHelper.YMultiplier = 1; + break; + case 3: // Break on High Level Step (SevenLinesPerInch) + OutputOtherPageSteps(cb, YTopMost, yPageStart, yTopMargin, yBottomMargin); + cb.PdfDocument.NewPage(); + yPageStart = yTopMargin + YTopMost; + MyPageHelper.YMultiplier = _SevenLinesPerInch / _SixLinesPerInch; + break; + } + yPageStart = ChildrenAbove.ToPdf(cb, yPageStart, yTopMargin, yBottomMargin); + yPageStart = ChildrenLeft.ToPdf(cb, yPageStart, yTopMargin, yBottomMargin); + yPageStart = ParagraphToPdf(cb, yPageStart, yTopMargin, yBottomMargin); + yPageStart = ChildrenRight.ToPdf(cb, yPageStart, yTopMargin, yBottomMargin); + yPageStart = ChildrenBelow.ToPdf(cb, yPageStart, yTopMargin, yBottomMargin); + return yPageStart; + } + + private void OutputOtherPageSteps(PdfContentByte cb, float YTopMost, float yPageStart, float yTopMargin, float yBottomMargin) + { + // Find any items remaining in MyPageHelper.MyParagraphs that should be printed on this page. + vlnParagraphs process = new vlnParagraphs(null); + foreach (vlnParagraph vPara in MyPageHelper.MyParagraphs.Values) + { + if (!vPara.Processed && ((vPara.YOffset + vPara.Height) < YTopMost)) + process.Add(vPara); + } + foreach (vlnParagraph vPara in process) + { + vPara.ParagraphToPdf(cb, yPageStart, yTopMargin, yBottomMargin); + } + } + + private int Paginate(float yLocation, float yTopMargin, float yBottomMargin) + { + float yPageSize = yTopMargin - yBottomMargin; + float yWithinMargins = CalculateYLocation(yLocation, yTopMargin) - yBottomMargin; + if (MyItemInfo.ItemID == 941) + Console.Write(",'Here'"); + if (MyItemInfo.IsStepSection) return 0; // Don't Paginate on a Step Section + float mySize = YSize * MyPageHelper.YMultiplier; + if (mySize <= yWithinMargins) + { + if (MyItemInfo.IsHigh) + Console.WriteLine("1,'No','HLS will fit on page',{0},{1},{2}, {3}, {4},'{5}'", MyItemInfo.ItemID, YSize, yPageSize, yWithinMargins, (int)(100 * yWithinMargins / yPageSize), MyItemInfo.ShortPath); + return 0; // Don't Paginate if there is enough room + } + if (MyItemInfo.IsRNOPart && MyParent.XOffset < XOffset) return 0; // Don't paginate on an RNO to the right + if (MyItemInfo.IsHigh) + { + if (YSize < yPageSize) // if the entire step can fit on one page, do a page break + { + Console.WriteLine("2,'Yes','HLS will fit on 1 Page',{0},{1},{2}, {3}, {4},'{5}'", MyItemInfo.ItemID, YSize, yPageSize, yWithinMargins, (int)(100 * yWithinMargins / yPageSize), MyItemInfo.ShortPath); + return 1; // Paginate on High Level Steps + } + else if (YSize < (yPageSize * _SixLinesPerInch / _SevenLinesPerInch)) + { + Console.WriteLine("6,'Yes','HLS will fit on 1 Page at 7 LPI',{0},{1},{2}, {3}, {4},'{5}'", MyItemInfo.ItemID, YSize, yPageSize, yWithinMargins, (int)(100 * yWithinMargins / yPageSize), MyItemInfo.ShortPath); + return 3; // High Level Step can fit at SevenLinesPerInch + } + else // The entire step cannot fit go ahead and kick to the next page + { + if (yWithinMargins > yPageSize / 2) + { + // If High level Step will not fit, kick to the next page + Console.WriteLine("3,'No','HLS will have to split anyway',{0},{1},{2}, {3}, {4},'{5}'", MyItemInfo.ItemID, YSize, yPageSize, yWithinMargins, (int)(100 * yWithinMargins / yPageSize), MyItemInfo.ShortPath); + return 0;// Otherwise stay on this page + } + Console.WriteLine("3,'Yes','HLS will have to split',{0},{1},{2}, {3}, {4},'{5}'", MyItemInfo.ItemID, YSize, yPageSize, yWithinMargins, (int)(100 * yWithinMargins / yPageSize), MyItemInfo.ShortPath); + return 1; // Paginate on High Level Steps + } + } + if (yWithinMargins > yPageSize / 2) + { + Console.WriteLine("4,'No','Not Half way down the page',{0},{1},{2}, {3}, {4},'{5}'", MyItemInfo.ItemID, YSize, yPageSize, yWithinMargins, (int)(100 * yWithinMargins / yPageSize), MyItemInfo.ShortPath); + return 0; // More than half way down the page + } + //if (ChildrenBelow.Count > 0 && ChildrenBelow[0].YSize < yWithinMargins) + // return 0; + Console.WriteLine("5,'Yes','At least half the page is filled',{0},{1},{2},{3}, {4},'{5}'", MyItemInfo.ItemID, YSize, yPageSize, yWithinMargins, (int)(100 * yWithinMargins / yPageSize), MyItemInfo.ShortPath); + return 2; + } + private int COL_WID_ADJ = 6; // adjusts for incorrect use of WidSTable when breaking a line (it breaks 6 chars too short) + public vlnParagraph(vlnParagraph parent, PdfContentByte cb, ItemInfo itemInfo, float xoff, float yoff, int rnoLevel, int maxRNO, FormatInfo formatInfo) + { + //int[] problemIDs = { 889 }; + //List lProblemIDs = new List(problemIDs); + //if (lProblemIDs.Contains(itemInfo.ItemID)) + // Console.WriteLine("Found Item {0}", itemInfo.ItemID); + MyParent = parent; + // The following code determines the last paragraph for an RNO + // MyTopRNO finds the Top paragraph for an RNO + if (itemInfo.IsInRNO) + { + if (rnoLevel <= maxRNO && itemInfo.IsRNOPart) // Not top level RNO + MyTopRNO = this; + else + MyTopRNO = MyParent.MyTopRNO; + MyTopRNO.LastRNO = this; + } + MyContentByte = cb; + MyPageHelper.MyParagraphs.Add(itemInfo.ItemID, this); + MyItemInfo = itemInfo; + XOffset = xoff; + YTopMost = YOffset = yoff; + vlnTab mytab = null; + if (itemInfo.MyTab != null && itemInfo.MyTab.Text != null && itemInfo.MyTab.Text != "") + { + mytab = new vlnTab(cb, itemInfo.MyTab.Text, itemInfo.MyTab.CleanText, XOffset, yoff, itemInfo.MyTab.MyFont); + PartsLeft.Add(mytab); + } + AdjustWidth(itemInfo, maxRNO, formatInfo, mytab); + AdjustXOffsetForTab(itemInfo, maxRNO, formatInfo, mytab); + if (itemInfo.Cautions != null) + { + //yoff += 2 * _SixLinesPerInch; + yoff = ChildrenAbove.Add(cb, itemInfo.Cautions, xoff, yoff, yoff, rnoLevel, maxRNO, formatInfo); + //yoff += 2 * _SixLinesPerInch; + } + if (itemInfo.Notes != null) + { + //yoff += 2 * _SixLinesPerInch; + yoff = ChildrenAbove.Add(cb, itemInfo.Notes, xoff, yoff, yoff, rnoLevel, maxRNO, formatInfo); + //yoff += 2 * _SixLinesPerInch; + } + YTop = yoff; + if (itemInfo.MyHeader != null && itemInfo.MyHeader.Text != null) + yoff += SetHeader(this, cb, itemInfo, formatInfo); + YOffset = yoff; + AddMacros(itemInfo, mytab); + if (mytab != null) mytab.YOffset = yoff; + Rtf = GetRtf(itemInfo); + if (itemInfo.IsTablePart) + { + Width = GetTableWidth(cb, IParagraph); + vlnParagraph hls = MyParent; + bool aerTable = itemInfo.FormatStepData.Type.Contains("AER"); + while (hls.MyParent != null) + { + if (aerTable && hls.MyItemInfo.IsHigh) break; + hls = hls.MyParent; + } + XOffset = hls.XOffset + hls.Width / 2 - Width / 2; + if (XOffset < (float)itemInfo.MyDocStyle.Layout.LeftMargin) + XOffsetBox = (float)itemInfo.MyDocStyle.Layout.LeftMargin; + } + if (!itemInfo.IsStepSection) // Don't add any lines for the Section Title + { + yoff += Height; + yoff += AdjustForBlankLines(); + } + float yOffRight = yoff; + float RnoOffset = ToInt(formatInfo.PlantFormat.FormatData.SectData.StepSectionData.StepSectionLayoutData.ColRTable, maxRNO); + if (rnoLevel < maxRNO && itemInfo.RNOs != null) yOffRight = ChildrenRight.Add(cb, itemInfo.RNOs, XOffset + RnoOffset, YTop, YTop, rnoLevel + 1, maxRNO, formatInfo); + // Need code to determine if the table will overlap the Right Column if it does then + // use YOffRight rather than yoff + if (itemInfo.Tables != null) yoff = ChildrenBelow.Add(cb, itemInfo.Tables, XOffset, yoff, yOffRight, rnoLevel, maxRNO, formatInfo); + if (itemInfo.Steps != null) yoff = ChildrenBelow.Add(cb, itemInfo.Steps, XOffset, yoff, yOffRight, rnoLevel, maxRNO, formatInfo); + if (itemInfo.Sections != null) yoff = ChildrenBelow.Add(cb, itemInfo.Sections, xoff, yoff, yoff, rnoLevel, maxRNO, formatInfo); + if (itemInfo.Procedures != null) yoff = ChildrenBelow.Add(cb, itemInfo.Procedures, xoff, yoff, yoff, rnoLevel, maxRNO, formatInfo); + if (rnoLevel >= maxRNO && itemInfo.RNOs != null) yoff = ChildrenBelow.Add(cb, itemInfo.RNOs, XOffset, yoff, yoff, rnoLevel + 1, maxRNO, formatInfo); + yoff = Math.Max(yoff, yOffRight); + // TODO - use RNOSepAfterAER flag too: + string tmpRnoSepStr = formatInfo.PlantFormat.FormatData.SectData.StepSectionData.StepSectionPrintData.RNOSepString; + if (rnoLevel < maxRNO && itemInfo.RNOs != null && tmpRnoSepStr != null) + { + float xsep = MyHighLevelParagraph.XOffset + RnoOffset; + vlnRNOSeparator myRnoSep = new vlnRNOSeparator(this, cb, tmpRnoSepStr, xsep, yoff, formatInfo.PlantFormat.FormatData.Font); + vlnParagraph rno = ChildrenRight[0]; + // TODO: May need to handle more than one RNO column for RNO Separator + rno.LastRNO.PartsBelow.Add(myRnoSep); + yoff += myRnoSep.Height + _SixLinesPerInch; + } + YBottomMost = yoff; + } + private float AdjustForBlankLines() + { + int everyNLines = MyItemInfo.FormatStepData == null ? 1 : MyItemInfo.FormatStepData.StepLayoutData.EveryNLines ?? 1; + if (MyItemInfo.Ordinal % everyNLines == 0 || MyItemInfo.NextItem == null) return _SixLinesPerInch; + return 0; + } + private void AddMacros(ItemInfo itemInfo, vlnTab mytab) + { + float y = YOffset; + float x = mytab == null ? XOffset : mytab.XOffset + mytab.TabOffset; + List myMacros = itemInfo.MyMacros; + if (myMacros != null) + { + foreach (Macro myMacro in myMacros) + { + PartsLeft.Add(new vlnMacro(x, y, myMacro.MacroDef)); + } + } + } + // HLP Change bar flags in format file: + // Locations: With Text, Outside Box, AER on Left RNO on Right, To The Left of Text + // Text: Date & Change ID, Revision Number, Change ID, None, Custom (use input data) + // Flag AERChgBarMsgRNOChgBarNoMsg and AERMsgRNONoMsg are NOT Used in 16-bit. + private string cbMess = null; + private vlnChangeBar DoChangeBar(PdfContentByte cb, ItemInfo itemInfo, VlnSvgPageHelper myPageHelper, float xoff, float yoff, int maxRNO, FormatInfo formatInfo) //, vlnChangeBar myCB) + { + // find column for the change bar based on format flags - this is code from 16-bit + // if AbsoluteFixedChangeColumn + // if FixedAERChangeColumn + // if col>ColsS+ColR+COL_WID+ADJ + // FixedChangeColumn + // else + // AERLeftChangeBarLocation() + // else + // FixedChangeColumn + // else + // ChangeBarLocation() + ChangeBarData cbd = formatInfo.PlantFormat.FormatData.ProcData.ChangeBarData; + int cols = formatInfo.PlantFormat.FormatData.SectData.StepSectionData.StepSectionLayoutData.ColS ?? 0; + int colr = ToInt(formatInfo.PlantFormat.FormatData.SectData.StepSectionData.StepSectionLayoutData.ColRTable, maxRNO); + float col = (cbd.AbsoluteFixedChangeColumn) ? + ((cbd.FixedAERChangeColumn ?? 0) > 0) ? + (xoff > (cols + colr + COL_WID_ADJ)) ? + cbd.FixedChangeColumn ?? 0 : AERLeftChangeBarLocation(formatInfo) : + cbd.FixedChangeColumn ?? 0 : ChangeBarLocation(xoff, this, formatInfo, maxRNO); + + if (myPageHelper.ChangeBarDefinition.MyChangeBarText == DocVersionConfig.PrintChangeBarText.ChgID) + cbMess = itemInfo.UserID; + else if (myPageHelper.ChangeBarDefinition.MyChangeBarText == DocVersionConfig.PrintChangeBarText.DateChgID) + { + string fmtDate = itemInfo.DTS.ToShortDateString(); + if (fmtDate.Length != 10) // need to add zeros + { + if (fmtDate.IndexOf("/") == 1) + fmtDate = "0" + fmtDate; + if (fmtDate.IndexOf("/", 3) == 1) + fmtDate = fmtDate.Substring(0, 3) + "0" + fmtDate.Substring(3, fmtDate.Length - 3); + } + cbMess = itemInfo.UserID + @"\n" + fmtDate; + } + else if (myPageHelper.ChangeBarDefinition.MyChangeBarText == DocVersionConfig.PrintChangeBarText.RevNum) + cbMess = myPageHelper.Rev; + else if (myPageHelper.ChangeBarDefinition.MyChangeBarText == DocVersionConfig.PrintChangeBarText.UserDef) + cbMess = myPageHelper.ChangeBarDefinition.MyChangeBarMessage; + + int msgAlign = Element.ALIGN_LEFT; + if (myPageHelper.ChangeBarDefinition.MyChangeBarLoc == DocVersionConfig.PrintChangeBarLoc.LeftOfText || + (myPageHelper.ChangeBarDefinition.MyChangeBarLoc == DocVersionConfig.PrintChangeBarLoc.AERleftRNOright && + !itemInfo.IsInRNO)) msgAlign = Element.ALIGN_RIGHT; + return new vlnChangeBar(cb, this, (float)itemInfo.MyDocStyle.Layout.LeftMargin + (col * _CharsToTwips), yoff, msgAlign); + } + + private int ChangeBarLocation(float c, vlnParagraph paragraph, FormatInfo formatInfo, int maxRNO) + { + int fixedChgCol = formatInfo.PlantFormat.FormatData.ProcData.ChangeBarData.FixedChangeColumn ?? 0; + int cols = formatInfo.PlantFormat.FormatData.SectData.StepSectionData.StepSectionLayoutData.ColS ?? 0; + int colr = ToInt(formatInfo.PlantFormat.FormatData.SectData.StepSectionData.StepSectionLayoutData.ColRTable, maxRNO); + if (fixedChgCol < -10 || fixedChgCol >= 0) + return ((fixedChgCol > 0) ? fixedChgCol : + (fixedChgCol == 0) ? (int)c + 1 : + (c > cols + colr + COL_WID_ADJ) ? -fixedChgCol : + AERLeftChangeBarLocation(formatInfo)); + else + return (fixedChgCol + (((c < cols + Width + colr) || TableTest() + || MyItemInfo.IsCaution || MyItemInfo.IsNote) ? 0 : cols + colr)); // || (GetColumnMode() == 0)) ? 0 : cols + colr)); + /* Change bars to left of text -- ColS+WidS+ColR is the end of RNO col*/ + } + /* + ** Centered tables whose width exceeds the end of the RNO column should + ** still have their change bars printed on the left. This procedure checks + ** to make sure the step is a table and that it is not an RNO. + */ + private bool TableTest() + { + return false; + //return ((s->Type == TABLE || s->Type == BORDERLESSTABLE) && + //!(strchr((char *)&s->dbseq[2],RNO_MARKER))); + } + private float GetBottomYoff(float bottomY) + { + foreach (vlnParagraph child in ChildrenBelow) + { + if (child.YOffset > bottomY) bottomY = child.YOffset; + bottomY = child.GetBottomYoff(bottomY); + } + return bottomY; + } + private int AERLeftChangeBarLocation(FormatInfo formatInfo) + { + // use -5 default unless it is format specified + int fixedAERChgCol = formatInfo.PlantFormat.FormatData.ProcData.ChangeBarData.FixedAERChangeColumn ?? 0; + return (fixedAERChgCol != 0) ? + (fixedAERChgCol > 100) ? + (fixedAERChgCol % 100) : -fixedAERChgCol : -5; + } + private StringBuilder _RtfSB = null; + + // return rtf and use for tab and other text + public string GetRtf(ItemInfo itemInfo) + { + _RtfSB = new StringBuilder(); + DisplayText vlntxt = new DisplayText(itemInfo, E_EditPrintMode.Print, E_ViewMode.View, true, E_FieldToEdit.StepText, false); + _RtfSB.Append(AddFontTable(vlntxt.TextFont.WindowsFont)); + _RtfSB.Append(vlntxt.StartText); + _RtfSB.Append("}"); + return _RtfSB.ToString(); + + //if (formatInfo.PlantFormat.FormatData.StepDataList[itemInfo.FormatStepType].Boxed) myParagraph.Parts.Add(new vlnBox(myParagraph)); + //Console.WriteLine("{0} {1} - {2}, {3}", itemInfo.MyTab.CleanText, itemInfo.MyContent.Text, xoff, yoff); + } + private float _XOffsetBox = -24; + public float XOffsetBox + { + get { return _XOffsetBox; } + set { _XOffsetBox = value; } + } + private float SetHeader(vlnParagraph para, PdfContentByte cb, ItemInfo itemInfo, FormatInfo formatInfo) + { + float xoff = (float)itemInfo.MyDocStyle.Layout.LeftMargin; + float hdrWidth = (itemInfo.MyHeader.CleanText == null) ? 0 : itemInfo.MyHeader.CleanText.Length * _CharsToTwips; // convert to twips + int typ = ((int)itemInfo.MyContent.Type) % 10000; + int? bxIndx = formatInfo.PlantFormat.FormatData.StepDataList[typ].StepLayoutData.STBoxindex; + if (itemInfo.MyHeader.Justify == System.Drawing.ContentAlignment.MiddleCenter) + { + if (bxIndx != null) + { + Box bx = formatInfo.PlantFormat.FormatData.BoxList[(int)bxIndx]; + if (bx.TabPos > 0) + xoff += (float)bx.TabPos; // xoff starts as left margin + else + { + xoff += (float)((bx.TxtStart + XOffsetBox + (bx.TxtWidth / 2)) - (hdrWidth / 2)); // xoff starts as left margin + } + } + else if (formatInfo.PlantFormat.FormatData.SectData.StepSectionData.StepSectionLayoutData.Separator.Location > 0) + { + // if there is a separator location, use it - 16bit code used the separator location as a divisor: + xoff = XOffset + AdjustToCharPosition((float)((para.Width - hdrWidth) / formatInfo.PlantFormat.FormatData.SectData.StepSectionData.StepSectionLayoutData.Separator.Location)); + } + else + xoff = XOffset + (para.Width / 2) + (hdrWidth / 2); // XOffset has left margin included + } + else + xoff = XOffset; // XOffset has left margin included + vlnHeader myHeader = new vlnHeader(this, cb, itemInfo.MyHeader.Text, itemInfo.MyHeader.CleanText.TrimStart(" ".ToCharArray()), xoff, YOffset, itemInfo.MyHeader.MyFont, itemInfo.MyHeader.Justify); + PartsAbove.Add(myHeader); + return myHeader.Height + _SixLinesPerInch; + } + private bool _Processed = false; + public bool Processed + { + get { return _Processed; } + set { _Processed = value; } + } + private vlnParagraph _LastRNO; + public vlnParagraph LastRNO + { + get { return _LastRNO; } + set { _LastRNO = value; } + } + private vlnParagraph _MyTopRNO; + public vlnParagraph MyTopRNO + { + get { return _MyTopRNO; } + set { _MyTopRNO = value; } + } + private static string _Prefix = ""; + public static string Prefix + { + get { return vlnParagraph._Prefix; } + set { vlnParagraph._Prefix = value; } + } + protected float _YBottomMost; // Bottom of the paragraph including the children + public float YBottomMost + { + get { return _YBottomMost; } + set { _YBottomMost = value; } + } + protected float _YTopMost; // Top of the paragraph including the children + public float YTopMost + { + get { return _YTopMost; } + set { _YTopMost = value; } + } + protected float _YTop; // Top of the paragraph including parts + public float YTop + { + get { return _YTop; } + set + { + vlnParagraph vp = this as vlnParagraph; + if (vp != null && vp.MyItemInfo != null && vp.MyItemInfo.ItemID == 55) Console.WriteLine("here"); + _YTop = value; + + } + } + public float YSize // How big this paragraph is with all of its children + { + get { return _YBottomMost - _YTopMost; } + } + private ItemInfo _MyItemInfo; + public ItemInfo MyItemInfo + { + get { return _MyItemInfo; } + set { _MyItemInfo = value; } + } + private vlnParagraph _MyHighLevelParagraph; + + public vlnParagraph MyHighLevelParagraph + { + get + { + if (_MyHighLevelParagraph == null) + { + _MyHighLevelParagraph = GetHighLevelParagraph(); + } + return _MyHighLevelParagraph; + } + } + private vlnParagraph GetHighLevelParagraph() + { + if (MyItemInfo.IsHigh) return this; + return MyParent.GetHighLevelParagraph(); + } + // Tab, Separator, ChangeBar, Box, Circle, Checkoff + private vlnPrintObjects _PartsAbove; + public vlnPrintObjects PartsAbove + { + get + { + if (_PartsAbove == null) _PartsAbove = new vlnPrintObjects(); + return _PartsAbove; + } + } + private vlnPrintObjects _PartsBelow; + public vlnPrintObjects PartsBelow + { + get + { + if (_PartsBelow == null) _PartsBelow = new vlnPrintObjects(); + return _PartsBelow; + } + } + private vlnPrintObjects _PartsRight; + public vlnPrintObjects PartsRight + { + get + { + if (_PartsRight == null) _PartsRight = new vlnPrintObjects(); + return _PartsRight; + } + } + private vlnPrintObjects _PartsLeft; + public vlnPrintObjects PartsLeft + { + get + { + if (_PartsLeft == null) _PartsLeft = new vlnPrintObjects(); + return _PartsLeft; + } + } + private vlnPrintObjects _PartsContainer; + public vlnPrintObjects PartsContainer + { + get + { + if (_PartsContainer == null) _PartsContainer = new vlnPrintObjects(); + return _PartsContainer; + } + } + private vlnParagraphs _ChildrenAbove; + public vlnParagraphs ChildrenAbove + { + get + { + if (_ChildrenAbove == null) _ChildrenAbove = new vlnParagraphs(this); + return _ChildrenAbove; + } + } + private vlnParagraphs _ChildrenBelow; + public vlnParagraphs ChildrenBelow + { + get + { + if (_ChildrenBelow == null) _ChildrenBelow = new vlnParagraphs(this); + return _ChildrenBelow; + } + } + private vlnParagraphs _ChildrenRight; + public vlnParagraphs ChildrenRight + { + get + { + if (_ChildrenRight == null) _ChildrenRight = new vlnParagraphs(this); + return _ChildrenRight; + } + } + private vlnParagraphs _ChildrenLeft; + public vlnParagraphs ChildrenLeft + { + get + { + if (_ChildrenLeft == null) _ChildrenLeft = new vlnParagraphs(this); + return _ChildrenLeft; + } + } + //public vlnParagraph(vlnParagraph myParent, ItemInfo myItemInfo, float xoff, float yoff, float width, string rtf, ChildLocation childRelation) + //{ + // MyParent = myParent; + // MyItemInfo = myItemInfo; + // XOffset = xoff; + // YOffset = yoff; + // Width = width; + // Rtf = rtf; + // switch (childRelation) + // { + // case ChildLocation.Below: + // myParent.ChildrenBelow.Add(this); + // break; + // case ChildLocation.Above: + // myParent.ChildrenAbove.Add(this); + // break; + // case ChildLocation.Right: + // myParent.ChildrenRight.Add(this); + // break; + // } + //} + + public void AdjustXOffsetForTab(ItemInfo itemInfo, int maxRNO, FormatInfo formatInfo, vlnTab myTab) + { + float tabWidth = (myTab == null) ? 0 : myTab.TabWidth; + int typ = ((int)itemInfo.MyContent.Type) % 10000; + int? bxIndx = formatInfo.PlantFormat.FormatData.StepDataList[typ].StepLayoutData.STBoxindex; + if (bxIndx != null) + { + Box bx = formatInfo.PlantFormat.FormatData.BoxList[(int)bxIndx]; + //XOffset += (float)bx.TxtStart + tabWidth + XOffsetBox; + XOffset = (float)itemInfo.MyDocStyle.Layout.LeftMargin + (float)bx.TxtStart + tabWidth + XOffsetBox; + if (myTab != null) myTab.XOffset = XOffset - tabWidth; + } + else if (itemInfo.IsHigh) + { + XOffset += tabWidth - myTab.TabAlign; + if (myTab != null) myTab.XOffset += tabWidth - myTab.TabAlign; + } + else if (itemInfo.IsRNOPart && !((ItemInfo)itemInfo.ActiveParent).IsHigh) + { + // don't adjust for rno + } + else if (MyParent != null) + { + XOffset += tabWidth - (myTab == null ? 0 : myTab.TabAlign); + if (myTab != null) myTab.XOffset += tabWidth - myTab.TabAlign; + } + } + public void AdjustWidth(ItemInfo itemInfo, int maxRNO, FormatInfo formatInfo, vlnTab myTab) + { + float tabWidth = (myTab == null) ? 0 : myTab.TabWidth; + int typ = ((int)itemInfo.MyContent.Type) % 10000; + int? bxIndx = formatInfo.PlantFormat.FormatData.StepDataList[typ].StepLayoutData.STBoxindex; + if (bxIndx != null) + { + Box bx = formatInfo.PlantFormat.FormatData.BoxList[(int)bxIndx]; + Width = _WidthAdjustBox + (float)bx.TxtWidth - tabWidth; + } + else if (itemInfo.IsHigh) + { + Width = _WidthAdjust + ToInt(formatInfo.PlantFormat.FormatData.SectData.StepSectionData.StepSectionLayoutData.WidSTablePrint, maxRNO); + } + else if (MyParent == null) + { + // 72 points / inch - 7 inches (about width of page) + Width = 72 * 7; + } + else if (itemInfo.IsRNOPart && !((ItemInfo)itemInfo.ActiveParent).IsHigh) + { + Width = MyParent.Width; + } + else if (itemInfo.IsTablePart) + { + Width = 72 * 7; // TODO: Need to determine the Width of the Table based upon the contents + } + else + { + Width = MyParent.Width - tabWidth + (myTab == null ? 0 : myTab.TabAlign); + } + } + } + + +} diff --git a/PROMS/Volian.Print.Library/vlnPrintObject.cs b/PROMS/Volian.Print.Library/vlnPrintObject.cs index 1416bd68..715ef97d 100644 --- a/PROMS/Volian.Print.Library/vlnPrintObject.cs +++ b/PROMS/Volian.Print.Library/vlnPrintObject.cs @@ -4,17 +4,36 @@ 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; namespace Volian.Print.Library { public abstract partial class vlnPrintObject { + // Used for debugging: + private static int _UniqueDebugId = 0; + public static int UniqueDebugId + { + 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. protected static float _WidthAdjustBox = 6; protected static float _CharsToTwips = 6; // assumes 12 char per inch internal static float _SixLinesPerInch = 12; // twips - protected static float _SevenLinesPerInch = 72F / 7F; + protected static float _SevenLinesPerInch = 10.1F;//72F / 7F; protected float _XOffset; public float XOffset @@ -28,6 +47,7 @@ namespace Volian.Print.Library get { return _YOffset; } set { _YOffset = value; } } + protected vlnParagraph _MyParent; public vlnParagraph MyParent { @@ -66,7 +86,7 @@ namespace Volian.Print.Library get { return _Width; } set { _Width = value; } } - private float _Height; + protected float _Height; public float Height { get @@ -75,6 +95,7 @@ namespace Volian.Print.Library _Height = GetParagraphHeight(MyContentByte, IParagraph, Width); return _Height; } + set { _Height = value; } } public static float GetParagraphHeight(PdfContentByte cb, Paragraph iParagraph, float width) { @@ -132,7 +153,7 @@ namespace Volian.Print.Library /// /// /// - public static int ToPrint(int value) + public static int ToInt(int value) { return value; } @@ -141,28 +162,28 @@ namespace Volian.Print.Library /// /// /// - public static int ToPrint(int? value) + public static int ToInt(int? value) { - return ToPrint((int)value); + return ToInt((int)value); } /// /// No conversion necessary: string twips -> int twips /// /// /// - public static int ToPrint(string value) + public static int ToInt(string value) { - return ToPrint(Convert.ToInt32(value)); + return ToInt(Convert.ToInt32(value)); } /// /// No conversion necessary: value from a list in a string, twips -> int twips /// /// /// - public static int ToPrint(string value, int i) + public static int ToInt(string value, int i) { string s = value.Split(",".ToCharArray())[i]; - return ToPrint(s); + return ToInt(s); } public float AdjustToCharPosition(float position) { @@ -170,10 +191,109 @@ namespace Volian.Print.Library iPosition = (iPosition / (int)_CharsToTwips) * (int)_CharsToTwips; return (float)iPosition; } + 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(vlntxt.StartText); + rtfSB.Append("}"); + return rtfSB.ToString(); + } + protected static string AddFontTable(System.Drawing.Font font) + { + StringBuilder rtfSB = new StringBuilder(); + StringBuilder sbbeg = new StringBuilder(); + StringBuilder sbend = new StringBuilder(); + if (font.Bold) + { + sbbeg.Append(@"\b"); + sbend.Append(@"\b0"); + } + if (font.Underline) + { + sbbeg.Append(@"\ul"); + sbend.Insert(0, @"\ulnone"); + } + if (font.Italic) + { + sbbeg.Append(@"\i"); + sbend.Insert(0, @"\i0"); + } + rtfSB.Append(@"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset2 " + font.FontFamily.Name + @";}"); //}\f0\fs" + this.Font.SizeInPoints * 2 + @" " + myDisplayTextElement.Text + @"}}"; + if (!FontIsFixed(font)) + rtfSB.Append(@"{\f1\fnil\fcharset0 Arial Unicode MS;}}{\colortbl ;\red255\green0\blue0;}"); + else + rtfSB.Append(@"{\f1\fnil\fcharset0 VESymbFix;}}{\colortbl ;\red255\green0\blue0;}"); + rtfSB.Append("\r\n"); + // use styles to construct rtf commands to insert into next line (where \b, etc is) + rtfSB.Append(@"\viewkind4\uc1\pard\sl-240\slmult0" + sbbeg.ToString() + @"\fs" + Convert.ToInt32(font.SizeInPoints * 2).ToString() + @" "); // \f0\fs" + this.Font.SizeInPoints * 2 + @" " + myDisplayTextElement.Text + @"}"; + return rtfSB.ToString(); + } + private static bool FontIsFixed(System.Drawing.Font font) + { + iTextSharp.text.Font iFont = Rtf2iTextSharp.GetFont(font); + float fW = iFont.BaseFont.GetWidthPointKerned("W", 12); + float fE = iFont.BaseFont.GetWidthPointKerned("!", 12); + return fW == fE; + } + protected static iTextSharp.text.Paragraph RtfToParagraph(string rtf) + { + IRtfDocument rtfDoc = RtfInterpreterTool.BuildDoc(rtf); + Rtf2iTextSharp rtf2IText = new Rtf2iTextSharp(rtfDoc); + iTextSharp.text.Paragraph para = rtf2IText.Convert(); + para.SetLeading(_SixLinesPerInch, 0); + return para; + } + public abstract float ToPdf(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin); + protected float CalculateYOffset(float yPageStart, float yTopMargin) + { + float yLocation = yPageStart - YOffset; + if (MyPageHelper.YMultiplier != 1) + { + yLocation = -1 + yTopMargin - (yTopMargin - yLocation) * MyPageHelper.YMultiplier; + if (Rtf != null) + IParagraph.Leading = _SevenLinesPerInch; + } + return yLocation; + } + protected float CalculateYLocation(float yLocation, float yTopMargin) + { + if (MyPageHelper.YMultiplier != 1) + yLocation = -1 + yTopMargin - (yTopMargin - yLocation) * MyPageHelper.YMultiplier; + return yLocation; + } + public void DebugPdf(PdfContentByte cb, float left, float top) + { + cb.SaveState(); + VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper; + PdfLayer debugLayer = _MyPageHelper == null ? null : _MyPageHelper.DebugLayer; + if (debugLayer != null) cb.BeginLayer(debugLayer); + ColumnText ct = new ColumnText(cb); + ct.SetSimpleColumn(left, top, left+50, top - 50); + iTextSharp.text.Font font = FontFactory.GetFont("Arial", 2); + Chunk chk = new Chunk(DebugId.ToString(), font); + Phrase ph = new Phrase(chk); + ct.AddElement(ph); + cb.SetColorFill(new iTextSharp.text.Color(System.Drawing.Color.CadetBlue)); + ct.Go(); + if (debugLayer != null) cb.EndLayer(); + cb.RestoreState(); + } } public partial class vlnPrintObjects : List { - }; + public float ToPdf(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin) + { + foreach (vlnPrintObject part in this) + { + yPageStart = part.ToPdf(cb, yPageStart, yTopMargin, yBottomMargin); + } + return yPageStart; + } + } + public enum PartLocation : int { None = 0, // Non-printable @@ -183,237 +303,6 @@ namespace Volian.Print.Library Left = 4, // Tabs, Checkoffs? (maybe part of tab) Container = 5 // Box }; - public partial class vlnParagraphs : List - { - private vlnParagraph _Parent; - public vlnParagraph Parent - { - get { return _Parent; } - set { _Parent = value; } - } - public vlnParagraphs(vlnParagraph parent) - { - _Parent = parent; - } - }; - public partial class vlnParagraph : vlnPrintObject - { - private static string _Prefix = ""; - public static string Prefix - { - get { return vlnParagraph._Prefix; } - set { vlnParagraph._Prefix = value; } - } - protected float _YBottomMost; // Bottom of the paragraph including the children - public float YBottomMost - { - get { return _YBottomMost; } - set { _YBottomMost = value; } - } - protected float _YTopMost; // Top of the paragraph including the children - public float YTopMost - { - get { return _YTopMost; } - set { _YTopMost = value; } - } - protected float _YTop; // Top of the paragraph including parts - public float YTop - { - get { return _YTop; } - set { _YTop = value; } - } - public float YSize // How big this paragraph is with all of its children - { - get { return _YBottomMost - _YTopMost; } - } - private ItemInfo _MyItemInfo; - public ItemInfo MyItemInfo - { - get { return _MyItemInfo; } - set { _MyItemInfo = value; } - } - private vlnParagraph _MyHighLevelParagraph; - - public vlnParagraph MyHighLevelParagraph - { - get - { - if (_MyHighLevelParagraph == null) - { - _MyHighLevelParagraph = GetHighLevelParagraph(); - } - return _MyHighLevelParagraph; - } - } - private vlnParagraph GetHighLevelParagraph() - { - if (MyItemInfo.IsHigh) return this; - return MyParent.GetHighLevelParagraph(); - } - // Tab, Separator, ChangeBar, Box, Circle, Checkoff - private vlnPrintObjects _PartsAbove; - public vlnPrintObjects PartsAbove - { - get - { - if (_PartsAbove == null) _PartsAbove = new vlnPrintObjects(); - return _PartsAbove; - } - } - private vlnPrintObjects _PartsBelow; - public vlnPrintObjects PartsBelow - { - get - { - if (_PartsBelow == null) _PartsBelow = new vlnPrintObjects(); - return _PartsBelow; - } - } - private vlnPrintObjects _PartsRight; - public vlnPrintObjects PartsRight - { - get - { - if (_PartsRight == null) _PartsRight = new vlnPrintObjects(); - return _PartsRight; - } - } - private vlnPrintObjects _PartsLeft; - public vlnPrintObjects PartsLeft - { - get - { - if (_PartsLeft == null) _PartsLeft = new vlnPrintObjects(); - return _PartsLeft; - } - } - private vlnPrintObjects _PartsContainer; - public vlnPrintObjects PartsContainer - { - get - { - if (_PartsContainer == null) _PartsContainer = new vlnPrintObjects(); - return _PartsContainer; - } - } - private vlnParagraphs _ChildrenAbove; - public vlnParagraphs ChildrenAbove - { - get - { - if (_ChildrenAbove == null) _ChildrenAbove = new vlnParagraphs(this); - return _ChildrenAbove; - } - } - private vlnParagraphs _ChildrenBelow; - public vlnParagraphs ChildrenBelow - { - get - { - if (_ChildrenBelow == null) _ChildrenBelow = new vlnParagraphs(this); - return _ChildrenBelow; - } - } - private vlnParagraphs _ChildrenRight; - public vlnParagraphs ChildrenRight - { - get - { - if (_ChildrenRight == null) _ChildrenRight = new vlnParagraphs(this); - return _ChildrenRight; - } - } - private vlnParagraphs _ChildrenLeft; - public vlnParagraphs ChildrenLeft - { - get - { - if (_ChildrenLeft == null) _ChildrenLeft = new vlnParagraphs(this); - return _ChildrenLeft; - } - } - //public vlnParagraph(vlnParagraph myParent, ItemInfo myItemInfo, float xoff, float yoff, float width, string rtf, ChildLocation childRelation) - //{ - // MyParent = myParent; - // MyItemInfo = myItemInfo; - // XOffset = xoff; - // YOffset = yoff; - // Width = width; - // Rtf = rtf; - // switch (childRelation) - // { - // case ChildLocation.Below: - // myParent.ChildrenBelow.Add(this); - // break; - // case ChildLocation.Above: - // myParent.ChildrenAbove.Add(this); - // break; - // case ChildLocation.Right: - // myParent.ChildrenRight.Add(this); - // break; - // } - //} - - public void AdjustXOffsetForTab(ItemInfo itemInfo, int maxRNO, FormatInfo formatInfo, vlnTab myTab) - { - float tabWidth = (myTab == null) ? 0 : myTab.TabWidth; - int typ = ((int)itemInfo.MyContent.Type) % 10000; - int? bxIndx = formatInfo.PlantFormat.FormatData.StepDataList[typ].StepLayoutData.STBoxindex; - if (bxIndx != null) - { - Box bx = formatInfo.PlantFormat.FormatData.BoxList[(int)bxIndx]; - //XOffset += (float)bx.TxtStart + tabWidth + XOffsetBox; - XOffset = (float)itemInfo.MyDocStyle.Layout.LeftMargin + (float)bx.TxtStart + tabWidth + XOffsetBox; - if (myTab!=null)myTab.XOffset = XOffset - tabWidth; - } - else if (itemInfo.IsHigh) - { - XOffset += tabWidth - myTab.TabAlign; - if (myTab != null) myTab.XOffset += tabWidth - myTab.TabAlign; - } - else if (itemInfo.IsRNOPart && !((ItemInfo)itemInfo.ActiveParent).IsHigh) - { - // don't adjust for rno - } - else if (MyParent != null) - { - XOffset += tabWidth - (myTab == null ? 0 : myTab.TabAlign); - if (myTab != null) myTab.XOffset += tabWidth - myTab.TabAlign; - } - } - public void AdjustWidth(ItemInfo itemInfo, int maxRNO, FormatInfo formatInfo, vlnTab myTab) - { - float tabWidth = (myTab == null) ? 0 : myTab.TabWidth; - int typ = ((int)itemInfo.MyContent.Type) % 10000; - int? bxIndx = formatInfo.PlantFormat.FormatData.StepDataList[typ].StepLayoutData.STBoxindex; - if (bxIndx != null) - { - Box bx = formatInfo.PlantFormat.FormatData.BoxList[(int)bxIndx]; - Width = _WidthAdjustBox + (float)bx.TxtWidth - tabWidth; - } - else if (itemInfo.IsHigh) - { - Width = _WidthAdjust + ToPrint(formatInfo.PlantFormat.FormatData.SectData.StepSectionData.StepSectionLayoutData.WidSTablePrint, maxRNO); - } - else if (MyParent == null) - { - // 72 points / inch - 7 inches (about width of page) - Width = 72 * 7; - } - else if (itemInfo.IsRNOPart && !((ItemInfo)itemInfo.ActiveParent).IsHigh) - { - Width = MyParent.Width; - } - else if (itemInfo.IsTablePart) - { - Width = 72*7; // TODO: Need to determine the Width of the Table based upon the contents - } - else - { - Width = MyParent.Width - tabWidth + (myTab == null ? 0 : myTab.TabAlign); - } - } - } public enum ChildLocation : int { None = 0, @@ -422,129 +311,5 @@ namespace Volian.Print.Library Right = 3, // RNO Left = 4 } - public partial class vlnTab : vlnPrintObject - { - public float TabWidth - { - get { return _CharsToTwips * TabText.Length; } - } - private float? _TabAlign; - /// - /// Used to Align Tabs for numeric tabs that can go to 2 digits - /// - public float TabAlign // Offset to Last printable character - { - get - { - if (_TabAlign == null) - { - _TabAlign = 0; - if (_TabText != null) - { - while (_TabText[(int)_TabAlign] == ' ') - _TabAlign++; - if ("0123456789".Contains(_TabText[(int)_TabAlign].ToString())) - { - while ("0123456789".Contains(_TabText[(int)_TabAlign].ToString())) - _TabAlign++; - _TabAlign--; - } - } - } - return (float)_TabAlign * _CharsToTwips; - } - } - private float? _TabOffset; - public float TabOffset // Offset to first printable character - { - get - { - if (_TabOffset == null) - { - _TabOffset = 0; - if(_TabText != null) - while(_TabText[(int)_TabOffset]==' ') - _TabOffset ++; - } - return (float)_TabOffset * _CharsToTwips; - } - } - private string _TabText; - public string TabText - { - get { return _TabText; } - set { _TabText = value; } - } - private VE_Font _MyFont; - public VE_Font MyFont - { - get { return _MyFont; } - set { _MyFont = value; } - } - } - public partial class vlnHeader : vlnPrintObject - { - public float HeaderWidth - { - get { return _WidthAdjust + (_CharsToTwips * HeaderText.Length); } - } - private string _HeaderText; - public string HeaderText - { - get { return _HeaderText; } - set { _HeaderText = value; } - } - private VE_Font _MyFont; - public VE_Font MyFont - { - get { return _MyFont; } - set { _MyFont = value; } - } - private ContentAlignment _ContentAlignment; - public ContentAlignment ContentAlignment - { - get { return _ContentAlignment; } - set { _ContentAlignment = value; } - } - } - public partial class vlnBox : vlnPrintObject - { - private int _LineType; /* how to represent?? */ - private System.Drawing.Color _Color; - public System.Drawing.Color Color - { - get { return _Color; } - set { _Color = value; } - } - public vlnBox(vlnParagraph paragraph/*, FormatBox box*/) - { - } - } - public partial class vlnChangeBar : vlnPrintObject - { - public vlnChangeBar(vlnParagraph parent, float xoff, float yoff) - { - _XOffset = xoff; - _YOffset = yoff; - _MyParent = parent; - } - } - public partial class vlnRNOSeparator : vlnPrintObject - { - private VE_Font _MyFont; - public VE_Font MyFont - { - get { return _MyFont; } - set { _MyFont = value; } - } - } - public partial class vlnMacro : vlnPrintObject - { - private string _MacroDef; - public string MacroDef - { - get { return _MacroDef; } - set { _MacroDef = value; } - } - } + } diff --git a/PROMS/Volian.Print.Library/vlnRNOSeparator.cs b/PROMS/Volian.Print.Library/vlnRNOSeparator.cs new file mode 100644 index 00000000..ca8f1d97 --- /dev/null +++ b/PROMS/Volian.Print.Library/vlnRNOSeparator.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Drawing; +using iTextSharp.text.pdf; +using iTextSharp.text; +using VEPROMS.CSLA.Library; + +namespace Volian.Print.Library +{ + public partial class vlnRNOSeparator : vlnPrintObject + { + private VE_Font _MyFont; + public VE_Font MyFont + { + get { return _MyFont; } + set { _MyFont = value; } + } + /* if flag set and separator defined then output separator */ + /*if separator is a control-A use RNOSepLine*/ + public vlnRNOSeparator(vlnParagraph parent, PdfContentByte cb, string sepStr, float xoffset, float yoffset, VE_Font vFont) + { + YOffset = yoffset; + XOffset = xoffset; + _MyParent = parent; + if (sepStr != null) + Rtf = GetRtf(sepStr, vFont); + else + Rtf = "--------------------------"; //TODO - What should this be: is this Ctrl-A? + MyFont = vFont; + Width = sepStr.Length * _CharsToTwips + _WidthAdjust; + } + public override float ToPdf(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin) + { + MyContentByte = cb; + float yLocation = CalculateYOffset(yPageStart, yTopMargin); + Rtf2Pdf.TextAt(cb, IParagraph, XOffset, yLocation, Width, 100, ""); + return yPageStart; + } + } +} diff --git a/PROMS/Volian.Print.Library/vlnTab.cs b/PROMS/Volian.Print.Library/vlnTab.cs new file mode 100644 index 00000000..15d639ec --- /dev/null +++ b/PROMS/Volian.Print.Library/vlnTab.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Drawing; +using iTextSharp.text.pdf; +using iTextSharp.text; +using VEPROMS.CSLA.Library; + +namespace Volian.Print.Library +{ + public partial class vlnTab : vlnPrintObject + { + public float TabWidth + { + get { return _CharsToTwips * TabText.Length; } + } + private float? _TabAlign; + /// + /// Used to Align Tabs for numeric tabs that can go to 2 digits + /// + public float TabAlign // Offset to Last printable character + { + get + { + if (_TabAlign == null) + { + _TabAlign = 0; + if (_TabText != null) + { + while (_TabText[(int)_TabAlign] == ' ') + _TabAlign++; + if ("0123456789".Contains(_TabText[(int)_TabAlign].ToString())) + { + while ("0123456789".Contains(_TabText[(int)_TabAlign].ToString())) + _TabAlign++; + _TabAlign--; + } + } + } + return (float)_TabAlign * _CharsToTwips; + } + } + private float? _TabOffset; + public float TabOffset // Offset to first printable character + { + get + { + if (_TabOffset == null) + { + _TabOffset = 0; + if (_TabText != null) + while (_TabText[(int)_TabOffset] == ' ') + _TabOffset++; + } + return (float)_TabOffset * _CharsToTwips; + } + } + private string _TabText; + public string TabText + { + get { return _TabText; } + set { _TabText = value; } + } + private VE_Font _MyFont; + public VE_Font MyFont + { + get { return _MyFont; } + set { _MyFont = value; } + } + public vlnTab(PdfContentByte cb, string origTab, string cleanTab, float xoffset, float yoffset, VE_Font vFont) + { + MyContentByte = cb; + YOffset = yoffset; + TabText = cleanTab; + Rtf = GetRtf(origTab, vFont); + XOffset = xoffset - TabWidth; + MyFont = vFont; + } + public override float ToPdf(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin) + { + float yLocation = CalculateYOffset(yPageStart, yTopMargin); + Rtf2Pdf.TextAt(cb, IParagraph, XOffset, yLocation, TabWidth, 100, ""); + return yPageStart; + } + } +}