diff --git a/Source/SvgElementStyle.cs b/Source/SvgElementStyle.cs index b73a2f34333b7ad6010e78e3282055969f6b0db4..8bc831c289281ba6054cbff3e4c4f4b09c5b3267 100644 --- a/Source/SvgElementStyle.cs +++ b/Source/SvgElementStyle.cs @@ -387,13 +387,11 @@ namespace Svg } } - public static System.Drawing.Text.PrivateFontCollection PrivateFonts = new System.Drawing.Text.PrivateFontCollection(); public static object ValidateFontFamily(string fontFamilyList, SvgDocument doc) { // Split font family list on "," and then trim start and end spaces and quotes. - var fontParts = (fontFamilyList ?? string.Empty).Split(new[] { ',' }).Select(fontName => fontName.Trim(new[] { '"', ' ', '\'' })); + var fontParts = (fontFamilyList ?? "").Split(new[] { ',' }).Select(fontName => fontName.Trim(new[] { '"', ' ', '\'' })); var families = System.Drawing.FontFamily.Families; - Func getFamily; FontFamily family; IEnumerable sFaces; @@ -403,13 +401,10 @@ namespace Svg { if (doc.FontDefns().TryGetValue(f, out sFaces)) return sFaces; - getFamily = new Func(ff => string.Equals(ff.Name, f, StringComparison.OrdinalIgnoreCase)); - family = families.FirstOrDefault(getFamily); - if (family != null) return family; - family = PrivateFonts.Families.FirstOrDefault(getFamily); + family = families.FirstOrDefault(ff => ff.Name.ToLower() == f.ToLower()); if (family != null) return family; - switch (f.ToLower()) + switch (f) { case "serif": return System.Drawing.FontFamily.GenericSerif; diff --git a/Tests/Svg.UnitTests/MultiThreadingTest.cs b/Tests/Svg.UnitTests/MultiThreadingTest.cs index 25b9f24932b58ee995665fb88e4c2990a38200e9..0b0bf4f478d53e96e42d42cc1cbc852f40999a1c 100644 --- a/Tests/Svg.UnitTests/MultiThreadingTest.cs +++ b/Tests/Svg.UnitTests/MultiThreadingTest.cs @@ -1,58 +1,75 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Svg.Exceptions; using System; using System.Diagnostics; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; using System.Threading.Tasks; +using System.Xml; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Svg.Exceptions; namespace Svg.UnitTests { - [TestClass] - public class MultiThreadingTest : SvgTestHelper - { - - protected override string TestFile { get { return @"d:\temp\test.svg"; } } - protected override int ExpectedSize { get { return 600000; } } - - private void LoadFile() - { - LoadSvg(GetXMLDocFromFile()); - } - - - [TestMethod] - public void TestSingleThread() - { - LoadFile(); - } + [TestClass()] + public class MultiThreadingTest + { + private const string TestFile = @"d:\temp\test.svg"; + private const int ExpectedSize = 600000; + private XmlDocument GetXMLDoc() + { + var xmlDoc = new XmlDocument(); + if(!System.IO.File.Exists(TestFile)) { Assert.Inconclusive("Test file missing"); } + xmlDoc.LoadXml(System.IO.File.ReadAllText(TestFile)); + return xmlDoc; + } - [TestMethod] - public void TestMultiThread() - { - Parallel.For(0, 10, (x) => - { - LoadFile(); - }); - Trace.WriteLine("Done"); - } + [TestMethod] + public void TestSingleThread() + { + LoadFile(); + } + [TestMethod] + public void TestMultiThread() + { + Parallel.For(0, 10, (x) => + { + LoadFile(); + }); + Trace.WriteLine("Done"); + } - [TestMethod] - [ExpectedException(typeof(SvgMemoryException))] - public void SVGGivesMemoryExceptionOnTooManyParallelTest() - { - try - { - Parallel.For(0, 50, (x) => - { - LoadFile(); - }); - } - catch (AggregateException ex) - { - throw ex.InnerException; - } - } - } -} + [TestMethod] + [ExpectedException(typeof(SvgMemoryException))] + public void SVGGivesMemoryExceptionOnTooManyParallelTest() + { + try + { + Parallel.For(0, 50, (x) => + { + LoadFile(); + }); + } + catch (AggregateException ex) + { + throw ex.InnerException; + } + } + private void LoadFile() + { + var xml = GetXMLDoc(); + Trace.WriteLine("Reading and drawing file"); + SvgDocument d = SvgDocument.Open(xml); + var b = d.Draw(); + Trace.WriteLine("Done reading file"); + using (var ms = new MemoryStream()) + { + b.Save(ms, ImageFormat.Png); + ms.Flush(); + Assert.IsTrue(ms.Length >= ExpectedSize, "File does not match expected minimum size"); + } + } + } +} \ No newline at end of file diff --git a/Tests/Svg.UnitTests/PrivateFontsTests.cs b/Tests/Svg.UnitTests/PrivateFontsTests.cs deleted file mode 100644 index a027df783d85df02cf109c53eef5a47fe392e9e3..0000000000000000000000000000000000000000 --- a/Tests/Svg.UnitTests/PrivateFontsTests.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System.Drawing.Text; -using System.Runtime.InteropServices; - -namespace Svg.UnitTests -{ - - /// - /// Test Class of the feature to use Private Fonts in SVGs. - /// Based on Issue 204. - /// - /// - /// Test use the following embedded resources: - /// - Issue204_PrivateFont\Text.svg - /// - Issue204_PrivateFont\BrushScriptMT2.ttf - /// - [TestClass] - public class PrivateFontsTests : SvgTestHelper - { - private const string PrivateFontSvg = "Issue204_PrivateFont.Text.svg"; - private const string PrivateFont = "Issue204_PrivateFont.BrushScriptMT2.ttf"; - //private const string PrivateFontName = "Brush Script MT2"; - - protected override int ExpectedSize { get { return 3512; } } - - - [TestMethod] - public void TestPrivateFont() - { - AddFontFromResource(SvgElement.PrivateFonts, GetFullResourceString(PrivateFont)); - LoadSvg(GetXMLDocFromResource(GetFullResourceString(PrivateFontSvg))); - } - - - private void AddFontFromResource(PrivateFontCollection privateFontCollection, string fullFontResourceString) - { - var fontBytes = GetResourceBytes(fullFontResourceString); - var fontData = Marshal.AllocCoTaskMem(fontBytes.Length); - Marshal.Copy(fontBytes, 0, fontData, fontBytes.Length); - privateFontCollection.AddMemoryFont(fontData, fontBytes.Length); // Add font to collection. - Marshal.FreeCoTaskMem(fontData); // Do not forget to frees the memory block. - } - } -} diff --git a/Tests/Svg.UnitTests/Resources/Issue204_PrivateFont/BrushScriptMT2.ttf b/Tests/Svg.UnitTests/Resources/Issue204_PrivateFont/BrushScriptMT2.ttf deleted file mode 100644 index 3f9632f4aec46cb0277458345ae1db437e135f25..0000000000000000000000000000000000000000 Binary files a/Tests/Svg.UnitTests/Resources/Issue204_PrivateFont/BrushScriptMT2.ttf and /dev/null differ diff --git a/Tests/Svg.UnitTests/Resources/Issue204_PrivateFont/Text.svg b/Tests/Svg.UnitTests/Resources/Issue204_PrivateFont/Text.svg deleted file mode 100644 index afc31fd565ded3d19f8342207f21e7aec7dd40ff..0000000000000000000000000000000000000000 --- a/Tests/Svg.UnitTests/Resources/Issue204_PrivateFont/Text.svg +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - Line01 - Line02 - - - - - \ No newline at end of file diff --git a/Tests/Svg.UnitTests/Svg.UnitTests.csproj b/Tests/Svg.UnitTests/Svg.UnitTests.csproj index c961e32900d7323cce0dd20c6b45eabdc84ad753..71d999956b6bff91afdfa08ba65e4f75f4e928ab 100644 --- a/Tests/Svg.UnitTests/Svg.UnitTests.csproj +++ b/Tests/Svg.UnitTests/Svg.UnitTests.csproj @@ -56,9 +56,7 @@ - - @@ -67,12 +65,8 @@ - - - -