using System; using System.Collections.Generic; using System.Text; using System.Xml; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using System.ComponentModel; using System.Diagnostics; namespace Svg { /// /// The class that all SVG elements should derive from when they are to be rendered. /// public abstract partial class SvgGraphicsElement : SvgElement, ISvgStylable { private bool _dirty; private bool _requiresSmoothRendering; /// /// Gets the for this element. /// public abstract GraphicsPath Path { get; } /// /// Gets the bounds of the element. /// /// The bounds. public abstract RectangleF Bounds { get; } /// /// Gets or sets a value indicating whether this element's is dirty. /// /// /// true if the path is dirty; otherwise, false. /// protected virtual bool IsPathDirty { get { return this._dirty; } set { this._dirty = value; } } /// /// Gets or sets a value to determine if anti-aliasing should occur when the element is being rendered. /// protected virtual bool RequiresSmoothRendering { get { return this._requiresSmoothRendering; } } /// /// Initializes a new instance of the class. /// public SvgGraphicsElement() { this._dirty = true; this._requiresSmoothRendering = false; } /// /// Renders the and contents to the specified object. /// /// The object to render to. protected override void Render(Graphics graphics) { if (this.Path != null && this.Visible) { this.PushTransforms(graphics); // If this element needs smoothing enabled turn anti aliasing on if (this.RequiresSmoothRendering) { graphics.SmoothingMode = SmoothingMode.AntiAlias; } // Fill first so that the stroke can overlay if (!SvgPaintServer.IsNullOrEmpty(this.Fill)) { using (Brush brush = this.Fill.GetBrush(this, this.FillOpacity)) { if (brush != null) { graphics.FillPath(brush, this.Path); } } } // Stroke is the last thing to do if (!SvgPaintServer.IsNullOrEmpty(this.Stroke)) { float strokeWidth = this.StrokeWidth.ToDeviceValue(this); using (Pen pen = new Pen(this.Stroke.GetBrush(this, this.StrokeOpacity), strokeWidth)) { if (pen != null) { graphics.DrawPath(pen, this.Path); } } } // Reset the smoothing mode if (this.RequiresSmoothRendering && graphics.SmoothingMode == SmoothingMode.AntiAlias) { graphics.SmoothingMode = SmoothingMode.Default; } this.PopTransforms(graphics); } } } }