Пример #1
0
        object MathML.MathMLVisitor.Visit(MathMLPresentationContainer e, object args)
        {
            MathMLElement c   = (MathMLElement)args;
            MathMLElement elm = null;

            switch (selection)
            {
            case SelectionType.Prev:
            {
                if ((elm = PreviousMathSibling(c)) != null)
                {
                    selection = SelectionType.End;
                    return(elm.Accept(this, null));
                }
                else
                {
                    MathMLElement p = e.ParentNode as MathMLElement;
                    return(p != null?p.Accept(this, e) : null);
                }
            }

            case SelectionType.Next:
            {
                if (e == c && (elm = e.FirstChild as MathMLElement) != null)
                {
                    return(elm.Accept(this, e));
                }
                else if ((elm = NextMathSibling(c)) != null)
                {
                    selection = SelectionType.Start;
                    return(elm.Accept(this, null));
                }
                else
                {
                    MathMLElement p = e.ParentNode as MathMLElement;
                    return(p != null?p.Accept(this, e) : null);
                }
            }

            case SelectionType.Start:
            {
                elm = e.FirstChild as MathMLElement;
                return(elm != null?elm.Accept(this, null) : e);
            }

            case SelectionType.End:
            {
                elm = e.LastChild as MathMLElement;
                return(elm != null?elm.Accept(this, null) : null);
            }

            default:
            {
                return(null);
            }
            }
        }
Пример #2
0
		object MathML.MathMLVisitor.Visit(MathMLPresentationContainer e, object args)
		{
			IFormattingContext context = ((IFormattingContext)args).Clone();
			MathMLNodeList arguments = e.Arguments;
			BoundingBox extent = BoundingBox.New();
			int stretchCount = 0;

			// save the stretch size because stretch scope can not extend into another 
			// level of nesting
			BoundingBox stretch = context.Stretch;
			context.Stretch = BoundingBox.New();

			// process all nodes that are not stretchy operators, get thier total 
			// extents
			for(int i = 0; i < arguments.Count; i++)
			{
				MathMLElement element = (MathMLElement)arguments[i];
				MathMLOperatorElement op = element as MathMLOperatorElement;

				if(op == null || op.Stretchy == false)
				{
					//areas[i] = (Area)element.Accept(this, context);
					extent.Append((BoundingBox)element.Accept(this, context));
				}	
				if(op != null && op.Stretchy)
				{
					stretchCount++;
				}
			}	

			// if we have any elements that can be stretched, stretch them
			if(stretchCount > 0)
			{	
				if(!stretch.Defined)
				{
					// avail width is epsilon because stretchy glyphs were not counted in the
					// width calculation
					context.Stretch = BoundingBox.New(Single.Epsilon, extent.Height, extent.Depth);
				}
				else
				{
					// set the stretch size back to stretch the child elements
					context.Stretch = stretch;

					// calculate availible width
					context.StretchWidth = context.StretchWidth - extent.Width;
					if(context.Stretch.Width < 0) context.StretchWidth = 0;

					// size to stretch each width equally
					context.StretchWidth = context.Stretch.Width / (float)stretchCount;
				}            

				// process all areas that need to be stretched			
				for(int i = 0; i < arguments.Count; i++)
				{
					MathMLOperatorElement op = arguments[i] as MathMLOperatorElement;
					if(op != null && op.Stretchy)
					{
						//areas[i] = (Area)op.Accept(this, context);
						extent.Append((BoundingBox)op.Accept(this, context));
					}
				}
			}

            return extent;			
		}
Пример #3
0
        object MathML.MathMLVisitor.Visit(MathMLPresentationContainer e, object args)
        {
            IFormattingContext context   = ((IFormattingContext)args).Clone();
            MathMLNodeList     arguments = e.Arguments;
            BoundingBox        extent    = BoundingBox.New();
            int stretchCount             = 0;

            // save the stretch size because stretch scope can not extend into another
            // level of nesting
            BoundingBox stretch = context.Stretch;

            context.Stretch = BoundingBox.New();

            // process all nodes that are not stretchy operators, get thier total
            // extents
            for (int i = 0; i < arguments.Count; i++)
            {
                MathMLElement         element = (MathMLElement)arguments[i];
                MathMLOperatorElement op      = element as MathMLOperatorElement;

                if (op == null || op.Stretchy == false)
                {
                    //areas[i] = (Area)element.Accept(this, context);
                    extent.Append((BoundingBox)element.Accept(this, context));
                }
                if (op != null && op.Stretchy)
                {
                    stretchCount++;
                }
            }

            // if we have any elements that can be stretched, stretch them
            if (stretchCount > 0)
            {
                if (!stretch.Defined)
                {
                    // avail width is epsilon because stretchy glyphs were not counted in the
                    // width calculation
                    context.Stretch = BoundingBox.New(Single.Epsilon, extent.Height, extent.Depth);
                }
                else
                {
                    // set the stretch size back to stretch the child elements
                    context.Stretch = stretch;

                    // calculate availible width
                    context.StretchWidth = context.StretchWidth - extent.Width;
                    if (context.Stretch.Width < 0)
                    {
                        context.StretchWidth = 0;
                    }

                    // size to stretch each width equally
                    context.StretchWidth = context.Stretch.Width / (float)stretchCount;
                }

                // process all areas that need to be stretched
                for (int i = 0; i < arguments.Count; i++)
                {
                    MathMLOperatorElement op = arguments[i] as MathMLOperatorElement;
                    if (op != null && op.Stretchy)
                    {
                        //areas[i] = (Area)op.Accept(this, context);
                        extent.Append((BoundingBox)op.Accept(this, context));
                    }
                }
            }

            return(extent);
        }