This commit is contained in:
parent
e22a080953
commit
df775b384e
@ -250,7 +250,14 @@ namespace Volian.Controls.Library
|
||||
{
|
||||
Regex regRefObj = new Regex(@"\#Link\:ReferencedObject:([0-9]*) ([0-9a-zA-Z]*) ([0-9]*)", RegexOptions.Singleline);
|
||||
string strippedText = StaticStripRtfCommands(text);
|
||||
string lookFor = string.Format(@"<START\](\\[^v \\]+)*\\v0(\\[^v \\]+)* (.*?)(\\[^v \\]+)*\\v(\\[^v \\]+)* #Link:(ReferencedObject|Transition[^:]*?):.*?\[END>");
|
||||
// (\\[^v \\]+)* --> look for any rtf commands (first part of lookFor)
|
||||
// \\v0 --> end of comment
|
||||
// (\\[^v \\]+)* --> more rtf commands ended by a space
|
||||
// (.*?) --> smallest anything to that matches this based on what's next
|
||||
// (\\[^v' \\]+)* --> look for rtf commands but exclude \' before the \v
|
||||
// \\v(\\[^v \\]+)* --> look for rtf commands after the \v
|
||||
// if it turns out that if ro's have any embedded unicode characters this needs expanded, such as /u8209? (hard hyphen)
|
||||
string lookFor = string.Format(@"<START\](\\[^v \\]+)*\\v0(\\[^v \\]+)* (.*?)(\\[^v' \\]+)*\\v(\\[^v \\]+)* #Link:(ReferencedObject|Transition[^:]*?):.*?\[END>");
|
||||
MatchCollection matches = Regex.Matches(text, lookFor);
|
||||
for (int i = matches.Count - 1; i >= 0; i--)
|
||||
{
|
||||
@ -261,6 +268,7 @@ namespace Volian.Controls.Library
|
||||
string beforeRO = StaticStripRtfCommands(text.Substring(0, g.Index));
|
||||
string afterRO = StaticStripRtfCommands(text.Substring(g.Index + g.Length));
|
||||
string newvalue = DoROFormatFlags(g.ToString(), beforeRO, afterRO);
|
||||
newvalue = DoROReplaceWords(_MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList, newvalue, _MyItemInfo.IsHigh);
|
||||
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);
|
||||
@ -272,6 +280,17 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
return text;
|
||||
}
|
||||
private string DoROReplaceWords(ReplaceStrList replaceStrList, string newvalue, bool isHigh)
|
||||
{
|
||||
foreach (ReplaceStr rs in replaceStrList)
|
||||
{
|
||||
if (((rs.Flag & E_ReplaceFlags.Setpoint) > 0) || (isHigh && (rs.Flag & E_ReplaceFlags.HLSSetpnt) > 0))
|
||||
{
|
||||
newvalue = newvalue.Replace(rs.ReplaceWord, rs.ReplaceWith);
|
||||
}
|
||||
}
|
||||
return newvalue;
|
||||
}
|
||||
// Replace spaces with hardspaces, but DO NOT replace the end of an Rtf Command with a hardspace
|
||||
private string ReplaceSpaceWithHardspace(string newvalue)
|
||||
{
|
||||
@ -315,6 +334,10 @@ namespace Volian.Controls.Library
|
||||
for (int i = matches.Count - 1; i >= 0; i--)
|
||||
{
|
||||
Match m = matches[i];
|
||||
// if this transition text already has a hard space, don't add another.
|
||||
if (m.Groups[3].Value.Contains("\xA0")) continue;
|
||||
// if the transition text does not start with a digit, don't add the hardspace.
|
||||
//if (!Char.IsDigit(m.Groups[3].Value[0])) continue;
|
||||
if (m != null && m.Groups.Count > 7 && m.Groups[6].ToString().StartsWith("Transition"))
|
||||
{
|
||||
if (m.Groups[7].Value != "" && StepTransition(int.Parse(m.Groups[7].Value)))
|
||||
@ -327,7 +350,7 @@ namespace Volian.Controls.Library
|
||||
if (indexLastSpace >= 0)
|
||||
text = beforeTran + newvalue.Substring(0, indexLastSpace) + @"\u160?" + newvalue.Substring(indexLastSpace + 1) + afterTran;
|
||||
else
|
||||
if (beforeTran.EndsWith(" "))
|
||||
if (beforeTran.EndsWith(" ") )
|
||||
text = ReplaceLastSpaceWithHardSpace(beforeTran) + newvalue + afterTran;
|
||||
else
|
||||
Console.Write("");// Don't know where to put the Hard Space
|
||||
@ -1232,6 +1255,7 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
#endregion
|
||||
#region ReplaceWords
|
||||
#region commented out
|
||||
//private string DoReplaceWords(string Text)
|
||||
//{
|
||||
// ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList;
|
||||
@ -1368,6 +1392,7 @@ namespace Volian.Controls.Library
|
||||
// Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space
|
||||
// return Text;
|
||||
//}
|
||||
#endregion
|
||||
private Dictionary<ReplaceStr, Regex> dicReplaceRegex = new Dictionary<ReplaceStr, Regex>();
|
||||
private string DoReplaceWords2(string Text)
|
||||
{
|
||||
@ -1390,7 +1415,7 @@ namespace Volian.Controls.Library
|
||||
else if (_MyItemInfo.IsStepPart && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true;
|
||||
//else if (_MyItemInfo.IsInFirstLevelSubStep && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsAccPages & (rs.Flag & E_ReplaceFlags.Attach) > 0) replaceit = true;
|
||||
|
||||
|
||||
if (replaceit)
|
||||
{
|
||||
if (!dicReplaceRegex.ContainsKey(rs))
|
||||
@ -1416,19 +1441,21 @@ namespace Volian.Controls.Library
|
||||
Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space
|
||||
return Text;
|
||||
}
|
||||
#region notused
|
||||
static Regex regFindLink = new Regex(@"\<START\].*?\[END\>", RegexOptions.Singleline);
|
||||
private string ReplaceWord(string text, string replace, string with, RegexOptions regexOptions)
|
||||
{
|
||||
MatchCollection myMatches = Regex.Matches(text, replace ,regexOptions);
|
||||
MatchCollection myMatches = Regex.Matches(text, replace, regexOptions);
|
||||
MatchCollection myLinks = regFindLink.Matches(text);
|
||||
for (int i = myMatches.Count - 1; i >= 0; i--)
|
||||
{
|
||||
Match myMatch = myMatches[i];
|
||||
if(!PartOfLinkText(myMatch,myLinks))
|
||||
if (!PartOfLinkText(myMatch, myLinks))
|
||||
text = text.Substring(0, myMatch.Index) + with + text.Substring(myMatch.Index + myMatch.Length);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private bool PartOfLinkText(Match myMatch, MatchCollection myLinks)
|
||||
{
|
||||
foreach (Match myLink in myLinks)
|
||||
@ -1437,6 +1464,7 @@ namespace Volian.Controls.Library
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
#region displayTextElementClass
|
||||
public enum E_TextElementType : uint
|
||||
|
Loading…
x
Reference in New Issue
Block a user