Commit 312eb943 authored by Tebjan Halm's avatar Tebjan Halm
Browse files

Merge pull request #159 from noynir/master

FIxed #132  - rendering inline images
parents a9d1cd69 e0475f26
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Net;
using Svg.Transforms;
namespace Svg
{
/// <summary>
/// Represents and SVG image
/// </summary>
[SvgElement("image")]
public class SvgImage : SvgVisualElement
{
/// <summary>
/// Initializes a new instance of the <see cref="SvgImage"/> class.
/// </summary>
public SvgImage()
{
Width = new SvgUnit(0.0f);
Height = new SvgUnit(0.0f);
}
/// <summary>
/// Gets an <see cref="SvgPoint"/> representing the top left point of the rectangle.
/// </summary>
public SvgPoint Location
{
get { return new SvgPoint(X, Y); }
namespace Svg
{
/// <summary>
/// Represents and SVG image
/// </summary>
[SvgElement("image")]
public class SvgImage : SvgVisualElement
{
/// <summary>
/// Initializes a new instance of the <see cref="SvgImage"/> class.
/// </summary>
public SvgImage()
{
Width = new SvgUnit(0.0f);
Height = new SvgUnit(0.0f);
}
/// <summary>
/// Gets an <see cref="SvgPoint"/> representing the top left point of the rectangle.
/// </summary>
public SvgPoint Location
{
get { return new SvgPoint(X, Y); }
}
/// <summary>
......@@ -40,67 +40,67 @@ namespace Svg
{
get { return this.Attributes.GetAttribute<SvgAspectRatio>("preserveAspectRatio"); }
set { this.Attributes["preserveAspectRatio"] = value; }
}
[SvgAttribute("x")]
public virtual SvgUnit X
{
get { return this.Attributes.GetAttribute<SvgUnit>("x"); }
set { this.Attributes["x"] = value; }
}
[SvgAttribute("y")]
public virtual SvgUnit Y
{
get { return this.Attributes.GetAttribute<SvgUnit>("y"); }
set { this.Attributes["y"] = value; }
}
[SvgAttribute("width")]
public virtual SvgUnit Width
{
get { return this.Attributes.GetAttribute<SvgUnit>("width"); }
set { this.Attributes["width"] = value; }
}
[SvgAttribute("height")]
public virtual SvgUnit Height
{
get { return this.Attributes.GetAttribute<SvgUnit>("height"); }
set { this.Attributes["height"] = value; }
}
[SvgAttribute("href", SvgAttributeAttribute.XLinkNamespace)]
public virtual Uri Href
{
get { return this.Attributes.GetAttribute<Uri>("href"); }
set { this.Attributes["href"] = value; }
}
/// <summary>
/// Gets the bounds of the element.
/// </summary>
/// <value>The bounds.</value>
public override RectangleF Bounds
{
get { return new RectangleF(this.Location.ToDeviceValue(null, this),
new SizeF(this.Width.ToDeviceValue(null, UnitRenderingType.Horizontal, this),
this.Height.ToDeviceValue(null, UnitRenderingType.Vertical, this))); }
}
/// <summary>
/// Gets the <see cref="GraphicsPath"/> for this element.
}
[SvgAttribute("x")]
public virtual SvgUnit X
{
get { return this.Attributes.GetAttribute<SvgUnit>("x"); }
set { this.Attributes["x"] = value; }
}
[SvgAttribute("y")]
public virtual SvgUnit Y
{
get { return this.Attributes.GetAttribute<SvgUnit>("y"); }
set { this.Attributes["y"] = value; }
}
[SvgAttribute("width")]
public virtual SvgUnit Width
{
get { return this.Attributes.GetAttribute<SvgUnit>("width"); }
set { this.Attributes["width"] = value; }
}
[SvgAttribute("height")]
public virtual SvgUnit Height
{
get { return this.Attributes.GetAttribute<SvgUnit>("height"); }
set { this.Attributes["height"] = value; }
}
[SvgAttribute("href", SvgAttributeAttribute.XLinkNamespace)]
public virtual Uri Href
{
get { return this.Attributes.GetAttribute<Uri>("href"); }
set { this.Attributes["href"] = value; }
}
/// <summary>
/// Gets the bounds of the element.
/// </summary>
public override GraphicsPath Path(ISvgRenderer renderer)
{
return null;
}
/// <summary>
/// Renders the <see cref="SvgElement"/> and contents to the specified <see cref="Graphics"/> object.
/// <value>The bounds.</value>
public override RectangleF Bounds
{
get { return new RectangleF(this.Location.ToDeviceValue(null, this),
new SizeF(this.Width.ToDeviceValue(null, UnitRenderingType.Horizontal, this),
this.Height.ToDeviceValue(null, UnitRenderingType.Vertical, this))); }
}
/// <summary>
/// Gets the <see cref="GraphicsPath"/> for this element.
/// </summary>
public override GraphicsPath Path(ISvgRenderer renderer)
{
return null;
}
/// <summary>
/// Renders the <see cref="SvgElement"/> and contents to the specified <see cref="Graphics"/> object.
/// </summary>
protected override void Render(ISvgRenderer renderer)
{
......@@ -251,7 +251,10 @@ namespace Svg
{
using (var stream = webResponse.GetResponseStream())
{
stream.Position = 0;
if (stream.CanSeek)
{
stream.Position = 0;
}
if (uri.LocalPath.EndsWith(".svg", StringComparison.InvariantCultureIgnoreCase))
{
var doc = SvgDocument.Open<SvgDocument>(stream);
......@@ -283,23 +286,23 @@ namespace Svg
}
ms.Seek(0, SeekOrigin.Begin);
return ms;
}
public override SvgElement DeepCopy()
{
return DeepCopy<SvgImage>();
}
public override SvgElement DeepCopy<T>()
{
var newObj = base.DeepCopy<T>() as SvgImage;
newObj.Height = this.Height;
newObj.Width = this.Width;
newObj.X = this.X;
newObj.Y = this.Y;
newObj.Href = this.Href;
return newObj;
}
}
}
public override SvgElement DeepCopy()
{
return DeepCopy<SvgImage>();
}
public override SvgElement DeepCopy<T>()
{
var newObj = base.DeepCopy<T>() as SvgImage;
newObj.Height = this.Height;
newObj.Width = this.Width;
newObj.X = this.X;
newObj.Y = this.Y;
newObj.Href = this.Href;
return newObj;
}
}
}
\ No newline at end of file
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