This commit is contained in:
Kathy Ruffing 2011-06-16 10:35:50 +00:00
parent 07b7f1e47c
commit a062a026b4

View File

@ -248,6 +248,7 @@ namespace Volian.Controls.Library
} }
private string DoROAdjustments(string text) private string DoROAdjustments(string text)
{ {
Regex regRefObj = new Regex(@"\#Link\:ReferencedObject:([0-9]*) ([0-9a-zA-Z]*) ([0-9]*)", RegexOptions.Singleline);
string strippedText = StaticStripRtfCommands(text); string strippedText = StaticStripRtfCommands(text);
string lookFor = string.Format(@"<START\](\\[^v \\]+)*\\v0(\\[^v \\]+)* (.*?)(\\[^v \\]+)*\\v(\\[^v \\]+)* #Link:(ReferencedObject|Transition[^:]*?):.*?\[END>"); string lookFor = string.Format(@"<START\](\\[^v \\]+)*\\v0(\\[^v \\]+)* (.*?)(\\[^v \\]+)*\\v(\\[^v \\]+)* #Link:(ReferencedObject|Transition[^:]*?):.*?\[END>");
MatchCollection matches = Regex.Matches(text, lookFor); MatchCollection matches = Regex.Matches(text, lookFor);
@ -260,17 +261,51 @@ namespace Volian.Controls.Library
string beforeRO = StaticStripRtfCommands(text.Substring(0, g.Index)); string beforeRO = StaticStripRtfCommands(text.Substring(0, g.Index));
string afterRO = StaticStripRtfCommands(text.Substring(g.Index + g.Length)); string afterRO = StaticStripRtfCommands(text.Substring(g.Index + g.Length));
string newvalue = DoROFormatFlags(g.ToString(), beforeRO, afterRO); string newvalue = DoROFormatFlags(g.ToString(), beforeRO, afterRO);
newvalue = ReplaceSpaceWithHardspace(newvalue); Match myMatch = regRefObj.Match(m.ToString());
int dbid = System.Convert.ToInt32(myMatch.Groups[2].Value.Substring(0, 4), 16);
int rodbid = int.Parse(myMatch.Groups[3].Value);
ROFstInfo myROFst = _MyItemInfo.MyDocVersion.GetROFst(rodbid);
if (myROFst.IsSetpointDB(dbid)) newvalue = ReplaceSpaceWithHardspace(newvalue);
if (g.ToString() != newvalue) if (g.ToString() != newvalue)
text = text.Substring(0, g.Index) + newvalue + text.Substring(g.Index + g.Length); text = text.Substring(0, g.Index) + newvalue + text.Substring(g.Index + g.Length);
} }
} }
return text; return text;
} }
private static Regex _RegExReplaceSpaceWithHardspace = new Regex(@"((\\[^\\ \?]+)*\\[^\\ \?]+[ ?])?( )"); // Replace spaces with hardspaces, but DO NOT replace the end of an Rtf Command with a hardspace
private string ReplaceSpaceWithHardspace(string newvalue) private string ReplaceSpaceWithHardspace(string newvalue)
{ {
return _RegExReplaceSpaceWithHardspace.Replace(newvalue, @"$1\u160?"); string oldvalue = newvalue;
int spindx = newvalue.IndexOf(" ");
int lstindx = -1;
while (spindx >= 0)
{
if (!EndsRtfCommand(newvalue, spindx, lstindx))
{
newvalue = newvalue.Remove(spindx, 1);
newvalue = newvalue.Insert(spindx, @"\u160?");
}
lstindx = spindx;
spindx = (spindx + 1 >= newvalue.Length)?spindx = -1: newvalue.IndexOf(" ", spindx+1);
}
return newvalue;
}
private bool EndsRtfCommand(string str, int spindx, int previndx)
{
// get text from last space to current, or from beginning of string to current:
int start = previndx < 0 ? 0 : previndx+1;
string substring = str.Substring(start, spindx-start);
if (substring.Contains(@"\"))
{
// is space ending an rtf command.
int startCmd = substring.LastIndexOf(@"\");
string Cmd = substring.Substring(startCmd);
char tst = Cmd[1];
// consider rtf commands up/dn/b/ul/i
if (tst == 'u' || tst == 'd' || tst == 'b' || tst == 'u' || tst == 'i') return true;
}
return false;
} }
private string DoTransitionAdjustments(string text) private string DoTransitionAdjustments(string text)
{ {
@ -1495,13 +1530,13 @@ namespace Volian.Controls.Library
{ {
return link.Contains("#Link:Transition"); return link.Contains("#Link:Transition");
} }
private static Regex regRefObj = new Regex(@"\#Link\:ReferencedObject\:([0-9]*) ([0-9]*) ([0-9]*)", RegexOptions.Singleline); private static Regex regRefObj = new Regex(@"\#Link\:ReferencedObject:([0-9]*) ([0-9a-zA-Z]*) ([0-9]*)", RegexOptions.Singleline);
private static bool IsSetpointRO(string link, DocVersionInfo myDocVersion) private static bool IsSetpointRO(string link, DocVersionInfo myDocVersion)
{ {
Match myMatch = regRefObj.Match(link); Match myMatch = regRefObj.Match(link);
if (myMatch.Success) if (myMatch.Success)
{ {
int dbid = int.Parse(myMatch.Groups[2].Value.Substring(0, 4)); int dbid = System.Convert.ToInt32(myMatch.Groups[2].Value.Substring(0, 4), 16);
int rodbid = int.Parse(myMatch.Groups[3].Value); int rodbid = int.Parse(myMatch.Groups[3].Value);
ROFstInfo myROFst = myDocVersion.GetROFst(rodbid); ROFstInfo myROFst = myDocVersion.GetROFst(rodbid);
return myROFst.IsSetpointDB(dbid); return myROFst.IsSetpointDB(dbid);