From 922104f9830df7348909be1654264ffde924e974 Mon Sep 17 00:00:00 2001 From: Kathy Date: Tue, 19 Apr 2011 14:15:55 +0000 Subject: [PATCH] --- .../Volian.Print.Library/VlnSvgPageHelper.cs | 94 ++++++++++++++++--- 1 file changed, 80 insertions(+), 14 deletions(-) diff --git a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs index d21e824b..7cc210e0 100644 --- a/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs +++ b/PROMS/Volian.Print.Library/VlnSvgPageHelper.cs @@ -478,10 +478,10 @@ namespace Volian.Print.Library //mySvg.SetValidWaterMark(token, _Watermark); // Need logic to limit watermark to tokens. break; case "{PROCTITLE}": - SplitTitle(svgGroup, pageItem, section.MyProcedure.DisplayText, (int)section.ActiveFormat.PlantFormat.FormatData.ProcData.TitleLength); + SplitTitle(svgGroup, pageItem, section.MyProcedure.MyContent.Text, (int)section.ActiveFormat.PlantFormat.FormatData.ProcData.TitleLength); break; case "{EOPNUM}": - svgGroup.Add(PageItemToSvgText(pageItem, section.MyProcedure.DisplayNumber)); + svgGroup.Add(PageItemToSvgText(pageItem, section.MyProcedure.MyContent.Number)); break; case "{SECTIONLEVELTITLE}": SplitTitle(svgGroup, pageItem, section.DisplayText, section.ActiveFormat.PlantFormat.FormatData.SectData.SectionTitleLength); @@ -539,7 +539,7 @@ namespace Volian.Print.Library private void SplitTitle(SvgGroup svgGroup, VEPROMS.CSLA.Library.PageItem pageItem, string title, int? len) { // TODO: need to calculate len in either points or inches and use the font from the pageItem to determine the number of characters - if (len == null || title.Length < len) + if (len == null || ItemInfo.StripRtfFormatting(title).Length < len) { svgGroup.Add(PageItemToSvgText(pageItem, title)); return; @@ -554,21 +554,87 @@ namespace Volian.Print.Library yOffset += 12; } } - private List SplitText(string title, int len) + private List SplitText(string text, int len) { - List retval = new List(); - int strlen = title.Length; + List results = new List(); + int width = 0; int start = 0; - while ((strlen - start) > len) + int lastspace = 0; + string rtfprefix = ""; + string nextprefix = ""; + for (int indx = 0; indx < text.Length; indx++) { - int width = FindWidth(title, start, len); - retval.Add(title.Substring(start, width)); - start += width; - while (title[start] == ' ') start++; + if (text[indx] == '\\') //rtf command + { + // look for three things at beginning of string: hex, unicode, rtfcommand. + Match m = Regex.Match(text.Substring(indx), @"^\\'[a-fA-F0-9][a-fA-F0-9]"); //hex + if (m.Success) + { + indx += m.Length - 1; + width++; + } + else + { + m = Regex.Match(text.Substring(indx), @"^\\u[a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]?"); + if (m.Success) + { + indx += m.Length - 1; + width++; + } + else + { + m = Regex.Match(text.Substring(indx), @"^\\[^ ]*? "); + if (m.Success) + { + indx += m.Length - 1; + rtfprefix = AdjustRtfPrefix(rtfprefix, m.Value); + } + } + } + + } + else + { + if (text[indx] == ' ') + { + lastspace = indx; + } + width++; + if (width > len) + { + // what should be done if lastspace == 0 + results.Add(nextprefix+text.Substring(start, lastspace)); + nextprefix = rtfprefix; + if (nextprefix != "") nextprefix += " "; + start = lastspace + 1; + width = 0; + lastspace = 0; + } + } + } - if (strlen - start > 0) - retval.Add(title.Substring(start, strlen - start)); - return retval; + if (width > 0) results.Add(nextprefix+text.Substring(start)); + return results; + } + + private string AdjustRtfPrefix(string rtfprefix, string rtfcommand) + { + if (rtfcommand.Contains(@"\ulnone") || rtfcommand.Contains(@"\ul0")) // off + rtfprefix = rtfprefix.Replace(@"\ul",""); + else if (rtfcommand.Contains(@"\ul")) + rtfprefix += @"\ul"; + if (rtfcommand.Contains(@"\up0") || rtfcommand.Contains(@"\dn0")) rtfprefix = rtfprefix.Replace(@"\up2", "").Replace(@"\dn2", ""); + else if (rtfcommand.Contains(@"\up")) rtfprefix += @"\up2"; + else if (rtfcommand.Contains(@"\dn")) rtfprefix += @"\dn2"; + if (rtfcommand.Contains(@"\b0")) + rtfprefix = rtfprefix.Replace(@"\b", ""); + else if (rtfcommand.Contains(@"\b")) + rtfprefix += @"\b"; + if (rtfcommand.Contains(@"\i0")) + rtfprefix = rtfprefix.Replace(@"\i", ""); + else if (rtfcommand.Contains(@"\i")) + rtfprefix += @"\i"; + return rtfprefix; } private int FindWidth(string title, int start, int len) {