Fix to import Transitions in Grids (tables) and handle the dash characters

Added a Set method to MyGrid
This commit is contained in:
John Jenko 2016-08-31 18:40:25 +00:00
parent ae2473ba24
commit 0245c9fe7a
2 changed files with 90 additions and 25 deletions

View File

@ -117,38 +117,99 @@ namespace VEPROMS.CSLA.Library
myLength += mg.Groups[3].Length; myLength += mg.Groups[3].Length;
} }
string gg = MyGrid.Data.Substring(myIndex, myLength); string gg = MyGrid.Data.Substring(myIndex, myLength);
if (newvalue.Contains(@"\u8209?")) // process dash if (newvalue.Contains(@"\u8209?")) // process dash
{ newvalue = ProcessSpecChar(gg, newvalue, @"\u8209?","-");
Match m = Regex.Match(newvalue, @"(\\f[0-9]+)(\\u[0-9]{1,4}\?)(\\f[0-9]+ ?)"); if (newvalue.Contains(@"\u8593?")) // process carrot/delta
if (m == null) newvalue = ProcessSpecChar(gg, newvalue, @"\u8593?","^");
newvalue = newvalue.Replace(@"\u8209?", "-"); if (newvalue.Contains(@"\u9586?")) // process backslash
else newvalue = ProcessSpecChar(gg, newvalue, @"\u9586?",@"\\");
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 (gg != newvalue) 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) public string ConvertTransitionToText(TransitionInfo tran, string value)
{ {
string retval = null; string retval = null;

View File

@ -453,6 +453,10 @@ namespace VEPROMS.CSLA.Library
if (_MyGrid == null) _MyGrid = Grid.New(this); if (_MyGrid == null) _MyGrid = Grid.New(this);
return _MyGrid; return _MyGrid;
} }
set
{
_MyGrid = value;
}
} }
private int _ContentImageCount = 0; private int _ContentImageCount = 0;
/// <summary> /// <summary>