Exemplo n.º 1
0
 /// <summary>
 /// Remove child
 /// </summary>
 /// <param name="node">node</param>
 public void RemoveChild(Node node)
 {
     CheckNodes();
     if (node == null)
         throw new ArgumentNullException("node");
     if (node == this)
         throw new ArgumentException("node != this");
     Nodes.Remove(node);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Insert node
 /// </summary>
 /// <param name="index">index</param>
 /// <param name="node">node</param>
 public void InsertNode(int index, Node node)
 {
     CheckNodes();
     if (node == null)
         throw new ArgumentNullException("node");
     if (node == this)
         throw new ArgumentException("node != this");
     
     node.Parent = this;
     node.OwnerDocument = InternalOwnerDocument;
     Nodes.Insert(index, node);
 }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Append child node
 /// </summary>
 /// <param name="node">node</param>
 public void AppendChild(Node node)
 {
     CheckNodes();
     if (node == null)
         throw new ArgumentNullException("node");
     if (node == this)
         throw new ArgumentException("node != this");
     node.Parent = this;
     node.OwnerDocument = InternalOwnerDocument;
     Nodes.Add(node);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Read date and time from node
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 private DateTime ReadDateTime(Node node)
 {
     var yr = node.Nodes.GetParameter("yr", 1900);
     var mo = node.Nodes.GetParameter("mo", 1);
     var dy = node.Nodes.GetParameter("dy", 1);
     var hr = node.Nodes.GetParameter("hr", 0);
     var min = node.Nodes.GetParameter("min", 0);
     var sec = node.Nodes.GetParameter("sec", 0);
     return new DateTime(yr, mo, dy, hr, min, sec);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Insert node
 /// </summary>
 /// <param name="index">Index</param>
 /// <param name="node">Node</param>
 internal void Insert(int index, Node node)
 {
     List.Insert(index, node);
 }
Exemplo n.º 7
0
 /// <summary>
 /// Remove node
 /// </summary>
 /// <param name="node">Node</param>
 internal void Remove(Node node)
 {
     List.Remove(node);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Add node
 /// </summary>
 /// <param name="node">Node</param>
 internal void Add(Node node)
 {
     //node.OwnerList = this ;
     List.Add(node);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Get index of node in this list
 /// </summary>
 /// <param name="node">node</param>
 /// <returns>index , if node does no in this list , return -1</returns>
 public int IndexOf(Node node)
 {
     return List.IndexOf(node);
 }