RTF Document format information
Ejemplo n.º 1
0
        /// <summary>
        /// write formatted string
        /// </summary>
        /// <param name="strText">text</param>
        /// <param name="info">format</param>
        public void WriteString(string strText, DocumentFormatInfo info)
        {
            if (this.bolCollectionInfo)
            {
                myFontTable.Add(info.FontName);
                myColorTable.Add(info.TextColor);
                myColorTable.Add(info.BackColor);
            }
            else
            {
                this.WriteStartString(info);

                if (info.Multiline)
                {
                    if (strText != null)
                    {
                        strText = strText.Replace("\n", "");
                        System.IO.StringReader reader = new System.IO.StringReader(strText);
                        string strLine = reader.ReadLine();
                        int    iCount  = 0;
                        while (strLine != null)
                        {
                            if (iCount > 0)
                            {
                                myWriter.WriteKeyword("line");
                            }

                            iCount++;
                            myWriter.WriteText(strLine);
                            strLine = reader.ReadLine();
                        }
                        reader.Close();
                    }
                }
                else
                {
                    myWriter.WriteText(strText);
                }

                this.WriteEndString(info);
            }
        }
Ejemplo n.º 2
0
        public void WriteEndString(DocumentFormatInfo info)
        {
            if (this.bolCollectionInfo)
            {
                return;
            }

            if (info.Subscript)
            {
                myWriter.WriteKeyword("sub0");
            }
            if (info.Superscript)
            {
                myWriter.WriteKeyword("super0");
            }

            if (info.Bold)
            {
                myWriter.WriteKeyword("b0");
            }
            if (info.Italic)
            {
                myWriter.WriteKeyword("i0");
            }
            if (info.Underline)
            {
                myWriter.WriteKeyword("ul0");
            }
            if (info.Strikeout)
            {
                myWriter.WriteKeyword("strike0");
            }
            if (info.Link != null && info.Link.Length > 0)
            {
                myWriter.WriteEndGroup();
                myWriter.WriteEndGroup();
                myWriter.WriteEndGroup();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// write write paragraph
        /// </summary>
        /// <param name="info">format</param>
        public void WriteStartParagraph(DocumentFormatInfo info)
        {
            if (this.bolCollectionInfo)
            {
                //myFontTable.Add("Wingdings");
            }
            else
            {
                if (bolFirstParagraph)
                {
                    bolFirstParagraph = false;
                    myWriter.WriteRaw(System.Environment.NewLine);
                    //myWriter.WriteKeyword("par");
                }
                else
                {
                    myWriter.WriteKeyword("par");
                }
                if (info.ListID >= 0)
                {
                    myWriter.WriteKeyword("pard");
                    myWriter.WriteKeyword("ls" + info.ListID.ToString());
                }
                //if( lo != null && listInfo != null )
                //{
                //    myWriter.WriteKeyword("pard");
                //    myWriter.WriteKeyword("ls" , lo.ListID );
                //    if( listInfo.LevelNfc info.NumberedList )
                //    {
                //        if( myLastParagraphInfo == null
                //            || myLastParagraphInfo.NumberedList != info.NumberedList )
                //        {
                //            myWriter.WriteKeyword("pard");
                //            myWriter.WriteStartGroup();
                //            myWriter.WriteKeyword("pn" , true );
                //            myWriter.WriteKeyword("pnlvlbody");
                //            myWriter.WriteKeyword("pnindent400");
                //            myWriter.WriteKeyword("pnstart1");
                //            myWriter.WriteKeyword("pndec");
                //            myWriter.WriteEndGroup();
                //        }
                //    }
                //    else
                //    {
                //        if( myLastParagraphInfo == null
                //            || myLastParagraphInfo.BulletedList != info.BulletedList )
                //        {
                //            myWriter.WriteKeyword("pard");
                //            myWriter.WriteStartGroup();
                //            myWriter.WriteKeyword("pn" , true );
                //            myWriter.WriteKeyword("pnlvlblt");
                //            myWriter.WriteKeyword("pnindent400");
                //            myWriter.WriteKeyword("pnf" + myFontTable.IndexOf( "Wingdings" ));
                //            myWriter.WriteStartGroup();
                //            myWriter.WriteKeyword("pntxtb");
                //            myWriter.WriteText("l");
                //            //myWriter.WriteKeyword("'B7");
                //            myWriter.WriteEndGroup();
                //            myWriter.WriteEndGroup();
                //        }
                //    }
                //    myWriter.WriteKeyword("fi-400");
                //}
                //else
                {
                    if (myLastParagraphInfo != null)
                    {
                        if (myLastParagraphInfo.ListID >= 0)
                        {
                            myWriter.WriteKeyword("pard");
                        }
                    }
                }

                switch (info.Align)
                {
                case RTFAlignment.Left:
                    myWriter.WriteKeyword("ql");
                    break;

                case RTFAlignment.Center:
                    myWriter.WriteKeyword("qc");
                    break;

                case RTFAlignment.Right:
                    myWriter.WriteKeyword("qr");
                    break;

                case RTFAlignment.Justify:
                    myWriter.WriteKeyword("qj");
                    break;
                }
                //
                //				if( info.LeftAlign )
                //					myWriter.WriteKeyword("ql");
                //				if( info.CenterAlign )
                //					myWriter.WriteKeyword("qc");
                //				else if( info.RigthAlign )
                //					myWriter.WriteKeyword("qr");

                //if( info.NumberedList == false && info.BulletedList == false )
                {
                    if (info.ParagraphFirstLineIndent != 0)
                    {
                        myWriter.WriteKeyword("fi" + Convert.ToInt32(
                                                  info.ParagraphFirstLineIndent * 400 / info.StandTabWidth));
                    }
                    else
                    {
                        myWriter.WriteKeyword("fi0");
                    }
                }
                //if( info.NumberedList == false && info.BulletedList == false )
                {
                    if (info.LeftIndent != 0)
                    {
                        myWriter.WriteKeyword("li" + Convert.ToInt32(
                                                  info.LeftIndent * 400 / info.StandTabWidth));
                    }
                    else
                    {
                        myWriter.WriteKeyword("li0");
                    }
                }
                myWriter.WriteKeyword("plain");
            }
            myLastParagraphInfo = info;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// start write formatted text
        /// </summary>
        /// <param name="info">format</param>
        /// <remarks>
        /// This function must assort with WriteEndString strict
        /// </remarks>
        public void WriteStartString(DocumentFormatInfo info)
        {
            if (this.bolCollectionInfo)
            {
                myFontTable.Add(info.FontName);
                myColorTable.Add(info.TextColor);
                myColorTable.Add(info.BackColor);
                if (info.BorderColor.A != 0)
                {
                    myColorTable.Add(info.BorderColor);
                }
                return;
            }
            if (info.Link != null && info.Link.Length > 0)
            {
                myWriter.WriteStartGroup();
                myWriter.WriteKeyword("field");
                myWriter.WriteStartGroup();
                myWriter.WriteKeyword("fldinst", true);
                myWriter.WriteStartGroup();
                myWriter.WriteKeyword("hich");
                myWriter.WriteText(" HYPERLINK \"" + info.Link + "\"");
                myWriter.WriteEndGroup();
                myWriter.WriteEndGroup();
                myWriter.WriteStartGroup();
                myWriter.WriteKeyword("fldrslt");
                myWriter.WriteStartGroup();
            }

            switch (info.Align)
            {
            case RTFAlignment.Left:
                myWriter.WriteKeyword("ql");
                break;

            case RTFAlignment.Center:
                myWriter.WriteKeyword("qc");
                break;

            case RTFAlignment.Right:
                myWriter.WriteKeyword("qr");
                break;

            case RTFAlignment.Justify:
                myWriter.WriteKeyword("qj");
                break;
            }

            myWriter.WriteKeyword("plain");
            int index = 0;

            index = myFontTable.IndexOf(info.FontName);
            if (index >= 0)
            {
                myWriter.WriteKeyword("f" + index);
            }
            if (info.Bold)
            {
                myWriter.WriteKeyword("b");
            }
            if (info.Italic)
            {
                myWriter.WriteKeyword("i");
            }
            if (info.Underline)
            {
                myWriter.WriteKeyword("ul");
            }
            if (info.Strikeout)
            {
                myWriter.WriteKeyword("strike");
            }
            myWriter.WriteKeyword("fs" + Convert.ToInt32(info.FontSize * 2));

            // back color
            index = myColorTable.IndexOf(info.BackColor);
            if (index >= 0)
            {
                myWriter.WriteKeyword("chcbpat" + Convert.ToString(index + 1));
            }

            index = myColorTable.IndexOf(info.TextColor);
            if (index >= 0)
            {
                myWriter.WriteKeyword("cf" + Convert.ToString(index + 1));
            }
            if (info.Subscript)
            {
                myWriter.WriteKeyword("sub");
            }
            if (info.Superscript)
            {
                myWriter.WriteKeyword("super");
            }
            if (info.NoWwrap)
            {
                myWriter.WriteKeyword("nowwrap");
            }
            if (info.LeftBorder ||
                info.TopBorder ||
                info.RightBorder ||
                info.BottomBorder)
            {
                // border color
                if (info.BorderColor.A != 0)
                {
                    myWriter.WriteKeyword("chbrdr");
                    myWriter.WriteKeyword("brdrs");
                    myWriter.WriteKeyword("brdrw10");
                    index = myColorTable.IndexOf(info.BorderColor);
                    if (index >= 0)
                    {
                        myWriter.WriteKeyword("brdrcf" + Convert.ToString(index + 1));
                    }
                }
            }
        }
 public bool EqualsSettings(DocumentFormatInfo format)
 {
     if (format == this)
         return true;
     if (format == null)
         return false;
     if (Align != format.Align)
         return false;
     if (BackColor != format.BackColor)
         return false;
     if (Bold != format.Bold)
         return false;
     if (BorderColor != format.BorderColor)
         return false;
     if (LeftBorder != format.LeftBorder)
         return false;
     if (TopBorder != format.TopBorder)
         return false;
     if (RightBorder != format.RightBorder)
         return false;
     if (BottomBorder != format.BottomBorder)
         return false;
     if (BorderStyle != format.BorderStyle)
         return false;
     if (BorderThickness != format.BorderThickness)
         return false;
     if (BorderSpacing != format.BorderSpacing)
         return false;
     if (ListId != format.ListId)
     {
         return false;
     }
     if (FontName != format.FontName)
         return false;
     if (FontSize != format.FontSize)
         return false;
     if (Italic != format.Italic)
         return false;
     if (Hidden != format.Hidden)
         return false;
     if (LeftIndent != format.LeftIndent)
         return false;
     if (LineSpacing != format.LineSpacing)
         return false;
     if (Link != format.Link)
         return false;
     if (Multiline != format.Multiline)
         return false;
     if (NoWwrap != format.NoWwrap)
         return false;
     if (ParagraphFirstLineIndent != format.ParagraphFirstLineIndent)
         return false;
     if (Spacing != format.Spacing)
         return false;
     if (StandTabWidth != format.StandTabWidth)
         return false;
     if (Strikeout != format.Strikeout)
         return false;
     if (Subscript != format.Subscript)
         return false;
     if (Superscript != format.Superscript)
         return false;
     if (TextColor != format.TextColor)
         return false;
     if (Underline != format.Underline)
         return false;
     if (ReadText != format.ReadText)
         return false;
     return true;
 }
Ejemplo n.º 6
0
 public bool EqualsSettings(DocumentFormatInfo format)
 {
     if (format == this)
     {
         return(true);
     }
     if (format == null)
     {
         return(false);
     }
     if (Align != format.Align)
     {
         return(false);
     }
     if (BackColor != format.BackColor)
     {
         return(false);
     }
     if (Bold != format.Bold)
     {
         return(false);
     }
     if (BorderColor != format.BorderColor)
     {
         return(false);
     }
     if (LeftBorder != format.LeftBorder)
     {
         return(false);
     }
     if (TopBorder != format.TopBorder)
     {
         return(false);
     }
     if (RightBorder != format.RightBorder)
     {
         return(false);
     }
     if (BottomBorder != format.BottomBorder)
     {
         return(false);
     }
     if (BorderStyle != format.BorderStyle)
     {
         return(false);
     }
     if (BorderThickness != format.BorderThickness)
     {
         return(false);
     }
     if (BorderSpacing != format.BorderSpacing)
     {
         return(false);
     }
     if (ListID != format.ListID)
     {
         return(false);
     }
     if (FontName != format.FontName)
     {
         return(false);
     }
     if (FontSize != format.FontSize)
     {
         return(false);
     }
     if (Italic != format.Italic)
     {
         return(false);
     }
     if (Hidden != format.Hidden)
     {
         return(false);
     }
     if (LeftIndent != format.LeftIndent)
     {
         return(false);
     }
     if (LineSpacing != format.LineSpacing)
     {
         return(false);
     }
     if (Link != format.Link)
     {
         return(false);
     }
     if (Multiline != format.Multiline)
     {
         return(false);
     }
     if (NoWwrap != format.NoWwrap)
     {
         return(false);
     }
     if (ParagraphFirstLineIndent != format.ParagraphFirstLineIndent)
     {
         return(false);
     }
     if (Spacing != format.Spacing)
     {
         return(false);
     }
     if (StandTabWidth != format.StandTabWidth)
     {
         return(false);
     }
     if (Strikeout != format.Strikeout)
     {
         return(false);
     }
     if (Subscript != format.Subscript)
     {
         return(false);
     }
     if (Superscript != format.Superscript)
     {
         return(false);
     }
     if (TextColor != format.TextColor)
     {
         return(false);
     }
     if (Underline != format.Underline)
     {
         return(false);
     }
     if (ReadText != format.ReadText)
     {
         return(false);
     }
     return(true);
 }
        /// <summary>
        /// start write formatted text
        /// </summary>
        /// <param name="info">format</param>
        /// <remarks>
        /// This function must assort with WriteEndString strict
        /// </remarks>
        public void WriteStartString(DocumentFormatInfo info)
        {
            if (this.bolCollectionInfo)
            {
                myFontTable.Add(info.FontName);
                myColorTable.Add(info.TextColor);
                myColorTable.Add(info.BackColor);
                if (info.BorderColor.A != 0)
                {
                    myColorTable.Add(info.BorderColor);
                }
                return;
            }
            if (info.Link != null && info.Link.Length > 0)
            {
                myWriter.WriteStartGroup();
                myWriter.WriteKeyword("field");
                myWriter.WriteStartGroup();
                myWriter.WriteKeyword("fldinst", true);
                myWriter.WriteStartGroup();
                myWriter.WriteKeyword("hich");
                myWriter.WriteText(" HYPERLINK \"" + info.Link + "\"");
                myWriter.WriteEndGroup();
                myWriter.WriteEndGroup();
                myWriter.WriteStartGroup();
                myWriter.WriteKeyword("fldrslt");
                myWriter.WriteStartGroup();
            }

            switch (info.Align)
            {
                case RTFAlignment.Left:
                    myWriter.WriteKeyword("ql");
                    break;
                case RTFAlignment.Center:
                    myWriter.WriteKeyword("qc");
                    break;
                case RTFAlignment.Right:
                    myWriter.WriteKeyword("qr");
                    break;
                case RTFAlignment.Justify:
                    myWriter.WriteKeyword("qj");
                    break;
            }

            myWriter.WriteKeyword("plain");
            int index = 0;
            index = myFontTable.IndexOf(info.FontName);
            if (index >= 0)
                myWriter.WriteKeyword("f" + index);
            if (info.Bold)
                myWriter.WriteKeyword("b");
            if (info.Italic)
                myWriter.WriteKeyword("i");
            if (info.Underline)
                myWriter.WriteKeyword("ul");
            if (info.Strikeout)
                myWriter.WriteKeyword("strike");
            myWriter.WriteKeyword("fs" + Convert.ToInt32(info.FontSize * 2));

            // back color
            index = myColorTable.IndexOf(info.BackColor);
            if (index >= 0)
            {
                myWriter.WriteKeyword("chcbpat" + Convert.ToString(index + 1));
            }

            index = myColorTable.IndexOf(info.TextColor);
            if (index >= 0)
            {
                myWriter.WriteKeyword("cf" + Convert.ToString(index + 1));
            }
            if (info.Subscript)
            {
                myWriter.WriteKeyword("sub");
            }
            if (info.Superscript)
                myWriter.WriteKeyword("super");
            if (info.NoWwrap)
                myWriter.WriteKeyword("nowwrap");
            if (info.LeftBorder
                || info.TopBorder
                || info.RightBorder
                || info.BottomBorder)
            {
                // border color
                if (info.BorderColor.A != 0)
                {
                    myWriter.WriteKeyword("chbrdr");
                    myWriter.WriteKeyword("brdrs");
                    myWriter.WriteKeyword("brdrw10");
                    index = myColorTable.IndexOf(info.BorderColor);
                    if (index >= 0)
                    {
                        myWriter.WriteKeyword("brdrcf" + Convert.ToString(index + 1));
                    }
                }
            }
        }
        /// <summary>
        /// write formatted string
        /// </summary>
        /// <param name="strText">text</param>
        /// <param name="info">format</param>
        public void WriteString( string strText , DocumentFormatInfo info )
        {
            if( this.bolCollectionInfo )
            {
                myFontTable.Add( info.FontName );
                myColorTable.Add( info.TextColor );
                myColorTable.Add( info.BackColor );
            }
            else
            {
                this.WriteStartString( info );

                if( info.Multiline )
                {
                    if( strText != null )
                    {
                        strText = strText.Replace( "\n" , "");
                        System.IO.StringReader reader = new System.IO.StringReader( strText );
                        string strLine = reader.ReadLine();
                        int iCount = 0 ;
                        while( strLine != null )
                        {
                            if( iCount > 0 )
                            {
                                myWriter.WriteKeyword("line");
                            }

                            iCount ++ ;
                            myWriter.WriteText( strLine );
                            strLine = reader.ReadLine();
                        }
                        reader.Close();
                    }
                }
                else
                {
                    myWriter.WriteText( strText );
                }

                this.WriteEndString( info );
            }
        }
        /// <summary>
        /// write write paragraph
        /// </summary>
        /// <param name="info">format</param>
        public void WriteStartParagraph( DocumentFormatInfo info )
        {
            if( this.bolCollectionInfo )
            {
                //myFontTable.Add("Wingdings");
            }
            else
            {
                if (bolFirstParagraph)
                {
                    bolFirstParagraph = false;
                    myWriter.WriteRaw(System.Environment.NewLine);
                    //myWriter.WriteKeyword("par");
                }
                else
                {
                    myWriter.WriteKeyword("par");
                }
                if (info.ListID >= 0)
                {
                    myWriter.WriteKeyword("pard");
                    myWriter.WriteKeyword("ls" + info.ListID.ToString());
                }
                //if( lo != null && listInfo != null )
                //{
                //    myWriter.WriteKeyword("pard");
                //    myWriter.WriteKeyword("ls" , lo.ListID );
                //    if( listInfo.LevelNfc info.NumberedList )
                //    {
                //        if( myLastParagraphInfo == null
                //            || myLastParagraphInfo.NumberedList != info.NumberedList )
                //        {
                //            myWriter.WriteKeyword("pard");
                //            myWriter.WriteStartGroup();
                //            myWriter.WriteKeyword("pn" , true );
                //            myWriter.WriteKeyword("pnlvlbody");
                //            myWriter.WriteKeyword("pnindent400");
                //            myWriter.WriteKeyword("pnstart1");
                //            myWriter.WriteKeyword("pndec");
                //            myWriter.WriteEndGroup();
                //        }
                //    }
                //    else
                //    {
                //        if( myLastParagraphInfo == null
                //            || myLastParagraphInfo.BulletedList != info.BulletedList )
                //        {
                //            myWriter.WriteKeyword("pard");
                //            myWriter.WriteStartGroup();
                //            myWriter.WriteKeyword("pn" , true );
                //            myWriter.WriteKeyword("pnlvlblt");
                //            myWriter.WriteKeyword("pnindent400");
                //            myWriter.WriteKeyword("pnf" + myFontTable.IndexOf( "Wingdings" ));
                //            myWriter.WriteStartGroup();
                //            myWriter.WriteKeyword("pntxtb");
                //            myWriter.WriteText("l");
                //            //myWriter.WriteKeyword("'B7");
                //            myWriter.WriteEndGroup();
                //            myWriter.WriteEndGroup();
                //        }
                //    }
                //    myWriter.WriteKeyword("fi-400");
                //}
                //else
                {
                    if (myLastParagraphInfo != null)
                    {
                        if (myLastParagraphInfo.ListID >= 0)
                        {
                            myWriter.WriteKeyword("pard");
                        }
                    }
                }

                switch (info.Align)
                {
                    case RTFAlignment.Left:
                        myWriter.WriteKeyword("ql");
                        break;
                    case RTFAlignment.Center:
                        myWriter.WriteKeyword("qc");
                        break;
                    case RTFAlignment.Right:
                        myWriter.WriteKeyword("qr");
                        break;
                    case RTFAlignment.Justify:
                        myWriter.WriteKeyword("qj");
                        break;
                }
                //
                //				if( info.LeftAlign )
                //					myWriter.WriteKeyword("ql");
                //				if( info.CenterAlign )
                //					myWriter.WriteKeyword("qc");
                //				else if( info.RigthAlign )
                //					myWriter.WriteKeyword("qr");

                //if( info.NumberedList == false && info.BulletedList == false )
                {
                    if (info.ParagraphFirstLineIndent != 0)
                    {
                        myWriter.WriteKeyword("fi" + Convert.ToInt32(
                            info.ParagraphFirstLineIndent * 400 / info.StandTabWidth));
                    }
                    else
                    {
                        myWriter.WriteKeyword("fi0");
                    }
                }
                //if( info.NumberedList == false && info.BulletedList == false )
                {
                    if (info.LeftIndent != 0)
                    {
                        myWriter.WriteKeyword("li" + Convert.ToInt32(
                            info.LeftIndent * 400 / info.StandTabWidth));
                    }
                    else
                    {
                        myWriter.WriteKeyword("li0");
                    }
                }
                myWriter.WriteKeyword("plain");
            }
            myLastParagraphInfo = info ;
        }
        /// <summary>
        /// start write document
        /// </summary>
        public void WriteStartDocument()
        {
            this.myLastParagraphInfo = null ;
            this.bolFirstParagraph = true ;
            if( bolCollectionInfo )
            {
                myInfo.Clear();
                myFontTable.Clear();
                myColorTable.Clear();
                myFontTable.Add( System.Windows.Forms.Control.DefaultFont.Name );
            }
            else
            {
                myWriter.WriteStartGroup();
                myWriter.WriteKeyword( RTFConsts._rtf );
                myWriter.WriteKeyword("ansi");
                myWriter.WriteKeyword("ansicpg" + myWriter.Encoding.CodePage );
                // write document information
                if( myInfo.Count > 0 )
                {
                    myWriter.WriteStartGroup();
                    myWriter.WriteKeyword("info");
                    foreach( string strKey in myInfo.Keys )
                    {
                        myWriter.WriteStartGroup();

                        object v = myInfo[ strKey ] ;
                        if( v is string )
                        {
                            myWriter.WriteKeyword( strKey );
                            myWriter.WriteText( ( string ) v );
                        }
                        else if( v is int )
                        {
                            myWriter.WriteKeyword( strKey + v );
                        }
                        else if( v is DateTime )
                        {
                            DateTime dtm = ( DateTime ) v ;
                            myWriter.WriteKeyword( strKey );
                            myWriter.WriteKeyword( "yr" + dtm.Year );
                            myWriter.WriteKeyword( "mo" + dtm.Month );
                            myWriter.WriteKeyword( "dy" + dtm.Day );
                            myWriter.WriteKeyword( "hr" + dtm.Hour );
                            myWriter.WriteKeyword( "min" + dtm.Minute );
                            myWriter.WriteKeyword( "sec" + dtm.Second );
                        }
                        else
                        {
                            myWriter.WriteKeyword( strKey );
                        }

                        myWriter.WriteEndGroup();
                    }
                    myWriter.WriteEndGroup();
                }
                // writing font table
                myWriter.WriteStartGroup();
                myWriter.WriteKeyword( RTFConsts._fonttbl );
                for( int iCount = 0 ; iCount < myFontTable.Count ; iCount ++ )
                {
                    //string f = myFontTable[ iCount ] ;
                    myWriter.WriteStartGroup();
                    myWriter.WriteKeyword( "f" + iCount );
                    RTFFont f = myFontTable[iCount];
                    myWriter.WriteText( f.Name );
                    if (f.Charset != 1)
                    {
                        myWriter.WriteKeyword("fcharset" + f.Charset);
                    }
                    myWriter.WriteEndGroup();
                }
                myWriter.WriteEndGroup();

                // write color table
                myWriter.WriteStartGroup();
                myWriter.WriteKeyword( RTFConsts._colortbl );
                myWriter.WriteRaw(";");
                for( int iCount = 0 ; iCount < myColorTable.Count ; iCount ++ )
                {
                    System.Drawing.Color c = myColorTable[ iCount ] ;
                    myWriter.WriteKeyword( "red" + c.R );
                    myWriter.WriteKeyword( "green" + c.G );
                    myWriter.WriteKeyword( "blue" + c.B );
                    myWriter.WriteRaw(";");
                }
                myWriter.WriteEndGroup();

                // write list table
                if (this.ListTable != null && this.ListTable.Count > 0)
                {
                    if (this.DebugMode)
                    {
                        myWriter.WriteRaw(Environment.NewLine);
                    }
                    myWriter.WriteStartGroup();
                    myWriter.WriteKeyword("listtable", true );
                    foreach (RTFList list in this.ListTable)
                    {
                        if (this.DebugMode)
                        {
                            myWriter.WriteRaw(Environment.NewLine);
                        }
                        myWriter.WriteStartGroup();
                        myWriter.WriteKeyword("list");
                        myWriter.WriteKeyword("listtemplateid" + list.ListTemplateID);
                        if (list.ListHybrid)
                        {
                            myWriter.WriteKeyword("listhybrid");
                        }
                        if (this.DebugMode)
                        {
                            myWriter.WriteRaw(Environment.NewLine);
                        }
                        myWriter.WriteStartGroup();
                        myWriter.WriteKeyword("listlevel");
                        myWriter.WriteKeyword("levelfollow" + list.LevelFollow);
                        myWriter.WriteKeyword("leveljc" + list.LevelJc);
                        myWriter.WriteKeyword("levelstartat" + list.LevelStartAt);
                        myWriter.WriteKeyword("levelnfc" + Convert.ToInt32( list.LevelNfc));
                        myWriter.WriteKeyword("levelnfcn" + Convert.ToInt32(list.LevelNfc));
                        myWriter.WriteKeyword("leveljc" + list.LevelJc);

                        //if (list.LevelNfc == LevelNumberType.Bullet)
                        {
                            if (string.IsNullOrEmpty(list.LevelText) == false)
                            {
                                myWriter.WriteStartGroup();
                                myWriter.WriteKeyword("leveltext");
                                myWriter.WriteKeyword("'0" + list.LevelText.Length);
                                if (list.LevelNfc == LevelNumberType.Bullet)
                                {
                                    myWriter.WriteUnicodeText(list.LevelText);
                                }
                                else
                                {
                                    myWriter.WriteText(list.LevelText , false );

                                }
                                //myWriter.WriteStartGroup();
                                //myWriter.WriteKeyword("uc1");
                                //int v = (int)list.LevelText[0];
                                //short uv = (short)v;
                                //myWriter.WriteKeyword("u" + uv);
                                //myWriter.WriteRaw(" ?");
                                //myWriter.WriteEndGroup();
                                //myWriter.WriteRaw(";");
                                myWriter.WriteEndGroup();
                                if (list.LevelNfc == LevelNumberType.Bullet)
                                {
                                    RTFFont f = this.FontTable["Wingdings"];
                                    if (f != null)
                                    {
                                        myWriter.WriteKeyword("f" + f.Index);
                                    }
                                }
                                else
                                {
                                    myWriter.WriteStartGroup();
                                    myWriter.WriteKeyword("levelnumbers");
                                    myWriter.WriteKeyword("'01");
                                    myWriter.WriteEndGroup();
                                }
                            }
                        }
                        myWriter.WriteEndGroup();

                        myWriter.WriteKeyword("listid" + list.ListID);
                        myWriter.WriteEndGroup();
                    }
                    myWriter.WriteEndGroup();
                }

                // write list overried table
                if (this.ListOverrideTable != null && this.ListOverrideTable.Count > 0)
                {
                    if (this.DebugMode)
                    {
                        myWriter.WriteRaw(Environment.NewLine);
                    }
                    myWriter.WriteStartGroup();
                    myWriter.WriteKeyword("listoverridetable");
                    foreach (RTFListOverride lo in this.ListOverrideTable)
                    {
                        if (this.DebugMode)
                        {
                            myWriter.WriteRaw(Environment.NewLine);
                        }
                        myWriter.WriteStartGroup();
                        myWriter.WriteKeyword("listoverride");
                        myWriter.WriteKeyword("listid" + lo.ListID);
                        myWriter.WriteKeyword("listoverridecount" + lo.ListOverriedCount);
                        myWriter.WriteKeyword("ls" + lo.ID);
                        myWriter.WriteEndGroup();
                    }
                    myWriter.WriteEndGroup();
                }

                if (this.DebugMode)
                {
                    myWriter.WriteRaw(Environment.NewLine);
                }
                myWriter.WriteKeyword("viewkind1");
            }
        }
        public void WriteEndString( DocumentFormatInfo info )
        {
            if( this.bolCollectionInfo )
            {
                return ;
            }

            if( info.Subscript )
                myWriter.WriteKeyword("sub0");
            if( info.Superscript )
                myWriter.WriteKeyword("super0");

            if( info.Bold )
                myWriter.WriteKeyword("b0");
            if( info.Italic )
                myWriter.WriteKeyword("i0");
            if( info.Underline )
                myWriter.WriteKeyword("ul0");
            if( info.Strikeout )
                myWriter.WriteKeyword("strike0");
            if( info.Link != null && info.Link.Length > 0 )
            {
                myWriter.WriteEndGroup();
                myWriter.WriteEndGroup();
                myWriter.WriteEndGroup();
            }
        }
        /// <summary>
        /// write formatted string
        /// </summary>
        /// <param name="strText">text</param>
        /// <param name="info">format</param>
        public void WriteString(string strText, DocumentFormatInfo info)
        {
            if (_bolCollectionInfo)
            {
                _myFontTable.Add(info.FontName);
                _myColorTable.Add(info.TextColor);
                _myColorTable.Add(info.BackColor);
            }
            else
            {
                WriteStartString(info);

                if (info.Multiline)
                {
                    if (strText != null)
                    {
                        strText = strText.Replace("\n", "");
                        using (var reader = new StringReader(strText))
                        {
                            var strLine = reader.ReadLine();
                            var iCount = 0;
                            while (strLine != null)
                            {
                                if (iCount > 0)
                                {
                                    Writer.WriteKeyword("line");
                                }

                                iCount++;
                                Writer.WriteText(strLine);
                                strLine = reader.ReadLine();
                            }
                        }
                    }
                }
                else
                {
                    Writer.WriteText(strText);
                }

                WriteEndString(info);
            }
        }
        /// <summary>
        /// start write document
        /// </summary>
        public void WriteStartDocument()
        {
            _myLastParagraphInfo = null;
            _bolFirstParagraph = true;
            if (_bolCollectionInfo)
            {
                _myInfo.Clear();
                _myFontTable.Clear();
                _myColorTable.Clear();
                _myFontTable.Add("Microsoft Sans Serif");
            }
            else
            {
                Writer.WriteStartGroup();
                Writer.WriteKeyword(RTFConsts.RTF);
                Writer.WriteKeyword("ansi");
                Writer.WriteKeyword("ansicpg" + Writer.CodePageNumber);
                // write document information
                if (_myInfo.Count > 0)
                {
                    Writer.WriteStartGroup();
                    Writer.WriteKeyword("info");
                    foreach (var strKey in _myInfo.Keys)
                    {
                        Writer.WriteStartGroup();

                        var v = _myInfo[strKey];
                        if (v is string)
                        {
                            Writer.WriteKeyword(strKey);
                            Writer.WriteText((string) v);
                        }
                        else if (v is int)
                        {
                            Writer.WriteKeyword(strKey + v);
                        }
                        else if (v is DateTime)
                        {
                            var dtm = (DateTime) v;
                            Writer.WriteKeyword(strKey);
                            Writer.WriteKeyword("yr" + dtm.Year);
                            Writer.WriteKeyword("mo" + dtm.Month);
                            Writer.WriteKeyword("dy" + dtm.Day);
                            Writer.WriteKeyword("hr" + dtm.Hour);
                            Writer.WriteKeyword("min" + dtm.Minute);
                            Writer.WriteKeyword("sec" + dtm.Second);
                        }
                        else
                        {
                            Writer.WriteKeyword(strKey);
                        }

                        Writer.WriteEndGroup();
                    }
                    Writer.WriteEndGroup();
                }
                // writing font table
                Writer.WriteStartGroup();
                Writer.WriteKeyword(RTFConsts.Fonttbl);
                for (var iCount = 0; iCount < _myFontTable.Count; iCount ++)
                {
                    //string f = myFontTable[ iCount ] ;
                    Writer.WriteStartGroup();
                    Writer.WriteKeyword("f" + iCount);
                    var f = _myFontTable[iCount];
                    Writer.WriteText(f.Name);
                    if (f.Charset != 1)
                    {
                        Writer.WriteKeyword("fcharset" + f.Charset);
                    }
                    Writer.WriteEndGroup();
                }
                Writer.WriteEndGroup();

                // write color table
                Writer.WriteStartGroup();
                Writer.WriteKeyword(RTFConsts.Colortbl);
                Writer.WriteRaw(";");
                for (var iCount = 0; iCount < _myColorTable.Count; iCount ++)
                {
                    var c = _myColorTable[iCount];
                    Writer.WriteKeyword("red" + c.R);
                    Writer.WriteKeyword("green" + c.G);
                    Writer.WriteKeyword("blue" + c.B);
                    Writer.WriteRaw(";");
                }
                Writer.WriteEndGroup();

                // write list table
                if (ListTable != null && ListTable.Count > 0)
                {
                    if (DebugMode)
                    {
                        Writer.WriteRaw(Environment.NewLine);
                    }
                    Writer.WriteStartGroup();
                    Writer.WriteKeyword("listtable", true);
                    foreach (var list in ListTable)
                    {
                        if (DebugMode)
                        {
                            Writer.WriteRaw(Environment.NewLine);
                        }
                        Writer.WriteStartGroup();
                        Writer.WriteKeyword("list");
                        Writer.WriteKeyword("listtemplateid" + list.ListTemplateId);
                        if (list.ListHybrid)
                        {
                            Writer.WriteKeyword("listhybrid");
                        }
                        if (DebugMode)
                        {
                            Writer.WriteRaw(Environment.NewLine);
                        }
                        Writer.WriteStartGroup();
                        Writer.WriteKeyword("listlevel");
                        Writer.WriteKeyword("levelfollow" + list.LevelFollow);
                        Writer.WriteKeyword("leveljc" + list.LevelJc);
                        Writer.WriteKeyword("levelstartat" + list.LevelStartAt);
                        Writer.WriteKeyword("levelnfc" + Convert.ToInt32(list.LevelNfc));
                        Writer.WriteKeyword("levelnfcn" + Convert.ToInt32(list.LevelNfc));
                        Writer.WriteKeyword("leveljc" + list.LevelJc);

                        //if (list.LevelNfc == LevelNumberType.Bullet)
                        {
                            if (string.IsNullOrEmpty(list.LevelText) == false)
                            {
                                Writer.WriteStartGroup();
                                Writer.WriteKeyword("leveltext");
                                Writer.WriteKeyword("'0" + list.LevelText.Length);
                                if (list.LevelNfc == LevelNumberType.Bullet)
                                {
                                    Writer.WriteUnicodeText(list.LevelText);
                                }
                                else
                                {
                                    Writer.WriteText(list.LevelText, false);
                                }
                                //myWriter.WriteStartGroup();
                                //myWriter.WriteKeyword("uc1");
                                //int v = (int)list.LevelText[0];
                                //short uv = (short)v;
                                //myWriter.WriteKeyword("u" + uv);
                                //myWriter.WriteRaw(" ?");
                                //myWriter.WriteEndGroup();
                                //myWriter.WriteRaw(";");
                                Writer.WriteEndGroup();
                                if (list.LevelNfc == LevelNumberType.Bullet)
                                {
                                    var f = FontTable["Wingdings"];
                                    if (f != null)
                                    {
                                        Writer.WriteKeyword("f" + f.Index);
                                    }
                                }
                                else
                                {
                                    Writer.WriteStartGroup();
                                    Writer.WriteKeyword("levelnumbers");
                                    Writer.WriteKeyword("'01");
                                    Writer.WriteEndGroup();
                                }
                            }
                        }
                        Writer.WriteEndGroup();

                        Writer.WriteKeyword("listid" + list.ListId);
                        Writer.WriteEndGroup();
                    }
                    Writer.WriteEndGroup();
                }

                // write list overried table
                if (ListOverrideTable != null && ListOverrideTable.Count > 0)
                {
                    if (DebugMode)
                    {
                        Writer.WriteRaw(Environment.NewLine);
                    }
                    Writer.WriteStartGroup();
                    Writer.WriteKeyword("listoverridetable");
                    foreach (var lo in ListOverrideTable)
                    {
                        if (DebugMode)
                        {
                            Writer.WriteRaw(Environment.NewLine);
                        }
                        Writer.WriteStartGroup();
                        Writer.WriteKeyword("listoverride");
                        Writer.WriteKeyword("listid" + lo.ListId);
                        Writer.WriteKeyword("listoverridecount" + lo.ListOverriedCount);
                        Writer.WriteKeyword("ls" + lo.Id);
                        Writer.WriteEndGroup();
                    }
                    Writer.WriteEndGroup();
                }

                if (DebugMode)
                {
                    Writer.WriteRaw(Environment.NewLine);
                }
                Writer.WriteKeyword("viewkind1");
            }
        }