From 9140d46c1d773928b580d815a0d247d0b4b3b0b1 Mon Sep 17 00:00:00 2001 From: Kathy Date: Wed, 23 Jun 2010 12:50:45 +0000 Subject: [PATCH] --- PROMS/Volian.Print.Library/Rtf2Pdf.cs | 23 +++ PROMS/Volian.Print.Library/vlnBox.cs | 2 +- PROMS/Volian.Print.Library/vlnChangeBar.cs | 2 +- PROMS/Volian.Print.Library/vlnParagraph.cs | 142 +++++++++++++++---- PROMS/Volian.Print.Library/vlnPrintObject.cs | 6 + 5 files changed, 143 insertions(+), 32 deletions(-) diff --git a/PROMS/Volian.Print.Library/Rtf2Pdf.cs b/PROMS/Volian.Print.Library/Rtf2Pdf.cs index 9ceeb7c4..50fe54b4 100644 --- a/PROMS/Volian.Print.Library/Rtf2Pdf.cs +++ b/PROMS/Volian.Print.Library/Rtf2Pdf.cs @@ -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; diff --git a/PROMS/Volian.Print.Library/vlnBox.cs b/PROMS/Volian.Print.Library/vlnBox.cs index 61a7689d..5cc8ce4a 100644 --- a/PROMS/Volian.Print.Library/vlnBox.cs +++ b/PROMS/Volian.Print.Library/vlnBox.cs @@ -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) { diff --git a/PROMS/Volian.Print.Library/vlnChangeBar.cs b/PROMS/Volian.Print.Library/vlnChangeBar.cs index 164f1291..a0ce3ac9 100644 --- a/PROMS/Volian.Print.Library/vlnChangeBar.cs +++ b/PROMS/Volian.Print.Library/vlnChangeBar.cs @@ -92,7 +92,7 @@ namespace Volian.Print.Library _MyParent = parent; _Messages = new SortedDictionary(); // 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; diff --git a/PROMS/Volian.Print.Library/vlnParagraph.cs b/PROMS/Volian.Print.Library/vlnParagraph.cs index bfd4a569..29698b61 100644 --- a/PROMS/Volian.Print.Library/vlnParagraph.cs +++ b/PROMS/Volian.Print.Library/vlnParagraph.cs @@ -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; diff --git a/PROMS/Volian.Print.Library/vlnPrintObject.cs b/PROMS/Volian.Print.Library/vlnPrintObject.cs index 7fb0143c..e463f2aa 100644 --- a/PROMS/Volian.Print.Library/vlnPrintObject.cs +++ b/PROMS/Volian.Print.Library/vlnPrintObject.cs @@ -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 {