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
454673b8
Commit
454673b8
authored
Jun 27, 2013
by
Tebjan Halm
Browse files
Merge pull request #4 from Ralf1108/master
Write fill attribute value if it differs from parent element, as a temporal fix.
parents
df86976f
12818509
Changes
3
Hide whitespace changes
Inline
Side-by-side
Source/Document Structure/SvgGroup.cs
View file @
454673b8
...
...
@@ -26,7 +26,7 @@ namespace Svg
[
SvgAttribute
(
"fill"
)]
public
override
SvgPaintServer
Fill
{
get
{
return
(
this
.
Attributes
[
"Fill"
]
==
null
)
?
n
ew
SvgColourServer
(
Color
.
Transparent
)
:
(
SvgPaintServer
)
this
.
Attributes
[
"Fill"
];
}
get
{
return
(
this
.
Attributes
[
"Fill"
]
==
null
)
?
n
ull
:
(
SvgPaintServer
)
this
.
Attributes
[
"Fill"
];
}
set
{
this
.
Attributes
[
"Fill"
]
=
value
;
}
}
...
...
Source/Painting/SvgColourServer.cs
View file @
454673b8
...
...
@@ -61,5 +61,18 @@ namespace Svg
}
public
override
bool
Equals
(
object
obj
)
{
var
objColor
=
obj
as
SvgColourServer
;
if
(
objColor
==
null
)
return
false
;
return
this
.
GetHashCode
()
==
objColor
.
GetHashCode
();
}
public
override
int
GetHashCode
()
{
return
_colour
.
GetHashCode
();
}
}
}
Source/SvgElement.cs
View file @
454673b8
...
...
@@ -357,20 +357,34 @@ namespace Svg
{
object
propertyValue
=
attr
.
Property
.
GetValue
(
this
);
var
forceWrite
=
false
;
if
((
attr
.
Attribute
.
Name
==
"fill"
)
&&
(
Parent
!=
null
))
{
object
parentValue
;
if
(
TryResolveParentAttributeValue
(
attr
.
Attribute
.
Name
,
out
parentValue
))
{
if
((
parentValue
==
propertyValue
)
||
((
parentValue
!=
null
)
&&
parentValue
.
Equals
(
propertyValue
)))
continue
;
forceWrite
=
true
;
}
}
if
(
propertyValue
!=
null
)
{
var
type
=
propertyValue
.
GetType
();
string
value
=
(
string
)
attr
.
Property
.
Converter
.
ConvertTo
(
propertyValue
,
typeof
(
string
));
if
(!
SvgDefaults
.
IsDefault
(
attr
.
Attribute
.
Name
,
value
))
if
(!
SvgDefaults
.
IsDefault
(
attr
.
Attribute
.
Name
,
value
)
||
forceWrite
)
{
writer
.
WriteAttributeString
(
attr
.
Attribute
.
NamespaceAndName
,
value
);
writer
.
WriteAttributeString
(
attr
.
Attribute
.
NamespaceAndName
,
value
);
}
}
else
if
(
attr
.
Attribute
.
Name
==
"fill"
)
//if fill equals null, write 'none'
{
string
value
=
(
string
)
attr
.
Property
.
Converter
.
ConvertTo
(
propertyValue
,
typeof
(
string
));
writer
.
WriteAttributeString
(
attr
.
Attribute
.
NamespaceAndName
,
value
);
string
value
=
(
string
)
attr
.
Property
.
Converter
.
ConvertTo
(
propertyValue
,
typeof
(
string
));
writer
.
WriteAttributeString
(
attr
.
Attribute
.
NamespaceAndName
,
value
);
}
}
}
...
...
@@ -380,7 +394,29 @@ namespace Svg
{
writer
.
WriteAttributeString
(
item
.
Key
,
item
.
Value
);
}
}
private
bool
TryResolveParentAttributeValue
(
string
attributeKey
,
out
object
parentAttributeValue
)
{
parentAttributeValue
=
null
;
attributeKey
=
char
.
ToUpper
(
attributeKey
[
0
])
+
attributeKey
.
Substring
(
1
);
var
currentParent
=
Parent
;
var
resolved
=
false
;
while
(
currentParent
!=
null
)
{
if
(
currentParent
.
Attributes
.
ContainsKey
(
attributeKey
))
{
resolved
=
true
;
parentAttributeValue
=
currentParent
.
Attributes
[
attributeKey
];
if
(
parentAttributeValue
!=
null
)
break
;
}
currentParent
=
currentParent
.
Parent
;
}
return
resolved
;
}
protected
virtual
void
Write
(
XmlTextWriter
writer
)
...
...
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