This commit is contained in:
179
PROMS/Volian.Print.Library/vlnChangeBar.cs
Normal file
179
PROMS/Volian.Print.Library/vlnChangeBar.cs
Normal file
@@ -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<float, vlnChangeBarMessage> _Messages;
|
||||
public SortedDictionary<float, vlnChangeBarMessage> 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<float, vlnChangeBarMessage>();
|
||||
// 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<float, vlnChangeBarMessage> 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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user