diff --git a/PROMS/Volian.Print.Library/vlnParagraph.cs b/PROMS/Volian.Print.Library/vlnParagraph.cs index d4805892..5cd6ca56 100644 --- a/PROMS/Volian.Print.Library/vlnParagraph.cs +++ b/PROMS/Volian.Print.Library/vlnParagraph.cs @@ -3553,9 +3553,10 @@ namespace Volian.Print.Library if (sc2 != null) { string resp = sc2.Step_Responsibility; + if (resp != null && resp != "") // lines are separated by "\r\n" { - resp = resp.TrimEnd(); + resp = DelimitResponse((int)MyItemInfo.MyDocStyle.SectTop.MaxLen, resp); if (!resp.EndsWith("\r\n")) resp = resp + "\r\n"; // parsing needs this. int indx = resp.IndexOf("\r\n"); int stindx = 0; @@ -3575,6 +3576,43 @@ namespace Volian.Print.Library } } } + private string DelimitResponse(int maxLen, string responsStr) + { + // This code handles whether user enters \r\n to separate lines or not. The + // max width that a line can be in the Responsibility column is a format flag (passed in) + List results = new List(); + int width = 0; + int start = 0; // start of line (index into string 'text') + int lastspace = 0; // location of lastspace (index into string) + for (int indx = 0; indx < responsStr.Length; indx++) + { + if ((indx + 1) < responsStr.Length && responsStr.Substring(indx, 2) == "\r\n") + { + results.Add(responsStr.Substring(start, indx - start).Trim(" ".ToCharArray()) + "\r\n"); + start = indx + 2; + width = 0; + } + else + { + if (responsStr[indx] == ' ') lastspace = indx; + width++; + if (width > maxLen) + { + // what should be done if lastspace == 0 + // cannot find space char to split on, so break the word + if (lastspace == 0) lastspace = indx; + results.Add(responsStr.Substring(start, lastspace - start).Trim(" ".ToCharArray()) + "\r\n"); + start = lastspace + 1; + width = 0; + lastspace = 0; + } + } + } + if (width > 0 || start < responsStr.Length) results.Add(responsStr.Substring(start).Trim(" ".ToCharArray())); + string retval = null; + foreach (string st in results) retval = retval + st; + return retval; + } public override string Rtf { get