Commit 4ba5243e authored by Tebjan Halm's avatar Tebjan Halm
Browse files

Merge pull request #233 from dittodhole/hotfix/image-data-uri

fixed SvgImage.GetImage
parents 3bb22f1e 0959752a
...@@ -88,8 +88,8 @@ namespace Svg ...@@ -88,8 +88,8 @@ namespace Svg
/// <value>The bounds.</value> /// <value>The bounds.</value>
public override RectangleF Bounds public override RectangleF Bounds
{ {
get { return new RectangleF(this.Location.ToDeviceValue(null, this), get { return new RectangleF(this.Location.ToDeviceValue(null, this),
new SizeF(this.Width.ToDeviceValue(null, UnitRenderingType.Horizontal, this), new SizeF(this.Width.ToDeviceValue(null, UnitRenderingType.Horizontal, this),
this.Height.ToDeviceValue(null, UnitRenderingType.Vertical, this))); } this.Height.ToDeviceValue(null, UnitRenderingType.Vertical, this))); }
} }
...@@ -143,10 +143,10 @@ namespace Svg ...@@ -143,10 +143,10 @@ namespace Svg
} }
var destClip = new RectangleF(this.Location.ToDeviceValue(renderer, this), var destClip = new RectangleF(this.Location.ToDeviceValue(renderer, this),
new SizeF(Width.ToDeviceValue(renderer, UnitRenderingType.Horizontal, this), new SizeF(Width.ToDeviceValue(renderer, UnitRenderingType.Horizontal, this),
Height.ToDeviceValue(renderer, UnitRenderingType.Vertical, this))); Height.ToDeviceValue(renderer, UnitRenderingType.Vertical, this)));
RectangleF destRect = destClip; RectangleF destRect = destClip;
this.PushTransforms(renderer); this.PushTransforms(renderer);
renderer.SetClip(new Region(destClip), CombineMode.Intersect); renderer.SetClip(new Region(destClip), CombineMode.Intersect);
this.SetClip(renderer); this.SetClip(renderer);
...@@ -203,7 +203,7 @@ namespace Svg ...@@ -203,7 +203,7 @@ namespace Svg
break; break;
} }
destRect = new RectangleF(destClip.X + xOffset, destClip.Y + yOffset, destRect = new RectangleF(destClip.X + xOffset, destClip.Y + yOffset,
srcRect.Width * fScaleX, srcRect.Height * fScaleY); srcRect.Width * fScaleX, srcRect.Height * fScaleY);
} }
...@@ -223,7 +223,7 @@ namespace Svg ...@@ -223,7 +223,7 @@ namespace Svg
renderer.PopBoundable(); renderer.PopBoundable();
} }
this.ResetClip(renderer); this.ResetClip(renderer);
this.PopTransforms(renderer); this.PopTransforms(renderer);
} }
...@@ -234,9 +234,20 @@ namespace Svg ...@@ -234,9 +234,20 @@ namespace Svg
protected object GetImage(string uriString) protected object GetImage(string uriString)
{ {
string safeUriString;
if (uriString.Length > 65519)
{
safeUriString = uriString.Substring(0,
65519);
}
else
{
safeUriString = uriString;
}
try try
{ {
var uri = new Uri(uriString.Substring(0, 65519)); //Uri MaxLength is 65519 (https://msdn.microsoft.com/en-us/library/z6c2z492.aspx) var uri = new Uri(safeUriString); //Uri MaxLength is 65519 (https://msdn.microsoft.com/en-us/library/z6c2z492.aspx)
// handle data/uri embedded images (http://en.wikipedia.org/wiki/Data_URI_scheme) // handle data/uri embedded images (http://en.wikipedia.org/wiki/Data_URI_scheme)
if (uri.IsAbsoluteUri && uri.Scheme == "data") if (uri.IsAbsoluteUri && uri.Scheme == "data")
...@@ -268,7 +279,7 @@ namespace Svg ...@@ -268,7 +279,7 @@ namespace Svg
{ {
if (stream.CanSeek) if (stream.CanSeek)
{ {
stream.Position = 0; stream.Position = 0;
} }
if (uri.LocalPath.EndsWith(".svg", StringComparison.InvariantCultureIgnoreCase)) if (uri.LocalPath.EndsWith(".svg", StringComparison.InvariantCultureIgnoreCase))
{ {
......
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" viewBox="0 0 452 440">
<g id="SFixTitle" />
<g id="SContent">
<g transform="scale(1.33333)">
<g transform="matrix(1,0,0,1,0,0)">
<g>
<defs>
<clipPath id="CLIP0">
<path d="M0,0 L339,0 L339,330 L0,330 Z " />
</clipPath>
</defs>
<g clip-path="url(#CLIP0)">
<g transform="matrix(1,0,0,1,0,0)">
<image Id="Image1" x="0" y="0" width="339" height="330" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwgAADsIBFShKgAAAABh0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC45bDN+TgAAAPtJREFUKFMtjsFLhEAUh/1TO3YJOkYdg2DbXVqaZrNrBduiBuuhQ+jBNsXDBlI06jrm0EhsdYxu6vQz/fjN48374PE0pVTTNF0tZSmlrOsa3w4NU+AHwdw0w5UVPlkz01guH3uN54PA/vne+/iy3zeLz9/9h5XteV6rsep8SqW9xZKEizIX5WuSWvHByWQMpQkhDP04mh+yOImTFGFxeuXT0fUgy7JWL/ShmA3Wa57+B40eXR7djDjnWlVVU0o3O7sseuF5gTwzth0MJ+QUqj3Ndd07QsW9mxfirRBOHI6NCwz7y4HjOOSMmuYtQgjtHOg1wCrcAdD0I6X+AFY0+G5kPytUAAAAAElFTkSuQmCC" />
</g>
</g>
<g>
<path d="M170.25,165.75 L225.007827759,88.731620789 L225.007827759,88.731620789 C226.193939209,89.574920654 227.360412598,90.445503235 228.506332397,91.342681885 Z " stroke="none" stroke-width="0" fill="#C0504D" fill-opacity="1" transform="matrix(1,0,0,1,0,0)" />
</g>
<g />
<g transform="matrix(1,0,0,1,0,0)">
<defs>
<clipPath id="CLIP2">
<path d="M153.75,240 L183.75,240 L183.75,261 L153.75,261 Z " />
</clipPath>
</defs>
<g clip-path="url(#CLIP2)">
<g transform="matrix(1,0,0,1,156.57810974,259.06246948)">
<text x="0" y="-2.9615624" font-family="Impact" font-size="14.03999996" fill="#568ED4">64%</text>
</g>
</g>
</g>
</g>
</g>
</g>
</g>
<defs />
</svg>
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Svg.UnitTests
{
/// <summary>
/// Test Class of rendering SVGs with a large embedded image
/// Based on Issue 225
/// </summary>
/// <remarks>
/// Test use the following embedded resources:
/// - Issue225_LargeUri\Speedometer.svg
/// </remarks>
[TestClass]
public class SmallEmbeddingImageTest : SvgTestHelper
{
protected override string TestResource
{
get
{
return this.GetFullResourceString("hotfix_image_data_uri.Speedometer.svg");
}
}
protected override int ExpectedSize
{
get
{
return 160000;
}
}
[TestMethod]
public void TestImageIsRendered()
{
this.LoadSvg(this.GetXMLDocFromResource());
}
}
}
\ No newline at end of file
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
<Compile Include="MultiThreadingTest.cs" /> <Compile Include="MultiThreadingTest.cs" />
<Compile Include="PrivateFontsTests.cs" /> <Compile Include="PrivateFontsTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SmallEmbeddingImageTest.cs" />
<Compile Include="SvgTestHelper.cs" /> <Compile Include="SvgTestHelper.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
...@@ -85,6 +86,9 @@ ...@@ -85,6 +86,9 @@
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Resources\Issue225_LargeUri\Speedometer.svg" /> <EmbeddedResource Include="Resources\Issue225_LargeUri\Speedometer.svg" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\hotfix-image-data-uri\Speedometer.svg" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
......
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