/// <summary>
/// Gets a <see cref="Brush"/> representing the current paint server.
/// </summary>
/// <param name="styleOwner">The owner <see cref="SvgVisualElement"/>.</param>
/// <param name="opacity">The opacity of the brush.</param>
public override Brush GetBrush(SvgVisualElement renderingElement, SvgRenderer renderer, float opacity)
{
// If there aren't any children, return null
if (this.Children.Count == 0)
{
return(null);
}
// Can't render if there are no dimensions
if (this._width.Value == 0.0f || this._height.Value == 0.0f)
{
return(null);
}
float width = this._width.ToDeviceValue(renderingElement);
float height = this._height.ToDeviceValue(renderingElement, true);
Bitmap image = new Bitmap((int)width, (int)height);
using (SvgRenderer texture_renderer = SvgRenderer.FromImage(image))
using (Matrix patternMatrix = new Matrix())
{
// Apply a translate if needed
if (this._x.Value > 0.0f || this._y.Value > 0.0f)
{
patternMatrix.Translate(this._x.ToDeviceValue(renderingElement) + -1.0f, this._y.ToDeviceValue(renderingElement, true) + -1.0f);
}
else
{
patternMatrix.Translate(-1, -1);
}
if (this.ViewBox.Height > 0 || this.ViewBox.Width > 0)
{
patternMatrix.Scale(this.Width.ToDeviceValue() / this.ViewBox.Width, this.Height.ToDeviceValue() / this.ViewBox.Height);
}
texture_renderer.Transform = patternMatrix;
texture_renderer.CompositingQuality = CompositingQuality.HighQuality;
texture_renderer.SmoothingMode = SmoothingMode.AntiAlias;
texture_renderer.PixelOffsetMode = PixelOffsetMode.Half;
texture_renderer.KnockoutBrush = renderer.KnockoutBrush;
foreach (SvgElement child in this.Children)
{
child.RenderElement(texture_renderer);
}
texture_renderer.Save();
}
TextureBrush textureBrush = new TextureBrush(image);
return(textureBrush);
}