- Put RO Adjustment code prior to Replace Words - Match 16 Bit
- Replaced logic for Replace Words so that they are replaced sequentially through the text rather than sequentially through the word list. - Added DoTransitionAdjustments that adds hardspaces to Transitions. - Changed the NextUnicode module to ignore Hard Spaces - Added logic to find 'real' spaces in ROs and replace only them. Spaces are also used to terminate RTF commands. Added code to handle "AND Range" Transitions - Use new ToolTip property - Use new MyStepSectionLayoutData - Remove Debug Remove unused code Renamed TwipsPerPage to PointsPerPage Adjusted Superscript offset to match 16-Bit - Added Debug Code to compare 16-Bit and 32-Bit text - Added Debug Code forr Pagination - Added optional code to match 16-Bit pagination Added Ruler for 6 and 7 lines per inch.
This commit is contained in:
@@ -141,13 +141,16 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
private string CreateRtf(bool colorLinks, string text, bool tableShouldBeOutlined, bool wordsShouldBeReplaced, bool numbersShouldBeFormated, bool tableHasBorder, bool ROsShouldBeAdjusted)
|
||||
{
|
||||
// if in print mode, view mode, or non-active richtextbox do replace words. Only if in
|
||||
// actual edit mode are replace words left as is.
|
||||
if (wordsShouldBeReplaced)
|
||||
text = DoReplaceWords(text);
|
||||
// Adjust RO display
|
||||
if (ROsShouldBeAdjusted)
|
||||
text = DoROAdjustments(text);
|
||||
// if in print mode, view mode, or non-active richtextbox do replace words. Only if in
|
||||
// actual edit mode are replace words left as is.
|
||||
if (wordsShouldBeReplaced)
|
||||
text = DoReplaceWords2(text);
|
||||
// Adjust RO display
|
||||
if (ROsShouldBeAdjusted)
|
||||
text = DoTransitionAdjustments(text);
|
||||
// add colors around links:
|
||||
if (colorLinks)
|
||||
text = DoColorLinks(text);
|
||||
@@ -196,7 +199,6 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private static string DoColorLinks(string text)
|
||||
{
|
||||
text = Regex.Replace(text, @"(<START\](\\[^v \\]+)*\\v0)((?= |\\))", @"$1\cf1");
|
||||
@@ -212,7 +214,13 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
private int NextUnicode(string text, int offset)
|
||||
{
|
||||
// Skip Hard Spaces
|
||||
Match m = Regex.Match(text.Substring(offset), @"\\u[0-9a-fA-F]");
|
||||
while(m.Success && text.Substring(offset+m.Index).StartsWith(@"\u160"))
|
||||
{
|
||||
offset += m.Index + 5;
|
||||
m = Regex.Match(text.Substring(offset), @"\\u[0-9a-fA-F]");
|
||||
}
|
||||
if (m.Success)
|
||||
return m.Index + offset;
|
||||
return -1;
|
||||
@@ -231,14 +239,73 @@ 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 = newvalue.Replace(" ", @"\u160?");
|
||||
newvalue = ReplaceSpaceWithHardspace(newvalue);
|
||||
if (g.ToString() != newvalue)
|
||||
text = text.Substring(0, g.Index) + newvalue + text.Substring(g.Index + g.Length);
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private static Regex _RegExReplaceSpaceWithHardspace = new Regex(@"((\\[^\\ \?]+)*\\[^\\ \?]+[ ?])?( )");
|
||||
private string ReplaceSpaceWithHardspace(string newvalue)
|
||||
{
|
||||
return _RegExReplaceSpaceWithHardspace.Replace(newvalue, @"$1\u160?");
|
||||
}
|
||||
private string DoTransitionAdjustments(string text)
|
||||
{
|
||||
if (_MyItemInfo.ItemID == 230 || _MyItemInfo.ItemID == 154 || _MyItemInfo.ItemID == 1932)
|
||||
Console.Write("");
|
||||
string strippedText = StaticStripRtfCommands(text);
|
||||
string lookFor = string.Format(@"<START\](\\[^v \\]+)*\\v0(\\[^v \\]+)* (.*?)(\\[^v \\]+)*\\v(\\[^v \\]+)* #Link:(ReferencedObject|Transition[^:]*?):[0-9]* ([0-9]*).*?\[END>");
|
||||
MatchCollection matches = Regex.Matches(text, lookFor);
|
||||
for (int i = matches.Count - 1; i >= 0; i--)
|
||||
{
|
||||
Match m = matches[i];
|
||||
if (m != null && m.Groups.Count > 7 && m.Groups[6].ToString().StartsWith("Transition"))
|
||||
{
|
||||
if (StepTransition(int.Parse(m.Groups[7].Value)))
|
||||
{
|
||||
System.Text.RegularExpressions.Group g = m.Groups[3];
|
||||
string beforeTran = text.Substring(0, g.Index);
|
||||
string afterTran = text.Substring(g.Index + g.Length);
|
||||
string newvalue = g.ToString();
|
||||
int indexLastSpace = newvalue.LastIndexOf(' ');
|
||||
if (indexLastSpace >= 0)
|
||||
text = beforeTran + newvalue.Substring(0, indexLastSpace) + @"\u160?" + newvalue.Substring(indexLastSpace + 1) + afterTran;
|
||||
else
|
||||
if (beforeTran.EndsWith(" "))
|
||||
text = ReplaceLastSpaceWithHardSpace(beforeTran) + newvalue + afterTran;
|
||||
else
|
||||
Console.Write("");// Don't know where to put the Hard Space
|
||||
}
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
private string ReplaceLastSpaceWithHardSpace(string str)
|
||||
{
|
||||
int ind =str.LastIndexOf("<START]");
|
||||
ind = str.LastIndexOf(@"\", ind);
|
||||
while (ind >= 0 && str[ind - 1] != ' ')
|
||||
{
|
||||
if (ind > 5 && str.Substring(0, ind).EndsWith(@"\u160?") || str.Substring(0, ind).ToLower().EndsWith(@"\'a0"))
|
||||
return str;//Already has a Hard Space
|
||||
ind = str.LastIndexOf(@"\", ind - 1);
|
||||
}
|
||||
// If the previous character is a comma or a space then don't add a Hard Space
|
||||
if (ind > 1 && (str[ind - 2] == ',' || str[ind - 2] == ' ')) return str;
|
||||
if (ind == -1)
|
||||
return str;
|
||||
return str.Substring(0,ind - 1) + @"\u160?" + str.Substring(ind);
|
||||
}
|
||||
private bool StepTransition(int TransId)
|
||||
{
|
||||
if (_MyItemInfo == null) return false;
|
||||
foreach (TransitionInfo trans in _MyItemInfo.MyContent.ContentTransitions)
|
||||
if (trans.TransitionID == TransId)
|
||||
return trans.MyItemToID.IsStep;
|
||||
return false;
|
||||
}
|
||||
private string DoFortranFormat(string text)
|
||||
{
|
||||
if (text.IndexOf(@".E") < 0) return text;
|
||||
@@ -1005,8 +1072,11 @@ namespace Volian.Controls.Library
|
||||
private string DoROFormatFlags(string roText, string beforeRO, string afterRO)
|
||||
{
|
||||
string rtnstr = roText;
|
||||
beforeRO = Regex.Replace(beforeRO, @"(\\[^v \\]+)*\\v(\\[^v \\]+)* .*?\\v0(\\[^v \\]+)*( |$)", "");
|
||||
afterRO = Regex.Replace(afterRO, @"(\\[^v \\]+)*\\v(\\[^v \\]+)* .*?\\v0(\\[^v \\]+)*( |$)", "");
|
||||
// The RO text is being changed to match it's context. Since it is changed in reverse order, the text before the RO
|
||||
// should ignore other RO text.
|
||||
beforeRO = Regex.Replace(beforeRO, @"(\\[^v \\]+)*\\v0[^v\\]*\\v(\\[^v \\]+)* #Link:Refer", ""); // Remove any RO Values.
|
||||
beforeRO = Regex.Replace(beforeRO, @"(\\[^v \\]+)*\\v(\\[^v \\]+)* .*?\\v0(\\[^v \\]+)*( |$)", ""); // Remove Comments
|
||||
afterRO = Regex.Replace(afterRO, @"(\\[^v \\]+)*\\v(\\[^v \\]+)* .*?\\v0(\\[^v \\]+)*( |$)", ""); // Remove Comments
|
||||
|
||||
// Underline all ROs, values and Units
|
||||
if (_MyItemInfo.ActiveFormat.PlantFormat.FormatData.ROData.UnderlineRo)
|
||||
@@ -1025,7 +1095,7 @@ namespace Volian.Controls.Library
|
||||
|
||||
// Caps ROs anywhere if no lower case text follows
|
||||
// and an upper case letter immediately precedes the RO.
|
||||
if (_MyItemInfo.ActiveFormat.PlantFormat.FormatData.ROData.CapRoIfLastLower && Regex.IsMatch(afterRO,".*[a-z].*") && char.IsUpper(LastAlpha(beforeRO)))
|
||||
if (_MyItemInfo.ActiveFormat.PlantFormat.FormatData.ROData.CapRoIfLastLower && !Regex.IsMatch(afterRO,"[a-z]") && char.IsUpper(LastAlpha(beforeRO)))
|
||||
{
|
||||
//int indx = startLinkText - 1;
|
||||
//int indx2 = endLinkText + 1;
|
||||
@@ -1095,11 +1165,24 @@ namespace Volian.Controls.Library
|
||||
|
||||
return rtnstr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uppercase alphabetical strings excluding any RTF token
|
||||
/// </summary>
|
||||
/// <param name="match"></param>
|
||||
/// <returns></returns>
|
||||
private string MatchEvaluatorUppercaseROUnits(Match match)
|
||||
{
|
||||
if (match.Value[0] == '\\') // If the previous character is a backslash then this is an RTF token
|
||||
return match.Value;
|
||||
return match.Value.ToUpper();
|
||||
}
|
||||
Regex _RegExUppercaseROUnits = new Regex("(^|[^a-zA-Z])[a-zA-Z]+");
|
||||
private string UpperCaseUnits(string rtnstr)
|
||||
{
|
||||
// Uppercase Units
|
||||
rtnstr = _RegExUppercaseROUnits.Replace(rtnstr, new MatchEvaluator(MatchEvaluatorUppercaseROUnits));
|
||||
// After converting the value to uppercase, change X10 to x10 to handle Fortran Formatted numbers
|
||||
return rtnstr.ToUpper().Replace("X10", "x10");
|
||||
return rtnstr.Replace("X10", "x10");
|
||||
}
|
||||
|
||||
// Find the last Alphabetical character
|
||||
@@ -1197,7 +1280,8 @@ namespace Volian.Controls.Library
|
||||
else if (_MyItemInfo.IsInRNO && (rs.Flag & E_ReplaceFlags.RNO) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsCaution && (rs.Flag & E_ReplaceFlags.Caution) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsNote && (rs.Flag & E_ReplaceFlags.Note) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsInFirstLevelSubStep && (rs.Flag & E_ReplaceFlags.Substep) > 0) replaceit = true;
|
||||
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)
|
||||
@@ -1230,7 +1314,8 @@ namespace Volian.Controls.Library
|
||||
string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?![\\u160?])(?=\W|$)";
|
||||
try
|
||||
{
|
||||
Text = Regex.Replace(Text, pat, rs.ReplaceWith, RegexOptions.IgnoreCase);
|
||||
Text = ReplaceWord(Text, pat, rs.ReplaceWith, RegexOptions.IgnoreCase);
|
||||
//Text = Regex.Replace(Text, pat, rs.ReplaceWith, RegexOptions.IgnoreCase);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -1259,7 +1344,8 @@ namespace Volian.Controls.Library
|
||||
string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?![\\u160?])(?=\W|$)";
|
||||
try
|
||||
{
|
||||
Text = Regex.Replace(Text, pat, rs.ReplaceWith);
|
||||
Text = ReplaceWord(Text, pat, rs.ReplaceWith, RegexOptions.None);
|
||||
//Text = Regex.Replace(Text, pat, rs.ReplaceWith);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -1274,6 +1360,116 @@ namespace Volian.Controls.Library
|
||||
//Console.WriteLine("--- After '{0}'", Text);
|
||||
return Text;
|
||||
}
|
||||
private string DoReplaceWords1(string Text)
|
||||
{
|
||||
if (_MyItemInfo.MyContent.Type < 20000) return Text; // for now only replace in steps.
|
||||
ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList;
|
||||
// Loop through text looking for words to be replaced
|
||||
foreach (ReplaceStr rs in rsl)
|
||||
{
|
||||
bool replaceit = false;
|
||||
|
||||
// note that the order of this check is important. Check in this order...
|
||||
// background here
|
||||
if (_MyItemInfo.IsHigh && (rs.Flag & E_ReplaceFlags.High) > 0) replaceit = true;
|
||||
else if ((_MyItemInfo.IsTable || _MyItemInfo.IsFigure) && (rs.Flag & E_ReplaceFlags.Table) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsInRNO && (rs.Flag & E_ReplaceFlags.RNO) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsCaution && (rs.Flag & E_ReplaceFlags.Caution) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsNote && (rs.Flag & E_ReplaceFlags.Note) > 0) replaceit = true;
|
||||
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)
|
||||
{
|
||||
// CASEINSENS: Do ReplaceWords for all words that match, regardless of case, and replace with the ReplaceWith string as is
|
||||
RegexOptions myOptions = (rs.Flag & E_ReplaceFlags.CaseInsens) == E_ReplaceFlags.CaseInsens ? RegexOptions.IgnoreCase : RegexOptions.None;
|
||||
string replaceWord = Regex.Replace(rs.ReplaceWord, @"[[\]\\()]", @"\$0");
|
||||
string pat = @"(?<=\W|^)(?<![\\u160?])" + replaceWord + @"(?![\\u160?])(?=\W|$)";
|
||||
try
|
||||
{
|
||||
Text = ReplaceWord(Text, pat, rs.ReplaceWith, myOptions);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("{0},'{1}',{2},'{3}'", _MyItemInfo.ActiveFormat.Name, replaceWord, ex.GetType().Name, ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space
|
||||
return Text;
|
||||
}
|
||||
private Dictionary<ReplaceStr, Regex> dicReplaceRegex = new Dictionary<ReplaceStr, Regex>();
|
||||
private string DoReplaceWords2(string Text)
|
||||
{
|
||||
if (_MyItemInfo.MyContent.Type < 20000) return Text; // for now only replace in steps.
|
||||
FoundMatches myMatches = new FoundMatches(Text);
|
||||
myMatches.Add(regFindLink, null);
|
||||
ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList;
|
||||
// Loop through text looking for words to be replaced
|
||||
foreach (ReplaceStr rs in rsl)
|
||||
{
|
||||
bool replaceit = false;
|
||||
|
||||
// note that the order of this check is important. Check in this order...
|
||||
// background here
|
||||
if (_MyItemInfo.IsHigh && (rs.Flag & E_ReplaceFlags.High) > 0) replaceit = true;
|
||||
else if ((_MyItemInfo.IsTable || _MyItemInfo.IsFigure) && (rs.Flag & E_ReplaceFlags.Table) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsInRNO && (rs.Flag & E_ReplaceFlags.RNO) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsCaution && (rs.Flag & E_ReplaceFlags.Caution) > 0) replaceit = true;
|
||||
else if (_MyItemInfo.IsNote && (rs.Flag & E_ReplaceFlags.Note) > 0) replaceit = true;
|
||||
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))
|
||||
{
|
||||
// CASEINSENS: Do ReplaceWords for all words that match, regardless of case, and replace with the ReplaceWith string as is
|
||||
RegexOptions myOptions = (rs.Flag & E_ReplaceFlags.CaseInsens) == E_ReplaceFlags.CaseInsens ? RegexOptions.IgnoreCase : RegexOptions.None;
|
||||
string replaceWord = Regex.Replace(rs.ReplaceWord, @"[[\]\\()]", @"\$0");
|
||||
string pat = @"(?<=\W|^)(?<!\\u160\?)" + replaceWord + @"(?!\\u160\?)(?=\W|$)";
|
||||
dicReplaceRegex.Add(rs, new Regex(pat, myOptions));
|
||||
}
|
||||
try
|
||||
{
|
||||
myMatches.Add(dicReplaceRegex[rs], rs);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("{0},'{1}',{2},'{3}'", _MyItemInfo.ActiveFormat.Name, rs.ReplaceWord, ex.GetType().Name, ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Text = myMatches.ReplaceMatches();
|
||||
Text = Text.Replace(@"\xA0", @"\u160?"); //replace hard space
|
||||
return Text;
|
||||
}
|
||||
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 myLinks = regFindLink.Matches(text);
|
||||
for (int i = myMatches.Count - 1; i >= 0; i--)
|
||||
{
|
||||
Match myMatch = myMatches[i];
|
||||
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)
|
||||
{
|
||||
if (_MyItemInfo.ItemID == 152)
|
||||
Console.Write("");
|
||||
foreach (Match myLink in myLinks)
|
||||
if (myMatch.Index > myLink.Index && myMatch.Index < (myLink.Index + myLink.Length))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#region displayTextElementClass
|
||||
@@ -1341,5 +1537,71 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public class FoundMatches : SortedList<int, FoundMatch>
|
||||
{
|
||||
private string _Text;
|
||||
public FoundMatches(string text)
|
||||
: base()
|
||||
{
|
||||
_Text = text;
|
||||
}
|
||||
public void Add(Regex myRegEx, ReplaceStr myWord)
|
||||
{
|
||||
MatchCollection myMatches = myRegEx.Matches(_Text);
|
||||
foreach (Match myMatch in myMatches)
|
||||
Add(myMatch, myWord);
|
||||
}
|
||||
public void Add(Match myMatch, ReplaceStr myWord)
|
||||
{
|
||||
// If one already exists for this location, then don't add another.
|
||||
if (ContainsKey(myMatch.Index)) return;
|
||||
// Start by Adding it.
|
||||
base.Add(myMatch.Index, new FoundMatch(myMatch, myWord));
|
||||
// Now see what I can do with it.
|
||||
int index = this.IndexOfKey(myMatch.Index);
|
||||
if (index > 0) // If this match is contained within the previous match remove it
|
||||
{
|
||||
FoundMatch previousMatch = Values[index - 1];
|
||||
if (previousMatch.MyMatch.Index + previousMatch.MyMatch.Length > myMatch.Index)
|
||||
Remove(myMatch.Index);
|
||||
} // If the next match is contained within this match, remove the next match
|
||||
while (index < Count - 1 && Values[index + 1].MyMatch.Index < (myMatch.Index + myMatch.Length))
|
||||
Remove(Values[index + 1].MyMatch.Index);
|
||||
}
|
||||
public string ReplaceMatches()
|
||||
{
|
||||
int offset = 0;
|
||||
string text = _Text;
|
||||
foreach (FoundMatch foundMatch in Values)
|
||||
{
|
||||
if (foundMatch.MyWord != null)
|
||||
{
|
||||
text = text.Substring(0, offset + foundMatch.MyMatch.Index) + foundMatch.MyWord.ReplaceWith + text.Substring(offset + foundMatch.MyMatch.Index + foundMatch.MyMatch.Length);
|
||||
offset += foundMatch.MyWord.ReplaceWith.Length - foundMatch.MyMatch.Length;
|
||||
}
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
public class FoundMatch
|
||||
{
|
||||
private Match _MyMatch;
|
||||
public Match MyMatch
|
||||
{
|
||||
get { return _MyMatch; }
|
||||
set { _MyMatch = value; }
|
||||
}
|
||||
private ReplaceStr _MyWord;
|
||||
public ReplaceStr MyWord
|
||||
{
|
||||
get { return _MyWord; }
|
||||
set { _MyWord = value; }
|
||||
}
|
||||
public FoundMatch(Match myMatch, ReplaceStr myWord)
|
||||
{
|
||||
_MyMatch = myMatch;
|
||||
_MyWord = myWord;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user