Changed CheckOffs

Made DisplayText more generic
Added comments
- Added parameter to DisplayText
- Removed specific OutlineTable
This commit is contained in:
Rich
2010-05-25 16:12:51 +00:00
parent 8fd6c2eac4
commit 9cc6174ad1
4 changed files with 76 additions and 49 deletions

View File

@@ -109,22 +109,63 @@ namespace Volian.Controls.Library
/// bool noEdit - flags whether to edit or not (used to set data in
/// rtb as resolved replacewords for non-active rtb.
/// E_FieldToEdit fieldToEdit - identifies the field to edit (number or text)
/// bool colorLinks - whether to add color to links
/// </summary>
public DisplayText(ItemInfo itemInfo, E_EditPrintMode epMode, E_ViewMode vwMode, bool noEdit,E_FieldToEdit fieldToEdit)
public DisplayText(ItemInfo itemInfo, E_EditPrintMode epMode, E_ViewMode vwMode, bool noEdit,E_FieldToEdit fieldToEdit, bool colorLinks)
{
_FieldToEdit = fieldToEdit;
_MyItemInfo = itemInfo;
OriginalText = InfoText;
TextFont = itemInfo.GetItemFont();//GetItemFont();
string text = InfoText;
_MyFormat = itemInfo.ActiveFormat;
bool tableShouldBeOutlined = (epMode == E_EditPrintMode.Print || vwMode == E_ViewMode.View || noEdit) &&
(_FieldToEdit == E_FieldToEdit.StepText || _FieldToEdit == E_FieldToEdit.Text) &&
(!itemInfo.IsSection && !itemInfo.IsProcedure) && (itemInfo.IsTable || itemInfo.IsFigure);
bool wordsShouldBeReplaced = epMode == E_EditPrintMode.Print || vwMode == E_ViewMode.View || noEdit;
bool numbersShouldBeFormated = (!_MyFormat.PlantFormat.FormatData.SectData.StepSectionData.FortranFormatNumbers && (epMode == E_EditPrintMode.Print || vwMode == E_ViewMode.View || noEdit));
int typ = ((int)itemInfo.MyContent.Type) % 10000;
bool tableHasBorder = tableShouldBeOutlined ? itemInfo.ActiveFormat.PlantFormat.FormatData.StepDataList[typ].Type.IndexOf(@"Borderless") < 0 : false;
text = CreateRtf(colorLinks, text, tableShouldBeOutlined, wordsShouldBeReplaced, numbersShouldBeFormated, tableHasBorder);
StartText = text;
}
public DisplayText(string text, VE_Font vFont, bool colorLinks)
{
TextFont = vFont;
StartText = CreateRtf(colorLinks, text, false, false, false, false);
}
private string CreateRtf(bool colorLinks, string text, bool tableShouldBeOutlined, bool wordsShouldBeReplaced, bool numbersShouldBeFormated, bool tableHasBorder)
{
// add colors around links:
if (colorLinks)
{
text = Regex.Replace(text, @"(<START\].*?\\v0) ", @"$1\cf1 ");
//text = Regex.Replace(text, @"<START]\b0\v0 ", @"<START]\b0\v0\cf1 ");
int indxcf = text.IndexOf("cf1");
while (indxcf != -1)
{
int indxend = text.IndexOf(@"\v", indxcf);
text = text.Insert(indxend, @"\cf0");
indxcf = text.IndexOf(@"cf1", indxend);
}
}
// determine whether the table/figure should be outlined:
if (tableShouldBeOutlined)
{
OutlineRTFTable myTable = new OutlineRTFTable(text, tableHasBorder);
myTable.OutlineTable();
text = myTable.Lines.ToString();
}
// 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.
_MyFormat = itemInfo.ActiveFormat;
if (epMode == E_EditPrintMode.Print || vwMode == E_ViewMode.View || noEdit) text = DoReplaceWords(text);
if (wordsShouldBeReplaced) text = DoReplaceWords(text);
// adjust formatting of exponents
if (!_MyFormat.PlantFormat.FormatData.SectData.StepSectionData.FortranFormatNumbers && (epMode == E_EditPrintMode.Print || vwMode == E_ViewMode.View || noEdit)) text = DoFortranFormat(text);
if (numbersShouldBeFormated) text = DoFortranFormat(text);
// as a precaution, convert any \~ to \u160?. This is for Hard spaces. see the commentary in the
// save portion of this code for an explanation.
@@ -134,17 +175,6 @@ namespace Volian.Controls.Library
// MessageBox.Show("Found rtf line");
text = text.Replace(@"\line", @"\par");
// add colors around links:
text = Regex.Replace(text, @"(<START\].*?\\v0) ", @"$1\cf1 ");
//text = Regex.Replace(text, @"<START]\b0\v0 ", @"<START]\b0\v0\cf1 ");
int indxcf = text.IndexOf("cf1");
while (indxcf != -1)
{
int indxend = text.IndexOf(@"\v", indxcf);
text = text.Insert(indxend, @"\cf0 ");
indxcf = text.IndexOf(@"cf1", indxend);
}
// Now put symbol (for fixed fonts) or unicode font (proportional) around symbols
// These fonts are VESymbFix & Arial Unicode MS respectively, and the font table
// is actually defined in the StepRTB code.
@@ -155,19 +185,19 @@ namespace Volian.Controls.Library
if (text[indxsym + 2] != 'l')
{
text = text.Insert(indxsym, @"\f1 ");
int indxendsym = text.IndexOfAny(@"\ ?".ToCharArray(),indxsym+5);
int indxendsym = text.IndexOfAny(@"\ ?".ToCharArray(), indxsym + 5);
if (indxendsym == -1) // must be end of line:
text = text.Insert(text.Length-1,@"\f0 ");
text = text.Insert(text.Length - 1, @"\f0 ");
else
{
if (text[indxendsym]=='?') indxendsym++;
if (text[indxendsym] == '?') indxendsym++;
text = text.Insert(indxendsym, @"\f0 "); // TODO: do I need a space??
}
incrindx = 5;
}
indxsym = text.IndexOf(@"\u",indxsym + incrindx);
indxsym = text.IndexOf(@"\u", indxsym + incrindx);
}
StartText = text;
return text;
}
private string DoFortranFormat(string text)
@@ -195,7 +225,7 @@ namespace Volian.Controls.Library
{
try
{
FormatInfo formatInfo = _MyItemInfo.ActiveFormat;
//FormatInfo formatInfo = _MyItemInfo.ActiveFormat;
using (_MyItem = _MyItemInfo.Get())
{
// check for different text, i.e. text from this itm doesn't match
@@ -973,13 +1003,6 @@ namespace Volian.Controls.Library
}
#endregion
#region ReplaceWords
private ReplaceStr _rs;
//private string ReplaceIt(Match m)
//{
// string s = m.ToString();
// string t = s.Replace(_rs.ReplaceWord, _rs.ReplaceWith);
// return m.ToString().Replace(_rs.ReplaceWord, _rs.ReplaceWith);
//}
private string DoReplaceWords(string Text)
{
ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList;
@@ -1032,7 +1055,7 @@ namespace Volian.Controls.Library
else
{
// If there are Regex Control Characters '\[]()' prefix them with backslash
string replaceWord = Regex.Replace(rs.ReplaceWord, @"\\[[\]()]", @"\$0");
string replaceWord = Regex.Replace(rs.ReplaceWord, @"[[\]\\()]", @"\$0");
string pat = @"(?<=\W|^)" + replaceWord + @"(?=\W|$)";
try
{