Beispiel #1
0
        internal void MergeText()
        {
            var nodeList      = new NodeList();
            var stringBuilder = new StringBuilder();
            var byteBuffer    = new ByteBuffer();

            foreach (Node node in InternalNodes)
            {
                if (node.Type == RtfNodeType.Text)
                {
                    AddString(stringBuilder, byteBuffer);
                    stringBuilder.Append(node.Keyword);
                    continue;
                }

                if (node.Type == RtfNodeType.Control &&
                    node.Keyword == "\'" &&
                    node.HasParameter)
                {
                    byteBuffer.Add((byte)node.Parameter);
                    continue;
                }

                if (node.Type == RtfNodeType.Control || node.Type == RtfNodeType.Keyword)
                {
                    if (node.Keyword == "tab")
                    {
                        AddString(stringBuilder, byteBuffer);
                        stringBuilder.Append('\t');
                        continue;
                    }
                    if (node.Keyword == "emdash")
                    {
                        AddString(stringBuilder, byteBuffer);
                        stringBuilder.Append('-');
                        continue;
                    }
                    if (node.Keyword == string.Empty)
                    {
                        AddString(stringBuilder, byteBuffer);
                        stringBuilder.Append('-');
                        continue;
                    }
                }

                AddString(stringBuilder, byteBuffer);

                if (stringBuilder.Length > 0)
                {
                    nodeList.Add(new Node(RtfNodeType.Text, stringBuilder.ToString()));
                    stringBuilder = new StringBuilder();
                }
                nodeList.Add(node);
            }

            AddString(stringBuilder, byteBuffer);

            if (stringBuilder.Length > 0)
            {
                nodeList.Add(new Node(RtfNodeType.Text, stringBuilder.ToString()));
            }

            InternalNodes.Clear();

            foreach (Node node in nodeList)
            {
                node.Parent        = this;
                node.OwnerDocument = InternalOwnerDocument;
                InternalNodes.Add(node);
            }
        }