Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to support multiple dotnet targets #448

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Tests/**/*.suo
Source/TestResults/
Source/.vs
/Source/Svg.sln.DotSettings.user
/Source/Svg.XML
5 changes: 0 additions & 5 deletions Source/DataTypes/SvgUnitConverter.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI.WebControls;

namespace Svg
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Document Structure/SvgGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected override void Render(ISvgRenderer renderer)
}

/// <summary>
/// Gets the <see cref="GraphicsPath"/> for this element.
/// Gets the <see cref="System.Drawing.Drawing2D.GraphicsPath"/> for this element.
/// </summary>
/// <value></value>
public override GraphicsPath Path(ISvgRenderer renderer)
Expand Down
2 changes: 1 addition & 1 deletion Source/Painting/EnumConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public EnumBaseConverter() { }

/// <summary>Creates a new instance.</summary>
/// <param name="defaultValue">Specified the default value of the enum.</param>
/// <param name="caseHandling">Specified the case.</param>
/// <param name="caseHandling">Defines if the value shall be converted to lower camel case or lower case</param>
public EnumBaseConverter(T defaultValue, CaseHandling caseHandling = CaseHandling.CamelCase)
{
this.DefaultValue = defaultValue;
Expand Down
4 changes: 1 addition & 3 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down Expand Up @@ -32,8 +31,7 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("2.4.3.*")]
//[assembly: AssemblyFileVersion("1.0.1.*")]
[assembly: AssemblyVersion("2.4.5.0")]

[assembly: CLSCompliant(true)]

Expand Down
494 changes: 119 additions & 375 deletions Source/Svg.csproj

Large diffs are not rendered by default.

55 changes: 21 additions & 34 deletions Source/Svg.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
# Visual Studio 15
VisualStudioVersion = 15.0.28307.168
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Svg", "Svg.csproj", "{886A98C5-37C0-4E8B-885E-30C1D2F98B47}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Svg", "Svg.csproj", "{886A98C5-37C0-4E8B-885E-30C1D2F98B47}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SVGViewer", "..\Samples\SVGViewer\SVGViewer.csproj", "{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Svg.UnitTests", "..\Tests\Svg.UnitTests\Svg.UnitTests.csproj", "{E702EB7D-D01D-438A-BADD-E72D4E49109F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Svg.UnitTests", "..\Tests\Svg.UnitTests\Svg.UnitTests.csproj", "{E702EB7D-D01D-438A-BADD-E72D4E49109F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A417AF1E-BEDB-4715-B4FD-D795579217F9}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -18,7 +16,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvgW3CTestRunner", "..\Tests\SvgW3CTestRunner\SvgW3CTestRunner.csproj", "{8ED74C39-6CFF-421E-952A-30F9E6957108}"
EndProject
Project("{FF286327-C783-4F7A-AB73-9BCBAD0D4460}") = "Svg.Package", "SvgNuget\Svg.Package.nuproj", "{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SVGViewer", "..\Samples\SVGViewer\SVGViewer.csproj", "{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -40,18 +38,6 @@ Global
{886A98C5-37C0-4E8B-885E-30C1D2F98B47}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{886A98C5-37C0-4E8B-885E-30C1D2F98B47}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{886A98C5-37C0-4E8B-885E-30C1D2F98B47}.Release|x86.ActiveCfg = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Any CPU.Build.0 = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Mixed Platforms.Build.0 = Debug|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|x86.ActiveCfg = Debug|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|x86.Build.0 = Debug|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Any CPU.Build.0 = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Mixed Platforms.ActiveCfg = Release|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Mixed Platforms.Build.0 = Release|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|x86.ActiveCfg = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|x86.Build.0 = Release|Any CPU
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Debug|Any CPU.Build.0 = Release|Any CPU
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
Expand All @@ -62,34 +48,35 @@ Global
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Release|x86.ActiveCfg = Release|Any CPU
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|Any CPU.ActiveCfg = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|Any CPU.Build.0 = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|Any CPU.ActiveCfg = Debug|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|Mixed Platforms.Build.0 = Debug|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|x86.ActiveCfg = Debug|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|x86.Build.0 = Debug|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|Any CPU.ActiveCfg = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|Any CPU.Build.0 = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|Mixed Platforms.ActiveCfg = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|Mixed Platforms.Build.0 = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|x86.ActiveCfg = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|x86.Build.0 = Release|x86
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|x86.ActiveCfg = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|x86.Build.0 = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|Any CPU.Build.0 = Release|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|x86.ActiveCfg = Release|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|x86.Build.0 = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Mixed Platforms.Build.0 = Debug|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|x86.ActiveCfg = Debug|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|x86.Build.0 = Debug|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Any CPU.Build.0 = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Mixed Platforms.ActiveCfg = Release|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Mixed Platforms.Build.0 = Release|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|x86.ActiveCfg = Release|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5096EEB3-8F41-44B5-BCF9-58743A59AB21}
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = Svg.vsmdi
EndGlobalSection
Expand Down
20 changes: 12 additions & 8 deletions Source/SvgDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,10 @@ public static SvgDocument Open(string path)

using (var strReader = new System.IO.StringReader(svg))
{
var reader = new SvgTextReader(strReader, null);
reader.XmlResolver = new SvgDtdResolver();
reader.WhitespaceHandling = WhitespaceHandling.None;
var reader = new SvgTextReader(strReader, null)
{
XmlResolver = new SvgDtdResolver(), WhitespaceHandling = WhitespaceHandling.None
};
return Open<T>(reader);
}
}
Expand All @@ -251,9 +252,10 @@ public static SvgDocument Open(string path)
}

// Don't close the stream via a dispose: that is the client's job.
var reader = new SvgTextReader(stream, entities);
reader.XmlResolver = new SvgDtdResolver();
reader.WhitespaceHandling = WhitespaceHandling.None;
var reader = new SvgTextReader(stream, entities)
{
XmlResolver = new SvgDtdResolver(), WhitespaceHandling = WhitespaceHandling.None
};
return Open<T>(reader);
}

Expand Down Expand Up @@ -621,8 +623,10 @@ public override void Write(XmlTextWriter writer)
public void Write(Stream stream, bool useBom = true)
{

var xmlWriter = new XmlTextWriter(stream, useBom ? Encoding.UTF8 : new System.Text.UTF8Encoding(false));
xmlWriter.Formatting = Formatting.Indented;
var xmlWriter = new XmlTextWriter(stream, useBom ? Encoding.UTF8 : new System.Text.UTF8Encoding(false))
{
Formatting = Formatting.Indented
};
xmlWriter.WriteStartDocument();
xmlWriter.WriteDocType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", null);

Expand Down
6 changes: 6 additions & 0 deletions Source/SvgElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,13 @@ private Dictionary<string, string> WritePropertyAttributes(XmlTextWriter writer)
}
}

#if NETFULL
var value = (string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string));
#else
// dotnetcore throws exception if input is null
string value = propertyValue==null?null:(string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string));
#endif

if (propertyValue != null)
{
var type = propertyValue.GetType();
Expand Down
4 changes: 3 additions & 1 deletion Source/Web/SvgHandler.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if NET35 || NET40 || NET452 || NET472
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -230,4 +231,5 @@ public WaitHandle AsyncWaitHandle
}
}
}
}
}
#endif
60 changes: 41 additions & 19 deletions Tests/Svg.UnitTests/ImageComparisonTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;

namespace Svg.UnitTests
{
Expand All @@ -13,6 +15,31 @@ namespace Svg.UnitTests
public class ImageComparisonTest
{
public TestContext TestContext { get; set; }
private static string _basePath = null;
private static string GetSuiteTestsFolder
{
get
{
if (_basePath != null) return _basePath;
var basePath = Environment.CurrentDirectory;
while (!basePath.ToLower().EndsWith("svg"))
{
basePath = Path.GetDirectoryName(basePath);
}

_basePath = Path.Combine(basePath, "Tests");
return _basePath;
}
}

private static IEnumerable<object[]> GetData()
{
var basePath = GetSuiteTestsFolder;
var testSuite = Path.Combine(basePath, "W3CTestSuite");
var rows = File.ReadAllLines(Path.Combine(basePath, "Svg.UnitTests", "PassingTests.csv")).Skip(1);
foreach (var row in rows)
yield return new[] { (object)testSuite, (object) row,};
}

/// <summary>
/// Compares SVG images against reference PNG images from the W3C SVG 1.1 test suite.
Expand All @@ -22,26 +49,24 @@ public class ImageComparisonTest
/// so this is not a definitive test for image equality yet.
/// </summary>
[TestMethod]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV",
@"|DataDirectory|\..\..\PassingTests.csv",
"PassingTests#csv", DataAccessMethod.Sequential)]
public void CompareSvgImageWithReference()
[DynamicData(nameof(GetData), DynamicDataSourceType.Method)]
// [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV",@"|DataDirectory|\..\..\PassingTests.csv","PassingTests#csv", DataAccessMethod.Sequential)]
//public void CompareSvgImageWithReference()
public void CompareSvgImageWithReference(string basePath, string baseName)
{
var basePath = TestContext.TestRunDirectory;
while (!basePath.ToLower().EndsWith("svg"))
{
basePath = Path.GetDirectoryName(basePath);
}
basePath = Path.Combine(basePath, "Tests", "W3CTestSuite");
var svgBasePath = Path.Combine(basePath, "svg");
var baseName = TestContext.DataRow[0] as string;
bool testSaveLoad = !baseName.StartsWith("#");
if (!testSaveLoad)
{
baseName = baseName.Substring(1);
}
var svgPath = Path.Combine(basePath, "svg", baseName + ".svg");
var pngPath = Path.Combine(basePath, "png", baseName + ".png");
CompareSvgImageWithReferenceImpl(baseName, svgPath, pngPath, testSaveLoad);
}

private void CompareSvgImageWithReferenceImpl(string baseName,
string svgPath, string pngPath, bool testSaveLoad)
{
var pngImage = Image.FromFile(pngPath);
var svgDoc = LoadSvgDocument(svgPath);
Assert.IsNotNull(svgDoc);
Expand All @@ -50,7 +75,7 @@ public void CompareSvgImageWithReference()
Assert.AreNotEqual(null, pngImage, "Failed to load " + pngPath);
Assert.AreNotEqual(null, svgImage, "Failed to load " + svgPath);
var difference = svgImage.PercentageDifference(pngImage);
Assert.IsTrue(difference < 0.05,
Assert.IsTrue(difference < 0.05,
baseName + ": Difference is " + (difference * 100.0).ToString() + "%");
if (!testSaveLoad)
{
Expand Down Expand Up @@ -85,15 +110,12 @@ public void CompareSvgImageWithReference()
// [TestClass]
public void RecordDiffForAllSvgImagesWithReference()
{
var basePath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(
TestContext.TestRunDirectory)));
basePath = Path.Combine(basePath, "Tests", "W3CTestSuite");
var svgBasePath = Path.Combine(basePath, "svg");
var basePath = Path.Combine(GetSuiteTestsFolder, "W3CTestSuite");
string[] lines = File.ReadAllLines(@"..\..\..\..\Tests\Svg.UnitTests\all.csv");
foreach (var baseName in lines)
{
var svgPath = Path.Combine(basePath, "svg", baseName + ".svg");
var pngPath = Path.Combine(basePath, "png", baseName + ".png");
var svgPath = Path.Combine(Path.Combine(basePath, "svg"), baseName + ".svg");
var pngPath = Path.Combine(Path.Combine(basePath, "png"), baseName + ".png");
if (File.Exists(pngPath) && File.Exists(svgPath))
{
var pngImage = Image.FromFile(pngPath);
Expand Down
3 changes: 3 additions & 0 deletions Tests/Svg.UnitTests/MultiThreadingTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#if NET35
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Svg.Exceptions;
using System;
Expand Down Expand Up @@ -37,3 +39,4 @@ public void LoadSVGThreading_MultiThread_YieldsNoErrorWhileInBounds()
}
}
}
#endif
5 changes: 2 additions & 3 deletions Tests/Svg.UnitTests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down Expand Up @@ -31,5 +30,5 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("2.4.5.0")]
[assembly: AssemblyFileVersion("2.4.5.0")]
Loading