예제 #1
0
 public void AppendChild(StiRtfTreeNode newNode)
 {
     if (newNode != null)
     {
         newNode.parent = this;
         children.Add(newNode);
     }
 }
예제 #2
0
        public void RemoveThisToken()
        {
            //int currentIndex = parent.children.IndexOf(this);
            int currentIndex = index;

            parent.children.RemoveAt(currentIndex);
            parent.UpdateNodeIndex(false);
            this.parent = null;
        }
예제 #3
0
        public string ToText()
        {
            StringBuilder res = new StringBuilder();
            //int headerLen = GetHeaderLength();
            int            headerLen = 1;
            StiRtfTreeNode node      = rootNode.ChildNodes[0].ChildNodes[headerLen];

            while (node != null)
            {
                if (node.NodeType == StiRtfNodeType.Text)
                {
                    res.Append(node.NodeKey);
                }
                if ((node.NodeType == StiRtfNodeType.Keyword) && (node.NodeKey == "par"))
                {
                    res.Append("\r\n");
                }
                node = node.NextFlateToken;
            }
            return(res.ToString());
        }
예제 #4
0
        private string toStringInm(StiRtfTreeNode curNode, int level, bool showNodeTypes)
        {
            StringBuilder        res      = new StringBuilder();
            StiRtfNodeCollection children = curNode.ChildNodes;

            for (int i = 0; i < level; i++)
            {
                res.Append("  ");
            }
            if (curNode.NodeType == StiRtfNodeType.Root)
            {
                res.Append("ROOT\r\n");
            }
            else if (curNode.NodeType == StiRtfNodeType.Group)
            {
                res.Append("GROUP\r\n");
            }
            else
            {
                if (showNodeTypes)
                {
                    res.Append(curNode.NodeType);
                    res.Append(": ");
                }
                res.Append(curNode.NodeKey);
                if (curNode.HasParameter)
                {
                    res.Append(" ");
                    res.Append(Convert.ToString(curNode.Parameter));
                }
                res.Append("\r\n");
            }
            foreach (StiRtfTreeNode node in children)
            {
                res.Append(toStringInm(node, level + 1, showNodeTypes));
            }
            return(res.ToString());
        }
예제 #5
0
 public StiRtfTree()
 {
     rootNode = new StiRtfTreeNode(StiRtfNodeType.Root, "ROOT", false, 0);
     mergeSpecialCharacters = false;
 }
예제 #6
0
        public ArrayList GetBandsData()
        {
            StiRtfNodeCollection main         = rootNode.ChildNodes[0].ChildNodes;
            StiRtfTreeNode       lastRootNode = rootNode.ChildNodes[0].LastChild;

            #region Skip header and info
            int pos = 0;
            //find first group
            while ((pos < main.Count) && (main[pos].NodeType != StiRtfNodeType.Group))
            {
                pos++;
            }
            //find last group in header or info
            while (pos < main.Count)
            {
                if (main[pos].NodeType == StiRtfNodeType.Group)
                {
                    pos++;
                }
                else
                {
                    //find next group
                    int pos2 = pos;
                    while ((pos2 < main.Count) && (main[pos2].NodeType != StiRtfNodeType.Group))
                    {
                        if ((main[pos2].NodeType == StiRtfNodeType.Keyword) &&
                            (TokensHash.ContainsKey(main[pos2].NodeKey)) && ((int)TokensHash[main[pos2].NodeKey] == 1))
                        {
                            pos  = pos2;
                            pos2 = main.Count;  //for break loop
                            break;
                        }
                        pos2++;
                    }
                    //check for header or info
                    if (pos2 < main.Count)
                    {
                        StiRtfTreeNode tempNode = main[pos2].ChildNodes[0];
                        if (((tempNode.NodeType == StiRtfNodeType.Keyword) &&
                             (TokensHash.ContainsKey(tempNode.NodeKey) && (int)TokensHash[tempNode.NodeKey] == 0)) ||
                            ((tempNode.NodeType == StiRtfNodeType.Control) && (tempNode.NodeKey == "*")))
                        {
                            pos = pos2;
                            pos++;
                            continue;
                        }
                    }
                    break;
                }
            }
            #endregion

            ArrayList bandsList = new ArrayList();

            StiRtfTreeNode node     = main[pos];
            StiRtfTreeNode lastNode = null;
            StiRtfBandData data     = null;

            while ((node != null) && (node != lastRootNode))
            {
                data       = new StiRtfBandData();
                data.start = node;
                bool tableFounded = false;

                while ((node != null) && (node != lastRootNode))
                {
                    if ((node.NodeType == StiRtfNodeType.Keyword) && (node.NodeKey == "page") && (node != data.start))
                    {
                        break;
                    }
                    if ((node.NodeType == StiRtfNodeType.Keyword) && (node.NodeKey == "sect") && (node != data.start))
                    {
                        break;
                    }
                    if ((node.NodeType == StiRtfNodeType.Keyword) && (node.NodeKey == "trowd"))
                    {
                        tableFounded = true;
                        break;
                    }
                    if ((node.NodeType == StiRtfNodeType.Keyword) && (node.NodeKey == "intbl"))
                    {
                        node         = data.start;
                        tableFounded = true;
                        break;
                    }
                    lastNode = node;
                    node     = node.NextFlateToken;
                }
                if (node != data.start)
                {
                    data.end        = lastNode;
                    data.isTableRow = false;
                    bandsList.Add(data);
                }

                if ((tableFounded) && (node != null) && (node != lastRootNode))
                {
                    data            = new StiRtfBandData();
                    data.start      = node;
                    data.isTableRow = true;
                    if ((node.NodeType == StiRtfNodeType.Keyword) && (node.NodeKey == "trowd"))
                    {
                        node = node.NextFlateToken;
                    }
                    else
                    {
                        data.isIntbl = true;
                    }

                    while ((node != null) && (node != lastRootNode))
                    {
                        if ((node.NodeType == StiRtfNodeType.Keyword) && (node.NodeKey == "row"))
                        {
                            node = node.NextFlateToken;
                            break;
                        }
                        //if ((node.NodeType == StiRtfNodeType.Keyword) && (node.NodeKey == "trowd")) break;
                        lastNode = node;
                        node     = node.NextFlateToken;
                    }
                    while ((node != null) && (node != lastRootNode) && ((node.NodeType == StiRtfNodeType.Group) || (node.NodeType == StiRtfNodeType.GroupEnd)))
                    {
                        lastNode = node;
                        node     = node.NextFlateToken;
                    }
                    data.end = lastNode;
                    //if ((node.NodeType == StiRtfNodeType.Keyword) && (node.NodeKey == "trowd"))
                    //{
                    //    data.end = node;	//
                    //}
                    bandsList.Add(data);
                }
            }

            return(bandsList);
        }
예제 #7
0
        private int ParseRtfTree()
        {
            int res         = 0;
            int level       = 0;
            int tokensCount = 0;
            int delayCount  = 0;

            Encoding encoding = Encoding.Default;

            StiRtfTreeNode curNode = rootNode;
            StiRtfTreeNode newNode = null;

            StiRtfToken tok = lex.NextToken();

            while (tok.Type != StiRtfTokenType.Eof)
            {
                tokensCount++;
                switch (tok.Type)
                {
                case StiRtfTokenType.GroupStart:
                    newNode = new StiRtfTreeNode(StiRtfNodeType.Group, "GROUP", false, 0);
                    curNode.AppendChild(newNode);
                    curNode = newNode;
                    level++;
                    break;

                case StiRtfTokenType.GroupEnd:
                    newNode = new StiRtfTreeNode(StiRtfNodeType.GroupEnd, "GROUPEND", false, 0);
                    curNode.AppendChild(newNode);
                    curNode = curNode.ParentNode;
                    //newNode = new StiRtfTreeNode(StiRtfNodeType.None, "NoneAfterGroup", false, 0);
                    //curNode.AppendChild(newNode);
                    level--;
                    //show progress
                    if (delayCount == 0)
                    {
                        delayCount = 8;
                    }
                    else
                    {
                        delayCount--;
                    }
                    break;

                case StiRtfTokenType.Keyword:
                case StiRtfTokenType.Control:
                case StiRtfTokenType.Text:
                    if (mergeSpecialCharacters)
                    {
                        bool isText = tok.Type == StiRtfTokenType.Text || (tok.Type == StiRtfTokenType.Control && tok.Key == "'");
                        if (curNode.LastChild != null && (curNode.LastChild.NodeType == StiRtfNodeType.Text && isText))
                        {
                            if (tok.Type == StiRtfTokenType.Text)
                            {
                                curNode.LastChild.NodeKey += tok.Key;
                                break;
                            }
                            if (tok.Type == StiRtfTokenType.Control && tok.Key == "'")
                            {
                                curNode.LastChild.NodeKey += DecodeControlChar(tok.Parameter, encoding);
                                break;
                            }
                        }
                        else
                        {
                            if (tok.Type == StiRtfTokenType.Control && tok.Key == "'")
                            {
                                newNode = new StiRtfTreeNode(StiRtfNodeType.Text, DecodeControlChar(tok.Parameter, encoding), false, 0);
                                curNode.AppendChild(newNode);
                                break;
                            }
                        }
                    }

                    newNode = new StiRtfTreeNode(tok);
                    curNode.AppendChild(newNode);

                    if (mergeSpecialCharacters)
                    {
                        if (level == 1 && newNode.NodeType == StiRtfNodeType.Keyword && newNode.NodeKey == "ansicpg")
                        {
                            encoding = Encoding.GetEncoding(newNode.Parameter);
                        }
                    }

                    break;

                default:
                    res = -1;
                    break;
                }
                tok = lex.NextToken();
            }

            rootNode.UpdateNodeIndex(true);

            if (level != 0)
            {
                res = -1;
            }
            return(res);
        }
예제 #8
0
 public int IndexOf(StiRtfTreeNode node)
 {
     return(InnerList.IndexOf(node));
 }
예제 #9
0
 public void Insert(int index, StiRtfTreeNode node)
 {
     InnerList.Insert(index, node);
 }
예제 #10
0
 public int Add(StiRtfTreeNode node)
 {
     InnerList.Add(node);
     return(InnerList.Count - 1);
 }