This commit is contained in:
Kathy Ruffing 2011-04-19 14:15:55 +00:00
parent 3f5d4f26fd
commit 922104f983

View File

@ -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<string> SplitText(string title, int len)
private List<string> SplitText(string text, int len)
{
List<string> retval = new List<string>();
int strlen = title.Length;
List<string> results = new List<string>();
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)
{