Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ImportedProjects
SVG
Commits
a7097113
Commit
a7097113
authored
Dec 27, 2015
by
HeinrichAD
Browse files
Revert "Add Feature to use Customer/ Private Fonts."
This reverts commit
480a54d8
.
parent
480a54d8
Changes
7
Show whitespace changes
Inline
Side-by-side
Source/SvgElementStyle.cs
View file @
a7097113
...
@@ -387,13 +387,11 @@ namespace Svg
...
@@ -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
)
public
static
object
ValidateFontFamily
(
string
fontFamilyList
,
SvgDocument
doc
)
{
{
// Split font family list on "," and then trim start and end spaces and quotes.
// 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
;
var
families
=
System
.
Drawing
.
FontFamily
.
Families
;
Func
<
FontFamily
,
bool
>
getFamily
;
FontFamily
family
;
FontFamily
family
;
IEnumerable
<
SvgFontFace
>
sFaces
;
IEnumerable
<
SvgFontFace
>
sFaces
;
...
@@ -403,13 +401,10 @@ namespace Svg
...
@@ -403,13 +401,10 @@ namespace Svg
{
{
if
(
doc
.
FontDefns
().
TryGetValue
(
f
,
out
sFaces
))
return
sFaces
;
if
(
doc
.
FontDefns
().
TryGetValue
(
f
,
out
sFaces
))
return
sFaces
;
getFamily
=
new
Func
<
FontFamily
,
bool
>(
ff
=>
string
.
Equals
(
ff
.
Name
,
f
,
StringComparison
.
OrdinalIgnoreCase
));
family
=
families
.
FirstOrDefault
(
ff
=>
ff
.
Name
.
ToLower
()
==
f
.
ToLower
());
family
=
families
.
FirstOrDefault
(
getFamily
);
if
(
family
!=
null
)
return
family
;
family
=
PrivateFonts
.
Families
.
FirstOrDefault
(
getFamily
);
if
(
family
!=
null
)
return
family
;
if
(
family
!=
null
)
return
family
;
switch
(
f
.
ToLower
()
)
switch
(
f
)
{
{
case
"serif"
:
case
"serif"
:
return
System
.
Drawing
.
FontFamily
.
GenericSerif
;
return
System
.
Drawing
.
FontFamily
.
GenericSerif
;
...
...
Tests/Svg.UnitTests/MultiThreadingTest.cs
View file @
a7097113
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Svg.Exceptions
;
using
System
;
using
System
;
using
System.Diagnostics
;
using
System.Diagnostics
;
using
System.Drawing
;
using
System.Drawing.Imaging
;
using
System.IO
;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
System.Xml
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Svg.Exceptions
;
namespace
Svg.UnitTests
namespace
Svg.UnitTests
{
{
[
TestClass
]
[
TestClass
()
]
public
class
MultiThreadingTest
:
SvgTestHelper
public
class
MultiThreadingTest
{
{
protected
override
string
TestFile
{
get
{
return
@"d:\temp\test.svg"
;
}
}
private
const
string
TestFile
=
@"d:\temp\test.svg"
;
protected
override
int
ExpectedSize
{
get
{
return
600000
;
}
}
private
const
int
ExpectedSize
=
600000
;
private
XmlDocument
GetXMLDoc
()
private
void
LoadFile
()
{
{
LoadSvg
(
GetXMLDocFromFile
());
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
]
[
TestMethod
]
public
void
TestSingleThread
()
public
void
TestSingleThread
()
{
{
LoadFile
();
LoadFile
();
}
}
[
TestMethod
]
[
TestMethod
]
public
void
TestMultiThread
()
public
void
TestMultiThread
()
{
{
...
@@ -37,7 +41,6 @@ namespace Svg.UnitTests
...
@@ -37,7 +41,6 @@ namespace Svg.UnitTests
Trace
.
WriteLine
(
"Done"
);
Trace
.
WriteLine
(
"Done"
);
}
}
[
TestMethod
]
[
TestMethod
]
[
ExpectedException
(
typeof
(
SvgMemoryException
))]
[
ExpectedException
(
typeof
(
SvgMemoryException
))]
public
void
SVGGivesMemoryExceptionOnTooManyParallelTest
()
public
void
SVGGivesMemoryExceptionOnTooManyParallelTest
()
...
@@ -54,5 +57,19 @@ namespace Svg.UnitTests
...
@@ -54,5 +57,19 @@ namespace Svg.UnitTests
throw
ex
.
InnerException
;
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
Tests/Svg.UnitTests/PrivateFontsTests.cs
deleted
100644 → 0
View file @
480a54d8
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
System.Drawing.Text
;
using
System.Runtime.InteropServices
;
namespace
Svg.UnitTests
{
/// <summary>
/// Test Class of the feature to use Private Fonts in SVGs.
/// Based on Issue 204.
/// </summary>
/// <remarks>
/// Test use the following embedded resources:
/// - Issue204_PrivateFont\Text.svg
/// - Issue204_PrivateFont\BrushScriptMT2.ttf
/// </remarks>
[
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.
}
}
}
Tests/Svg.UnitTests/Resources/Issue204_PrivateFont/BrushScriptMT2.ttf
deleted
100644 → 0
View file @
480a54d8
File deleted
Tests/Svg.UnitTests/Resources/Issue204_PrivateFont/Text.svg
deleted
100644 → 0
View file @
480a54d8
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:xlink=
"http://www.w3.org/1999/xlink"
xmlns=
"http://www.w3.org/2000/svg"
version=
"1.1"
>
<defs>
<symbol
id=
"Lines"
overflow=
"visible"
>
<text
x=
"100"
y=
"60"
style=
"font-family: Brush Script MT2; font-size: 50px"
>
<tspan
x=
"100"
y=
"160"
>
Line01
</tspan>
<tspan
x=
"100"
y=
"220"
>
Line02
</tspan>
</text>
</symbol>
</defs>
<use
xlink:href=
"#Lines"
/>
</svg>
\ No newline at end of file
Tests/Svg.UnitTests/Svg.UnitTests.csproj
View file @
a7097113
...
@@ -56,9 +56,7 @@
...
@@ -56,9 +56,7 @@
<ItemGroup>
<ItemGroup>
<Compile
Include=
"CssQueryTest.cs"
/>
<Compile
Include=
"CssQueryTest.cs"
/>
<Compile
Include=
"MultiThreadingTest.cs"
/>
<Compile
Include=
"MultiThreadingTest.cs"
/>
<Compile
Include=
"PrivateFontsTests.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"SvgTestHelper.cs"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ProjectReference
Include=
"..\..\Source\Svg.csproj"
>
<ProjectReference
Include=
"..\..\Source\Svg.csproj"
>
...
@@ -67,12 +65,8 @@
...
@@ -67,12 +65,8 @@
</ProjectReference>
</ProjectReference>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<EmbeddedResource
Include=
"Resources\Issue204_PrivateFont\BrushScriptMT2.ttf"
/>
<None
Include=
"svgkey.snk"
/>
<None
Include=
"svgkey.snk"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<EmbeddedResource
Include=
"Resources\Issue204_PrivateFont\Text.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.
...
...
Tests/Svg.UnitTests/SvgTestHelper.cs
deleted
100644 → 0
View file @
480a54d8
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
System
;
using
System.Diagnostics
;
using
System.Drawing
;
using
System.Drawing.Imaging
;
using
System.IO
;
using
System.Xml
;
namespace
Svg.UnitTests
{
public
abstract
class
SvgTestHelper
{
/// <summary>
/// Test file path.
/// </summary>
protected
virtual
string
TestFile
{
get
{
const
string
msg
=
"Test file not overridden."
;
Assert
.
Inconclusive
(
msg
);
throw
new
NotImplementedException
(
msg
);
}
}
/// <summary>
/// Full Unit Test resource string for test file.
/// </summary>
/// <remarks>
/// For the full Unit Test resource string you can use <see cref="GetFullResourceString(string)"/>.
/// </remarks>
protected
virtual
string
TestResource
{
get
{
const
string
msg
=
"Test resource not overridden."
;
Assert
.
Inconclusive
(
msg
);
throw
new
NotImplementedException
(
msg
);
}
}
/// <summary>
/// Expected size of svg file after drawing.
/// </summary>
protected
virtual
int
ExpectedSize
{
get
{
const
string
msg
=
"Expected size not overridden."
;
Assert
.
Inconclusive
(
msg
);
throw
new
NotImplementedException
(
msg
);
}
}
/// <summary>
/// Get full Unit Test resource string.
/// </summary>
/// <param name="resourcePath">Resource path.</param>
/// <returns>Full resource string.</returns>
/// <example>
/// var s = GetFullResourceString("Issue204_PrivateFont.Text.svg");
/// // s content: "Svg.UnitTests.Resources.Issue204_PrivateFont.Text.svg"
/// </example>
protected
virtual
string
GetFullResourceString
(
string
resourcePath
)
{
const
string
DefaultResourcesDir
=
"Resources"
;
return
string
.
Format
(
"{0}.{1}.{2}"
,
this
.
GetType
().
Assembly
.
GetName
().
Name
,
DefaultResourcesDir
,
resourcePath
);
}
/// <summary>
/// Get embedded resource as stream from Unit Test resources.
/// </summary>
/// <param name="fullResourceString">Full Unit Test resource string.</param>
/// <returns>Embedded resource data steam.</returns>
/// <remarks>Do not forget to close, dispose the stream.</remarks>
protected
virtual
Stream
GetResourceStream
(
string
fullResourceString
)
{
Trace
.
WriteLine
(
"Get resource data."
);
var
s
=
this
.
GetType
().
Assembly
.
GetManifestResourceStream
(
fullResourceString
);
if
(
s
==
null
)
Assert
.
Fail
(
"Unable to find embedded resource"
,
fullResourceString
);
Trace
.
WriteLine
(
"Done getting resource data."
);
return
s
;
}
/// <summary>
/// Get embedded resource as byte array from Unit Test resources.
/// </summary>
/// <param name="fullResourceString">Full Unit Test resource string.</param>
/// <returns>Embedded resource data bytes.</returns>
protected
virtual
byte
[]
GetResourceBytes
(
string
fullResourceString
)
{
using
(
var
s
=
GetResourceStream
(
fullResourceString
))
{
var
resource
=
new
byte
[
s
.
Length
];
s
.
Read
(
resource
,
0
,
(
int
)
s
.
Length
);
return
resource
;
}
}
/// <summary>
/// Get embedded resource as xml document from Unit Test resources.
/// </summary>
/// <param name="fullResourceString">Full Unit Test resource string.</param>
/// <returns>Embedded resource data xml document.</returns>
protected
virtual
XmlDocument
GetResourceXmlDoc
(
string
fullResourceString
)
{
using
(
var
s
=
GetResourceStream
(
fullResourceString
))
{
Trace
.
WriteLine
(
"Load XmlDocument from resource data."
);
var
xmlDoc
=
new
XmlDocument
();
xmlDoc
.
Load
(
s
);
Trace
.
WriteLine
(
"Done XmlDocument loading from resource data."
);
return
xmlDoc
;
}
}
/// <summary>
/// Get xml document from <see cref="TestFile"/>.
/// </summary>
/// <returns>File data as xml document.</returns>
protected
virtual
XmlDocument
GetXMLDocFromFile
()
{
return
GetXMLDocFromFile
(
TestFile
);
}
/// <summary>
/// Get xml document from file.
/// </summary>
/// <param name="file">File to load.</param>
/// <returns>File data as xml document.</returns>
protected
virtual
XmlDocument
GetXMLDocFromFile
(
string
file
)
{
if
(!
File
.
Exists
(
file
))
Assert
.
Fail
(
"Test file missing."
,
file
);
var
xmlDoc
=
new
XmlDocument
();
xmlDoc
.
LoadXml
(
File
.
ReadAllText
(
file
));
return
xmlDoc
;
}
/// <summary>
/// Get xml document from <see cref="TestResource"/>.
/// </summary>
/// <returns>Resource data as xml document.</returns>
protected
virtual
XmlDocument
GetXMLDocFromResource
()
{
return
GetResourceXmlDoc
(
TestResource
);
}
/// <summary>
/// Get xml document from resource.
/// </summary>
/// <param name="fullResourceString">Full Unit Test resource string.</param>
/// <returns>Resource data as xml document.</returns>
protected
virtual
XmlDocument
GetXMLDocFromResource
(
string
fullResourceString
)
{
return
GetResourceXmlDoc
(
fullResourceString
);
}
/// <summary>
/// Load, draw and check svg file.
/// </summary>
/// <param name="xml">Svg file data.</param>
protected
virtual
void
LoadSvg
(
XmlDocument
xml
)
{
Trace
.
WriteLine
(
"SvgDocument open xml."
);
var
svgDoc
=
SvgDocument
.
Open
(
xml
);
Trace
.
WriteLine
(
"Done SvgDocument open xml."
);
Trace
.
WriteLine
(
"Draw svg."
);
var
img
=
svgDoc
.
Draw
();
Trace
.
WriteLine
(
"Done drawing."
);
CheckSvg
(
svgDoc
,
img
);
}
/// <summary>
/// Check svg file data.
/// </summary>
/// <param name="svgDoc">Svg document.</param>
/// <param name="img">Image of svg file from <paramref name="svgDoc"/>.</param>
protected
virtual
void
CheckSvg
(
SvgDocument
svgDoc
,
Bitmap
img
)
{
using
(
var
ms
=
new
MemoryStream
())
{
img
.
Save
(
ms
,
ImageFormat
.
Png
);
ms
.
Flush
();
Assert
.
IsTrue
(
ms
.
Length
>=
ExpectedSize
,
"Svg file does not match expected minimum size."
);
}
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment