Esempio n. 1
0
        void Parse(XmlElement mathNodeElem, MathNode parentNode)
        {
            //this is a single math node
            foreach (XmlAttribute att in mathNodeElem.Attributes)
            {
                parentNode.AddAttribute(att.Name, att.Value);
            }

            foreach (XmlNode node in mathNodeElem)
            {
                switch (node.NodeType)
                {
                case XmlNodeType.Comment:
                    //nothing
                    break;

                case XmlNodeType.Text:
                {
                    //text content inside parent node
                    XmlText textnode = (XmlText)node;
                    string  value    = textnode.Value.Trim();
                    if (value.Length > 0)
                    {
                        parentNode.Text = value;
                    }
                }
                break;

                case XmlNodeType.Element:
                {
                    //create dom from each node type
                    XmlElement elem    = (XmlElement)node;
                    MathNode   newNode = _defStore.CreateMathNode(elem);
                    parentNode.AppendChild(newNode);
                    //inside this elem may has child
                    //parse node inside this
                    Parse(elem, newNode);
                }
                break;
                }
            }
        }
Esempio n. 2
0
 public virtual void AppendChild(MathNode node)
 {
     _children.Add(node);
 }
Esempio n. 3
0
 public static object UnsafeGetController(MathNode elem) => elem._controller;
Esempio n. 4
0
        Box CreateMathBox(MathNode node)
        {
            //create box foreach node
            //TODO: most box are glyph box + its text content
            //except some boxes are Horizontal (eg. mrow) or some box are vertical (...)
            //this should be config from DomSpec.xml or Autogen code
            Box result = null;

            switch (node.Name)
            {
            default:
            {
                //text span box
                if (node.Text == null)
                {
                    return(null);
                }
                char[] text_buff = node.Text.ToCharArray();
                if (text_buff.Length == 0)
                {
                    //????
                    return(null);
                }
                else if (text_buff.Length > 1)
                {
                    HorizontalStackBox textSpan = new HorizontalStackBox();
                    textSpan.MathNode = node;
                    for (int i = 0; i < text_buff.Length; ++i)
                    {
                        GlyphBox glyphBox = NewGlyphBox();
                        glyphBox.Character = text_buff[i];
                        textSpan.AddChild(glyphBox);
                    }
                    //return textSpan;
                    result = textSpan;
                }
                else
                {
                    //len=1
                    GlyphBox glyphBox = NewGlyphBox();
                    glyphBox.MathNode  = node;
                    glyphBox.Character = text_buff[0];
                    //return glyphBox;
                    result = glyphBox;
                }
            }
            break;

            case "math":
            case "mrow":
            case "msub":
            case "msup":
            {
                HorizontalStackBox hbox = new HorizontalStackBox();
                hbox.MathNode = node;
                //
                int child_count = node.ChildCount;
                for (int i = 0; i < child_count; ++i)
                {
                    Box childBox = CreateMathBox(node.GetNode(i));
                    if (childBox != null)
                    {
                        hbox.AddChild(childBox);
                    }
                }
                //return hbox;
                result = hbox;
            }
            break;

            case "mfrac":
            case "munder":
            {
                VerticalStackBox vbox = new VerticalStackBox();
                vbox.MathNode = node;

                int child_count = node.ChildCount;
                for (int i = 0; i < child_count; ++i)
                {
                    Box childBox = CreateMathBox(node.GetNode(i));
                    if (childBox != null)
                    {
                        vbox.AddChild(childBox);
                    }
                }
                //return hbox;
                result = vbox;
            }
            break;

            case "mover":
            {
                VerticalStackBox vbox = new VerticalStackBox();
                vbox.MathNode = node;

                int child_count = node.ChildCount;
                if (child_count != 2)        //expect 2
                {
                    return(null);
                }
                Box baseBox = CreateMathBox(node.GetNode(0));
                Box overBox = CreateMathBox(node.GetNode(1));
                vbox.AddChild(overBox);
                vbox.AddChild(baseBox);
                //return hbox;
                result = vbox;
            }
            break;
            }
            if (result != null)
            {
                AssignGlyphVxs(result);
            }
            return(result);
        }