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