Exemplo n.º 1
0
        /// <summary>
        /// Draw the current mathml equation to an image object.
        /// </summary>
        /// <param name="type">The type of image to return, currently this can be
        /// either Bitmap or Metafile</param>
        /// <param name="gr">The graphics context in which this bitmap should be created.</param>
        /// <returns>A new image, null if an invalid type is given or there is no current element</returns>
        public Image GetImage(Type type, Graphics gr)
        {
            if (mathElement == null)
            {
                return(null);
            }

            gr.PageUnit = GraphicsUnit.Pixel;

            // build the formatting tree
            MathMLFormatter      formatter = new MathMLFormatter();
            WinFormattingContext ctx       = new WinFormattingContext(gr, fontSize);

            format = formatter.Format(mathElement, ctx);

            // build the are tree
            box  = format.BoundingBox;
            area = format.Fit(box);


            Image image  = null;
            int   height = (int)Math.Ceiling(2 + box.VerticalExtent);
            int   width  = (int)Math.Ceiling(2 + box.HorizontalExtent);

            if (type.Equals(typeof(Bitmap)))
            {
                image = new Bitmap(width, height);
            }
            else if (type.Equals(typeof(Metafile)))
            {
                IntPtr dc = gr.GetHdc();
                image = new Metafile(new MemoryStream(), dc, EmfType.EmfOnly);
                gr.ReleaseHdc(dc);
            }

            if (image != null && area != null)
            {
                using (Graphics gi = Graphics.FromImage(image))
                {
                    gi.PageUnit      = GraphicsUnit.Pixel;
                    gi.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    DrawWithoutFormatting(gi, width, height, 1, 1);
                }
            }

            return(image);
        }
Exemplo n.º 2
0
        public void MathMLFormatter_CanRead_ReturnsFalseForUnsupportedMediaTypes(string requestContentType)
        {
            // Arrange
            var formatter   = new MathMLFormatter();
            var httpContext = new DefaultHttpContext();

            httpContext.Request.ContentType = requestContentType;

            var provider = new EmptyModelMetadataProvider();
            var metadata = provider.GetMetadataForType(typeof(void));
            var context  = new InputFormatterContext(
                httpContext,
                modelName: string.Empty,
                modelState: new ModelStateDictionary(),
                metadata: metadata);

            // Act
            var result = formatter.CanRead(context);

            // Assert
            Assert.False(result);
        }
Exemplo n.º 3
0
 /// <summary>
 /// this is essentially a stateless object, so nothing done here
 /// </summary>
 public MathMLMeasurer(MathMLFormatter formatter)
 {
     this.formatter = formatter;
     this.cache     = new Hashtable();
 }
Exemplo n.º 4
0
        public void MathMLFormatter_CanRead_ReturnsFalseForUnsupportedMediaTypes(string requestContentType)
        {
            // Arrange
            var formatter = new MathMLFormatter();
            var httpContext = new DefaultHttpContext();
            httpContext.Request.ContentType = requestContentType;

            var provider = new EmptyModelMetadataProvider();
            var metadata = provider.GetMetadataForType(typeof(void));
            var context = new InputFormatterContext(
                httpContext,
                modelName: string.Empty,
                modelState: new ModelStateDictionary(),
                metadata: metadata);

            // Act
            var result = formatter.CanRead(context);

            // Assert
            Assert.False(result);
        }