123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Drawing.Text;
- #pragma warning disable
- namespace Svg
- {
- /// <summary>
- /// Convenience wrapper around a graphics object
- /// </summary>
- public sealed class SvgRenderer : IDisposable, IGraphicsProvider, ISvgRenderer
- {
- private Graphics _innerGraphics;
- private Stack<ISvgBoundable> _boundables = new Stack<ISvgBoundable>();
- public void SetBoundable(ISvgBoundable boundable)
- {
- _boundables.Push(boundable);
- }
- public ISvgBoundable GetBoundable()
- {
- return _boundables.Peek();
- }
- public ISvgBoundable PopBoundable()
- {
- return _boundables.Pop();
- }
- public float DpiY
- {
- get { return _innerGraphics.DpiY; }
- }
- /// <summary>
- /// Initializes a new instance of the <see cref="ISvgRenderer"/> class.
- /// </summary>
- 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 SetClip(GraphicsPath path, CombineMode combineMode = CombineMode.Replace)
- {
- this._innerGraphics.SetClip(path, combineMode);
- }
- public void EndClip()
- {
- }
- 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;
- }
- /// <summary>
- /// Creates a new <see cref="ISvgRenderer"/> from the specified <see cref="Image"/>.
- /// </summary>
- /// <param name="image"><see cref="Image"/> from which to create the new <see cref="ISvgRenderer"/>.</param>
- 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);
- }
- /// <summary>
- /// Creates a new <see cref="ISvgRenderer"/> from the specified <see cref="Graphics"/>.
- /// </summary>
- /// <param name="graphics">The <see cref="Graphics"/> to create the renderer from.</param>
- public static ISvgRenderer FromGraphics(Graphics graphics)
- {
- return new SvgRenderer(graphics);
- }
- public static ISvgRenderer FromNull()
- {
- var img = new Bitmap(1, 1);
- return SvgRenderer.FromImage(img);
- }
- }
- }
- #pragma warning restore
|