using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Text; namespace Svg { /// /// Convenience wrapper around a graphics object /// public sealed class SvgRenderer : IDisposable, IGraphicsProvider, ISvgRenderer { private Graphics _innerGraphics; private Stack _boundables = new Stack(); public void SetBoundable(ISvgBoundable boundable) { _boundables.Push(new ImmutableBoundable(boundable)); } public ISvgBoundable GetBoundable() { return _boundables.Peek(); } public ISvgBoundable PopBoundable() { return _boundables.Pop(); } public float DpiY { get { return _innerGraphics.DpiY; } } /// /// Initializes a new instance of the class. /// private SvgRenderer(Graphics graphics) { this._innerGraphics = graphics; } public void DrawImage(Image image, RectangleF destRect, RectangleF srcRect, GraphicsUnit graphicsUnit) { _innerGraphics.DrawImage(image, destRect, srcRect, graphicsUnit); } public void DrawImageUnscaled(Image image, Point location) { this._innerGraphics.DrawImageUnscaled(image, location); } public void DrawPath(Pen pen, GraphicsPath path) { this._innerGraphics.DrawPath(pen, path); } public void FillPath(Brush brush, GraphicsPath path) { this._innerGraphics.FillPath(brush, path); } public Region GetClip() { return this._innerGraphics.Clip; } public void RotateTransform(float fAngle, MatrixOrder order = MatrixOrder.Append) { this._innerGraphics.RotateTransform(fAngle, order); } public void ScaleTransform(float sx, float sy, MatrixOrder order = MatrixOrder.Append) { this._innerGraphics.ScaleTransform(sx, sy, order); } public void SetClip(Region region, CombineMode combineMode = CombineMode.Replace) { this._innerGraphics.SetClip(region, combineMode); } public void TranslateTransform(float dx, float dy, MatrixOrder order = MatrixOrder.Append) { this._innerGraphics.TranslateTransform(dx, dy, order); } public SmoothingMode SmoothingMode { get { return this._innerGraphics.SmoothingMode; } set { this._innerGraphics.SmoothingMode = value; } } public Matrix Transform { get { return this._innerGraphics.Transform; } set { this._innerGraphics.Transform = value; } } public void Dispose() { this._innerGraphics.Dispose(); } Graphics IGraphicsProvider.GetGraphics() { return _innerGraphics; } /// /// Creates a new from the specified . /// /// from which to create the new . public static ISvgRenderer FromImage(Image image) { var g = Graphics.FromImage(image); g.TextRenderingHint = TextRenderingHint.AntiAlias; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half; g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; g.TextContrast = 1; return new SvgRenderer(g); } /// /// Creates a new from the specified . /// /// The to create the renderer from. public static ISvgRenderer FromGraphics(Graphics graphics) { return new SvgRenderer(graphics); } public static ISvgRenderer FromNull() { var img = new Bitmap(1, 1); return SvgRenderer.FromImage(img); } } }