Handle embedded text in xyplot for CPLS

This commit is contained in:
Kathy Ruffing 2013-05-14 12:44:03 +00:00
parent 732fadab95
commit 85d0e02a4f

View File

@ -656,9 +656,21 @@ namespace VEPROMS.CSLA.Library
LBRange myRange = selxy.Paragraphs.First.Range;
float yTop = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToPage);
float yTop1 = (float)myRange.get_Information(LBWdInformation.wdVerticalPositionRelativeToTextBoundary);
selxy.Text = "";
if (cnt>0)for (int icnt = 0; icnt < cnt; icnt++) selxy.Text = selxy.Text + "\r";
// some data had regular text embedded in the xyplot definition. If so, the plain text must
// be left in the file. Otherwise, we can replace with empty text.
string resXyPlot = xyplot;
string txt = FindEmbeddedText(selxy.Text, ref resXyPlot);
if (txt != null)
{
selxy.Text = txt;
xyplot = resXyPlot.Replace(">\r>", ">>\r");
}
else
{
selxy.Text = "";
if (cnt > 0) for (int icnt = 0; icnt < cnt; icnt++) selxy.Text = selxy.Text + "\r";
}
pngFile = VlnSettings.TemporaryFolder + @"\XYPlot" + filecount.ToString() + @".png"; //@"C:\Temp\XYPlot1.png";
filecount++;
@ -811,6 +823,79 @@ namespace VEPROMS.CSLA.Library
return fileName;
}
}
private static string FindEmbeddedText(string p, ref string resXyPlot)
{
StringBuilder sb = new StringBuilder(); // contains embedded text
StringBuilder xy = new StringBuilder(); // contains xyplot without embedded text.
string origXy = p;
bool findEmbeddedText = false;
// get past opening command:
int indxCmd = p.IndexOf("<");
indxCmd = p.IndexOf("<", indxCmd + 1);
xy.Append(p.Substring(0, indxCmd));
// While there are xyplot commands, check for beginning/ending.
// Any text not in a command, save.
while (indxCmd > 0)
{
// find end of command. Look for another beginning of command, newline,
// regular text, or end of graph and handle each of these cases.
int indxClose = GetNonStringCmdClose(p, indxCmd + 1); // p.IndexOf(">", indxCmd + 1);
int nxtIndxCmd = p.IndexOf("<", indxCmd + 1);
xy.Append(p.Substring(indxCmd, indxClose - indxCmd+1));
xy.Append("\r"); // the xyplot code assumes a return exists.
// get substrings between end index & start of next and if any
// non white space text, add it to return string and flag that we have
// embedded text. If there's a newline and just other white space put a
// newline in return string.
if (nxtIndxCmd > 0)
{
string mydebug = p.Substring(indxClose + 1);
for (int i = indxClose + 1; i < nxtIndxCmd; i++)
{
if (!System.Char.IsWhiteSpace(p[i]))
{
sb.Append(p[i]);
findEmbeddedText = true;
}
if (p[i] == '\r' || p[i] == ' ') sb.Append(p[i]);
}
}
indxCmd = nxtIndxCmd;
}
xy.Append(">");
if (findEmbeddedText)
{
resXyPlot = xy.ToString();
return sb.ToString();
}
resXyPlot = origXy;
return null;
}
private static int GetNonStringCmdClose(string p, int indxCmd)
{
int indxClose = p.IndexOf(">", indxCmd);
if (indxClose >= 0)
{
// if there are any quotes between the open of command and close,
// need to see if the close command is quoted.
if (p.IndexOf('"', indxCmd, indxClose - indxCmd) > -1)
{
// see how many quotes between open/close command, if
// an odd number, the close command char '>' is in quotes.
int countQuotes = 0;
for (int i = indxCmd; i < indxClose; i++) if (p[i] == '"') countQuotes++;
if ((countQuotes % 2) != 0)
{
// find quote after close, and then get next close.
int closeQuote = p.IndexOf('"', indxClose);
if (closeQuote < 0) return -1; // this is error, so return end not found.
return p.IndexOf(">", closeQuote + 1);
}
}
}
return indxClose;
}
public static void AddPrecedingText(LBSelection sel, string val)
{
if (val.IndexOf("_") == -1) // Is some of the text underlined?