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 = 4.75F; 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) { // for grids, a y adjustment is made to match 16bit output, see the variable 'GridTopAdjust'. Take this // adjustment into account for the change bar. 6.5 positioned the change bar to match 16bit output. if (parent.MyItemInfo.MyContent.MyGrid != null) yoff -= 6.5F; 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 + (parent.MyItemInfo.IsFigure?SixLinesPerInch:0); foreach (vlnPrintObject vpo in parent.PartsBelow) { if (vpo is vlnRNOSeparator) { // see if any of children don't have changebar if ((vpo as vlnRNOSeparator).ExtendChangeBar) _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.Text == sep) && parent.MyItemInfo.MyPrevious != null && 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 = -3.75F; //0.5F; float xAdj = 3F; //cb.SetColorStroke(Color.GREEN); // TODO: Should default to black iTextSharp.text.Color changeBarColor = new iTextSharp.text.Color(PrintOverride.OverrideChangeBarColor(System.Drawing.Color.Black)); 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 + xAdj - 1.5F, YOffset - yAdj + 4); DebugPdf(cb, XOffset + xAdj - 1.5F, YChangeBarBottomExtend - yAdj - 1); 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 = Volian.Svg.Library.VolianPdf.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, MyParent.MyItemInfo.MyDocStyle.Layout.PageWidth); 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, "", yBottomMargin); lastMsg = vcbm.Message; } } } if (textLayer != null) cb.EndLayer(); cb.RestoreState(); return yPageStart; } } }