Commit 302ca29e authored by owaits's avatar owaits
Browse files

Adds support for linked gradient stops.

parent 4ad323d5
......@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using Svg.Transforms;
namespace Svg
{
......@@ -63,7 +64,18 @@ namespace Svg
if (graphicsElement != null && graphicsElement.Path != null)
{
path.FillMode = (graphicsElement.ClipRule == SvgClipRule.NonZero) ? FillMode.Winding : FillMode.Alternate;
path.AddPath(graphicsElement.Path, false);
GraphicsPath childPath = graphicsElement.Path;
if (graphicsElement.Transforms != null)
{
foreach (SvgTransform transform in graphicsElement.Transforms)
{
childPath.Transform(transform.Matrix);
}
}
path.AddPath(childPath, false);
}
foreach (SvgElement child in element.Children)
......
......@@ -85,10 +85,18 @@ namespace Svg
set { this._gradientUnits = value; }
}
/// <summary>
/// Gets or sets another gradient fill from which to inherit the stops from.
/// </summary>
[SvgAttributeAttribute("href")]
public SvgGradientServer InheritGradient
{
get { return this._inheritGradient; }
set { this._inheritGradient = value; }
set
{
this._inheritGradient = value;
this.InheritStops();
}
}
/// <summary>
......@@ -161,22 +169,15 @@ namespace Svg
return blend;
}
protected virtual List<SvgGradientStop> InheritStops()
/// <summary>
// If this gradient contains no stops then it will search any inherited gradients for stops.
/// </summary>
protected virtual void InheritStops()
{
List<SvgGradientStop> stops = new List<SvgGradientStop>();
if (this.Stops.Count > 0)
if (this.Stops.Count == 0 && this.InheritGradient != null)
{
return stops;
_stops.AddRange(this.InheritGradient.Stops);
}
if (this.InheritGradient != null)
{
List<SvgGradientStop> ownerStops = this.InheritGradient.InheritStops();
stops.AddRange(ownerStops);
}
return stops;
}
}
}
\ No newline at end of file
......@@ -33,6 +33,11 @@ namespace Svg
Uri id = new Uri(match.Groups[1].Value, UriKind.Relative);
return (SvgPaintServer)document.IdManager.GetElementById(id);
}
// If referenced to to a different (linear or radial) gradient
else if (document.IdManager.GetElementById(value) != null && document.IdManager.GetElementById(value).GetType().BaseType == typeof(SvgGradientServer))
{
return (SvgPaintServer)document.IdManager.GetElementById(value);
}
else // Otherwise try and parse as colour
{
return new SvgColourServer((Color)_colourConverter.ConvertFrom(value.Trim()));
......
......@@ -62,14 +62,6 @@ namespace Svg
segment.AddToPath(_path);
}
if (base.Transforms != null)
{
foreach (SvgTransform transform in base.Transforms)
{
_path.Transform(transform.Matrix);
}
}
this.IsPathDirty = false;
}
return _path;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment