Commit e0475f26 authored by Nir Noy's avatar Nir Noy
Browse files

FIxed #132 - rendering inline images

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