From cb355b71aaaea209a7d9f74827e1b198522a9f13 Mon Sep 17 00:00:00 2001 From: Rich Date: Wed, 8 Oct 2014 20:13:15 +0000 Subject: [PATCH] Command Line switch to skip ReplaceWords function (Edit and Print) Added Hanging Indent Logic for Grids. --- PROMS/Volian.Controls.Library/DisplayText.cs | 19 ++++++++++ PROMS/Volian.Print.Library/Grid2Pdf.cs | 37 ++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/PROMS/Volian.Controls.Library/DisplayText.cs b/PROMS/Volian.Controls.Library/DisplayText.cs index 86fc511c..61860bbd 100644 --- a/PROMS/Volian.Controls.Library/DisplayText.cs +++ b/PROMS/Volian.Controls.Library/DisplayText.cs @@ -1706,8 +1706,27 @@ namespace Volian.Controls.Library //} #endregion private Dictionary dicReplaceRegex = new Dictionary(); + private static bool? _ProcessReplaceWords; + public static bool ProcessReplaceWords + { + get + { + if (_ProcessReplaceWords == null) + { + string[] parameters = System.Environment.CommandLine.Split(" ".ToCharArray()); + _ProcessReplaceWords = true; + foreach (string parameter in parameters) + { + if (parameter.ToUpper() == "/NRW") + _ProcessReplaceWords = false; + } + } + return (bool) _ProcessReplaceWords; + } + } private string DoReplaceWords2(string Text) { + if(!ProcessReplaceWords) return Text; if (_MyItemInfo.MyContent.Type < 20000) return Text; // for now only replace in steps. FoundMatches myMatches = new FoundMatches(Text,_MyItemInfo.FormatStepData.Font,_MyItemInfo); // Exclude Link Text from Replace Word process diff --git a/PROMS/Volian.Print.Library/Grid2Pdf.cs b/PROMS/Volian.Print.Library/Grid2Pdf.cs index facff77e..4c88caa8 100644 --- a/PROMS/Volian.Print.Library/Grid2Pdf.cs +++ b/PROMS/Volian.Print.Library/Grid2Pdf.cs @@ -9,6 +9,7 @@ using Itenso.Rtf.Interpreter; using Itenso.Rtf.Support; using Volian.Print.Library; using Volian.Controls.Library; +using iTextSharp.text; using iTextSharp.text.pdf; @@ -212,6 +213,20 @@ namespace Volian.Print.Library str = PreProcessRTF(w, str); iTextSharp.text.Paragraph myPara = RtfToParagraph(str); myColumnText1.SetSimpleColumn(0, 0, w - 2, MyContentByte.PdfDocument.PageSize.Top); // Padding = 4 + if (str.Contains(@"\'05")) + { + // if there is a hanging indent, the iTextSharp paragraph properties must be set + // to print the indent. Replace the indent 'token' with a non-used symbol, this will + // create a chunk with that symbol. Then loop through all of the chunks until we find + // this symbol, adding up the widths to that point. This width is the value that + // needs to be used to set the indent. + // Notes: + // A hard return will reset the chkW (indent width) back to zero. + // We jump out of the processing loop after the first indent token is found and ignor any other ones + float chkW = CalculateHangingIndent(str); + myPara.IndentationLeft = chkW; + myPara.FirstLineIndent = -chkW; + } // RHM 20120925 - Line spacing should be 6 lines per inch. In order to get a valid value // for TotalLeading you have to set MultipliedLeading first: @@ -234,6 +249,28 @@ namespace Volian.Print.Library } } } + public static float CalculateHangingIndent(string rtf) + { + float chkW = 0; + IRtfDocument rtfDoc2 = RtfInterpreterTool.BuildDoc(rtf.Replace(@"\'05", @"\f1 \u9999? \f0 ")); + Rtf2iTextSharp rtf2IText2 = new Rtf2iTextSharp(rtfDoc2); + iTextSharp.text.Paragraph para2 = rtf2IText2.Convert(); + foreach (Chunk chk in para2.Chunks) + { + if (chk.Content[0] == 9999) break; + if (chk.Content.Contains("\u270f")) + { + int i = chk.Content.IndexOf('\u270F'); + int n = chk.Content.Length; + chkW += chk.GetWidthPoint() * i / (n - i); + break; + } + if (chk.Content.Contains("\n")) chkW = 0; //hard return - reset chkW (indent start) + chkW += chk.GetWidthPoint(); + } + return chkW; + } + private static StepRTB _StatRTB = new StepRTB(); private string PreProcessRTF(float w, string str) {