This commit is contained in:
Kathy Ruffing 2010-06-23 12:50:45 +00:00
parent 5af2c31559
commit 9140d46c1d
5 changed files with 143 additions and 32 deletions

View File

@ -103,6 +103,29 @@ namespace Volian.Print.Library
DrawPdfDebug(cb, left, top, left + width, myColumnText.YLine, debugText,yDescent);
return myColumnText.YLine;
}
public static float FigureAt(PdfContentByte cb, iTextSharp.text.Image image, float x, float y, float width, float height, string debugText, float yBottommargin, bool hasBorder)
{
VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper;
PdfLayer textLayer = _MyPageHelper == null ? null : _MyPageHelper.TextLayer;
float left = x + Offset.X;
float top = y + Offset.Y;
float bottom = top - height;
image.ScaleAbsoluteWidth(width);
image.ScaleAbsoluteHeight(height);
image.SetAbsolutePosition(left, bottom);
if (textLayer != null) cb.BeginLayer(textLayer);
cb.AddImage(image);
if (hasBorder)
{
iTextSharp.text.Color boxColor = new iTextSharp.text.Color(System.Drawing.Color.Black); // (PrintOverride.OverrideBoxColor(System.Drawing.Color.Black));
cb.SetColorStroke(boxColor);
cb.SetLineWidth(.85F);
cb.Rectangle(left-1.5F, bottom-1.5F, width+3, height+3);
cb.Stroke();
}
if (textLayer != null) cb.EndLayer();
return bottom;
}
private static void DrawPdfDebug(PdfContentByte cb, float left, float top, float right, float bottom, string debugText, float yDescent)
{
VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper;

View File

@ -31,7 +31,7 @@ namespace Volian.Print.Library
public vlnBox(vlnParagraph paragraph)
{
}
const string BoxThin = "\x2510.\x2500.\x250c.\x2502. . .\x2518.\x2514. .\x2500. . ";
public const string BoxThin = "\x2510.\x2500.\x250c.\x2502. . .\x2518.\x2514. .\x2500. . ";
const string BoxThick = "\x2584.\x2584.\x2584.\x2588. . .\x2580.\x2580. .\x2580. . ";
public override float ToPdf(PdfContentByte cb, float yPageStart, float yTopMargin, float yBottomMargin)
{

View File

@ -92,7 +92,7 @@ namespace Volian.Print.Library
_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;
_Height = parent.Height * MyPageHelper.YMultiplier + (parent.MyItemInfo.IsFigure?SixLinesPerInch:0);
foreach (vlnPrintObject vpo in parent.PartsBelow)
{
if (vpo is vlnRNOSeparator) _YExtendLine = (vpo.Height + vpo.YOffset - (parent.Height + parent.YOffset)) * MyPageHelper.YMultiplier;

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Text.RegularExpressions;
using iTextSharp.text.pdf;
using iTextSharp.text;
using Itenso.Rtf;
@ -95,18 +96,18 @@ namespace Volian.Print.Library
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
if (MyItemInfo.IsFigure)
{
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);
}
yLocation -= (SixLinesPerInch * MyPageHelper.YMultiplier);
if (ImageText != null)
retval = DrawFigure(cb, yBottomMargin, yLocation);
else
retval = DrawText(cb, ref yPageStart, yTopMargin, yBottomMargin, ref yLocation);
}
else if (!MyItemInfo.IsStepSection) // Don't ouput the Step Section title
{
retval = DrawText(cb, ref yPageStart, yTopMargin, yBottomMargin, ref yLocation);
}
//Height = yLocation - retval;
if (_PartsLeft != null && _PartsLeft.Count > 0) yPageStart = PartsLeft.ToPdf(cb, yPageStart, yTopMargin, yBottomMargin);
@ -116,6 +117,41 @@ namespace Volian.Print.Library
return yPageStart;
}
private float DrawText(PdfContentByte cb, ref float yPageStart, float yTopMargin, float yBottomMargin, ref float yLocation)
{
float retval = yLocation;
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);
}
return retval;
}
private float DrawFigure(PdfContentByte cb, float yBottomMargin, float yLocation)
{
float retval = yLocation;
if (ImageText != null)
{
string[] vals = ImageText.Split("\n".ToCharArray());
ProcedureInfo proc = MyItemInfo.MyProcedure;
DocVersionInfo dvi = proc.ActiveParent as DocVersionInfo;
ROFstInfo rofst = dvi.DocVersionAssociations[0].MyROFst;
ROImageInfo roImage = ROImageInfo.GetByROFstID_FileName(rofst.ROFstID, vals[0]);
if (roImage != null)
{
iTextSharp.text.Image it_image = iTextSharp.text.Image.GetInstance(roImage.Content);
retval = Rtf2Pdf.FigureAt(cb, it_image, XOffset + _CharsToTwips, yLocation, Width * MyPageHelper.YMultiplier, Height * MyPageHelper.YMultiplier, PdfDebugText, yBottomMargin, !MyItemInfo.FormatStepData.Type.Contains("Borderless"));
}
}
return retval;
}
private string PdfDebugText
{
get
@ -312,30 +348,59 @@ namespace Volian.Print.Library
YOffset = yoff;
AddMacros(itemInfo, mytab);
if (mytab != null) mytab.YOffset = yoff;
Rtf = GetRtf(itemInfo);
if (itemInfo.IsTablePart)
if (itemInfo.IsFigure) // if a figure we've got to determine the size:
{
Width = GetTableWidth(cb, IParagraph);
vlnParagraph hls = MyParent;
bool aerTable = itemInfo.FormatStepData.Type.Contains("AER");
while (hls.MyParent != null)
if (itemInfo.MyContent.Text != null)
{
if (aerTable && hls.MyItemInfo.IsHigh) break;
hls = hls.MyParent;
ProcedureInfo proc = itemInfo.MyProcedure;
DocVersionInfo dvi = proc.ActiveParent as DocVersionInfo;
ROFstInfo rofst = dvi.DocVersionAssociations[0].MyROFst;
ROFSTLookup lookup = rofst.ROFSTLookup;
string linkInfoText = itemInfo.MyContent.Text.Replace(@"\v ", "");
Match m = Regex.Match(linkInfoText, @"(.*)[#]Link:([A-Za-z]*):(.*)");
string[] subs = m.Groups[3].Value.Split(" ".ToCharArray());
string roid = subs[1];
string val = lookup.GetRoValue(subs[1]);
if (val == null) val = lookup.GetRoValue(subs[1].Substring(0, 12));
if (val != null)
{
string[] vals = val.Split("\n".ToCharArray());
Width = Int32.Parse(vals[3], System.Globalization.NumberStyles.AllowHexSpecifier) * _CharsToTwips;
int lines = Int32.Parse(vals[2], System.Globalization.NumberStyles.AllowHexSpecifier);
Height = lines * SixLinesPerInch;
yoff += (Height + (2 * SixLinesPerInch));
string erMsg = null;
try
{
ROImageInfo roImage = ROImageInfo.GetByROFstID_FileName(rofst.ROFstID, vals[0]);
if (roImage != null)
ImageText = val;
else
erMsg = string.Format("Image {0} does not exist.", vals[0]);
}
catch (Exception ex)
{
erMsg = string.Format("Image {0} does not exist, error = {1}.", vals[0], ex.Message);
}
if (erMsg != null) Rtf = GetRtf(erMsg, itemInfo.ActiveFormat.PlantFormat.FormatData.Font);
}
CalculateXOffset(itemInfo, maxRNO, formatInfo);
}
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
else
{
yoff += Height;
yoff += AdjustForBlankLines();
}
if (itemInfo.IsFigure)
{
// get image from ro.
string myro = itemInfo.MyContent.Text;
Rtf = GetRtf(itemInfo);
if (itemInfo.IsTablePart)
{
Width = GetTableWidth(cb, IParagraph);
CalculateXOffset(itemInfo, maxRNO, formatInfo);
}
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);
@ -361,6 +426,23 @@ namespace Volian.Print.Library
}
YBottomMost = yoff;
}
private void CalculateXOffset(ItemInfo itemInfo, int maxRNO, FormatInfo formatInfo)
{
bool aerFigure = itemInfo.FormatStepData.Type.Contains("AER");
vlnParagraph hls1 = MyParent;
while (hls1.MyParent != null && !hls1.MyItemInfo.IsHigh) hls1 = hls1.MyParent;
XOffset = hls1.XOffset + hls1.Width / 2 - Width / 2; // xoffset if AER column
if (!aerFigure)
{
// adjust for RNO
int colR = int.Parse(formatInfo.PlantFormat.FormatData.SectData.StepSectionData.StepSectionLayoutData.ColRTable.Split(",".ToCharArray())[itemInfo.ColumnMode]);
XOffset += (colR * maxRNO) / 2;
XOffset -= (hls1.XOffset - (float)itemInfo.MyDocStyle.Layout.LeftMargin) / 2;
}
if (XOffset < (float)itemInfo.MyDocStyle.Layout.LeftMargin)
XOffsetBox = (float)itemInfo.MyDocStyle.Layout.LeftMargin;
}
private float AdjustForBlankLines()
{
int everyNLines = MyItemInfo.FormatStepData == null ? 1 : MyItemInfo.FormatStepData.StepLayoutData.EveryNLines ?? 1;

View File

@ -66,6 +66,12 @@ namespace Volian.Print.Library
}
}
}
private string _ImageText; // ro definition, value part of #Link in case of image/figure
public string ImageText
{
get { return _ImageText; }
set { _ImageText = value; }
}
private string _Rtf; // may become iTextSharp paragraph
public string Rtf
{