Ejemplo 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);
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
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)
         {
             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);
             }
         }
     }
 }
Ejemplo n.º 6
0
 public void Add(RTFFont f)
 {
     this.List.Add(f);
 }
Ejemplo n.º 7
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();
        }