772 lines
31 KiB
C#
772 lines
31 KiB
C#
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<vlnParagraph>
|
|
{
|
|
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;
|
|
vlnBox box = null;
|
|
foreach (ItemInfo childItemInfo in itemInfoList)
|
|
{
|
|
int? bxIndx = childItemInfo.FormatStepData.StepLayoutData.STBoxindex;
|
|
if (bxIndex != bxIndx)
|
|
{
|
|
if (bxIndex == null) // First boxed step
|
|
{
|
|
box = new vlnBox();
|
|
box.MyBox = formatInfo.PlantFormat.FormatData.BoxList[(int)bxIndx];
|
|
box.YOffset = yoff;
|
|
yoff += 2 * vlnPrintObject.SixLinesPerInch;
|
|
}
|
|
else // Change Box Style
|
|
{
|
|
if (box != null) box.Height = yoff - box.YOffset; // new height, with children
|
|
box = new vlnBox();
|
|
box.MyBox = formatInfo.PlantFormat.FormatData.BoxList[(int)bxIndx];
|
|
box.YOffset = yoff;
|
|
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);
|
|
if (box != null && box.MyParent == null)
|
|
{
|
|
box.MyParent = para;
|
|
para.PartsContainer.Add(box);
|
|
}
|
|
Add(para);
|
|
yoff = para.YBottomMost;
|
|
}
|
|
if (bxIndex != null) // End Box Style
|
|
{
|
|
if (box != null) box.Height = yoff - box.YOffset; // new height, with children
|
|
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, yBottomMargin);
|
|
if (retval == 0) // problem occurred - paragraph was not able to be printed on page
|
|
{ // pagination logic needs to be fixed.
|
|
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, yBottomMargin);
|
|
}
|
|
}
|
|
//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);
|
|
DocStyle docstyle = MyItemInfo.MyDocStyle;
|
|
string myMsg = docstyle.Continue.Bottom.Message;
|
|
if (myMsg.IndexOf(@"%d") > -1)
|
|
myMsg = myMsg.Replace(@"%d", MyItemInfo.MyHLS.MyTab.CleanText.Trim());
|
|
float msg_yLocation = 0;
|
|
switch (docstyle.Continue.Bottom.Location)
|
|
{
|
|
case E_ContBottomLoc.EndOfText: // place continue string at end of text
|
|
case E_ContBottomLoc.BtwnTextAndBottom: // place continue string between end of text & bottom of page
|
|
Console.WriteLine("Not done yet");
|
|
break;
|
|
case E_ContBottomLoc.BottomOfPage: // place continue message at bottom of page
|
|
msg_yLocation = yBottomMargin; // +2 * _SixLinesPerInch; // 2 lines above bottom margin
|
|
break;
|
|
}
|
|
//float msg_yLocation = CalculateYOffset(yPageStart, yTopMargin);
|
|
MyPageHelper.BottomMessage = new vlnText(cb, this, myMsg, myMsg, docstyle.Layout.LeftMargin + XOffsetBox + docstyle.Continue.Bottom.Margin ?? 0, msg_yLocation, MyItemInfo.ActiveFormat.PlantFormat.FormatData.Font);
|
|
cb.PdfDocument.NewPage();
|
|
yPageStart = yTopMargin + YTopMost - 2 * SixLinesPerInch;
|
|
msg_yLocation = CalculateYOffset(yPageStart, yTopMargin);
|
|
myMsg = docstyle.Continue.Top.Message;
|
|
if (myMsg.IndexOf(@"%d") > -1)
|
|
myMsg = myMsg.Replace(@"%d", MyItemInfo.MyHLS.MyTab.CleanText.Trim());
|
|
MyPageHelper.TopMessage = new vlnText(cb, this, myMsg, myMsg, docstyle.Layout.LeftMargin + XOffsetBox + docstyle.Continue.Top.Margin ?? 0, yTopMargin + 0.1F, MyItemInfo.ActiveFormat.PlantFormat.FormatData.Font);
|
|
|
|
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);
|
|
if (MyItemInfo.IsHigh && MyItemInfo.NextItem == null) // last hls, add the 'end' message, if there is one
|
|
{
|
|
DocStyle docstyle = MyItemInfo.MyDocStyle;
|
|
string myMsg = (docstyle.End == null) ? null : docstyle.End.Message;
|
|
if (myMsg != null)
|
|
{
|
|
float msg_yLocation = yBottomMargin + SixLinesPerInch;
|
|
// use the 'flag' to position the message. Just implementing OHLP
|
|
if (docstyle.End.Flag >= 2)
|
|
{
|
|
msg_yLocation = yTopMargin - (float)(docstyle.End.Flag * SixLinesPerInch);
|
|
}
|
|
// center it. Just implementing OHLP
|
|
float wtpm = (float)docstyle.Layout.PageWidth - (float)docstyle.Layout.LeftMargin;
|
|
float centerpos = XOffsetBox + (float)docstyle.Layout.LeftMargin + (wtpm - (myMsg.Length * vlnPrintObject._CharsToTwips)) / 2;
|
|
MyPageHelper.BottomMessage = new vlnText(cb, this, myMsg, myMsg, centerpos, msg_yLocation, docstyle.End.Font);
|
|
}
|
|
}
|
|
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 == 832)
|
|
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<int> lProblemIDs = new List<int>(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, this, 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();
|
|
}
|
|
if (itemInfo.IsFigure)
|
|
{
|
|
// get image from ro.
|
|
string myro = itemInfo.MyContent.Text;
|
|
}
|
|
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<Macro> 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();
|
|
}
|
|
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);
|
|
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.Width;
|
|
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.Width;
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|