diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs index 467e6176..a480ed2b 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ContentExt.cs @@ -117,38 +117,99 @@ namespace VEPROMS.CSLA.Library myLength += mg.Groups[3].Length; } string gg = MyGrid.Data.Substring(myIndex, myLength); - if (newvalue.Contains(@"\u8209?")) // process dash - { - Match m = Regex.Match(newvalue, @"(\\f[0-9]+)(\\u[0-9]{1,4}\?)(\\f[0-9]+ ?)"); - if (m == null) - newvalue = newvalue.Replace(@"\u8209?", "-"); - else - newvalue = newvalue.Replace(@"\u8209?", m.Groups[1].Value + @"\u8209?" + m.Groups[3].Value); - } - if (newvalue.Contains(@"\u8593?")) // process carrot/delta - { - Match m = Regex.Match(newvalue, @"(\\f[0-9]+)(\\u[0-9]{1,4}\?)(\\f[0-9]+ ?)"); - if (m == null) - newvalue = newvalue.Replace(@"\u8593?", "^"); - else - newvalue = newvalue.Replace(@"\u8593?", m.Groups[1].Value + @"\u8593?" + m.Groups[3].Value); - } - if (newvalue.Contains(@"\u9586?")) // process backslash - { - Match m = Regex.Match(newvalue, @"(\\f[0-9]+)(\\u[0-9]{1,4}\?)(\\f[0-9]+ ?)"); - if (m == null) - newvalue = newvalue.Replace(@"\u9586?", @"\\"); - else - newvalue = newvalue.Replace(@"\u9586?", m.Groups[1].Value + @"\u9586?" + m.Groups[3].Value); - } + if (newvalue.Contains(@"\u8209?")) // process dash + newvalue = ProcessSpecChar(gg, newvalue, @"\u8209?","-"); + if (newvalue.Contains(@"\u8593?")) // process carrot/delta + newvalue = ProcessSpecChar(gg, newvalue, @"\u8593?","^"); + if (newvalue.Contains(@"\u9586?")) // process backslash + newvalue = ProcessSpecChar(gg, newvalue, @"\u9586?",@"\\"); if (gg != newvalue) { - MyGrid.Data = MyGrid.Data.Substring(0, myIndex) + newvalue + MyGrid.Data.Substring(myIndex + myLength); + if (newvalue == "?") + ConvertTransitionToTextInGrid(tran, newvalue); + else + MyGrid.Data = MyGrid.Data.Substring(0, myIndex) + newvalue + MyGrid.Data.Substring(myIndex + myLength); } } } } } + + private string ProcessSpecChar(string orgText, string newValue, string specChar, string kbChar) + { + Match m = Regex.Match(newValue, @"(\\f[0-9]+)(\\u[0-9]{1,4}\?)(\\f[0-9]+ ?)"); + { + if (m == null)// || (m.Groups[1].Value == "" && m.Groups[3].Value == "")) + newValue = newValue.Replace(specChar, kbChar); + else + { // look for rtf font command and insert it around the special char (i.e. symbol char) + int ii = orgText.IndexOf(specChar); + int fnt1 = -1; + int fnt2 = -1; + if (ii > -1) + { + fnt1 = orgText.LastIndexOf(@"\f", ii); + fnt2 = orgText.IndexOf(@"\f", ii); + if (fnt1 != -1 && fnt2 != -1) + newValue = newValue.Replace(specChar, orgText.Substring(fnt1, 3) + specChar + orgText.Substring(fnt2, 3) + " "); + } + } + } + GC.Collect(); // regex has a memory leak + return newValue; // could not find rtf font spec so just return the newValue as is + } + + public void ConvertTransitionToTextInGrid(TransitionInfo tran, string value) + { + string newvalue = value; + string findLink = @"<START\].*?\[END>"; + MatchCollection ms = Regex.Matches(MyGrid.Data, findLink); + string lookFor; + if (tran == null) + { + int loc1 = MyGrid.Data.IndexOf("#Link:Transition:", 0) + ("#Link:Transition:").Length; + int loc2 = MyGrid.Data.IndexOf(" ", loc1); + string trantype = MyGrid.Data.Substring(loc1, loc2 - loc1); + loc1 = loc2 + 1; + loc2 = MyGrid.Data.IndexOf(" ", loc1); + string tranid = MyGrid.Data.Substring(loc1, loc2 - loc1); + lookFor = string.Format(@"^<START\](\\[^v \\]+)*\\v0(\\[^v '?{{}}~\\]+)*( |\\u[0-9]{{1,4}}?|\\'[0-9a-fA-F]{{2}}|\\[{{}}~])(.*?)(\\[^v'?{{}}~ \\]+)*\\v(\\[^v \\]+)* #Link:Transition[^:]*?:{0} {1}( [0-9]*){{1,2}}\[END>", trantype, tranid); + } + else + lookFor = string.Format(@"^<START\](\\[^v \\]+)*\\v0(\\[^v '?{{}}~\\]+)*( |\\u[0-9]{{1,4}}?|\\'[0-9a-fA-F]{{2}}|\\[{{}}~])(.*?)(\\[^v'?{{}}~ \\]+)*\\v(\\[^v \\]+)* #Link:Transition[^:]*?:{0} {1}( [0-9]*){{1,2}}\[END>", tran.TranType, tran.TransitionID); + int lastIndex = 0; + string newText = MyGrid.Data; + foreach (Match mm in ms) + { + int offset = mm.Index; + Match m = Regex.Match(mm.Value, lookFor, RegexOptions.Singleline); + if (m != null && m.Groups.Count > 1) + { + int myIndex = m.Groups[4].Index + mm.Index; + int myLength = m.Groups[4].Length; + if (m.Groups[3].Value != " ") + { + myIndex = m.Groups[3].Index + mm.Index; + myLength += m.Groups[3].Length; + } + string ss = MyGrid.Data.Substring(myIndex, myLength); + if (ss != newvalue) + { + int ii = MyGrid.Data.Substring(0, mm.Index).LastIndexOf(@"\v"); + int iil = MyGrid.Data.Substring(mm.Index + m.Value.Length).IndexOf(@"\v0"); + string part1 = MyGrid.Data.Substring(0, ii); // length up to \v + string part2 = MyGrid.Data.Substring(ii + 2, mm.Index - (ii + 2)); + string part3 = ss; + string part4 = MyGrid.Data.Substring(mm.Index + m.Value.Length, iil); + string part5 = MyGrid.Data.Substring(mm.Index + (m.Value.Length + iil + 3)); + MyGrid.Data = part1 + part2 + part3 + part4 + part5; + } + break; // Text has been processed + } + lastIndex = mm.Index + mm.Length; + } + return; + } public string ConvertTransitionToText(TransitionInfo tran, string value) { string retval = null; diff --git a/PROMS/VEPROMS.CSLA.Library/Generated/Content.cs b/PROMS/VEPROMS.CSLA.Library/Generated/Content.cs index 4b0baae2..eb472de3 100644 --- a/PROMS/VEPROMS.CSLA.Library/Generated/Content.cs +++ b/PROMS/VEPROMS.CSLA.Library/Generated/Content.cs @@ -453,6 +453,10 @@ namespace VEPROMS.CSLA.Library if (_MyGrid == null) _MyGrid = Grid.New(this); return _MyGrid; } + set + { + _MyGrid = value; + } } private int _ContentImageCount = 0; ///