Exemplo n.º 1
0
        public Node ParseMstyle(XmlNode XMLNode, Types mTypes, EntityManager mEntities, bool bAll, StyleAttributes styleAttributes)
        {
            StyleAttributes s = null;

            if ((XMLNode.Attributes == null) || (XMLNode.Attributes.Count <= 0))
            {
                return(Parse(XMLNode, mTypes, mEntities, bAll, styleAttributes, true));
            }
            Node node = new Node();

            node.type_ = mTypes["mstyle"];
            node.attrs = new AttributeList();
            for (int i = 0; i < XMLNode.Attributes.Count; i++)
            {
                node.attrs.Add(new Attribute(XMLNode.Attributes[i].Name, XMLNode.Attributes[i].Value, ""));
            }
            StyleAttributes fromNode = new StyleAttributes();

            s        = new StyleAttributes();
            fromNode = AttributeBuilder.StyleAttrsFromNode(node, true);
            if (fromNode != null)
            {
                if (styleAttributes != null)
                {
                    node.style_ = new StyleAttributes();
                    fromNode.CopyTo(node.style_);
                    node.style_.canOverride = true;
                    s = node.CascadeOverride(styleAttributes);
                }
                else
                {
                    fromNode.CopyTo(s);
                }
            }
            else
            {
                if (styleAttributes != null)
                {
                    styleAttributes.CopyTo(s);
                }
            }
            s.canOverride = true;
            XMLNode.Attributes.RemoveAll();
            return(Parse(XMLNode, mTypes, mEntities, bAll, s, true));
        }
Exemplo n.º 2
0
        public void MeasurePass(Painter g)
        {
            if (parent_ != null)
            {
                level = parent_.level + 1;
            }
            int  x      = 0;
            int  y      = 0;
            bool hasBox = false;

            if ((box != null))
            {
                hasBox = true;
                x      = box.X;
                y      = box.Y;
            }

            if ((((box == null) || ((level < 2))) || ((level == 2))) || ((level > 2)))
            {
                BoxBuilder.MakeBox(this, g);
            }
            if ((type_ != null) && (type_.type == ElementType.Math))
            {
                PushdownStyleScript();
            }

            if (hasBox)
            {
                box.X = x;
                box.Y = y;
            }


            NodesList list = GetChildrenNodes();
            Node      n    = list.Next();

            if ((style_ != null) && (style_.size.Length > 0))
            {
                try
                {
                    style_.scale = StyleAttributes.FontScale(style_.size, (double)g.GetSuitableFont(this, style_).SizeInPoints);
                    style_.size  = "";
                }
                catch
                {
                }
            }
            if ((style_ != null))
            {
                if (type_.type == ElementType.Math)
                {
                    style_.isTop = true;
                }
                else if (style_.canOverride)
                {
                    style_.isTop = false;
                }
            }
            while (n != null)
            {
                if (style_ != null)
                {
                    if (((n.style_ != null) && n.style_.canOverride) && n.IsSameStyleParent())
                    {
                        n.CombineStyles(n.style_, style_);
                    }
                    else if (n.type_.type == ElementType.Entity)
                    {
                        n.style_ = null;
                    }
                    else
                    {
                        try
                        {
                            StyleAttributes style = n.CascadeOverride(style_);
                            if (style != null)
                            {
                                if (type_.type == ElementType.Math)
                                {
                                    style.fontFamily  = "";
                                    style.isUnderline = false;
                                }
                                n.style_ = new StyleAttributes();
                                style.CopyTo(n.style_);
                                if ((style_ != null) && style_.isTop)
                                {
                                    n.style_.canOverride = false;
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                n.MeasurePass(g);
                box.setChildSize(n);
                n = list.Next();
            }

            if (((((level < 2)) || ((level == 2))) || ((level > 2))))
            {
                box.getSize(this);
            }
        }
Exemplo n.º 3
0
        public StyleAttributes ParseMStyle(XmlNode xmlNode, StyleAttributes baseStyle)
        {
            bool            hasStyleAttrs = false;
            bool            hasColor      = false;
            bool            hasBackground = false;
            bool            hasMathsize   = false;
            bool            hasVariant    = false;
            StyleAttributes r             = null;

            int count = 0;

            if (((xmlNode != null) &&
                 (((xmlNode.Name == "mi") || (xmlNode.Name == "mo")) ||
                  (((xmlNode.Name == "mn") || (xmlNode.Name == "ms")) || (xmlNode.Name == "mtext")))) &&
                (xmlNode.Attributes != null))
            {
                try
                {
                    count = xmlNode.Attributes.Count;

                    for (int i = 0; i < count; i++)
                    {
                        string name = xmlNode.Attributes[i].Name.Trim().ToLower();

                        if (((name == "mathvariant") || (name == "mathcolor")) ||
                            ((name == "mathbackground") || (name == "mathsize")))
                        {
                            hasStyleAttrs = true;
                        }
                        if (name == "mathvariant")
                        {
                            hasVariant = true;
                        }
                        if (name == "mathcolor")
                        {
                            hasColor = true;
                        }
                        if (name == "mathbackground")
                        {
                            hasBackground = true;
                        }
                        if (name == "mathsize")
                        {
                            hasMathsize = true;
                        }
                    }
                }
                catch
                {
                }
            }

            if (hasStyleAttrs)
            {
                try
                {
                    Node n = new Node();
                    n.attrs = new AttributeList();
                    for (int i = 0; i < count; i++)
                    {
                        n.attrs.Add(new Attribute(xmlNode.Attributes[i].Name, xmlNode.Attributes[i].Value, ""));
                    }

                    StyleAttributes nodeStyleAttrs = AttributeBuilder.StyleAttrsFromNode(n);
                    if (nodeStyleAttrs != null)
                    {
                        nodeStyleAttrs.canOverride = true;

                        r = new StyleAttributes();
                        if (baseStyle != null)
                        {
                            n.style_ = new StyleAttributes();
                            nodeStyleAttrs.CopyTo(n.style_);
                            r = n.CascadeOverride(baseStyle);
                        }
                        else
                        {
                            nodeStyleAttrs.CopyTo(r);
                        }
                        r.canOverride = true;
                    }
                    if (hasMathsize)
                    {
                        xmlNode.Attributes.RemoveNamedItem("mathsize", "");
                    }
                    if (hasVariant)
                    {
                        xmlNode.Attributes.RemoveNamedItem("mathvariant", "");
                    }
                    if (hasColor)
                    {
                        xmlNode.Attributes.RemoveNamedItem("mathcolor", "");
                    }
                    if (hasBackground)
                    {
                        xmlNode.Attributes.RemoveNamedItem("mathbackground", "");
                    }
                }
                catch
                {
                }
            }
            return(r);
        }
Exemplo n.º 4
0
        public StyleAttributes ParseMStyle(XmlNode xmlNode, StyleAttributes baseStyle)
        {
            bool hasStyleAttrs = false;
            bool hasColor = false;
            bool hasBackground = false;
            bool hasMathsize = false;
            bool hasVariant = false;
            StyleAttributes r = null;
            
            int count = 0;

            if (((xmlNode != null) &&
                 (((xmlNode.Name == "mi") || (xmlNode.Name == "mo")) ||
                  (((xmlNode.Name == "mn") || (xmlNode.Name == "ms")) || (xmlNode.Name == "mtext")))) &&
                (xmlNode.Attributes != null))
            {
                try
                {
                    count = xmlNode.Attributes.Count;

                    for (int i = 0; i < count; i++)
                    {
                        string name = xmlNode.Attributes[i].Name.Trim().ToLower();
                        
                        if (((name == "mathvariant") || (name == "mathcolor")) ||
                            ((name == "mathbackground") || (name == "mathsize")))
                        {
                            hasStyleAttrs = true;
                        }
                        if (name == "mathvariant")
                        {
                            hasVariant = true;
                        }
                        if (name == "mathcolor")
                        {
                            hasColor = true;
                        }
                        if (name == "mathbackground")
                        {
                            hasBackground = true;
                        }
                        if (name == "mathsize")
                        {
                            hasMathsize = true;
                        }
                    }
                }
                catch
                {
                }
            }

            if (hasStyleAttrs)
            {
                try
                {
                    Node n = new Node();
                    n.attrs = new AttributeList();
                    for (int i = 0; i < count; i++)
                    {
                        n.attrs.Add(new Attribute(xmlNode.Attributes[i].Name, xmlNode.Attributes[i].Value, ""));
                    }

                    StyleAttributes nodeStyleAttrs = AttributeBuilder.StyleAttrsFromNode(n);
                    if (nodeStyleAttrs != null)
                    {
                        nodeStyleAttrs.canOverride = true;
                        
                        r = new StyleAttributes();
                        if (baseStyle != null)
                        {
                            n.style_ = new StyleAttributes();
                            nodeStyleAttrs.CopyTo(n.style_);
                            r = n.CascadeOverride(baseStyle);
                        }
                        else
                        {
                            nodeStyleAttrs.CopyTo(r);
                        }
                        r.canOverride = true;
                    }
                    if (hasMathsize)
                    {
                        xmlNode.Attributes.RemoveNamedItem("mathsize", "");
                    }
                    if (hasVariant)
                    {
                        xmlNode.Attributes.RemoveNamedItem("mathvariant", "");
                    }
                    if (hasColor)
                    {
                        xmlNode.Attributes.RemoveNamedItem("mathcolor", "");
                    }
                    if (hasBackground)
                    {
                        xmlNode.Attributes.RemoveNamedItem("mathbackground", "");
                    }
                }
                catch
                {
                }
            }
            return r;
        }
Exemplo n.º 5
0
 public Node ParseMstyle(XmlNode XMLNode, Types mTypes, EntityManager mEntities, bool bAll, StyleAttributes styleAttributes)
 {
     StyleAttributes s = null;
     if ((XMLNode.Attributes == null) || (XMLNode.Attributes.Count <= 0))
     {
         return Parse(XMLNode, mTypes, mEntities, bAll, styleAttributes, true);
     }
     Node node = new Node();
     node.type_ = mTypes["mstyle"];
     node.attrs = new AttributeList();
     for (int i = 0; i < XMLNode.Attributes.Count; i++)
     {
         node.attrs.Add(new Attribute(XMLNode.Attributes[i].Name, XMLNode.Attributes[i].Value, ""));
     }
     StyleAttributes fromNode = new StyleAttributes();
     s = new StyleAttributes();
     fromNode = AttributeBuilder.StyleAttrsFromNode(node, true);
     if (fromNode != null)
     {
         if (styleAttributes != null)
         {
             node.style_ = new StyleAttributes();
             fromNode.CopyTo(node.style_);
             node.style_.canOverride = true;
             s = node.CascadeOverride(styleAttributes);
         }
         else
         {
             fromNode.CopyTo(s);
         }
     }
     else
     {
         if (styleAttributes != null)
             styleAttributes.CopyTo(s);
     }
     s.canOverride = true;
     XMLNode.Attributes.RemoveAll();
     return Parse(XMLNode, mTypes, mEntities, bAll, s, true);
 }