diff --git a/EduNetworkBuilder/RTFWindow.cs b/EduNetworkBuilder/RTFWindow.cs index c20e3e1..ffd5efe 100644 --- a/EduNetworkBuilder/RTFWindow.cs +++ b/EduNetworkBuilder/RTFWindow.cs @@ -10,6 +10,7 @@ using System.Windows.Forms; using System.IO; using System.Globalization; using System.Resources; +using System.Text.RegularExpressions; namespace EduNetworkBuilder @@ -81,21 +82,117 @@ namespace EduNetworkBuilder } if (WhatToShow == RTFWindowContents.help) { - myRTF = Properties.Resources.Help; + myRTF = SafeRTF(Properties.Resources.Help); rtbContent.Rtf = myRTF; } else if (WhatToShow == RTFWindowContents.about) { - myRTF = Properties.Resources.about; + myRTF = SafeRTF(Properties.Resources.about); rtbContent.Rtf = myRTF; } else if (WhatToShow == RTFWindowContents.release_notes) { - myRTF = Properties.Resources.ReleaseNotes; + myRTF = SafeRTF(Properties.Resources.ReleaseNotes); rtbContent.Rtf = myRTF; } } + /// + /// When running using Mono (on Linux) the RTF reader fails on some images. + /// + /// + /// + public string SafeRTF(string inRTF) + { + string What = string.Copy(inRTF); + if (!NB.IsRunningOnMono()) return What; + string newWhat = ""; + List ToMatch = new List(); + ToMatch.Add(@"{\nonshppict"); + ToMatch.Add(@"{\*\shppict"); + ToMatch.Add(@"{\pict"); + + string MatchedSoFar = ""; + int count = 0; + int posincompare = 0; + bool Foundit = false; + bool FoundPartMatch = false; + int posinfile = 0; + using (var ms = new MemoryStream()) + { + var sw = new StreamWriter(ms); + foreach (char c in What) + { + posinfile++; + if (posinfile % 10000 == 0) + Console.WriteLine(" Place " + posinfile); + if (Foundit) + { + if (c == '{') count++; + if (c == '}') count--; + if (count == 0) + { + Foundit = false; //We have finished finding it. + posincompare = 0;//start from the beginning again + } + } + else + { + MatchedSoFar += c; + FoundPartMatch = false; + for(int i=0; i< ToMatch.Count; i++) + { + int howfar = MatchedSoFar.Length; + if (ToMatch[i].Length < howfar) howfar = ToMatch[i].Length; + if (MatchedSoFar.Equals(ToMatch[i].Substring(0,howfar))) + { + FoundPartMatch = true; + break; + } + } + + if (FoundPartMatch) + { + posincompare++; + for (int i = 0; i < ToMatch.Count; i++) + { + if (ToMatch[i].Equals(MatchedSoFar)) + Foundit = true; + } + if (Foundit) + { + posincompare = 0; + Foundit = true; + count = 1; //There is one { in the compare string + MatchedSoFar = "";//reset it + } + } + else + { + if (posincompare > 0) + { + //newWhat += picstart.Substring(0, posincompare); + sw.Write(MatchedSoFar); //What has matched up to this point + posincompare = 0; + } + else + { + //newWhat += c; + sw.Write(c); + } + MatchedSoFar = ""; //reset it + } + } + } + Console.WriteLine(" Place " + posinfile); + sw.Flush(); + ms.Position = 0; + var sr = new StreamReader(ms); + newWhat = sr.ReadToEnd(); + } + return newWhat; + } + public void JumpToSelection(string WhatToFind) { int indexToText = rtbContent.Find(WhatToFind);