rtf font information
Esempio n. 1
0
        /// <summary>
        /// Remove font
        /// </summary>
        /// <param name="f">font name</param>
        public void Remove(string f)
        {
            RTFFont item = this[f];

            if (item != null)
            {
                this.List.Remove(item);
            }
        }
Esempio n. 2
0
        public RTFFont Clone()
        {
            var f = new RTFFont(intIndex, strName);

            f.intCharset = intCharset;
            f.intIndex   = intIndex;
            f.myEncoding = myEncoding;
            f.strName    = strName;
            return(f);
        }
Esempio n. 3
0
        public RTFFont Clone()
        {
            RTFFont f = new RTFFont(this.intIndex, this.strName);

            f.intCharset = this.intCharset;
            f.intIndex   = this.intIndex;
            f.myEncoding = this.myEncoding;
            f.strName    = this.strName;
            return(f);
        }
Esempio n. 4
0
        /// <summary>
        /// close object
        /// </summary>
        /// <returns>new object</returns>
        public RTFFontTable Clone()
        {
            RTFFontTable table = new RTFFontTable();

            foreach (RTFFont item in this)
            {
                RTFFont newItem = item.Clone();
                table.List.Add(newItem);
            }
            return(table);
        }
Esempio n. 5
0
        /// <summary>
        /// get font object special font index
        /// </summary>
        /// <param name="fontIndex">font index</param>
        /// <returns>font object</returns>
        public string GetFontName(int fontIndex)
        {
            RTFFont font = this[fontIndex];

            if (font != null)
            {
                return(font.Name);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 6
0
 /// <summary>
 /// add font
 /// </summary>
 /// <param name="index">special font index</param>
 /// <param name="f">font name</param>
 public RTFFont Add(int index, string f, Encoding encoding)
 {
     if (this[f] == null)
     {
         var font = new RTFFont(index, f);
         if (encoding != null)
         {
             font.Charset = RTFFont.GetCharset(encoding);
         }
         List.Add(font);
         return(font);
     }
     return(this[f]);
 }
Esempio n. 7
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);
             }
         }
     }
 }
Esempio n. 8
0
        /// <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");
            }
        }
Esempio n. 9
0
 public void Add(RTFFont f)
 {
     List.Add(f);
 }
 public void Add(RTFFont f)
 {
     this.List.Add(f);
 }
 /// <summary>
 /// add font
 /// </summary>
 /// <param name="index">special font index</param>
 /// <param name="f">font name</param>
 public RTFFont Add(int index, string f, Encoding encoding)
 {
     if (this[f] == null)
     {
         RTFFont font = new RTFFont(index, f);
         if (encoding != null)
         {
             font.Charset = RTFFont.GetCharset(encoding);
         }
         this.List.Add(font);
         return font ;
     }
     return this[f];
 }
 public RTFFont Clone()
 {
     RTFFont f = new RTFFont( this.intIndex , this.strName );
     f.intCharset = this.intCharset;
     f.intIndex = this.intIndex;
     f.myEncoding = this.myEncoding;
     f.strName = this.strName;
     return f;
 }
Esempio n. 13
0
 public void Add(RTFFont f)
 {
     this.List.Add(f);
 }
 /// <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)
         {
             int index = -1;
             string name = null;
             int 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 );
                 RTFFont font = new RTFFont(index, name);
                 font.Charset = charset;
                 myFontTable.Add(font);
             }
         }
     }
 }
Esempio n. 15
0
        /// <summary>
        /// load rtf
        /// </summary>
        /// <param name="reader">RTF text reader</param>
        public void Load(RTFReader reader)
        {
            myNodes.Clear();
            System.Collections.Stack groups   = new System.Collections.Stack();
            RTFNodeGroup             NewGroup = null;
            RTFNode NewNode = null;

            while (reader.ReadToken() != null)
            {
                if (reader.TokenType == RTFTokenType.GroupStart)
                {
                    // begin group
                    if (NewGroup == null)
                    {
                        NewGroup = this;
                    }
                    else
                    {
                        NewGroup = new RTFNodeGroup();
                        NewGroup.OwnerDocument = this;
                    }
                    if (NewGroup != this)
                    {
                        RTFNodeGroup g = ( RTFNodeGroup )groups.Peek();
                        g.AppendChild(NewGroup);
                    }
                    groups.Push(NewGroup);
                }
                else if (reader.TokenType == RTFTokenType.GroupEnd)
                {
                    // end group
                    NewGroup = ( RTFNodeGroup )groups.Pop();
                    NewGroup.MergeText();
                    if (NewGroup.FirstNode is RTFNode)
                    {
                        switch (NewGroup.Keyword)
                        {
                        case RTFConsts._fonttbl:
                            // read font table
                            ReadFontTable(NewGroup);
                            break;

                        case RTFConsts._colortbl:
                            // read color table
                            ReadColorTable(NewGroup);
                            break;

                        case RTFConsts._info:
                            // read document information
                            ReadDocumentInfo(NewGroup);
                            break;
                        }
                    }
                    if (groups.Count > 0)
                    {
                        NewGroup = (RTFNodeGroup)groups.Peek();
                    }
                    else
                    {
                        break;
                    }
                    //NewGroup.MergeText();
                }
                else
                {
                    // read content

                    NewNode = new RTFNode(reader.CurrentToken);
                    NewNode.OwnerDocument = this;
                    NewGroup.AppendChild(NewNode);
                    if (NewNode.Keyword == RTFConsts._f)
                    {
                        RTFFont font = this.FontTable[NewNode.Parameter];
                        if (font != null)
                        {
                            myFontChartset = font.Encoding;
                        }
                        else
                        {
                            myFontChartset = null;
                        }
                        //myFontChartset = RTFFont.GetRTFEncoding( NewNode.Parameter );
                    }
                    else if (NewNode.Keyword == RTFConsts._af)
                    {
                        RTFFont font = this.FontTable[NewNode.Parameter];
                        if (font != null)
                        {
                            myAssociateFontChartset = font.Encoding;
                        }
                        else
                        {
                            myAssociateFontChartset = null;
                        }
                    }
                }
            }            // while( reader.ReadToken() != null )
            while (groups.Count > 0)
            {
                NewGroup = ( RTFNodeGroup )groups.Pop();
                NewGroup.MergeText();
            }
            //this.UpdateInformation();
        }