Esempio n. 1
0
        /// <summary>
        /// Read document information
        /// </summary>
        /// <param name="group"></param>
        private void ReadDocumentInfo(NodeGroup group)
        {
            InternalInfo.Clear();
            //var nodeList = group.GetAllNodes(false);

            foreach (Node node in group.Nodes)
            {
                if ((node is NodeGroup) == false)
                {
                    continue;
                }
                if (node.Keyword == "creatim")
                {
                    InternalInfo.CreationTime = ReadDateTime(node);
                }
                else if (node.Keyword == "revtim")
                {
                    InternalInfo.RevisionTime = ReadDateTime(node);
                }
                else if (node.Keyword == "printim")
                {
                    InternalInfo.PrintTime = ReadDateTime(node);
                }
                else if (node.Keyword == "buptim")
                {
                    InternalInfo.BackupTime = ReadDateTime(node);
                }
                else
                {
                    InternalInfo.SetInfo(node.Keyword, node.HasParameter ? node.Parameter.ToString(CultureInfo.InvariantCulture) : node.Nodes.Text);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Read font table
        /// </summary>
        /// <param name="group"></param>
        private void ReadFontTable(NodeGroup group)
        {
            InternalFontTable.Clear();
            foreach (Node node in group.Nodes)
            {
                if (node is NodeGroup)
                {
                    var    index   = -1;
                    string name    = null;
                    var    charset = 0;

                    foreach (Node item in node.Nodes)
                    {
                        if (item.Keyword == "f" && item.HasParameter)
                        {
                            index = item.Parameter;
                        }
                        else if (item.Keyword == Consts.Fcharset)
                        {
                            charset = item.Parameter;
                        }
                        else if (item.Type == RtfNodeType.Text)
                        {
                            if (!string.IsNullOrEmpty(item.Keyword))
                            {
                                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 Font(index, name)
                        {
                            Charset = charset
                        };
                        InternalFontTable.Add(font);
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Read color table
        /// </summary>
        /// <param name="group"></param>
        private void ReadColorTable(NodeGroup group)
        {
            InternalColorTable.Clear();
            var r = -1;
            var g = -1;
            var b = -1;

            foreach (Node node in group.Nodes)
            {
                if (node.Keyword == "red")
                {
                    r = node.Parameter;
                }
                else if (node.Keyword == "green")
                {
                    g = node.Parameter;
                }
                else if (node.Keyword == "blue")
                {
                    b = node.Parameter;
                }

                if (node.Keyword == ";")
                {
                    if (r >= 0 && g >= 0 && b >= 0)
                    {
                        var c = Color.FromArgb(255, r, g, b);
                        InternalColorTable.Add(c);
                        r = -1;
                        g = -1;
                        b = -1;
                    }
                }
            }

            if (r >= 0 && g >= 0 && b >= 0)
            {
                // Read the last color
                var c = Color.FromArgb(255, r, g, b);
                InternalColorTable.Add(c);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Load rtf from rtf reader
        /// </summary>
        /// <param name="reader">RTF text reader</param>
        // ReSharper disable once MemberCanBePrivate.Global
        public void Load(Reader reader)
        {
            InternalNodes.Clear();
            var       groups   = new Stack();
            NodeGroup newGroup = null;

            while (reader.ReadToken() != null)
            {
                if (reader.TokenType == RtfTokenType.GroupStart)
                {
                    // Begin group
                    if (newGroup == null)
                    {
                        newGroup = this;
                    }
                    else
                    {
                        newGroup = new NodeGroup {
                            OwnerDocument = this
                        };
                    }
                    if (newGroup != this)
                    {
                        var group = (NodeGroup)groups.Peek();
                        group.AppendChild(newGroup);
                    }
                    groups.Push(newGroup);
                }
                else if (reader.TokenType == RtfTokenType.GroupEnd)
                {
                    // end group
                    newGroup = (NodeGroup)groups.Pop();
                    newGroup.MergeText();
                    // ReSharper disable once CSharpWarnings::CS0183
                    if (newGroup.FirstNode is Node)
                    {
                        switch (newGroup.Keyword)
                        {
                        case Consts.Fonttbl:
                            // Read font table
                            ReadFontTable(newGroup);
                            break;

                        case Consts.Colortbl:
                            // Read color table
                            ReadColorTable(newGroup);
                            break;

                        case Consts.Info:
                            // Read document information
                            ReadDocumentInfo(newGroup);
                            break;
                        }
                    }

                    if (groups.Count > 0)
                    {
                        newGroup = (NodeGroup)groups.Peek();
                    }
                    else
                    {
                        break;
                    }
                    //NewGroup.MergeText();
                }
                else
                {
                    // Read content
                    var newNode = new Node(reader.CurrentToken)
                    {
                        OwnerDocument = this
                    };

                    if (newGroup != null)
                    {
                        newGroup.AppendChild(newNode);
                    }

                    switch (newNode.Keyword)
                    {
                    case Consts.F:
                    {
                        var font = FontTable[newNode.Parameter];
                        _fontChartset = font != null ? font.Encoding : null;
                        //myFontChartset = RTFFont.GetRTFEncoding( NewNode.Parameter );
                    }
                    break;

                    case Consts.Af:
                    {
                        var font = FontTable[newNode.Parameter];
                        _associatedFontChartset = font != null ? font.Encoding : null;
                    }
                    break;
                    }
                }
            }

            while (groups.Count > 0)
            {
                newGroup = (NodeGroup)groups.Pop();
                newGroup.MergeText();
            }
            //this.UpdateInformation();
        }
Esempio n. 5
0
        /// <summary>
        /// Load rtf from rtf reader
        /// </summary>
        /// <param name="reader">RTF text reader</param>
        // ReSharper disable once MemberCanBePrivate.Global
        public void Load(Reader reader)
        {
            InternalNodes.Clear();
            var groups = new Stack();
            NodeGroup newGroup = null;
            while (reader.ReadToken() != null)
            {
                if (reader.TokenType == RtfTokenType.GroupStart)
                {
                    // Begin group
                    if (newGroup == null)
                        newGroup = this;
                    else
                    {
                        newGroup = new NodeGroup {OwnerDocument = this};
                    }
                    if (newGroup != this)
                    {
                        var group = (NodeGroup) groups.Peek();
                        group.AppendChild(newGroup);
                    }
                    groups.Push(newGroup);
                }
                else if (reader.TokenType == RtfTokenType.GroupEnd)
                {
                    // end group
                    newGroup = (NodeGroup) groups.Pop();
                    newGroup.MergeText();
                    // ReSharper disable once CSharpWarnings::CS0183
                    if (newGroup.FirstNode is Node)
                    {
                        switch (newGroup.Keyword)
                        {
                            case Consts.Fonttbl:
                                // Read font table
                                ReadFontTable(newGroup);
                                break;

                            case Consts.Colortbl:
                                // Read color table
                                ReadColorTable(newGroup);
                                break;

                            case Consts.Info:
                                // Read document information
                                ReadDocumentInfo(newGroup);
                                break;
                        }
                    }

                    if (groups.Count > 0)
                        newGroup = (NodeGroup) groups.Peek();
                    else
                        break;
                    //NewGroup.MergeText();
                }
                else
                {
                    // Read content
                    var newNode = new Node(reader.CurrentToken) {OwnerDocument = this};
                    
                    if (newGroup != null) newGroup.AppendChild(newNode);

                    switch (newNode.Keyword)
                    {
                        case Consts.F:
                        {
                            var font = FontTable[newNode.Parameter];
                            _fontChartset = font != null ? font.Encoding : null;
                            //myFontChartset = RTFFont.GetRTFEncoding( NewNode.Parameter );
                        }
                            break;

                        case Consts.Af:
                        {
                            var font = FontTable[newNode.Parameter];
                            _associatedFontChartset = font != null ? font.Encoding : null;
                        }
                            break;

                    }

                }
            } 

            while (groups.Count > 0)
            {
                newGroup = (NodeGroup) groups.Pop();
                newGroup.MergeText();
            }
            //this.UpdateInformation();
        }
Esempio n. 6
0
 /// <summary>
 /// Read document information
 /// </summary>
 /// <param name="group"></param>
 private void ReadDocumentInfo(NodeGroup group)
 {
     InternalInfo.Clear();
     //var nodeList = group.GetAllNodes(false);
     
     foreach (Node node in group.Nodes)
     {
         if ((node is NodeGroup) == false)
             continue;
         if (node.Keyword == "creatim")
             InternalInfo.CreationTime = ReadDateTime(node);
         else if (node.Keyword == "revtim")
             InternalInfo.RevisionTime = ReadDateTime(node);
         else if (node.Keyword == "printim")
             InternalInfo.PrintTime = ReadDateTime(node);
         else if (node.Keyword == "buptim")
             InternalInfo.BackupTime = ReadDateTime(node);
         else
             InternalInfo.SetInfo(node.Keyword, node.HasParameter ? node.Parameter.ToString(CultureInfo.InvariantCulture) : node.Nodes.Text);
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Read color table
        /// </summary>
        /// <param name="group"></param>
        private void ReadColorTable(NodeGroup group)
        {
            InternalColorTable.Clear();
            var r = -1;
            var g = -1;
            var b = -1;

            foreach (Node node in group.Nodes)
            {
                if (node.Keyword == "red")
                    r = node.Parameter;
                else if (node.Keyword == "green")
                    g = node.Parameter;
                else if (node.Keyword == "blue")
                    b = node.Parameter;
            
                if (node.Keyword == ";")
                {
                    if (r >= 0 && g >= 0 && b >= 0)
                    {
                        var c = Color.FromArgb(255, r, g, b);
                        InternalColorTable.Add(c);
                        r = -1;
                        g = -1;
                        b = -1;
                    }
                }
            }

            if (r >= 0 && g >= 0 && b >= 0)
            {
                // Read the last color
                var c = Color.FromArgb(255, r, g, b);
                InternalColorTable.Add(c);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Read font table
        /// </summary>
        /// <param name="group"></param>
        private void ReadFontTable(NodeGroup group)
        {
            InternalFontTable.Clear();
            foreach (Node node in group.Nodes)
            {
                if (node is NodeGroup)
                {
                    var index = -1;
                    string name = null;
                    var charset = 0;

                    foreach (Node item in node.Nodes)
                    {
                        if (item.Keyword == "f" && item.HasParameter)
                            index = item.Parameter;
                        else if (item.Keyword == Consts.Fcharset)
                            charset = item.Parameter;
                        else if (item.Type == RtfNodeType.Text)
                        {
                            if (!string.IsNullOrEmpty(item.Keyword))
                            {
                                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 Font(index, name) {Charset = charset};
                        InternalFontTable.Add(font);
                    }
                }
            }
        }