Ejemplo n.º 1
0
        object MathML.MathMLVisitor.Visit(MathMLPresentationToken e, object args)
        {
            Area area = null;

            // make an updated context
            IFormattingContext context  = ((IFormattingContext)args).Clone();
            XmlNode            node     = null;
            MathMLElement      element  = null;
            MathMLNodeList     contents = e.Contents;

            // update the font size, pres-tokens can specify font size
            context.Size = context.Evaluate(e.MathSize);

            MathVariant variant = e.MathVariant;

            if (variant != MathVariant.Unknown)
            {
                context.MathVariant = variant;
            }

            if (contents.Count == 1)            // create a single string area
            {
                if ((node = e.FirstChild) != null && node.NodeType == XmlNodeType.Text)
                {
                    area = AreaFactory.String(context, node.Value);
                }
                else if ((element = e.FirstChild as MathMLElement) != null)
                {
                    // sets area to a new glyph area
                    area = (Area)element.Accept(formatter, context);
                }
                else
                {
                    // TODO this is bad, need error handler
                }
            }
            else             // create a sequence of areas
            {
                Area[] areas = new Area[contents.Count];
                int    i     = 0;
                foreach (XmlNode n in contents)
                {
                    if (n.NodeType == XmlNodeType.Text)
                    {
                        area = AreaFactory.String(context, n.Value);
                    }
                    else if ((element = n as MathMLElement) != null)
                    {
                        area = (Area)element.Accept(formatter, context);
                    }
                    areas[i++] = area;
                }
                area = AreaFactory.Horizontal(areas);
            }

            return(area.BoundingBox);
        }
Ejemplo n.º 2
0
		object MathML.MathMLVisitor.Visit(MathMLPresentationToken e, object args)
		{
			Area area = null;

			// make an updated context
			IFormattingContext context = ((IFormattingContext)args).Clone();
			XmlNode node = null;
			MathMLElement element = null;
			MathMLNodeList contents = e.Contents;
			
			// update the font size, pres-tokens can specify font size
			context.Size = context.Evaluate(e.MathSize);			

			MathVariant variant = e.MathVariant;
			if(variant != MathVariant.Unknown)
			{
				context.MathVariant = variant;
			}

			if(contents.Count == 1) // create a single string area
			{
				if((node = e.FirstChild) != null && node.NodeType == XmlNodeType.Text)
				{
					area = AreaFactory.String(context, node.Value);
				}
				else if((element = e.FirstChild as MathMLElement) != null) 
				{
					// sets area to a new glyph area
					area = (Area)element.Accept(formatter, context);
				}
				else
				{
					// TODO this is bad, need error handler
				}
			}
			else // create a sequence of areas
			{
				Area[] areas = new Area[contents.Count];
				int i = 0;
				foreach(XmlNode n in contents)
				{
					if(n.NodeType == XmlNodeType.Text)
					{
						area = AreaFactory.String(context, n.Value);
					}
					else if((element = n as MathMLElement) != null)
					{
						area = (Area)element.Accept(formatter, context);
					}
					areas[i++] = area;
				}
				area = AreaFactory.Horizontal(areas);
			}

			return area.BoundingBox;
		}
Ejemplo n.º 3
0
        object MathML.MathMLVisitor.Visit(MathMLPresentationToken e, object args)
        {
            MathMLElement p = null;

            switch (selection)
            {
            case SelectionType.Prev:
            {
                if (index > 1)
                {
                    index--;
                    return(e);
                }
                else if (index == 1)
                {
                    if ((e.ParentNode is MathMLPresentationContainer && !(PreviousMathSibling(e) is MathMLPresentationToken)) ||
                        (!(e.ParentNode is MathMLPresentationContainer)))
                    {
                        index--;
                        return(e);
                    }
                    else
                    {
                        return(((MathMLElement)e.ParentNode).Accept(this, e));
                    }
                }
                else if (e.ParentNode is MathMLPresentationContainer && (p = PreviousMathSibling(e) as MathMLPresentationToken) != null)
                {
                    selection = SelectionType.End;
                    return(p.Accept(this, null));
                }
                else
                {
                    return(((MathMLElement)e.ParentNode).Accept(this, e));
                }
            }

            case SelectionType.Next:
            {
                if (e.ChildNodes.Count == 1 && e.FirstChild.NodeType == XmlNodeType.Text && index < e.FirstChild.Value.Length)
                {
                    index++;
                    return(e);
                }
                else if ((e.ParentNode is MathMLPresentationContainer || e.ParentNode is MathMLMathElement) &&
                         (p = NextMathSibling(e) as MathMLPresentationToken) != null)
                {
                    selection = SelectionType.Start;
                    index     = 0;
                    return(p.Accept(this, null));
                }
                else
                {
                    return(((MathMLElement)e.ParentNode).Accept(this, e));
                }
            }

            case SelectionType.End:
            {
                index = e.FirstChild.Value.Length;
                return(e);
            }

            case SelectionType.Start:
            default:
            {
                if (((e.ParentNode is MathMLPresentationContainer || e.ParentNode is MathMLMathElement) &&
                     !(PreviousMathSibling(e) is MathMLPresentationToken)) ||
                    (!(e.ParentNode is MathMLPresentationContainer || e.ParentNode is MathMLMathElement)))
                {
                    index = 0;
                }
                else
                {
                    index = 1;
                }
                return(e);
            }
            }
        }