Example #1
0
        public FormatNode SplitNodeBeforeChild(FormatNode child)
        {
            FormatStore.NodeEntry[] array = this.nodes.Plane(this.nodeHandle);
            int num    = this.nodes.Index(this.nodeHandle);
            int handle = this.nodes.Allocate(this.NodeType, array[num].BeginTextPosition);

            FormatStore.NodeEntry[] array2 = this.nodes.Plane(handle);
            int num2 = this.nodes.Index(handle);

            array2[num2].NodeFlags       = array[num].NodeFlags;
            array2[num2].TextMapping     = array[num].TextMapping;
            array2[num2].EndTextPosition = child.BeginTextPosition;
            array2[num2].FlagProperties  = array[num].FlagProperties;
            array2[num2].PropertyMask    = array[num].PropertyMask;
            array2[num2].Properties      = array[num].Properties;
            array[num].BeginTextPosition = child.BeginTextPosition;
            FormatNode formatNode = new FormatNode(this.nodes, handle);

            do
            {
                FormatNode firstChild = this.FirstChild;
                firstChild.RemoveFromParent();
                formatNode.AppendChild(firstChild);
            }while (this.FirstChild != child);
            this.InsertSiblingBefore(formatNode);
            return(formatNode);
        }
Example #2
0
 public NodePropertiesEnumerator(FormatNode node)
 {
     this.FlagProperties       = node.FlagProperties;
     this.Properties           = node.Properties;
     this.CurrentPropertyIndex = 0;
     this.CurrentProperty      = Property.Null;
 }
Example #3
0
        public void InsertSiblingBefore(FormatNode newSiblingNode)
        {
            int num = newSiblingNode.nodeHandle;

            FormatStore.NodeEntry[] array = this.nodes.Plane(num);
            int num2 = this.nodes.Index(num);

            FormatStore.NodeEntry[] array2 = this.nodes.Plane(this.nodeHandle);
            int num3   = this.nodes.Index(this.nodeHandle);
            int parent = array2[num3].Parent;

            FormatStore.NodeEntry[] array3 = this.nodes.Plane(parent);
            int num4   = this.nodes.Index(parent);
            int handle = array3[num4].LastChild;

            FormatStore.NodeEntry[] array4 = this.nodes.Plane(handle);
            int num5 = this.nodes.Index(handle);

            while (array4[num5].NextSibling != this.nodeHandle)
            {
                handle = array4[num5].NextSibling;
                array4 = this.nodes.Plane(handle);
                num5   = this.nodes.Index(handle);
            }
            array[num2].Parent       = parent;
            array[num2].NextSibling  = this.nodeHandle;
            array4[num5].NextSibling = num;
        }
Example #4
0
 public void Restart(FormatNode rootNode)
 {
     this.outputStackTop           = 0;
     this.currentOutputLevel.Node  = rootNode;
     this.currentOutputLevel.State = FormatOutput.OutputState.NotStarted;
     this.rootNode = rootNode;
 }
        protected FormatNode CreateNode(FormatContainerType type)
        {
            FormatNode result = this.Store.AllocateNode(type);

            result.EndTextPosition = result.BeginTextPosition;
            result.SetOutOfOrder();
            return(result);
        }
Example #6
0
        public void Restart(FormatNode rootNode)
        {
            outputStackTop = 0;

            currentOutputLevel.node  = rootNode;
            currentOutputLevel.state = OutputState.NotStarted;

            this.rootNode = rootNode;
        }
Example #7
0
 public void MoveAllChildrenToNewParent(FormatNode newParent)
 {
     while (!this.FirstChild.IsNull)
     {
         FormatNode firstChild = this.FirstChild;
         firstChild.RemoveFromParent();
         newParent.AppendChild(firstChild);
     }
 }
Example #8
0
        private void PopPushNextSibling()
        {
            FormatNode nextSibling = this.currentOutputLevel.Node.NextSibling;

            this.Pop();
            this.currentOutputLevel.ChildIndex = this.currentOutputLevel.ChildIndex + 1;
            if (!nextSibling.IsNull)
            {
                this.Push(nextSibling);
                return;
            }
            this.currentOutputLevel.State = FormatOutput.OutputState.EndPending;
        }
Example #9
0
        private void PushFirstChild()
        {
            FormatNode firstChild = this.currentOutputLevel.Node.FirstChild;

            if (!firstChild.IsNull)
            {
                this.currentOutputLevel.State = FormatOutput.OutputState.Started;
                this.Push(firstChild);
                return;
            }
            if (this.currentOutputLevel.Node.IsText)
            {
                this.currentOutputLevel.State = FormatOutput.OutputState.Started;
                return;
            }
            this.currentOutputLevel.State = FormatOutput.OutputState.EndPending;
        }
Example #10
0
        private void Push(FormatNode node)
        {
            if (outputStack == null)
            {
                InternalDebug.Assert(outputStackTop == 0 && formatStore != null);

                outputStack = new OutputStackEntry[32];
            }
            else if (outputStackTop == outputStack.Length)
            {
                if (outputStackTop >= HtmlSupport.HtmlNestingLimit)
                {
                    throw new TextConvertersException(Strings.InputDocumentTooComplex);
                }

                var newOutputStack = new OutputStackEntry[outputStack.Length * 2];
                Array.Copy(outputStack, 0, newOutputStack, 0, outputStackTop);
                outputStack = newOutputStack;
            }

#if DEBUG
            if (formatOutputTraceWriter != null)
            {
                formatOutputTraceWriter.WriteLine("{0}{1} Push {2}", Indent(outputStackTop), outputStackTop, node.NodeType.ToString());

                formatOutputTraceWriter.Flush();
            }
#endif
            outputStack[outputStackTop++] = currentOutputLevel;

            currentOutputLevel.node              = node;
            currentOutputLevel.state             = OutputState.NotStarted;
            currentOutputLevel.index             = currentOutputLevel.childIndex;
            currentOutputLevel.childIndex        = 0;
            currentOutputLevel.propertyUndoLevel = propertyState.ApplyProperties(node.FlagProperties, node.Properties, FormatStoreData.GlobalInheritanceMasks[node.InheritanceMaskIndex].flagProperties, FormatStoreData.GlobalInheritanceMasks[node.InheritanceMaskIndex].propertyMask);
#if DEBUG
            if (formatOutputTraceWriter != null)
            {
                formatOutputTraceWriter.WriteLine("{0}{1} Props After {2}", Indent(outputStackTop), outputStackTop, propertyState.ToString());
                formatOutputTraceWriter.Flush();
            }
#endif

            node.SetOnLeftEdge();
        }
Example #11
0
 private void PrepareToCloseContainer(int stackPosition)
 {
     if (this.BuildStack[stackPosition].Properties != null)
     {
         for (int i = 0; i < this.BuildStack[stackPosition].Properties.Length; i++)
         {
             if (this.BuildStack[stackPosition].Properties[i].Value.IsRefCountedHandle)
             {
                 this.Store.ReleaseValue(this.BuildStack[stackPosition].Properties[i].Value);
             }
         }
         this.BuildStack[stackPosition].Properties = null;
     }
     if (this.BuildStack[stackPosition].Node != 0)
     {
         FormatNode node = this.Store.GetNode(this.BuildStack[stackPosition].Node);
         if (!this.newLine && (byte)(node.NodeType & FormatContainerType.BlockFlag) != 0)
         {
             this.Store.AddBlockBoundary();
             this.newLine             = true;
             this.textQuotingExpected = true;
         }
         node.PrepareToClose(this.Store.CurrentTextPosition);
         if (!node.Parent.IsNull && node.Parent.NodeType == FormatContainerType.TableContainer)
         {
             node.Parent.PrepareToClose(this.Store.CurrentTextPosition);
         }
         if (this.BuildStack[stackPosition].Node == this.LastNodeInternal)
         {
             for (int j = stackPosition - 1; j >= 0; j--)
             {
                 if (this.BuildStack[j].Node != 0)
                 {
                     this.LastNodeInternal = this.BuildStack[j].Node;
                     break;
                 }
             }
         }
     }
     this.Store.SetTextBoundary();
     this.EmptyContainer = false;
 }
Example #12
0
        public FormatNode SplitTextNode(uint splitPosition)
        {
            FormatStore.NodeEntry[] array = this.nodes.Plane(this.nodeHandle);
            int num    = this.nodes.Index(this.nodeHandle);
            int handle = this.nodes.Allocate(FormatContainerType.Text, array[num].BeginTextPosition);

            FormatStore.NodeEntry[] array2 = this.nodes.Plane(handle);
            int num2 = this.nodes.Index(handle);

            array2[num2].NodeFlags       = array[num].NodeFlags;
            array2[num2].TextMapping     = array[num].TextMapping;
            array2[num2].EndTextPosition = splitPosition;
            array2[num2].FlagProperties  = array[num].FlagProperties;
            array2[num2].PropertyMask    = array[num].PropertyMask;
            array2[num2].Properties      = array[num].Properties;
            array[num].BeginTextPosition = splitPosition;
            FormatNode formatNode = new FormatNode(this.nodes, handle);

            this.InsertSiblingBefore(formatNode);
            return(formatNode);
        }
Example #13
0
        public FormatNode DuplicateInsertAsChild()
        {
            int handle = this.nodes.Allocate(this.NodeType, this.BeginTextPosition);

            FormatStore.NodeEntry[] array = this.nodes.Plane(this.nodeHandle);
            int num = this.nodes.Index(this.nodeHandle);

            FormatStore.NodeEntry[] array2 = this.nodes.Plane(handle);
            int num2 = this.nodes.Index(handle);

            array2[num2].NodeFlags       = array[num].NodeFlags;
            array2[num2].TextMapping     = array[num].TextMapping;
            array2[num2].EndTextPosition = array[num].EndTextPosition;
            array2[num2].FlagProperties  = array[num].FlagProperties;
            array2[num2].PropertyMask    = array[num].PropertyMask;
            array2[num2].Properties      = array[num].Properties;
            FormatNode formatNode = new FormatNode(this.nodes, handle);

            this.MoveAllChildrenToNewParent(formatNode);
            this.AppendChild(formatNode);
            return(formatNode);
        }
Example #14
0
        public void InsertSiblingAfter(FormatNode newSiblingNode)
        {
            int num = newSiblingNode.nodeHandle;

            FormatStore.NodeEntry[] array = this.nodes.Plane(num);
            int num2 = this.nodes.Index(num);

            FormatStore.NodeEntry[] array2 = this.nodes.Plane(this.nodeHandle);
            int num3   = this.nodes.Index(this.nodeHandle);
            int parent = array2[num3].Parent;

            FormatStore.NodeEntry[] array3 = this.nodes.Plane(parent);
            int num4 = this.nodes.Index(parent);

            array[num2].Parent       = parent;
            array[num2].NextSibling  = array2[num3].NextSibling;
            array2[num3].NextSibling = num;
            if (this.nodeHandle == array3[num4].LastChild)
            {
                array3[num4].LastChild = num;
            }
        }
Example #15
0
 private void Push(FormatNode node)
 {
     if (this.outputStack == null)
     {
         this.outputStack = new FormatOutput.OutputStackEntry[32];
     }
     else if (this.outputStackTop == this.outputStack.Length)
     {
         if (this.outputStackTop >= 4096)
         {
             throw new TextConvertersException(TextConvertersStrings.InputDocumentTooComplex);
         }
         FormatOutput.OutputStackEntry[] destinationArray = new FormatOutput.OutputStackEntry[this.outputStack.Length * 2];
         Array.Copy(this.outputStack, 0, destinationArray, 0, this.outputStackTop);
         this.outputStack = destinationArray;
     }
     this.outputStack[this.outputStackTop++]   = this.currentOutputLevel;
     this.currentOutputLevel.Node              = node;
     this.currentOutputLevel.State             = FormatOutput.OutputState.NotStarted;
     this.currentOutputLevel.Index             = this.currentOutputLevel.ChildIndex;
     this.currentOutputLevel.ChildIndex        = 0;
     this.currentOutputLevel.PropertyUndoLevel = this.propertyState.ApplyProperties(node.FlagProperties, node.Properties, FormatStoreData.GlobalInheritanceMasks[node.InheritanceMaskIndex].FlagProperties, FormatStoreData.GlobalInheritanceMasks[node.InheritanceMaskIndex].PropertyMask);
     node.SetOnLeftEdge();
 }
Example #16
0
        public void OutputFragment(FormatNode beginNode, uint beginTextPosition, FormatNode endNode, uint endTextPosition)
        {
            this.Restart(this.rootNode);
            FormatNode formatNode = beginNode;
            int        num        = 0;

            while (formatNode != this.rootNode)
            {
                num++;
                formatNode = formatNode.Parent;
            }
            if (this.outputStack == null)
            {
                this.outputStack = new FormatOutput.OutputStackEntry[Math.Max(32, num)];
            }
            else if (this.outputStack.Length < num)
            {
                if (this.outputStackTop >= 4096)
                {
                    throw new TextConvertersException(TextConvertersStrings.InputDocumentTooComplex);
                }
                this.outputStack = new FormatOutput.OutputStackEntry[Math.Max(this.outputStack.Length * 2, num)];
            }
            formatNode = beginNode;
            int i = num - 1;

            while (formatNode != this.rootNode)
            {
                this.outputStack[i--].Node = formatNode;
                formatNode = formatNode.Parent;
            }
            for (i = 0; i < num; i++)
            {
                if (!this.StartCurrentLevel())
                {
                    this.PopPushNextSibling();
                    break;
                }
                this.currentOutputLevel.State = FormatOutput.OutputState.Started;
                this.Push(this.outputStack[i].Node);
            }
            bool flag = false;

            while (this.currentOutputLevel.State != FormatOutput.OutputState.Ended)
            {
                if (this.currentOutputLevel.State == FormatOutput.OutputState.NotStarted)
                {
                    if (this.StartCurrentLevel())
                    {
                        this.PushFirstChild();
                    }
                    else
                    {
                        this.PopPushNextSibling();
                    }
                }
                else if (this.currentOutputLevel.State == FormatOutput.OutputState.Started)
                {
                    uint num2 = (this.currentOutputLevel.Node == beginNode) ? beginTextPosition : this.currentOutputLevel.Node.BeginTextPosition;
                    uint num3 = (this.currentOutputLevel.Node == endNode) ? endTextPosition : this.currentOutputLevel.Node.EndTextPosition;
                    if (num2 <= num3)
                    {
                        this.ContinueText(num2, num3);
                    }
                    this.currentOutputLevel.State = FormatOutput.OutputState.EndPending;
                }
                else
                {
                    this.EndCurrentLevel();
                    this.currentOutputLevel.State = FormatOutput.OutputState.Ended;
                    if (this.outputStackTop != 0)
                    {
                        if (!flag && this.currentOutputLevel.Node != endNode && (this.currentOutputLevel.Node.NextSibling.IsNull || this.currentOutputLevel.Node.NextSibling != endNode || (this.currentOutputLevel.Node.NextSibling.NodeType == FormatContainerType.Text && this.currentOutputLevel.Node.NextSibling.BeginTextPosition < endTextPosition)))
                        {
                            this.PopPushNextSibling();
                        }
                        else
                        {
                            this.Pop();
                            this.currentOutputLevel.State = FormatOutput.OutputState.EndPending;
                            flag = true;
                        }
                    }
                }
            }
        }
Example #17
0
 public void OutputFragment(FormatNode fragmentNode)
 {
     this.Restart(fragmentNode);
     this.FlushFragment();
 }
Example #18
0
        private void FlushContainer(int stackPos)
        {
            FormatContainerType formatContainerType = this.FixContainerType(this.BuildStack[stackPos].Type, this.ContainerStyleBuildHelper);

            if (formatContainerType != this.BuildStack[stackPos].Type)
            {
                this.BuildStack[stackPos].Type = formatContainerType;
            }
            this.ContainerStyleBuildHelper.GetPropertyList(out this.BuildStack[stackPos].Properties, out this.BuildStack[stackPos].FlagProperties, out this.BuildStack[stackPos].PropertyMask);
            if (!this.BuildStack[stackPos].IsPropertyContainerOrNull)
            {
                if (!this.newLine && (byte)(this.BuildStack[stackPos].Type & FormatContainerType.BlockFlag) != 0)
                {
                    this.Store.AddBlockBoundary();
                    this.newLine             = true;
                    this.textQuotingExpected = true;
                }
                FormatNode formatNode;
                if (formatContainerType == FormatContainerType.Document)
                {
                    formatNode = this.Store.AllocateNode(this.BuildStack[stackPos].Type, 0U);
                }
                else
                {
                    formatNode = this.Store.AllocateNode(this.BuildStack[stackPos].Type);
                }
                formatNode.SetOnRightEdge();
                if ((byte)(this.BuildStack[stackPos].Type & FormatContainerType.InlineObjectFlag) != 0)
                {
                    this.Store.AddInlineObject();
                }
                FormatNode node = this.Store.GetNode(this.LastNodeInternal);
                int        num;
                this.GetParentForNewNode(formatNode, node, stackPos, out num).AppendChild(formatNode);
                this.BuildStack[stackPos].Node = formatNode.Handle;
                this.LastNodeInternal          = formatNode.Handle;
                FlagProperties  flagProperties2;
                Property[]      properties;
                PropertyBitMask propertyMask;
                if (num < stackPos)
                {
                    FlagProperties  flagProperties  = FlagProperties.AllOn;
                    PropertyBitMask propertyBitMask = PropertyBitMask.AllOn;
                    int             num2            = stackPos;
                    while (num2 >= num && (!flagProperties.IsClear || !propertyBitMask.IsClear))
                    {
                        if (num2 == stackPos || this.BuildStack[num2].Type == FormatContainerType.PropertyContainer)
                        {
                            flagProperties2 = (this.BuildStack[num2].FlagProperties & flagProperties);
                            this.ContainerStyleBuildHelper.AddProperties(11, flagProperties2, propertyBitMask, this.BuildStack[num2].Properties);
                            flagProperties  &= ~this.BuildStack[num2].FlagProperties;
                            propertyBitMask &= ~this.BuildStack[num2].PropertyMask;
                            flagProperties  &= FormatStoreData.GlobalInheritanceMasks[this.BuildStack[num2].InheritanceMaskIndex].FlagProperties;
                            propertyBitMask &= FormatStoreData.GlobalInheritanceMasks[this.BuildStack[num2].InheritanceMaskIndex].PropertyMask;
                        }
                        num2--;
                    }
                    this.ContainerStyleBuildHelper.GetPropertyList(out properties, out flagProperties2, out propertyMask);
                }
                else
                {
                    flagProperties2 = this.BuildStack[stackPos].FlagProperties;
                    propertyMask    = this.BuildStack[stackPos].PropertyMask;
                    properties      = this.BuildStack[stackPos].Properties;
                    if (properties != null)
                    {
                        for (int i = 0; i < properties.Length; i++)
                        {
                            if (properties[i].Value.IsRefCountedHandle)
                            {
                                this.Store.AddRefValue(properties[i].Value);
                            }
                        }
                    }
                }
                formatNode.SetProps(flagProperties2, propertyMask, properties, this.BuildStack[stackPos].InheritanceMaskIndex);
            }
            this.ContainerStyleBuildHelper.Clean();
            this.ContainerFlushed = true;
        }
Example #19
0
        public void OutputFragment(FormatNode beginNode, uint beginTextPosition, FormatNode endNode, uint endTextPosition)
        {
            Restart(rootNode);

            var node             = beginNode;
            var countStartLevels = 0;



            while (node != rootNode)
            {
                countStartLevels++;
                node = node.Parent;
            }

            if (outputStack == null)
            {
                InternalDebug.Assert(outputStackTop == 0 && formatStore != null);

                outputStack = new OutputStackEntry[Math.Max(32, countStartLevels)];
            }
            else if (outputStack.Length < countStartLevels)
            {
                if (outputStackTop >= HtmlSupport.HtmlNestingLimit)
                {
                    throw new TextConvertersException(Strings.InputDocumentTooComplex);
                }

                outputStack = new OutputStackEntry[Math.Max(outputStack.Length * 2, countStartLevels)];
            }



            node = beginNode;
            var level = countStartLevels - 1;

            while (node != rootNode)
            {
                outputStack[level--].node = node;
                node = node.Parent;
            }
            InternalDebug.Assert(level == -1);



            for (level = 0; level < countStartLevels; level++)
            {
                if (!StartCurrentLevel())
                {
                    PopPushNextSibling();
                    break;
                }

                currentOutputLevel.state = OutputState.Started;

                Push(outputStack[level].node);
            }

            var endReached = false;

            while (currentOutputLevel.state != OutputState.Ended)
            {
                if (currentOutputLevel.state == OutputState.NotStarted)
                {
                    if (StartCurrentLevel())
                    {
                        PushFirstChild();
                    }
                    else
                    {
                        PopPushNextSibling();
                    }
                }
                else if (currentOutputLevel.state == OutputState.Started)
                {
                    InternalDebug.Assert(currentOutputLevel.node.NodeType == FormatContainerType.Text);

                    var nodeBeginTextPosition = currentOutputLevel.node == beginNode ? beginTextPosition : currentOutputLevel.node.BeginTextPosition;
                    var nodeEndTextPosition   = currentOutputLevel.node == endNode ? endTextPosition : currentOutputLevel.node.EndTextPosition;

                    if (nodeBeginTextPosition <= nodeEndTextPosition)
                    {
                        ContinueText(nodeBeginTextPosition, nodeEndTextPosition);
                    }

                    currentOutputLevel.state = OutputState.EndPending;
                }
                else
                {
                    InternalDebug.Assert(currentOutputLevel.state == OutputState.EndPending);

                    EndCurrentLevel();

                    currentOutputLevel.state = OutputState.Ended;

                    if (outputStackTop != 0)
                    {
                        if (!endReached &&
                            currentOutputLevel.node != endNode &&
                            (currentOutputLevel.node.NextSibling.IsNull ||
                             currentOutputLevel.node.NextSibling != endNode ||
                             (currentOutputLevel.node.NextSibling.NodeType == FormatContainerType.Text &&
                              currentOutputLevel.node.NextSibling.BeginTextPosition < endTextPosition)))
                        {
                            PopPushNextSibling();
                        }
                        else
                        {
                            Pop();



                            currentOutputLevel.state = OutputState.EndPending;

                            endReached = true;
                        }
                    }
                }
            }

            InternalDebug.Assert(outputStackTop == 0);
            InternalDebug.Assert(propertyState.UndoStackTop == 0);
        }
Example #20
0
 public void OutputFragment(FormatNode fragmentNode)
 {
     Restart(fragmentNode);
     FlushFragment();
 }
Example #21
0
 public void PrependChild(FormatNode newChildNode)
 {
     FormatNode.InternalPrependChild(this.nodes, this.nodeHandle, newChildNode.Handle);
 }
Example #22
0
 internal static void InternalAppendChild(FormatStore.NodeStore nodes, int thisNode, int newChildNode)
 {
     FormatNode.InternalPrependChild(nodes, thisNode, newChildNode);
     nodes.Plane(thisNode)[nodes.Index(thisNode)].LastChild = newChildNode;
 }
Example #23
0
 protected virtual FormatNode GetParentForNewNode(FormatNode node, FormatNode defaultParent, int stackPos, out int propContainerInheritanceStopLevel)
 {
     propContainerInheritanceStopLevel = this.DefaultPropContainerInheritanceStopLevel(stackPos);
     return(defaultParent);
 }