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
1a5baee0
"Source/vscode:/vscode.git/clone" did not exist on "8ef8a97af20b73c357fae173e8fb964e050d6d77"
Commit
1a5baee0
authored
Aug 20, 2015
by
Gertjan van Heertum
Browse files
Partial solution for threading issues
parent
537fc79e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Source/Css/CssQuery.cs
View file @
1a5baee0
...
...
@@ -9,9 +9,9 @@ namespace Svg.Css
{
internal
static
class
CssQuery
{
public
static
IEnumerable
<
SvgElement
>
QuerySelectorAll
(
this
SvgElement
elem
,
string
selector
)
public
static
IEnumerable
<
SvgElement
>
QuerySelectorAll
(
this
SvgElement
elem
,
string
selector
,
SvgElementFactory
elementFactory
)
{
var
generator
=
new
SelectorGenerator
<
SvgElement
>(
new
SvgElementOps
());
var
generator
=
new
SelectorGenerator
<
SvgElement
>(
new
SvgElementOps
(
elementFactory
));
Fizzler
.
Parser
.
Parse
(
selector
,
generator
);
return
generator
.
Selector
(
Enumerable
.
Repeat
(
elem
,
1
));
}
...
...
Source/Css/SvgElementOps.cs
View file @
1a5baee0
...
...
@@ -8,10 +8,17 @@ namespace Svg.Css
{
internal
class
SvgElementOps
:
IElementOps
<
SvgElement
>
{
public
Selector
<
SvgElement
>
Type
(
NamespacePrefix
prefix
,
string
name
)
private
readonly
SvgElementFactory
_elementFactory
;
public
SvgElementOps
(
SvgElementFactory
elementFactory
)
{
_elementFactory
=
elementFactory
;
}
public
Selector
<
SvgElement
>
Type
(
NamespacePrefix
prefix
,
string
name
)
{
SvgElementFactory
.
ElementInfo
type
=
null
;
if
(
SvgE
lementFactory
.
AvailableElements
.
TryGetValue
(
name
,
out
type
))
if
(
_e
lementFactory
.
AvailableElements
.
TryGetValue
(
name
,
out
type
))
{
return
nodes
=>
nodes
.
Where
(
n
=>
n
.
GetType
()
==
type
.
ElementType
);
}
...
...
Source/SvgDocument.cs
View file @
1a5baee0
...
...
@@ -243,7 +243,8 @@ namespace Svg
SvgElement
element
=
null
;
SvgElement
parent
;
T
svgDocument
=
null
;
var
elementFactory
=
new
SvgElementFactory
();
var
styles
=
new
List
<
ISvgNode
>();
while
(
reader
.
Read
())
...
...
@@ -259,11 +260,11 @@ namespace Svg
// Create element
if
(
elementStack
.
Count
>
0
)
{
element
=
SvgE
lementFactory
.
CreateElement
(
reader
,
svgDocument
);
element
=
e
lementFactory
.
CreateElement
(
reader
,
svgDocument
);
}
else
{
svgDocument
=
SvgE
lementFactory
.
CreateDocument
<
T
>(
reader
);
svgDocument
=
e
lementFactory
.
CreateDocument
<
T
>(
reader
);
element
=
svgDocument
;
}
...
...
@@ -349,7 +350,7 @@ namespace Svg
foreach
(
var
selector
in
selectors
)
{
elemsToStyle
=
svgDocument
.
QuerySelectorAll
(
rule
.
Selector
.
ToString
());
elemsToStyle
=
svgDocument
.
QuerySelectorAll
(
rule
.
Selector
.
ToString
()
,
elementFactory
);
foreach
(
var
elem
in
elemsToStyle
)
{
foreach
(
var
decl
in
rule
.
Declarations
)
...
...
Source/SvgElementFactory.cs
View file @
1a5baee0
...
...
@@ -14,13 +14,13 @@ namespace Svg
/// </summary>
internal
class
SvgElementFactory
{
private
static
Dictionary
<
string
,
ElementInfo
>
availableElements
;
private
static
Parser
cssParser
=
new
Parser
();
private
Dictionary
<
string
,
ElementInfo
>
availableElements
;
private
Parser
cssParser
=
new
Parser
();
/// <summary>
/// Gets a list of available types that can be used when creating an <see cref="SvgElement"/>.
/// </summary>
public
static
Dictionary
<
string
,
ElementInfo
>
AvailableElements
public
Dictionary
<
string
,
ElementInfo
>
AvailableElements
{
get
{
...
...
@@ -47,7 +47,7 @@ namespace Svg
/// <param name="reader">The <see cref="XmlTextReader"/> containing the node to parse into an <see cref="SvgDocument"/>.</param>
/// <exception cref="ArgumentNullException">The <paramref name="reader"/> parameter cannot be <c>null</c>.</exception>
/// <exception cref="InvalidOperationException">The CreateDocument method can only be used to parse root <svg> elements.</exception>
public
static
T
CreateDocument
<
T
>(
XmlReader
reader
)
where
T
:
SvgDocument
,
new
()
public
T
CreateDocument
<
T
>(
XmlReader
reader
)
where
T
:
SvgDocument
,
new
()
{
if
(
reader
==
null
)
{
...
...
@@ -68,7 +68,7 @@ namespace Svg
/// <param name="reader">The <see cref="XmlTextReader"/> containing the node to parse into a subclass of <see cref="SvgElement"/>.</param>
/// <param name="document">The <see cref="SvgDocument"/> that the created element belongs to.</param>
/// <exception cref="ArgumentNullException">The <paramref name="reader"/> and <paramref name="document"/> parameters cannot be <c>null</c>.</exception>
public
static
SvgElement
CreateElement
(
XmlReader
reader
,
SvgDocument
document
)
public
SvgElement
CreateElement
(
XmlReader
reader
,
SvgDocument
document
)
{
if
(
reader
==
null
)
{
...
...
@@ -78,7 +78,7 @@ namespace Svg
return
CreateElement
<
SvgDocument
>(
reader
,
false
,
document
);
}
private
static
SvgElement
CreateElement
<
T
>(
XmlReader
reader
,
bool
fragmentIsDocument
,
SvgDocument
document
)
where
T
:
SvgDocument
,
new
()
private
SvgElement
CreateElement
<
T
>(
XmlReader
reader
,
bool
fragmentIsDocument
,
SvgDocument
document
)
where
T
:
SvgDocument
,
new
()
{
SvgElement
createdElement
=
null
;
string
elementName
=
reader
.
LocalName
;
...
...
@@ -122,7 +122,7 @@ namespace Svg
return
createdElement
;
}
private
static
void
SetAttributes
(
SvgElement
element
,
XmlReader
reader
,
SvgDocument
document
)
private
void
SetAttributes
(
SvgElement
element
,
XmlReader
reader
,
SvgDocument
document
)
{
//Trace.TraceInformation("Begin SetAttributes");
...
...
Source/Text/GdiFontDefn.cs
View file @
1a5baee0
...
...
@@ -68,8 +68,8 @@ namespace Svg
return
new
SizeF
(
rect
.
Width
,
Ascent
(
renderer
));
}
private
static
Graphics
_graphics
;
private
static
Graphics
GetGraphics
(
object
renderer
)
private
Graphics
_graphics
;
private
Graphics
GetGraphics
(
object
renderer
)
{
var
provider
=
renderer
as
IGraphicsProvider
;
if
(
provider
==
null
)
...
...
Tests/Svg.UnitTests/MultiThreadingTest.cs
View file @
1a5baee0
...
...
@@ -34,17 +34,9 @@ namespace Svg.UnitTests
public
void
TestMultiThread
()
{
bool
valid
=
true
;
Parallel
.
For
(
0
,
10
,
(
x
)
=>
Parallel
.
For
(
0
,
3
,
(
x
)
=>
{
try
{
LoadFile
();
}
catch
(
Exception
e
)
{
Trace
.
WriteLine
(
"Run error in parallel: "
+
e
.
Message
);
valid
=
false
;
}
LoadFile
();
});
Assert
.
IsTrue
(
valid
,
"One or more of the runs was invalid"
);
Trace
.
WriteLine
(
"Done"
);
...
...
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