示例#1
0
        public Node Parse(XmlNode XMLNode, Types mTypes, EntityManager mEntities, bool recurse, StyleAttributes styleAttributes, bool bParentShift)
        {
            bool hasSelect      = false;
            bool hasSelectRight = false;
            Node result         = null;

            if (!bParentShift)
            {
                xmlTagName   = XMLNode.LocalName;
                namespaceURI = XMLNode.NamespaceURI;
            }

            int numAttrs = 0;

            if ((recurse && (XMLNode.Attributes != null)) && !bParentShift)
            {
                StyleAttributes attributes = ParseMStyle(XMLNode, style_);
                if (attributes != null)
                {
                    if (style_ == null)
                    {
                        style_ = new StyleAttributes();
                    }
                    attributes.CopyTo(style_);
                }

                numAttrs = XMLNode.Attributes.Count;
                if (numAttrs > 0)
                {
                    if (attrs == null)
                    {
                        attrs = new AttributeList();
                    }

                    for (int i = 0; i < numAttrs; i++)
                    {
                        if (XMLNode.Attributes[i].Name == "nugenCursor")
                        {
                            result    = this;
                            hasSelect = true;
                        }
                        else if (XMLNode.Attributes[i].Name == "nugenCursorEnd")
                        {
                            result          = this;
                            result.IsAppend = true;
                            hasSelectRight  = true;
                        }
                        else
                        {
                            attrs.Add(new Attribute(XMLNode.Attributes[i].Name, XMLNode.Attributes[i].Value, XMLNode.Attributes[i].NamespaceURI));
                        }
                    }

                    if (hasSelect)
                    {
                        XMLNode.Attributes.RemoveNamedItem("nugenCursor");
                    }
                    if (hasSelectRight)
                    {
                        XMLNode.Attributes.RemoveNamedItem("nugenCursorEnd");
                    }
                }
            }

            if ((XMLNode.NodeType == XmlNodeType.Element) && !bParentShift)
            {
                if (type_ == null)
                {
                    type_ = mTypes[xmlTagName];
                }
                if ((hasSelect && (type_.type == ElementType.Mi)) &&
                    (literalText != null))
                {
                    InternalMark = literalText.Length;
                }
            }

            if (recurse && XMLNode.HasChildNodes)
            {
                XmlNodeList list = XMLNode.ChildNodes;
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].NodeType == XmlNodeType.Text)
                    {
                        if ((type_.type == ElementType.Mtext) || (type_.type == ElementType.Ms))
                        {
                            literalText += list[i].Value;
                            continue;
                        }

                        if (type_.type == ElementType.Mn)
                        {
                            literalText += list[i].Value.Trim();
                            continue;
                        }

                        if (type_.type == ElementType.Mi)
                        {
                            literalText += list[i].Value.Trim();
                            continue;
                        }

                        if (type_.type != ElementType.Mo)
                        {
                            continue;
                        }

                        string entityChar = list[i].Value.Trim();
                        bool   isGlyph    = false;
                        try
                        {
                            Glyph glyph;

                            if (!(((((entityChar != "(") && (entityChar != ")")) && ((entityChar != "[") && (entityChar != "]"))) &&
                                   (((entityChar != "{") && (entityChar != "}")) && ((entityChar != "|") && (entityChar != "||")))) &&
                                  (((entityChar != "+") && (entityChar != "-")) && ((entityChar != "=") && (entityChar != "/")))))
                            {
                                string entityName = "";


                                switch (entityChar)
                                {
                                case "(":
                                {
                                    entityName = "lpar";
                                    break;
                                }

                                case ")":
                                {
                                    entityName = "rpar";
                                    break;
                                }

                                case "[":
                                {
                                    entityName = "lbrack";
                                    break;
                                }

                                case "]":
                                {
                                    entityName = "rbrack";
                                    break;
                                }

                                case "{":
                                {
                                    entityName = "lbrace";
                                    break;
                                }

                                case "}":
                                {
                                    entityName = "rbrace";
                                    break;
                                }

                                case "|":
                                {
                                    entityName = "verbar";
                                    break;
                                }

                                case "||":
                                {
                                    entityName = "Verbar";
                                    break;
                                }

                                case "+":
                                {
                                    entityName = "plus";
                                    break;
                                }

                                case "-":
                                {
                                    entityName = "minus";
                                    break;
                                }

                                case "=":
                                {
                                    entityName = "equals";
                                    break;
                                }

                                case "/":
                                {
                                    entityName = "sol";
                                    break;
                                }
                                }

                                glyph = mEntities.ByName(entityName);
                                if (glyph != null)
                                {
                                    Node glyphNode = new Node();
                                    glyphNode.type_       = mTypes["entity"];
                                    glyphNode.literalText = "" + glyph.CharValue;
                                    glyphNode.fontFamily  = glyph.FontFamily;
                                    glyphNode.glyph       = glyph;
                                    glyphNode.xmlTagName  = glyph.Name;
                                    AdoptChild(glyphNode);

                                    isGlyph = true;
                                }
                            }
                        }
                        catch
                        {
                        }

                        if (!isGlyph)
                        {
                            literalText += entityChar;
                        }
                        continue;
                    }

                    if (list[i].NodeType == XmlNodeType.SignificantWhitespace)
                    {
                        continue;
                    }

                    if (list[i].NodeType == XmlNodeType.Whitespace)
                    {
                        if ((type_.type == ElementType.Mtext) || (type_.type == ElementType.Ms))
                        {
                            literalText += " ";
                        }
                        continue;
                    }

                    if (list[i].NodeType == XmlNodeType.Element)
                    {
                        if ((list[i].NamespaceURI == "http://www.w3.org/1998/Math/MathML") && (list[i].LocalName == "mstyle"))
                        {
                            Node mstyl = ParseMstyle(list[i], mTypes, mEntities, recurse, styleAttributes);
                            if (mstyl != null)
                            {
                                result = mstyl;
                            }
                        }
                        else
                        {
                            Node n = new Node(XMLNode.Name, styleAttributes);
                            n.type_ = mTypes[list[i].LocalName];

                            if (AdoptChild(n))
                            {
                                Node sn = n.Parse(list[i], mTypes, mEntities, recurse, styleAttributes, false);
                                if (sn != null)
                                {
                                    result = sn;
                                }
                            }
                        }

                        continue;
                    }

                    if (list[i].NodeType == XmlNodeType.EntityReference)
                    {
                        Node n = new Node();
                        n.type_ = mTypes["entity"];
                        if ((type_.type == ElementType.Mtext) ||
                            (type_.type == ElementType.Ms))
                        {
                            Glyph glyph = mEntities.ByName(list[i].LocalName);
                            if (glyph != null)
                            {
                                char c = Convert.ToChar(Convert.ToUInt32(glyph.Code, 0x10));
                                if (char.IsWhiteSpace(c) || char.IsControl(c))
                                {
                                    literalText = literalText + " ";
                                }
                                else
                                {
                                    literalText = literalText + c;
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                Glyph glyph = mEntities.ByName(list[i].LocalName);
                                if (glyph != null)
                                {
                                    n.literalText = "";
                                    n.literalText = n.literalText + glyph.CharValue;
                                    n.fontFamily  = glyph.FontFamily;
                                    n.glyph       = glyph;
                                    n.xmlTagName  = list[i].LocalName;
                                }
                                else
                                {
                                    n.literalText = "?";
                                    n.xmlTagName  = list[i].LocalName;
                                }
                                AdoptChild(n);
                            }
                            catch
                            {
                                n.literalText = "?";
                                n.xmlTagName  = list[i].LocalName;
                                AdoptChild(n);
                            }
                        }
                    }
                }
            }
            return(result);
        }
示例#2
0
        // 
        private void InsertFromXml (Node currentSelectedNode, XmlNode xmlChildNode, Node newNode, ref Node newSelectedNode, ref bool selected)
        {
            newNode = new Node();
            newNode.Parse(xmlChildNode, this.types_, this.entityManager, false, null, false);
            if (newNode.type_ != null)
            {
                currentSelectedNode.PrependNode(newNode);

                newSelectedNode = newNode.Parse(xmlChildNode, this.types_, this.entityManager, true, null, false);
                
                if (newSelectedNode != null)
                {
                    this.SelectNode(newSelectedNode, newSelectedNode.IsAppend);
                    selected = true;
                }
            }
        }
示例#3
0
 //
 private void MakeTopTable ()
 {
     Node root = this.FindRoot ();
     if (root != null)
     {
         bool append = false;
         bool isLast = false;
         Node top = null;
         bool wasSplit = false;
         Node cur = this.GetCurrentlySelectedNode ();
         top = this.FindRootChild ();
         if (((top != null) && (top.parent_ != null)) && (top.parent_ == root))
         {
             if (top != cur)
             {
                 this.SelectNode (top, false);
                 cur = this.GetCurrentlySelectedNode ();
             }
             if (((cur.InternalMark > 0) && !cur.IsAppend) && ((cur.literalText != null) && (cur.literalText.Length > 1)))
             {
                 cur = this.CarriageReturn (cur, ref wasSplit);
             }
             append = cur.IsAppend;
             if (append)
             {
                 if (cur.nextSibling == null)
                 {
                     isLast = true;
                 }
                 else if (cur == top)
                 {
                     this.SelectNode (cur.nextSibling, false);
                     cur = this.GetCurrentlySelectedNode ();
                     top = cur;
                     append = false;
                 }
             }
             string xml =  "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">";
             xml += "<mtable columnalign=\"left\" class=\"nugentoplevel\">";
             xml = xml + "<mtr>";
             xml = xml + "<mtd><mrow></mrow></mtd>";
             xml = xml + "</mtr>";
             xml = xml + "<mtr>";
             xml = xml + "<mtd nugenCursor=''><mrow></mrow></mtd>";
             xml = xml + "</mtr>";
             xml = xml + "</mtable>";
             xml = xml + "</math>";
             XmlDocument doc = new XmlDocument ();
             doc.LoadXml (xml);
             XmlNode first = doc.DocumentElement.FirstChild;
             Node r = new Node ();
             Node sel = r.Parse (first, this.types_, this.entityManager, true, null);
             Node last = r;
             Node next = sel;
             Node prev = next.parent_.prevSibling.firstChild;
             if ((((last != null) && (last.type_.type == ElementType.Mtable)) &&
                  ((prev != null) && (next != null))) &&
                 (((prev.type_.type == ElementType.Mtd) &&
                   (next.type_.type == ElementType.Mtd)) && (root.numChildren > 0)))
             {
                 root.firstChild.PrependNode (last);
                 root.UpdateChildrenIndices ();
                 root.UpdateLevel ();
                 int count = 0;
                 while (last.nextSibling != null)
                 {
                     Node ns = last.nextSibling;
                     if (!append)
                     {
                         if (ns == cur)
                         {
                             count++;
                         }
                     }
                     else if (ns == cur.nextSibling)
                     {
                         count++;
                     }
                     if (count == 0)
                     {
                         this.ReParent (ns.parent_, prev, ns);
                         continue;
                     }
                     this.ReParent (ns.parent_, next, ns);
                 }
                 Node pc = prev.firstChild;
                 Node nc = next.firstChild;
                 if (((pc != null) && (pc.type_.type == ElementType.Mrow)) &&
                     ((pc.numChildren == 0) && (pc.nextSibling != null)))
                 {
                     this.Tear (pc, false, false);
                 }
                 if (((nc != null) && (nc.type_.type == ElementType.Mrow)) &&
                     ((nc.numChildren == 0) && (nc.nextSibling != null)))
                 {
                     this.SelectNode (nc.nextSibling, false);
                     this.Tear (nc, false, false);
                 }
                 if (isLast)
                 {
                     this.SelectNode (next.firstChild, false);
                 }
                 else
                 {
                     this.SelectNode (cur, false);
                 }
             }
         }
     }
 }
示例#4
0
 //
 private bool EnterPressed_NeedSplit (bool splitCell)
 {
     bool isTop = false;
     try
     {
         Node cur = this.GetCurrentlySelectedNode ();
         if (((cur == null)) || (cur.type_.type == ElementType.Math))
         {
             return isTop;
         }
         try
         {
             bool isLast = false;
             bool isfirst = false;
             Node td = null;
             Node c = cur;
             bool isMath = false;
             while (((c.parent_ != null) && !isMath) && (c.type_.type != ElementType.Mtd))
             {
                 if (c.type_.type == ElementType.Math)
                 {
                     isMath = true;
                     continue;
                 }
                 td = c;
                 c = c.parent_;
             }
             if ((c != null) && (c.type_.type == ElementType.Mtd))
             {
                 Node cell = c;
                 if (cell.nextSibling == null)
                 {
                     isLast = true;
                 }
                 if (((cell.nextSibling != null) && (cell.prevSibling == null)) &&
                     ((cell.firstChild == cur) && (cur.InternalMark == 0)))
                 {
                     isfirst = true;
                 }
                 if ((cell.parent_ != null) && (cell.parent_.type_.type == ElementType.Mtr))
                 {
                     Node row = cell.parent_;
                     int numCols = row.numChildren;
                     string xml = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">";
                     xml = xml + "<mtable columnalign=\"left\">";
                     xml = xml + "<mtr>";
                     for (int i = 0; i < numCols; i++)
                     {
                         if (i == 0)
                         {
                             xml = xml + "<mtd nugenCursor=''/>";
                         }
                         else
                         {
                             xml = xml + "<mtd><mrow/></mtd>";
                         }
                     }
                     xml = xml + "</mtr>";
                     xml = xml + "</mtable>";
                     xml = xml + "</math>";
                     XmlDocument doc = new XmlDocument ();
                     doc.LoadXml (xml);
                     XmlNode topnode = doc.DocumentElement.FirstChild;
                     Node newNode = new Node ();
                     Node newSelected = newNode.Parse (topnode, this.types_, this.entityManager, true, null);
                     Node toSel = null;
                     if (newNode.HasChildren ())
                     {
                         newNode = newNode.firstChild;
                     }
                     if (newNode.type_.type != ElementType.Mtr)
                     {
                         return isTop;
                     }
                     if (isfirst)
                     {
                         row.PrependNode (newNode);
                         this.PropogateAttributes (row, newNode);
                         if ((newSelected.type_.type == ElementType.Mtd) && (newSelected.numChildren == 0))
                         {
                             newSelected.AdoptChild (this.CreateRow ());
                         }
                         this.SelectNode (cur, false);
                         return isTop;
                     }
                     row.AppendNode (newNode);
                     this.PropogateAttributes (row, newNode);
                     if (newSelected == null)
                     {
                         return isTop;
                     }
                     if (splitCell && isLast)
                     {
                         if (td != null)
                         {
                             Node cel = td;
                             toSel = newSelected;
                             int num = 0;
                             if ((cel.InternalMark == 0) && (cel.prevSibling == null))
                             {
                                 Node rrow = cel.parent_;
                                 while (rrow.numChildren > 0)
                                 {
                                     this.ReParent (rrow.firstChild.parent_, newSelected, rrow.firstChild);
                                     if (num == 0)
                                     {
                                         toSel = rrow.firstChild;
                                     }
                                     num++;
                                 }
                                 if ((rrow.type_.type == ElementType.Mtd) &&
                                     (rrow.numChildren == 0))
                                 {
                                     rrow.AdoptChild (this.CreateRow ());
                                 }
                             }
                             else
                             {
                                 bool wasSplit = false;
                                 if (cel.InternalMark == 0)
                                 {
                                     cel = cel.prevSibling;
                                 }
                                 else if (!cel.IsAppend && (cel.literalText.Length > 1))
                                 {
                                     this.CarriageReturn (cel, ref wasSplit);
                                 }
                                 while (cel.nextSibling != null)
                                 {
                                     this.ReParent (cel.nextSibling.parent_, newSelected, cel.nextSibling);
                                     if (num == 0)
                                     {
                                         toSel = cel.nextSibling;
                                     }
                                     num++;
                                 }
                             }
                         }
                         if (toSel != null)
                         {
                             this.SelectNode (toSel, false);
                             if (toSel.type_.type == ElementType.Mtd)
                             {
                                 if (toSel.firstChild != null)
                                 {
                                     this.SelectNode (toSel.firstChild, false);
                                 }
                                 else
                                 {
                                     toSel.AdoptChild (this.CreateRow ());
                                     toSel.UpdateChildrenIndices ();
                                     toSel.UpdateLevel ();
                                     this.SelectNode (toSel.firstChild, false);
                                 }
                             }
                         }
                         if (((newSelected != null) && (newSelected.type_.type == ElementType.Mtd)) &&
                             (newSelected.numChildren == 0))
                         {
                             newSelected.AdoptChild (this.CreateRow ());
                             newSelected.UpdateChildrenIndices ();
                             newSelected.UpdateLevel ();
                             this.SelectNode (newSelected.firstChild, false);
                         }
                         return isTop;
                     }
                     if (newSelected.firstChild != null)
                     {
                         this.SelectNode (newSelected.firstChild, false);
                         return isTop;
                     }
                     newSelected.AdoptChild (this.CreateRow ());
                     if (newSelected.firstChild != null)
                     {
                         this.SelectNode (newSelected.firstChild, false);
                     }
                 }
                 return isTop;
             }
             this.MakeTopTable ();
             return isTop;
         }
         finally
         {
             this.SelectCell ();
             isTop = true;
         }
     }
     catch
     {
     }
     return isTop;
 }
        private void tryAddMathXML (bool isInsert, string xml, bool isPaste)
        {
            string s = "";
            bool hasS = false;
            bool ok = false;
            try
            {
                if (this.HasSelection)
                {
                    xml = xml.Trim ();
                    if ((xml.IndexOf ("<math", 0, 5) != -1) &&
                        (((xml.IndexOf (" nugenCursor=\"") != -1) || (xml.IndexOf (" nugenCursor='") != -1)) ||
                         ((xml.IndexOf (" nugenCursorEnd=\"") != -1) || (xml.IndexOf (" nugenCursorEnd='") != -1))))
                    {
                        Selection selection = this.CaptureSelection ();
                        if ((selection != null))
                        {
                            XmlDocument doc = new XmlDocument ();
                            if (this.SaveToXml (doc, selection))
                            {
                                string outerxml = doc.OuterXml;
                                int startIndex = outerxml.IndexOf ("<math");
                                if (startIndex != -1)
                                {
                                    outerxml = outerxml.Substring (startIndex, outerxml.Length - startIndex);
                                    outerxml = outerxml.Trim ();
                                    if ((outerxml.IndexOf ("<math", 0, 5) != -1) &&
                                        (outerxml.Substring (outerxml.Length - 7, 7) == "</math>"))
                                    {
                                        s = outerxml;
                                        hasS = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            if (isInsert)
            {
                this.OnInsert (true);
            }

            bool emptyRow = false;
          
            Node selectedNode = this.GetCurrentlySelectedNode ();
            
            if (selectedNode == null)
            {
                return;
            }
            if (selectedNode.type_ == null)
            {
                return;
            }
            
            if (!this.IsEditable ())
            {
                return;
            }
            NodeClass nodeClass = this.GetNodeClass (selectedNode);
            selectedNode = this.GetCurrentlySelectedNode ();
            bool wasSplit = false;
            selectedNode = this.CarriageReturn (selectedNode, ref wasSplit);
            if (wasSplit)
            {
                this.SelectNode (selectedNode, false);
            }

            XmlNode xmlRoot = this.LoadXml (xml, new XmlDocument ());
            
            if (xmlRoot == null)
            {
                return;
            }
            
            if (!this.IsMultiline)
            {
                Node wasSelected = selectedNode;
                if (this.CreateTopLevelTable ())
                {
                    nodeClass = this.GetNodeClass (selectedNode);
                    selectedNode = this.GetCurrentlySelectedNode ();
                }
                else
                {
                    return;
                }
            }
            
            if ((nodeClass == NodeClass.unknown) )
            {
                return;
            }

            bool wasSelect = false;
            Node lastRow = null;
            if (!((xmlRoot == null) || !xmlRoot.HasChildNodes))
            {
                Node selRow = selectedNode;
                int count = 0;
                count = xmlRoot.ChildNodes.Count;
                int rCount = 0;
                if (((selRow.type_ != null) && (selRow.type_.type == ElementType.Mrow)) && !selRow.HasChildren())
                {
                    emptyRow = true;
                    rCount = 1;
                }
                if ((((selRow.parent_ != null)) &&
                     ((selRow.parent_.type_.maxChilds != -1) &&
                      (((selRow.parent_.numChildren - rCount) + count) >= selRow.parent_.type_.maxChilds))) ||
                    ((selRow.parent_.type_.type == ElementType.Mmultiscripts) ||
                     (selRow.parent_.type_.type == ElementType.Maction)))
                {
                    selRow = this.WrapInRowInplace(selRow);
                }

                if (selRow.IsAppend)
                {
                    Node row = selRow;
                    Node lastCell = null;
                    if (isPaste && (xmlRoot.Name == "math"))
                    {
                        Node newNode = new Node();
                        newNode.Parse(xmlRoot, this.types_, this.entityManager, true, null);
                        if ((newNode.type_ != null) && newNode.HasChildren())
                        {
                            NodesList list = newNode.GetChildrenNodes();
                            Node n = list.Next();
                            lastRow = row;
                            for (int i = 0; (row != null) && (n != null); i++)
                            {
                                row.AppendNode(n);
                                lastCell = n;
                                n = list.Next();
                                row = row.nextSibling;
                            }
                            if (lastCell != null)
                            {
                                if (lastCell.nextSibling != null)
                                {
                                    this.SelectNode(lastCell.nextSibling, false);
                                }
                                else
                                {
                                    this.SelectNode(lastCell, true);
                                }
                                wasSelect = true;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < count; i++)
                        {
                            XmlNode x = xmlRoot.ChildNodes[i];
                            Node n = new Node();
                            n.Parse(x, this.types_, this.entityManager, false, null);
                            if (n.type_ != null)
                            {
                                row.AppendNode(n);

                                lastCell = n.Parse(x, this.types_, this.entityManager, true, null);
                                if (lastCell != null)
                                {
                                    this.SelectNode(lastCell, lastCell.IsAppend);
                                    wasSelect = true;
                                    ok = true;
                                }
                                else if (i == 0)
                                {
                                    lastRow = n;
                                }
                            }
                            row = n;
                        }
                    }
                }
                else
                {
                    Node newSelectedNode = null;
                    if (isPaste && (xmlRoot.Name == "math"))
                    {
                        Node newNode = new Node();
                        newNode.Parse(xmlRoot, this.types_, this.entityManager, true, null);
                        if ((newNode.type_ != null) && newNode.HasChildren())
                        {
                            NodesList list = newNode.GetChildrenNodes();
                            Node n = list.Next();
                            for (int i = 0; (selRow != null) && (n != null); i++)
                            {
                                selRow.PrependNode(n);
                                n = list.Next();
                            }
                            this.SelectNode(selRow, false);
                            wasSelect = true;
                        }
                    }
                    else if (xmlRoot.Name == "math")
                    {
                        for (int i = 0; i < count; i++)
                        {
                            XmlNode x = xmlRoot.ChildNodes[i];
                            Node newMode = new Node();
                            newMode.Parse(x, this.types_, this.entityManager, false, null);
                            if (newMode.type_ != null)
                            {
                                selRow.PrependNode(newMode);

                                newSelectedNode =
                                    newMode.Parse(x, this.types_, this.entityManager, true, null);
                                if (newSelectedNode != null)
                                {
                                    this.SelectNode(newSelectedNode, newSelectedNode.IsAppend);
                                    ok = true;
                                    wasSelect = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < count; i++)
                        {
                            Node newNode = new Node();
                            XmlNode x = xmlRoot.ChildNodes[i];
                        
                            this.InsertFromXml(selRow, x, newNode, ref newSelectedNode, ref wasSelect);
                        }
                    }
                }

                if (!wasSelect && (lastRow != null))
                {
                    this.SelectNode(lastRow, false);
                }
                if (emptyRow)
                {
                    if (selRow == this.selectedNode)
                    {
                        this.SelectNeighbor(selRow);
                    }
                    this.Tear(selRow);
                }
            }
            
            if ((!hasS || !ok) || ((this.selectedNode.type_.type != ElementType.Mrow) || (this.selectedNode.numChildren != 0)))
            {
                return;
            }
            Node lastSelected = null;
            Node firstSelected = null;
            Node singleSelected = null;
            try
            {
                Node curPrev = null;
                Node curNext = null;
                Node cur = null;
                cur = this.selectedNode;
                cur.InternalMark = 0;
                curPrev = cur.prevSibling;
                curNext = cur.nextSibling;
                singleSelected = cur.parent_;
                
                Node targetSelected = null;
                this.tryAddMathXML (false, s, false);
                try
                {
                    targetSelected = singleSelected.GetChildrenNodes ().Get (this.selectedNode.childIndex);
                }
                catch
                {
                }
                if (targetSelected != null)
                {
                    if ((targetSelected.type_.type == ElementType.Mrow) && (targetSelected.firstChild != null))
                    {
                        cur = targetSelected;
                        lastSelected = cur.firstChild;
                        firstSelected = cur.lastChild;
                    }
                    else if (((curPrev != null) && !curPrev.tagDeleted) && ((curNext != null) && !curNext.tagDeleted))
                    {
                        lastSelected = curPrev.nextSibling;
                        firstSelected = curNext.prevSibling;
                    }
                    else if ((curPrev != null) && !curPrev.tagDeleted)
                    {
                        lastSelected = curPrev.nextSibling;
                        firstSelected = singleSelected.lastChild;
                    }
                    else if ((curNext != null) && !curNext.tagDeleted)
                    {
                        lastSelected = singleSelected.firstChild;
                        firstSelected = curNext.prevSibling;
                    }
                }
            }
            catch
            {
            }
            if ((lastSelected != null) && (firstSelected != null))
            {
                this.SelectNode (firstSelected, true);
                this.multiSelectNode = lastSelected;
                this.hasSelection = true;
            }
            else if (singleSelected != null)
            {
                this.SelectNode (singleSelected, false);
            }
        }
示例#6
0
        public Node Parse(XmlNode XMLNode, Types mTypes, EntityManager mEntities, bool recurse, StyleAttributes styleAttributes, bool bParentShift)
        {
            bool hasSelect = false;
            bool hasSelectRight = false;
            Node result = null;
            if (!bParentShift)
            {
                xmlTagName = XMLNode.LocalName;
                namespaceURI = XMLNode.NamespaceURI;
            }
            
            int numAttrs = 0;
            
            if ((recurse && (XMLNode.Attributes != null)) && !bParentShift)
            {
                StyleAttributes attributes = ParseMStyle(XMLNode, style_);
                if (attributes != null)
                {
                    if (style_ == null)
                    {
                        style_ = new StyleAttributes();
                    }
                    attributes.CopyTo(style_);
                }
            
                numAttrs = XMLNode.Attributes.Count;
                if (numAttrs > 0)
                {
                    if (attrs == null)
                    {
                        attrs = new AttributeList();
                    }

                    for (int i = 0; i < numAttrs; i++)
                    {
                        
                        if (XMLNode.Attributes[i].Name == "nugenCursor")
                        {
                            result = this;
                            hasSelect = true;
                        }
                        else if (XMLNode.Attributes[i].Name == "nugenCursorEnd")
                        {
                            result = this;
                            result.IsAppend = true;
                            hasSelectRight = true;
                        }
                        else
                        {
                            attrs.Add(new Attribute(XMLNode.Attributes[i].Name, XMLNode.Attributes[i].Value, XMLNode.Attributes[i].NamespaceURI));
                        }
                    }

                    if (hasSelect)
                    {
                        XMLNode.Attributes.RemoveNamedItem("nugenCursor");
                    }
                    if (hasSelectRight)
                    {
                        XMLNode.Attributes.RemoveNamedItem("nugenCursorEnd");
                    }
                }
            }

            if ((XMLNode.NodeType == XmlNodeType.Element) && !bParentShift)
            {
                if (type_ == null)
                {
                    type_ = mTypes[xmlTagName];
                }
                if ((hasSelect && (type_.type == ElementType.Mi)) &&
                    (literalText != null))
                {
                    InternalMark = literalText.Length;
                }
            }

            if (recurse && XMLNode.HasChildNodes)
            {
                XmlNodeList list = XMLNode.ChildNodes;
                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].NodeType == XmlNodeType.Text)
                    {
                        if ((type_.type == ElementType.Mtext) || (type_.type == ElementType.Ms))
                        {
                            literalText += list[i].Value;
                            continue;
                        }
                        
                        if (type_.type == ElementType.Mn)
                        {
                            literalText += list[i].Value.Trim();
                            continue;
                        }
                        
                        if (type_.type == ElementType.Mi)
                        {
                            literalText += list[i].Value.Trim();
                            continue;
                        }

                        if (type_.type != ElementType.Mo)
                        {
                            continue;
                        }

                        string entityChar = list[i].Value.Trim();
                        bool isGlyph = false;
                        try
                        {
                            Glyph glyph;

                            if (! (((((entityChar != "(") && (entityChar != ")")) && ((entityChar != "[") && (entityChar != "]"))) &&
                                    (((entityChar != "{") && (entityChar != "}")) && ((entityChar != "|") && (entityChar != "||")))) &&
                                   (((entityChar != "+") && (entityChar != "-")) && ((entityChar != "=") && (entityChar != "/")))))
                            {
                                string entityName = "";


                                switch (entityChar)
                                {
                                    case "(":
                                    {
                                        entityName = "lpar";
                                        break;
                                    }
                                    case ")":
                                    {
                                        entityName = "rpar";
                                        break;
                                    }
                                    case "[":
                                    {
                                        entityName = "lbrack";
                                        break;
                                    }
                                    case "]":
                                    {
                                        entityName = "rbrack";
                                        break;
                                    }
                                    case "{":
                                    {
                                        entityName = "lbrace";
                                        break;
                                    }
                                    case "}":
                                    {
                                        entityName = "rbrace";
                                        break;
                                    }
                                    case "|":
                                    {
                                        entityName = "verbar";
                                        break;
                                    }
                                    case "||":
                                    {
                                        entityName = "Verbar";
                                        break;
                                    }
                                    case "+":
                                    {
                                        entityName = "plus";
                                        break;
                                    }
                                    case "-":
                                    {
                                        entityName = "minus";
                                        break;
                                    }
                                    case "=":
                                    {
                                        entityName = "equals";
                                        break;
                                    }
                                    case "/":
                                    {
                                        entityName = "sol";
                                        break;
                                    }
                                }

                                glyph = mEntities.ByName(entityName);
                                if (glyph != null)
                                {
                                    Node glyphNode = new Node();
                                    glyphNode.type_ = mTypes["entity"];
                                    glyphNode.literalText = "" + glyph.CharValue;
                                    glyphNode.fontFamily = glyph.FontFamily;
                                    glyphNode.glyph = glyph;
                                    glyphNode.xmlTagName = glyph.Name;
                                    AdoptChild(glyphNode);
                                    
                                    isGlyph = true;
                                }
                            }
                        }
                        catch
                        {
                        }

                        if (!isGlyph)
                        {
                            literalText += entityChar;
                        }
                        continue;
                    }

                    if (list[i].NodeType == XmlNodeType.SignificantWhitespace)
                    {
                        continue;
                    }

                    if (list[i].NodeType == XmlNodeType.Whitespace)
                    {
                        if ((type_.type == ElementType.Mtext) || (type_.type == ElementType.Ms))
                        {
                            literalText += " ";
                        }
                        continue;
                    }

                    if (list[i].NodeType == XmlNodeType.Element)
                    {
                        if ((list[i].NamespaceURI == "http://www.w3.org/1998/Math/MathML") && (list[i].LocalName == "mstyle"))
                        {
                            Node mstyl = ParseMstyle(list[i], mTypes, mEntities, recurse, styleAttributes);
                            if (mstyl != null)
                            {
                                result = mstyl;
                            }
                        }
                        else
                        {
                            Node n = new Node(XMLNode.Name, styleAttributes);
                            n.type_ = mTypes[list[i].LocalName];

                            if (AdoptChild(n))
                            {
                                Node sn = n.Parse(list[i], mTypes,  mEntities, recurse, styleAttributes, false);
                                if (sn != null)
                                {
                                    result = sn;
                                }
                            }
                        }

                        continue;
                    }
                
                    if (list[i].NodeType == XmlNodeType.EntityReference)
                    {
                        Node n = new Node();
                        n.type_ = mTypes["entity"];
                        if ((type_.type == ElementType.Mtext) ||
                            (type_.type == ElementType.Ms))
                        {
                            Glyph glyph = mEntities.ByName(list[i].LocalName);
                            if (glyph != null)
                            {
                                char c = Convert.ToChar(Convert.ToUInt32(glyph.Code, 0x10));
                                if (char.IsWhiteSpace(c) || char.IsControl(c))
                                {
                                    literalText = literalText + " ";
                                }
                                else
                                {
                                    literalText = literalText + c;
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                Glyph glyph = mEntities.ByName(list[i].LocalName);
                                if (glyph != null)
                                {
                                    n.literalText = "";
                                    n.literalText = n.literalText + glyph.CharValue;
                                    n.fontFamily = glyph.FontFamily;
                                    n.glyph = glyph;
                                    n.xmlTagName = list[i].LocalName;
                                }
                                else
                                {
                                    n.literalText = "?";
                                    n.xmlTagName = list[i].LocalName;
                                }
                                AdoptChild(n);
                            }
                            catch
                            {
                                n.literalText = "?";
                                n.xmlTagName = list[i].LocalName;
                                AdoptChild(n);
                            }
                        }
                    }
                }
            }
            return result;
        }