2009-03-09 13:09:02 +00:00

411 lines
63 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System; 
using System.Text; 
using System.Text.RegularExpressions; 
瀀 倀
{瀀  瀀
{ 倀瀀
private ItemInfo _MyItemInfo;   瀀       倀    
// transitions & plain text.਍ऀऀ瀀爀椀瘀愀琀攀 䰀椀猀琀㰀搀椀猀瀀氀愀礀吀攀砀琀䔀氀攀洀攀渀琀㸀 开䐀椀猀瀀氀愀礀吀攀砀琀䔀氀攀洀攀渀琀䰀椀猀琀㬀ഀ
public List<displayTextElement> DisplayTextElementList
get { return _DisplayTextElementList; }  瀀   
}             
// go away (it is not really used).਍ऀऀ瀀爀椀瘀愀琀攀 䐀椀挀琀椀漀渀愀爀礀㰀椀渀琀Ⰰ 猀琀爀椀渀最㸀 开搀椀挀刀琀昀䘀漀渀琀吀愀戀氀攀㬀ഀ
public Dictionary<int, string> dicRtfFontTable
get { return _dicRtfFontTable; }     
}瀀        
public VE_Font TextFont
get { return _textFont; }       
}瀀   瀀      
public string OriginalConfigText;瀀  
#endregion 
/// <summary>਍ऀऀ⼀⼀⼀     䐀椀猀瀀氀愀礀吀攀砀琀 挀漀渀猀琀爀甀挀琀漀爀㨀ഀ
/// Creates a DisplayText object that converts the database text into a list of ਍ऀऀ⼀⼀⼀ऀऀऀऀ搀椀猀瀀氀愀礀吀攀砀琀䔀氀攀洀攀渀琀 攀氀攀洀攀渀琀猀⸀ഀ
/// Arguments are:਍ऀऀ⼀⼀⼀ऀऀऀऀ䤀琀攀洀䤀渀昀漀 椀琀攀洀䤀渀昀漀 ⴀ 琀栀攀 椀琀攀洀 眀栀漀猀攀 琀攀砀琀 眀椀氀氀 戀攀 爀攀猀漀氀瘀攀搀ഀ
/// E_EditPrintMode ep_mode - edit or print.਍ऀऀ⼀⼀⼀ऀऀऀऀ䔀开嘀椀攀眀䴀漀搀攀 瘀眀开洀漀搀攀 ⴀ 瘀椀攀眀 漀爀 攀搀椀琀⸀ഀ
/// </summary>਍ऀऀ瀀甀戀氀椀挀 䐀椀猀瀀氀愀礀吀攀砀琀⠀䤀琀攀洀䤀渀昀漀 椀琀攀洀䤀渀昀漀Ⰰ 䔀开䔀搀椀琀倀爀椀渀琀䴀漀搀攀 攀瀀䴀漀搀攀Ⰰ 䔀开嘀椀攀眀䴀漀搀攀 瘀眀䴀漀搀攀⤀ഀ
{  
DisplayTextElementList = new List<displayTextElement>();  
TextFont = GetItemFont();   
   瀀      瀀         瀀
// words left as is.਍ऀऀऀ开䴀礀䘀漀爀洀愀琀 㴀 椀琀攀洀䤀渀昀漀⸀䄀挀琀椀瘀攀䘀漀爀洀愀琀㬀ഀ
if (epMode == E_EditPrintMode.Print || vwMode == E_ViewMode.View) text = DoReplaceWords(text);
// as a precaution, convert any \~ to \u160?. This is for Hard spaces.. see the commentary in the਍ऀऀऀ⼀⼀ 猀愀瘀攀 瀀漀爀琀椀漀渀 漀昀 琀栀椀猀 挀漀搀攀 昀漀爀 愀渀 攀砀瀀氀愀渀愀琀椀漀渀⸀ഀ
text = text.Replace(@"\~", @"\u160?");
// replace the dash/hyphen or whatever you want to call it, with a hard hyphen. The 16-bit program਍ऀऀऀ⼀⼀ 琀爀攀愀琀攀搀 琀栀攀 搀愀猀栀⼀栀礀瀀栀攀渀 愀猀 猀甀挀栀⸀  吀爀愀渀猀氀愀琀攀 戀愀挀欀 漀渀 愀渀礀 搀愀琀愀 猀愀瘀攀猀⸀ഀ
text = text.Replace(@"-", @"\u8209?");
// displayTextElement List items are created for anything that is handled differently in RTB, i.e.਍ऀऀऀ⼀⼀ 猀礀洀戀漀氀猀Ⰰ 爀漀猀Ⰰ 琀爀愀渀猀Ⰰ 琀攀砀琀⸀ഀ
int startIndex = 0;   
while ((index = FindTokenChar(text, startIndex))>-1)
// Do any 'plain' text that preceeds the token.਍ऀऀऀऀ椀昀 ⠀椀渀搀攀砀 㸀 猀琀愀爀琀䤀渀搀攀砀⤀ 䐀漀吀攀砀琀䔀氀攀洀攀渀琀⠀琀攀砀琀Ⰰ 猀琀愀爀琀䤀渀搀攀砀Ⰰ 椀渀搀攀砀⤀㬀ഀ
     瀀
if (text[index] == '\x15')   
else if (text[index] == '\x252C' || text[index]=='\x2566')   
else    
startIndex = index; // +1;਍ऀऀऀऀ椀昀 ⠀猀琀愀爀琀䤀渀搀攀砀 㸀㴀 琀攀砀琀⸀䰀攀渀最琀栀⤀ 戀爀攀愀欀㬀ഀ
}    
if (startIndex < text.Length) DoTextElement(text, startIndex, index);
#endregion 
public bool Save(RichTextBox rtb)
try
List<displayLinkElement> origList = GetLinkList(DisplayTextElementList);      瀀
RtfToDisplayTextElements(rtb);               
StringBuilder sret = new StringBuilder(); 瀀   瀀
{ 瀀  瀀  瀀  瀀
sret.Append(vte.Text);  瀀  瀀
sret.Append(ToData_RO((displayLinkElement)vte));  瀀  瀀  瀀  瀀
sret.Append(ToData_Trans((displayLinkElement)vte));
string modtext = sret.ToString();
if (modtext != OriginalText)
Item itm = _MyItemInfo.Get();           
// original text.਍ऀऀऀऀऀ椀昀 ⠀伀爀椀最椀渀愀氀吀攀砀琀 ℀㴀 椀琀洀⸀䴀礀䌀漀渀琀攀渀琀⸀吀攀砀琀⤀ഀ
{         
return false;
// Compare ro/transition lists and delete or add any to the item for any ros/transitions that have been਍ऀऀऀऀऀ⼀⼀ 愀搀搀攀搀⼀搀攀氀攀琀攀搀 漀爀 洀漀搀椀昀椀攀搀⸀ഀ
ProcessRoTranChanges(itm, origList);  
itm.Save();  
}
return true; // no text changed, but did not fail so return true.਍ऀऀऀ紀ഀ
catch (Exception ex)
Console.WriteLine("Save Failed with error: {0}", ex.Message); 
} 
}瀀  倀  瀀 
{             
// 1) delete any that are in origList but not in the DisplayTextElementList਍ऀऀऀ⼀⼀ऀऀ琀栀愀琀 爀攀瀀爀攀猀攀渀琀猀 琀栀攀 挀甀爀爀攀渀琀 琀攀砀琀  氀椀渀欀猀⤀ഀ
// 2) add any that are only in DisplayTextElementList਍ऀऀऀ⼀⼀ऀ㌀⤀ऀ搀攀氀攀琀攀⼀愀搀搀 昀漀爀 洀漀搀椀昀礀㼀ഀ
              
// in the original list.਍ऀऀऀ昀漀爀攀愀挀栀 ⠀搀椀猀瀀氀愀礀䰀椀渀欀䔀氀攀洀攀渀琀 漀搀琀攀 椀渀 漀爀椀最䰀椀猀琀⤀ഀ
{   
foreach (displayTextElement dte in DisplayTextElementList)
if (dte.Type == odte.Type)
displayLinkElement l_dte = (displayLinkElement)dte;   
{  
break;
}
// remove the link element from the item.਍ऀऀऀऀ椀昀 ⠀℀昀漀甀渀搀⤀ഀ
{               
// in the item's list. remove it.਍ऀऀऀऀऀ椀渀琀 爀攀挀椀搀 㴀 ⴀ㄀㬀ഀ
if (odte.Type != E_TextElementType.ReferencedObject)
int sp = odte.Link.IndexOf(" ") + 1; // get past tran type਍ऀऀऀऀऀऀ猀琀爀椀渀最 猀爀攀挀椀搀  漀搀琀攀⸀䰀椀渀欀⸀匀甀戀猀琀爀椀渀最猀瀀Ⰰ 漀搀琀攀⸀䰀椀渀欀⸀䤀渀搀攀砀伀昀 ∀Ⰰ 猀瀀⤀  猀瀀⤀㬀ഀ
recid = System.Convert.ToInt32(srecid);    
{   
{
break;
}
else
int sp = odte.Link.IndexOf(" ");          
string srecid = odte.Link.Substring(23, sp-23);  
foreach (ContentRoUsage cr in itm.MyContent.ContentRoUsages)
if (cr.ROUsageID == recid)
itm.MyContent.ContentRoUsages.Remove(cr);
}
}
}           
foreach (displayTextElement dte in DisplayTextElementList)
bool found = false; 瀀  瀀  瀀  瀀  瀀  瀀
{ 瀀   
{ 瀀  瀀
{             
displayLinkElement l_dte = (displayLinkElement)dte;   
{  
break;
}
// Insert the link (ro or transition) to the item਍ऀऀऀऀऀ椀昀 ℀昀漀甀渀搀⤀ഀ
{ 瀀  瀀    
{瀀   瀀
Match m = Regex.Match(l_dte.Link, ".*[#]Link:([A-Za-z]*):(.*)");  瀀
//_Roid = m.Groups[3].Value;਍ऀऀऀऀऀऀऀ猀琀爀椀渀最 氀椀渀欀猀琀爀 㴀 洀⸀䜀爀漀甀瀀猀嬀㈀崀⸀嘀愀氀甀攀㬀ഀ
if (linkstr[0] == ' ') linkstr = linkstr.Substring(1, linkstr.Length - 1);     
string roid = linkstr.Substring(roidindx, linkstr.Length - roidindx);            
//int rou਍ऀऀऀऀऀऀऀ⼀⼀椀渀琀 琀爀椀搀  挀琀⸀吀爀愀渀猀椀琀椀漀渀䤀䐀㬀ഀ
break;
else if (dte.Type == E_TextElementType.TransitionRange || dte.Type == E_TextElementType.Transition)
displayLinkElement l_dte = (displayLinkElement)dte;    
string linkstr = m.Groups[2].Value;           
int type = System.Convert.ToInt32(linkstr.Substring(0,1));          瀀  瀀   瀀
int trindx2 = linkstr.IndexOf(" ", trindx + 1);        
int tr1 = System.Convert.ToInt32(linkstr.Substring(trindx + 1, trindx2 - trindx));   
int tr2 = 0;   
if (dte.Type == E_TextElementType.TransitionRange)
tr2 = System.Convert.ToInt32(linkstr.Substring(trindx2,linkstr.Length-trindx2));   
}    
ct.TranType = type;   
}
}
}瀀 瀀 瀀 瀀
{瀀    瀀
foreach (displayTextElement vte in locDisplayTextElementList)
if (vte.Type == E_TextElementType.ReferencedObject || vte.Type == E_TextElementType.TransitionRange || vte.Type == E_TextElementType.Transition)
displayLinkElement tmp = (displayLinkElement)vte;瀀 瀀   瀀
copy_vte.Type = tmp.Type;瀀  瀀
copy_vte.Text = tmp.Text;瀀
}
return retList;
private void RtfToDisplayTextElements(RichTextBox rtb)
// For hardspaces, the windows richtextbox does some 'quirky' things:਍ऀऀऀ⼀⼀ 䄀 甀渀椀挀漀搀攀 爀攀瀀爀攀猀攀渀琀愀琀椀漀渀 漀昀 尀甀㄀㘀 㼀 椀猀 猀攀渀琀 䤀一吀伀 琀栀攀 爀琀戀⸀  䌀漀洀椀渀最 漀甀琀Ⰰ ഀ
// that \u160? was translated to a \~ (by the underlying windows rtb).਍ऀऀऀ⼀⼀ 一漀琀攀 琀栀愀琀 椀昀 琀栀攀 尀縀 椀猀 猀攀渀琀 琀漀 琀栀攀 爀琀戀Ⰰ 椀琀 椀猀 琀爀攀愀琀攀搀 愀猀 愀 爀攀最甀氀愀爀 猀瀀愀挀攀Ⰰഀ
// i.e. no longer a hardspace, and actually is converted to a regular space.਍ऀऀऀ⼀⼀ 匀伀Ⰰ 漀渀 琀栀攀 眀愀礀 漀甀琀Ⰰ 挀漀渀瘀攀爀琀 愀渀礀 尀縀 琀漀 尀甀㄀㘀 㼀ഀ
string noExtraRtfStr = rtb.Rtf.Replace(@"\~", @"\u160?");
         
// font table for the unicode font, if it is used (otherwise -1)਍ऀऀऀ⼀⼀椀渀琀 甀渀椀挀漀搀攀䘀漀渀琀 㴀 䜀攀琀䘀漀渀琀吀愀戀氀攀⠀爀琀戀⸀刀琀昀⤀㬀ഀ
 瀀    
noExtraRtfStr = StripRtfCommands(noExtraRtfStr);瀀   
                
// of other rtf commands though since the \u8209 was surrounded by font commands਍ऀऀऀ⼀⼀ 琀栀愀琀Ⰰ 眀椀琀栀漀甀琀 琀栀攀爀攀 爀攀洀漀瘀愀氀 昀椀爀猀琀Ⰰ 眀愀猀 愀氀猀漀 爀攀洀漀瘀椀渀最 琀栀攀 搀愀猀栀⸀  䠀愀瘀攀 椀琀 眀椀琀栀 
// a space & without because if it is at the end, there will be no space (leave਍ऀऀऀ⼀⼀ 椀琀 琀漀 爀琀昀 瀀爀漀挀攀猀猀椀渀最 琀漀 洀愀欀攀 椀琀 洀漀爀攀 挀漀洀瀀氀椀挀愀琀攀搀⤀ഀ
noExtraRtfStr = noExtraRtfStr.Replace(@"\u8209? ", @"-");  瀀䀀  䀀
瀀
int startIndex = 0;   
while ((index = FindRtfChar(noExtraRtfStr, startIndex)) > -1)
int fndindx = -1;   瀀   瀀  
if (index > startIndex)    
if ((fndindx = noExtraRtfStr.IndexOf(@"\protect",index)) == index)   
else   
startIndex = index + 1;    
}    
if (startIndex < noExtraRtfStr.Length) DoTextElement(noExtraRtfStr, startIndex, index);
}瀀       
{瀀    瀀
vte.Type = E_TextElementType.Text;             
vte.Text = data.Substring(startIndex, len);瀀
return index;
private int SaveSymbolTE(string data, int startIndex)
displayLinkElement vte = new displayLinkElement();瀀  瀀
// symbols are just the unicode/rtf command, no font associated with it਍ऀऀऀ⼀⼀ 戀礀 琀栀攀 琀椀洀攀 椀琀 最攀琀猀 栀攀爀攀⸀⸀⸀  猀礀洀戀漀氀 挀愀渀 戀攀 爀攀瀀爀攀猀攀渀琀攀搀 戀礀 尀✀砀礀 漀爀 尀甀砀礀稀㼀ഀ
// if the \'xy is used the length of the symbol number will always be two,਍ऀऀऀ⼀⼀ 漀琀栀攀爀眀椀猀攀 昀椀渀搀 琀栀攀 椀渀搀攀砀 漀昀 琀栀攀 ✀㼀✀ 琀漀 昀椀渀搀 琀栀攀 攀渀搀⸀ഀ
int endindx = -1;          
else endindx = data.IndexOf("?", startIndex);          
vte.Text = data.Substring(startIndex, endindx - startIndex + 1);瀀
if (endindx+1<data.Length && data[endindx + 1] != ' ') return endindx;        瀀  瀀           
}瀀     
{瀀    瀀
// find the end of the link text, i.e. either the ending \v0 or \protect0. The win32 rtf box can਍ऀऀऀ⼀⼀ 瀀甀琀 琀栀攀猀攀 椀渀 攀椀琀栀攀爀 漀爀搀攀爀Ⰰ 琀愀欀攀 琀栀攀 氀漀眀攀猀琀 椀渀搀攀砀⸀ഀ
int startIndex = stIndex + @"\protect ".Length;    䀀  
int indx_protect0 = data.IndexOf(@"\protect0", startIndex);    瀀  瀀 
LinkText lt = new LinkText(data.Substring(startIndex,indx-startIndex));瀀    瀀
vte.Type = (E_TextElementType)lt.MyParsedLinkType;  
vte.Link = lt.MyLink;瀀
return (indx_v0<indx_protect0?indx_protect0+1:indx_v0+1);
//private int SaveTranTE(string data, int startIndex, E_TextElementType type)਍ऀऀ⼀⼀笀ഀ
// displayLinkElement vte = new displayLinkElement();਍ऀऀऀഀ
// vte.Type = type;਍ऀऀ⼀⼀    ⼀⼀ 尀瀀爀漀琀攀挀琀 笀琀爀愀渀猀椀琀椀漀渀 琀攀砀琀紀 尀瘀 ⌀䰀椀渀欀㨀吀爀愀渀猀椀琀椀漀渀⠀刀愀渀最攀⤀㨀 ㄀ ㈀ ㌀尀瀀爀漀琀攀挀琀 尀瘀   ഀ
// // where 1 2 3 are transition type and ids਍ऀऀ⼀⼀    椀渀琀 椀渀搀砀  搀愀琀愀⸀䤀渀搀攀砀伀昀∀尀尀瘀 ⌀䰀椀渀欀㨀吀爀愀渀猀椀琀椀漀渀∀Ⰰ 猀琀愀爀琀䤀渀搀攀砀⤀㬀ഀ
// // use '9' to get past \\protect਍ऀऀ⼀⼀    瘀琀攀⸀吀攀砀琀  搀愀琀愀⸀匀甀戀猀琀爀椀渀最猀琀愀爀琀䤀渀搀攀砀  㤀Ⰰ 椀渀搀砀  猀琀愀爀琀䤀渀搀攀砀  㤀⤀㬀ഀ
// // the link is the text between the #Link... and the next '\\'.਍ऀऀ⼀⼀    椀渀琀 椀攀渀搀 㴀 搀愀琀愀⸀䤀渀搀攀砀伀昀⠀∀尀尀∀Ⰰ 椀渀搀砀⬀㄀⤀㬀ഀ
// int bindx = data.IndexOf("#", indx);਍ऀऀ⼀⼀    瘀琀攀⸀䰀椀渀欀 㴀 搀愀琀愀⸀匀甀戀猀琀爀椀渀最⠀戀椀渀搀砀Ⰰ 椀攀渀搀 ⴀ 戀椀渀搀砀⤀㬀ऀऀऀ ഀ
// DisplayTextElementList.Add(vte);਍ऀऀ⼀⼀    ⼀⼀ 甀渀昀漀爀琀甀渀愀琀攀氀礀Ⰰ 琀栀攀 爀琀昀 戀漀砀 洀愀礀 愀搀搀 琀栀攀 尀瀀爀漀琀攀挀琀  尀瘀  椀渀 攀椀琀栀攀爀 漀爀搀攀爀ഀ
// // and with or without one or more spaces between then. The number of text਍ऀऀ⼀⼀    ⼀⼀ 挀栀愀爀愀挀琀攀爀猀  ㄀㄀ 昀漀爀 尀瀀爀漀琀攀挀琀 尀瘀   昀椀渀搀 琀栀攀 渀甀洀戀攀爀 漀昀 猀瀀愀挀攀猀 戀攀琀眀攀攀渀 琀栀攀洀ഀ
// // if any?਍ऀऀ⼀⼀    椀渀琀 渀猀瀀 㴀  㬀ഀ
// for (int c = iend; c < iend + 11; c++) if (data[c] == ' ') nsp++;਍ऀऀ⼀⼀    爀攀琀甀爀渀 椀攀渀搀 ⬀ ㄀㄀ ⬀ 渀猀瀀㬀ഀ
//}਍ऀऀ⼀⼀瀀爀椀瘀愀琀攀 椀渀琀 匀愀瘀攀刀伀吀䔀⠀猀琀爀椀渀最 搀愀琀愀Ⰰ 椀渀琀 猀琀愀爀琀䤀渀搀攀砀⤀ഀ
//{਍ऀऀ⼀⼀    搀椀猀瀀氀愀礀䰀椀渀欀䔀氀攀洀攀渀琀 瘀琀攀 㴀 渀攀眀 搀椀猀瀀氀愀礀䰀椀渀欀䔀氀攀洀攀渀琀⠀⤀㬀ഀ
// vte.Type = E_TextElementType.ReferencedObject;਍ऀऀ⼀⼀    ⼀⼀ 尀瀀爀漀琀攀挀琀 笀爀漀瘀愀氀甀攀紀 尀瘀 ⌀䰀椀渀欀㨀刀攀昀攀爀攀渀挀攀搀伀戀樀攀挀琀 ⠀刀漀唀猀愀最攀䤀搀⤀ 笀刀伀䤀䐀紀尀瀀爀漀琀攀挀琀 尀瘀 ഀ
// int indx = data.IndexOf("\\v #Link:ReferencedObject", startIndex);਍ऀऀ⼀⼀    ⼀⼀ 甀猀攀 ✀㤀✀ 琀漀 最攀琀 瀀愀猀琀 尀尀瀀爀漀琀攀挀琀ഀ
// vte.Text = data.Substring(startIndex + 9, indx - startIndex - 9);਍ऀऀ⼀⼀    ⼀⼀ 琀栀攀 氀椀渀欀 椀猀 琀栀攀 琀攀砀琀 戀攀琀眀攀攀渀 琀栀攀 ⌀䰀椀渀欀⸀⸀⸀ 愀渀搀 琀栀攀 渀攀砀琀 ✀尀尀✀⸀ഀ
// int iend = data.IndexOf("\\", indx);਍ऀऀ⼀⼀    椀渀琀 戀椀渀搀砀 㴀 搀愀琀愀⸀䤀渀搀攀砀伀昀⠀∀⌀∀Ⰰ 椀渀搀砀⤀㬀ഀ
// vte.Link = data.Substring(bindx, iend - bindx);਍ऀऀ⼀⼀    䐀椀猀瀀氀愀礀吀攀砀琀䔀氀攀洀攀渀琀䰀椀猀琀⸀䄀搀搀⠀瘀琀攀⤀㬀ഀ
// // unfortunately, the rtf box may add the \protect0 \v0 in either order਍ऀऀ⼀⼀    ⼀⼀ 愀渀搀 眀椀琀栀 漀爀 眀椀琀栀漀甀琀 漀渀攀 漀爀 洀漀爀攀 猀瀀愀挀攀猀 戀攀琀眀攀攀渀 琀栀攀渀⸀  吀栀攀 渀甀洀戀攀爀 漀昀 琀攀砀琀ഀ
// // characters = 11 for \protect0\v0 - find the number of spaces between them਍ऀऀ⼀⼀    ⼀⼀ 椀昀 愀渀礀㼀ഀ
// int nsp = 0;਍ऀऀ⼀⼀    昀漀爀 ⠀椀渀琀 挀 㴀 椀攀渀搀㬀 挀 㰀 椀攀渀搀 ⬀ ㄀㄀㬀 挀⬀⬀⤀ 椀昀 ⠀搀愀琀愀嬀挀崀 㴀㴀 ✀ ✀⤀ 渀猀瀀⬀⬀㬀ഀ
// return iend + 11 + nsp;਍ऀऀ⼀⼀紀ഀ
private int FindRtfChar(string text, int startIndex)
// look for the first 'rtf' token that represents either a link or symbol. Skip਍ऀऀऀ⼀⼀ 漀瘀攀爀 愀渀礀 昀漀爀洀愀琀琀椀渀最 挀漀洀洀愀渀搀猀⸀⸀ഀ
bool done = false;   
while (!done)
indx = text.IndexOf("\\", indx);     
if ((indx + 8) < text.Length && text.Substring(indx + 1, 7) == "protect") return indx;        
if (text.Substring(indx + 1, 1) == "u" && text.Substring(indx + 2, 1) != "l") return indx;         瀀    
} 
 瀀  瀀 
//int symindx1 = text.IndexOf("\\'", startIndex);਍ऀऀऀ⼀⼀椀渀琀 猀礀洀椀渀搀砀㈀ 㴀 琀攀砀琀⸀䤀渀搀攀砀伀昀⠀∀尀尀甀∀Ⰰ 猀琀愀爀琀䤀渀搀攀砀⤀㬀ഀ
//// if a 'u' is found, it can be either unicode or underline, if it's underline,਍ऀऀऀ⼀⼀⼀⼀ 猀攀愀爀挀栀 琀栀攀 猀琀爀椀渀最 昀漀爀 ഀ
//if (symindx2 > -1)਍ऀऀऀ⼀⼀笀ഀ
// if (text[symindx2+2] == 'l') symindx2 = -1; // don't process underlines਍ऀऀऀ⼀⼀紀ഀ
//if (prindx == -1 && symindx1 == -1 && symindx2 == -1) return -1;਍ऀऀऀ⼀⼀椀昀 ⠀瀀爀椀渀搀砀 㴀㴀 ⴀ㄀⤀ 瀀爀椀渀搀砀 㴀 琀攀砀琀⸀䰀攀渀最琀栀 ⬀ ㄀㬀ഀ
//if (symindx1 == -1) symindx1 = text.Length + 1;਍ऀऀऀ⼀⼀椀昀 ⠀猀礀洀椀渀搀砀㈀ 㴀㴀 ⴀ㄀⤀ 猀礀洀椀渀搀砀㈀ 㴀 琀攀砀琀⸀䰀攀渀最琀栀 ⬀ ㄀㬀ഀ
           
//// in the string. If it is a symbol - see if it has a font specifier਍ऀऀऀ⼀⼀⼀⼀ 昀椀爀猀琀⸀ഀ
//int symindx = symindx1 < symindx2 ? symindx1 : symindx2;਍ऀऀऀ⼀⼀椀渀琀 猀洀愀氀氀攀猀琀 㴀 ⠀瀀爀椀渀搀砀 㰀 猀礀洀椀渀搀砀 㼀 瀀爀椀渀搀砀 㨀 猀礀洀椀渀搀砀⤀㬀ഀ
//return smallest;਍ऀऀ紀ഀ
private int GetFontTable(string rtf)
dicRtfFontTable = new Dictionary<int, string>();          瀀 
// the font for symbols.਍ऀऀऀ椀渀琀 甀渀椀挀漀搀攀䘀漀渀琀 㴀 ⴀ㄀㬀ഀ
int bindx = rtf.IndexOf(@"{\fonttbl");     
int eindx = rtf.IndexOf("}}", bindx);         瀀     
// with font name.਍ऀऀऀ猀琀爀椀渀最 琀戀氀 㴀 爀琀昀⸀匀甀戀猀琀爀椀渀最⠀戀椀渀搀砀 ⬀ 㤀Ⰰ 攀椀渀搀砀 ⴀ 戀椀渀搀砀 ⴀ 㠀⤀㬀ഀ
tbl = tbl.Replace("{", "<");  瀀 
string pat = @"(?:<\\f)([0-9]+)(?:[\S]+ )([\w ]+)";    
foreach (Match m in Regex.Matches(tbl, pat))
int num = Convert.ToInt32(m.Result("${1}"));   
dicRtfFontTable.Add(num, nam);            
} 
}瀀   
{   
// remove rtf commands for any styles that were added. Note that if਍ऀऀऀ⼀⼀ 琀栀攀 攀渀琀椀爀攀 椀琀攀洀 栀愀猀  猀琀礀氀攀Ⰰ 愀渀搀 愀氀猀漀 挀漀渀琀愀椀渀猀 ✀瀀椀攀挀攀猀✀ 漀昀 琀攀砀琀 眀椀琀栀ഀ
// the same style, the underlying rtf box removes the embedded rtf commands,਍ऀऀऀ⼀⼀ 昀漀爀 攀砀愀洀瀀氀攀Ⰰ 椀昀 琀栀攀 攀渀琀椀爀攀 猀琀攀瀀 椀猀 戀漀氀搀攀搀Ⰰ 愀渀搀 ✀吀䠀䔀一✀ 栀愀猀 戀漀氀搀 漀渀⼀漀昀昀ഀ
// surrounding it, the rtf box removes the bold around the 'THEN'਍ऀऀऀ⼀⼀ 吀栀攀猀攀 爀攀洀漀瘀攀 琀栀攀 挀漀洀洀愀渀搀 眀椀琀栀 愀 昀漀氀氀漀眀椀渀最 猀瀀愀挀攀 漀爀 琀栀攀 挀漀洀洀愀渀搀 愀氀漀渀攀Ⰰഀ
// either case may exist, because if there are rtf commands following the਍ऀऀऀ⼀⼀ 猀琀礀氀攀 挀漀洀洀愀渀搀Ⰰ 琀栀攀爀攀 眀椀氀氀 戀攀 渀漀 猀瀀愀挀攀 挀栀愀爀愀挀琀攀爀 昀漀氀氀漀眀椀渀最 琀栀攀 猀琀礀氀攀 挀漀洀洀愀渀搀⸀ഀ
if ((TextFont.Style & E_Style.Bold) > 0)
retval = Regex.Replace(retval, @"\\b0 ?", "");  瀀 䀀 
}      
{  瀀 䀀  
retval = Regex.Replace(retval, @"\\ul ?", "");
if ((TextFont.Style & E_Style.Italics) > 0)
retval = Regex.Replace(retval, @"\\i0 ?", "");  瀀 䀀  
} 
}瀀  瀀 
{ 
{ 
if (Regex.IsMatch(m.Value, @"\\u[0-9]+"))   瀀 
if (Regex.IsMatch(m.Value, @"\\ulnone")) 
if (Regex.IsMatch(m.Value, @"\\ul.*"))   
break;   瀀 
return m.Value;   
return m.Value;    瀀
if (m.Value == @"\sub") return m.Value;   䀀瀀  
break;  瀀
if (m.Value == @"\nosupersub") return m.Value;
case 'i': // Italics਍ऀऀऀऀऀ爀攀琀甀爀渀 洀⸀嘀愀氀甀攀㬀ഀ
case '{': // look for escape for curly braces:਍ऀऀऀऀऀ爀攀琀甀爀渀 洀⸀嘀愀氀甀攀㬀ഀ
case '}': 
case 'v': // save link hidden info਍ऀऀऀऀऀ椀昀 洀⸀嘀愀氀甀攀 㴀㴀 䀀∀尀瘀∀⤀ 爀攀琀甀爀渀 洀⸀嘀愀氀甀攀㬀ऀ⼀⼀ 瀀愀爀琀 漀昀 氀椀渀欀ഀ
if (Regex.IsMatch(m.Value, @"\\v0"))     
break; 瀀
if (m.Value == @"\par") return "\r\n";   䀀瀀
return m.Value;   䀀瀀 
return m.Value;
} 瀀 
}瀀  瀀 
{ 瀀        瀀         
// are rtf so were getting removed and/or not handled correctly.਍ऀऀऀ猀琀爀椀渀最 爀攀琀瘀愀氀 㴀 爀琀昀⸀刀攀瀀氀愀挀攀⠀䀀∀尀笀∀Ⰰ 䀀∀⠀℀嬀∀⤀㬀ഀ
retval = retval.Replace(@"\}", @"(!]");  瀀 䀀  瀀  瀀    
retval = Regex.Replace(retval, @"^\{(.*)\}$", "$1", RegexOptions.Singleline); // Strip Opening and Closing Braces਍ऀऀऀ爀攀琀瘀愀氀  刀攀最攀砀⸀刀攀瀀氀愀挀攀爀攀琀瘀愀氀Ⰰ 䀀∀尀笀嬀帀笀崀⨀㼀尀紀∀Ⰰ ∀∀Ⰰ 刀攀最攀砀伀瀀琀椀漀渀猀⸀匀椀渀最氀攀氀椀渀攀⤀㬀 ⼀⼀ 匀琀爀椀瀀 䌀氀愀甀猀攀猀  爀攀洀漀瘀攀 愀渀礀琀栀椀渀最 昀爀漀洀 挀甀爀氀礀 戀爀愀挀攀猀ഀ
retval = Regex.Replace(retval, @"\{[^{]*?\}", "", RegexOptions.Singleline); // Strip Clauses - remove anything from curly braces਍ऀऀऀ爀攀琀瘀愀氀  刀攀最攀砀⸀刀攀瀀氀愀挀攀爀攀琀瘀愀氀Ⰰ 䀀∀尀尀嬀帀 尀尀㼀崀⬀∀Ⰰ 渀攀眀 䴀愀琀挀栀䔀瘀愀氀甀愀琀漀爀刀攀瀀氀愀挀攀刀吀䘀䌀氀愀甀猀攀⤀⤀㬀  ⼀⼀ 琀愀欀攀 戀愀挀欀猀氀愀猀栀 砀礀稀 愀渀搀 攀瘀愀氀甀愀琀攀猀 琀栀攀洀ഀ
// remove a space if there is one as the first character..਍ऀऀऀ椀昀 ⠀爀攀琀瘀愀氀嬀 崀㴀㴀✀ ✀⤀爀攀琀瘀愀氀 㴀 爀攀琀瘀愀氀⸀刀攀洀漀瘀攀⠀ Ⰰ ㄀⤀㬀ഀ
// remove \r\n at end of string - this was added with the \par at the end of string by the rtf box਍ऀऀऀ椀昀 爀攀琀瘀愀氀⸀匀甀戀猀琀爀椀渀最爀攀琀瘀愀氀⸀䰀攀渀最琀栀  ㈀Ⰰ ㈀⤀ 㴀㴀 ∀尀爀尀渀∀⤀ 爀攀琀瘀愀氀  爀攀琀瘀愀氀⸀刀攀洀漀瘀攀爀攀琀瘀愀氀⸀䰀攀渀最琀栀  ㈀Ⰰ ㈀⤀㬀ഀ
retval = RemoveRtfStyles(retval);  瀀䀀 䀀
retval = retval.Replace(@"(!]", @"\}"); 
}瀀  瀀 
{  瀀   瀀   
return String.Format("\x15ReferencedObject RO\\v0 {0}\\v #{1}\\v0", vte.Text, vte.Link.Substring(23, vte.Link.Length-23));
private string ToData_Trans(displayLinkElement vte)
char trchar = vte.Type == E_TextElementType.Transition ? '\x252C' : '\x2566'; 瀀  瀀  瀀     瀀
// of text.਍ऀऀऀ椀渀琀 椀渀搀砀 㴀 瘀琀攀⸀吀礀瀀攀 㴀㴀 䔀开吀攀砀琀䔀氀攀洀攀渀琀吀礀瀀攀⸀吀爀愀渀猀椀琀椀漀渀 㼀 ㄀㠀 㨀 ㈀㌀㬀ഀ
return String.Format("{0}\\v TRAN\\v0 {1}\\v {2}\\v0", trchar, vte.Text, vte.Link.Substring(indx, vte.Link.Length-indx));
#endregion 
private VE_Font GetItemFont()
VE_Font font = null;   
int type = (int)_MyItemInfo.MyContent.Type; 瀀    
{   瀀
font = format.PlantFormat.FormatData.Font;
case 1: // section਍ऀऀऀऀऀ昀漀渀琀  昀漀爀洀愀琀⸀倀氀愀渀琀䘀漀爀洀愀琀⸀䘀漀爀洀愀琀䐀愀琀愀⸀匀攀挀琀䐀愀琀愀⸀匀攀挀琀椀漀渀䠀攀愀搀攀爀⸀䘀漀渀琀㬀ഀ
break;   瀀 瀀
int typindx = type - 20000; // what to do for other types rather than steps਍ऀऀऀऀऀ昀漀渀琀  昀漀爀洀愀琀⸀倀氀愀渀琀䘀漀爀洀愀琀⸀䘀漀爀洀愀琀䐀愀琀愀⸀匀琀攀瀀䐀愀琀愀䰀椀猀琀嬀琀礀瀀椀渀搀砀崀⸀䘀漀渀琀㬀ഀ
break;
TextFont = font; 
}
#region DoListElements瀀     
{      瀀 
char[] tok = { '\x15', '\x252C', '\x2566', '\\' };   
// If there is only an rtf token from the indexed position on, don't return the਍ऀऀऀ⼀⼀ 䤀渀搀攀砀伀昀䄀渀礀 椀渀搀攀砀 瘀愀氀甀攀Ⰰ 戀攀挀愀甀猀攀 椀琀 眀椀氀氀 戀礀 漀渀攀 挀栀愀爀愀挀琀攀爀 瀀愀猀琀 琀栀攀 ✀尀✀ 愀渀搀 琀栀爀漀眀ഀ
// of the return value of where in the string the text should be saved. For example਍ऀऀऀ⼀⼀ 昀漀爀 琀栀攀 猀琀爀椀渀最 ✀尀戀 琀攀砀琀 尀瘀 猀漀洀攀瘀愀氀甀攀 尀瘀 尀戀 ✀Ⰰ 琀栀攀 昀椀爀猀琀 琀椀洀攀 琀栀爀漀甀最栀 琀栀攀 眀栀椀氀攀ഀ
// loop has the index at the '\b' char of the b0. ਍ऀऀऀ⼀⼀椀渀琀 猀愀瘀猀琀愀爀琀䤀渀搀攀砀 㴀 猀琀愀爀琀䤀渀搀攀砀㬀ഀ
while (!done)
int indx = txt.IndexOfAny(tok, startIndex);      
if (txt[indx] != '\\') return indx;              
// followed by a non-underline or single quote, and if so, return it. ਍ऀऀऀऀ⼀⼀ 伀琀栀攀爀眀椀猀攀Ⰰ 最攀琀 渀攀砀琀 椀渀搀攀砀Ⰰ 洀甀猀琀 栀愀瘀攀 戀攀攀渀 愀 猀氀愀猀栀 漀爀 漀琀栀攀爀 爀琀昀 挀漀洀洀愀渀搀⸀ഀ
if (((txt[indx + 1] == 'u' && txt[indx + 2] != 'l')) || (txt[indx + 1] == '\'')) return indx;
} 
}瀀       
{瀀    瀀
vte.Type = E_TextElementType.Text;             
vte.Text = text.Substring(startIndex, len);瀀
return index+1;
private string CreateLink(E_TextElementType type, string linktxt)
string retlink = ""; 瀀  瀀
retlink = "#Link:ReferencedObject:" + linktxt;  瀀  瀀
retlink = "#Link:Transition:" + linktxt;
retlink = "#Link:TransitionRange:" + linktxt;
return retlink;
private int DoRO(string text, int index)
displayLinkElement vte = new displayLinkElement();瀀  瀀
int iend = text.IndexOf(@"\v", index);
vte.Text = text.Substring(index + 1, iend - index - 1);    
iend = text.IndexOf(@"\v0", istart);     
DisplayTextElementList.Add(vte);   
}瀀     
{   瀀 
// Find the transition਍ऀऀऀ昀漀爀攀愀挀栀 吀爀愀渀猀椀琀椀漀渀䤀渀昀漀 琀椀 椀渀 开䴀礀䤀琀攀洀䤀渀昀漀⸀䴀礀䌀漀渀琀攀渀琀⸀䌀漀渀琀攀渀琀吀爀愀渀猀椀琀椀漀渀猀⤀ഀ
{   
{ 瀀  倀瀀  倀 倀   
//path = path.Replace(" Section PROCEDURE STEPS", "");਍ऀऀऀऀऀ猀琀爀椀渀最 瀀愀琀栀 㴀 琀椀⸀刀攀猀漀氀瘀攀倀愀琀栀吀漀⠀开䴀礀䘀漀爀洀愀琀Ⰰ 开䴀礀䤀琀攀洀䤀渀昀漀Ⰰ 䤀琀攀洀䤀渀昀漀⸀䜀攀琀⠀琀椀⸀吀漀䤀䐀⤀Ⰰ 琀椀⸀刀愀渀最攀䤀䐀㴀㴀 㼀渀甀氀氀㨀䤀琀攀洀䤀渀昀漀⸀䜀攀琀⠀琀椀⸀刀愀渀最攀䤀䐀⤀⤀㬀ഀ
return path;
} 
}瀀    
{瀀    瀀
if (text[index]=='\x252C') vte.Type = E_TextElementType.Transition; 瀀  瀀 
int iend = text.IndexOf(@"\v",index);         
int istart = text.IndexOf("#", index);  䀀  
vte.Link = text.Substring(istart, iend-istart);         
DisplayTextElementList.Add(vte);   
}瀀       
{瀀    瀀
vte.Type = E_TextElementType.Symbol;          瀀    
// in the text from the database \uxyz?. If the \'xy is used the length of the ਍ऀऀऀ⼀⼀ 猀礀洀戀漀氀 渀甀洀戀攀爀 眀椀氀氀 愀氀眀愀礀猀 戀攀 琀眀漀Ⰰ 漀琀栀攀爀眀椀猀攀 昀椀渀搀 琀栀攀 椀渀搀攀砀 漀昀 琀栀攀 ✀㼀✀ 琀漀 ഀ
// find the end.਍ऀऀऀ椀渀琀 攀渀搀椀渀搀砀 㴀 ⴀ㄀㬀ഀ
if (text[index + 1] == '\'') endindx = index + 3;    
vte.Text = text.Substring(index, endindx - index + 1);瀀
// return the position just past the symbol.਍ऀऀऀ爀攀琀甀爀渀 攀渀搀椀渀搀砀⬀㄀㬀ഀ
}
#region ReplaceWords瀀 瀀 
private string ReplaceIt(Match m)
string s = m.ToString();   瀀瀀 瀀
return m.ToString().Replace(_rs.ReplaceWord, _rs.ReplaceWith);
private string DoReplaceWords(string Text)
ReplaceStrList rsl = _MyFormat.PlantFormat.FormatData.SectData.ReplaceStrList; 瀀   
{ 瀀               瀀  瀀
bool replaceit = false;
// note that the order of this check is important. Check in this order...਍ऀऀऀऀ⼀⼀ 戀愀挀欀最爀漀甀渀搀 栀攀爀攀ഀ
if (_MyItemInfo.IsHigh && (rs.Flag & E_ReplaceFlags.High)>0) replaceit = true;        瀀    瀀  
else if (_MyItemInfo.IsInRNO && (rs.Flag & E_ReplaceFlags.RNO) > 0) replaceit = true;      瀀    瀀  
else if (_MyItemInfo.IsNote && (rs.Flag & E_ReplaceFlags.Note) > 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 ਍ऀऀऀऀऀ⼀⼀ 眀椀琀栀 琀栀攀 刀攀瀀氀愀挀攀圀椀琀栀 猀琀爀椀渀最 愀猀 椀猀ഀ
if ((rs.Flag & E_ReplaceFlags.CaseInsens) > 0)
string res = "";   瀀瀀
string pat = @"(?<=\W|^)" + rs.ReplaceWord.ToUpper() + @"(?=\W|$)"; 瀀   
foreach (Match m in Regex.Matches(fortest, pat))
res += Text.Substring(cpindx, m.Index-cpindx);瀀    瀀
res += rs.ReplaceWith;瀀  瀀
} 瀀     瀀   瀀
Text = res;
// CASEINSENSALL: Do ReplaceWords for all words that match the ReplaceWord, regardless of case਍ऀऀऀऀऀ攀氀猀攀 椀昀 爀猀⸀䘀氀愀最  䔀开刀攀瀀氀愀挀攀䘀氀愀最猀⸀䌀愀猀攀䤀渀猀攀渀猀䄀氀氀⤀   ⤀ഀ
{   瀀
}  瀀        瀀  
// except the case where the first character may be different਍ऀऀऀऀऀ攀氀猀攀 椀昀 爀猀⸀䘀氀愀最  䔀开刀攀瀀氀愀挀攀䘀氀愀最猀⸀䌀愀猀攀䤀渀猀攀渀猀䘀椀爀猀琀⤀   ⤀ഀ
{   瀀
}
{ 瀀  䀀  瀀  䀀
Text = Regex.Replace(Text, pat, rs.ReplaceWith);
} 
}
} 瀀
public enum E_TextElementType : uint
Text = 0,  
TransitionRange = 2,  
Symbol = 4
public class displayTextElement
private E_TextElementType _Type;瀀 瀀 瀀
{   瀀 
set { _Type = value; }
private string _Text;瀀  
{    
set { _Text = value; }
}瀀  瀀  瀀
{瀀  
public string Link
get { return _Link; }     
}
#endregion
}<EFBFBD>