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
0b3df0a9
Commit
0b3df0a9
authored
Mar 12, 2014
by
tebjan
Browse files
renamed FixID to ForceUniqueID
parent
03f7a46b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Source/SvgElement.cs
View file @
0b3df0a9
...
...
@@ -259,11 +259,11 @@ namespace Svg
get
{
return
this
.
Attributes
.
GetAttribute
<
string
>(
"id"
);
}
set
{
SetAndF
ix
ID
(
value
,
false
);
SetAndF
orceUnique
ID
(
value
,
false
);
}
}
public
void
SetAndF
ix
ID
(
string
value
,
bool
autoF
ix
ID
=
true
,
Action
<
SvgElement
,
string
,
string
>
logElementOldIDNewID
=
null
)
public
void
SetAndF
orceUnique
ID
(
string
value
,
bool
autoF
orceUnique
ID
=
true
,
Action
<
SvgElement
,
string
,
string
>
logElementOldIDNewID
=
null
)
{
// Don't do anything if it hasn't changed
if
(
string
.
Compare
(
this
.
ID
,
value
)
==
0
)
...
...
@@ -280,7 +280,7 @@ namespace Svg
if
(
this
.
OwnerDocument
!=
null
)
{
this
.
OwnerDocument
.
IdManager
.
AddAndF
ix
ID
(
this
,
null
,
autoF
ix
ID
,
logElementOldIDNewID
);
this
.
OwnerDocument
.
IdManager
.
AddAndF
orceUnique
ID
(
this
,
null
,
autoF
orceUnique
ID
,
logElementOldIDNewID
);
}
}
...
...
@@ -288,7 +288,7 @@ namespace Svg
/// Only used by the ID Manager
/// </summary>
/// <param name="newID"></param>
internal
void
F
ix
ID
(
string
newID
)
internal
void
F
orceUnique
ID
(
string
newID
)
{
this
.
Attributes
[
"id"
]
=
newID
;
}
...
...
Source/SvgElementCollection.cs
View file @
0b3df0a9
...
...
@@ -53,12 +53,12 @@ namespace Svg
/// <param name="item">The <see cref="SvgElement"/> to be added.</param>
public
void
Insert
(
int
index
,
SvgElement
item
)
{
InsertAndF
ix
ID
(
index
,
item
,
false
,
false
);
InsertAndF
orceUnique
ID
(
index
,
item
,
false
,
false
);
}
public
void
InsertAndF
ix
ID
(
int
index
,
SvgElement
item
,
bool
autoF
ix
ID
=
true
,
bool
autoFixChildrenID
=
true
,
Action
<
SvgElement
,
string
,
string
>
logElementOldIDNewID
=
null
)
public
void
InsertAndF
orceUnique
ID
(
int
index
,
SvgElement
item
,
bool
autoF
orceUnique
ID
=
true
,
bool
autoFixChildrenID
=
true
,
Action
<
SvgElement
,
string
,
string
>
logElementOldIDNewID
=
null
)
{
AddToIdManager
(
item
,
this
.
_elements
[
index
],
autoF
ix
ID
,
autoFixChildrenID
,
logElementOldIDNewID
);
AddToIdManager
(
item
,
this
.
_elements
[
index
],
autoF
orceUnique
ID
,
autoFixChildrenID
,
logElementOldIDNewID
);
this
.
_elements
.
Insert
(
index
,
item
);
item
.
_parent
.
OnElementAdded
(
item
,
index
);
}
...
...
@@ -81,29 +81,29 @@ namespace Svg
public
void
Add
(
SvgElement
item
)
{
this
.
AddAndF
ix
ID
(
item
,
false
,
false
);
this
.
AddAndF
orceUnique
ID
(
item
,
false
,
false
);
}
public
void
AddAndF
ix
ID
(
SvgElement
item
,
bool
autoF
ix
ID
=
true
,
bool
autoFixChildrenID
=
true
,
Action
<
SvgElement
,
string
,
string
>
logElementOldIDNewID
=
null
)
public
void
AddAndF
orceUnique
ID
(
SvgElement
item
,
bool
autoF
orceUnique
ID
=
true
,
bool
autoFixChildrenID
=
true
,
Action
<
SvgElement
,
string
,
string
>
logElementOldIDNewID
=
null
)
{
AddToIdManager
(
item
,
null
,
autoF
ix
ID
,
autoFixChildrenID
,
logElementOldIDNewID
);
AddToIdManager
(
item
,
null
,
autoF
orceUnique
ID
,
autoFixChildrenID
,
logElementOldIDNewID
);
this
.
_elements
.
Add
(
item
);
item
.
_parent
.
OnElementAdded
(
item
,
this
.
Count
-
1
);
}
private
void
AddToIdManager
(
SvgElement
item
,
SvgElement
sibling
,
bool
autoF
ix
ID
=
true
,
bool
autoFixChildrenID
=
true
,
Action
<
SvgElement
,
string
,
string
>
logElementOldIDNewID
=
null
)
private
void
AddToIdManager
(
SvgElement
item
,
SvgElement
sibling
,
bool
autoF
orceUnique
ID
=
true
,
bool
autoFixChildrenID
=
true
,
Action
<
SvgElement
,
string
,
string
>
logElementOldIDNewID
=
null
)
{
if
(!
this
.
_mock
)
{
if
(
this
.
_owner
.
OwnerDocument
!=
null
)
{
this
.
_owner
.
OwnerDocument
.
IdManager
.
AddAndF
ix
ID
(
item
,
sibling
,
autoF
ix
ID
,
logElementOldIDNewID
);
this
.
_owner
.
OwnerDocument
.
IdManager
.
AddAndF
orceUnique
ID
(
item
,
sibling
,
autoF
orceUnique
ID
,
logElementOldIDNewID
);
if
(!(
item
is
SvgDocument
))
//don't add subtree of a document to parent document
{
foreach
(
var
child
in
item
.
Children
)
{
child
.
ApplyRecursive
(
e
=>
this
.
_owner
.
OwnerDocument
.
IdManager
.
AddAndF
ix
ID
(
e
,
null
,
autoFixChildrenID
,
logElementOldIDNewID
));
child
.
ApplyRecursive
(
e
=>
this
.
_owner
.
OwnerDocument
.
IdManager
.
AddAndF
orceUnique
ID
(
e
,
null
,
autoFixChildrenID
,
logElementOldIDNewID
));
}
}
}
...
...
Source/SvgElementIdManager.cs
View file @
0b3df0a9
...
...
@@ -48,7 +48,7 @@ namespace Svg
/// <param name="element">The <see cref="SvgElement"/> to be managed.</param>
public
virtual
void
Add
(
SvgElement
element
)
{
AddAndF
ix
ID
(
element
,
null
,
false
);
AddAndF
orceUnique
ID
(
element
,
null
,
false
);
}
/// <summary>
...
...
@@ -56,20 +56,20 @@ namespace Svg
/// And can auto fix the ID if it already exists or it starts with a number.
/// </summary>
/// <param name="element">The <see cref="SvgElement"/> to be managed.</param>
/// <param name="autoF
ix
ID">Pass true here, if you want the ID to be fixed</param>
/// <param name="autoF
orceUnique
ID">Pass true here, if you want the ID to be fixed</param>
/// <param name="logElementOldIDNewID">If not null, the action is called before the id is fixed</param>
/// <returns>true, if ID was altered</returns>
public
virtual
bool
AddAndF
ix
ID
(
SvgElement
element
,
SvgElement
sibling
,
bool
autoF
ix
ID
=
true
,
Action
<
SvgElement
,
string
,
string
>
logElementOldIDNewID
=
null
)
public
virtual
bool
AddAndF
orceUnique
ID
(
SvgElement
element
,
SvgElement
sibling
,
bool
autoF
orceUnique
ID
=
true
,
Action
<
SvgElement
,
string
,
string
>
logElementOldIDNewID
=
null
)
{
var
result
=
false
;
if
(!
string
.
IsNullOrEmpty
(
element
.
ID
))
{
var
newID
=
this
.
EnsureValidId
(
element
.
ID
,
autoF
ix
ID
);
if
(
autoF
ix
ID
&&
newID
!=
element
.
ID
)
var
newID
=
this
.
EnsureValidId
(
element
.
ID
,
autoF
orceUnique
ID
);
if
(
autoF
orceUnique
ID
&&
newID
!=
element
.
ID
)
{
if
(
logElementOldIDNewID
!=
null
)
logElementOldIDNewID
(
element
,
element
.
ID
,
newID
);
element
.
F
ix
ID
(
newID
);
element
.
F
orceUnique
ID
(
newID
);
result
=
true
;
}
this
.
_idValueMap
.
Add
(
element
.
ID
,
element
);
...
...
@@ -101,7 +101,7 @@ namespace Svg
/// <para>The ID cannot start with a digit.</para>
/// <para>An element with the same ID already exists within the containing <see cref="SvgDocument"/>.</para>
/// </exception>
public
string
EnsureValidId
(
string
id
,
bool
autoF
ix
ID
=
false
)
public
string
EnsureValidId
(
string
id
,
bool
autoF
orceUnique
ID
=
false
)
{
if
(
string
.
IsNullOrEmpty
(
id
))
...
...
@@ -111,7 +111,7 @@ namespace Svg
if
(
char
.
IsDigit
(
id
[
0
]))
{
if
(
autoF
ix
ID
)
if
(
autoF
orceUnique
ID
)
{
return
EnsureValidId
(
"id"
+
id
,
true
);
}
...
...
@@ -120,7 +120,7 @@ namespace Svg
if
(
this
.
_idValueMap
.
ContainsKey
(
id
))
{
if
(
autoF
ix
ID
)
if
(
autoF
orceUnique
ID
)
{
var
match
=
regex
.
Match
(
id
);
...
...
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