/// <summary> /// make a new copy of an existing context /// </summary> public WinFormattingContext(WinFormattingContext ctx) : base(ctx._graphics) { this.actualSize = ctx.actualSize; this.BackgroundColor = ctx.BackgroundColor; this.Color = ctx.Color; this.DisplayStyle = ctx.DisplayStyle; this.minSize = ctx.minSize; this.scriptLevel = ctx.scriptLevel; this.size = ctx.size; this.SizeMultiplier = ctx.SizeMultiplier; this.Stretch = ctx.Stretch; this.cacheArea = ctx.cacheArea; this.Parens = ctx.Parens; }
/// <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); }
/// <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; }