Add() public method

add font
public Add ( int index, string f, Encoding encoding ) : RTFFont
index int special font index
f string font name
encoding System.Text.Encoding
return RTFFont
Beispiel #1
0
 /// <summary>
 /// read font table
 /// </summary>
 /// <param name="group"></param>
 private void ReadFontTable(RTFNodeGroup group)
 {
     myFontTable.Clear();
     foreach (RTFNode node in group.Nodes)
     {
         if (node is RTFNodeGroup)
         {
             var    index   = -1;
             string name    = null;
             var    charset = 0;
             foreach (RTFNode item in node.Nodes)
             {
                 if (item.Keyword == "f" && item.HasParameter)
                 {
                     index = item.Parameter;
                 }
                 else if (item.Keyword == RTFConsts._fcharset)
                 {
                     charset = item.Parameter;
                 }
                 else if (item.Type == RTFNodeType.Text)
                 {
                     if (item.Keyword != null && item.Keyword.Length > 0)
                     {
                         name = item.Keyword;
                         break;
                     }
                 }
             }
             if (index >= 0 && name != null)
             {
                 if (name.EndsWith(";"))
                 {
                     name = name.Substring(0, name.Length - 1);
                 }
                 name = name.Trim();
                 //System.Console.WriteLine( "Index:" + index + "  Name:" + name );
                 var font = new RTFFont(index, name);
                 font.Charset = charset;
                 myFontTable.Add(font);
             }
         }
     }
 }
        /// <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");
            }
        }