Commit 9fc47d84 authored by mrbean-bremen's avatar mrbean-bremen Committed by mrbean-bremen
Browse files

Added handling of invalid color as default color

- adapted test to check for default value
- see #399
parent 326dae7c
...@@ -554,10 +554,13 @@ namespace Svg.ExCSS ...@@ -554,10 +554,13 @@ namespace Svg.ExCSS
{ {
HtmlColor htmlColor; HtmlColor htmlColor;
if(HtmlColor.TryFromHex(color, out htmlColor)) if (HtmlColor.TryFromHex(color, out htmlColor))
return AddTerm(htmlColor); return AddTerm(htmlColor);
else
return false; // the value is invalid - remove the property to use the default value
RemoveCurrentProperty();
return true;
} }
#region Namespace #region Namespace
......
...@@ -62,8 +62,29 @@ namespace Svg.UnitTests ...@@ -62,8 +62,29 @@ namespace Svg.UnitTests
[TestMethod] [TestMethod]
public void Lexer_FileWithInvalidHex_ColorTagIsIgnored() public void Lexer_FileWithInvalidHex_ColorTagIsIgnored()
{ {
Assert.Inconclusive("This test fails due to a lexer error"); // valid colors
GenerateLexerTestFile("color: #0046;"); var doc = GenerateLexerTestFile("fill: #ff0000; stroke: #ffff00");
var path = doc.GetElementById<SvgPath>("path1");
Assert.AreEqual(System.Drawing.Color.Red, ((SvgColourServer)path.Fill).Colour);
Assert.AreEqual(System.Drawing.Color.Yellow, ((SvgColourServer)path.Stroke).Colour);
// invalid/valid color combinations - default color is used for each invalid color
doc = GenerateLexerTestFile("fill: #ff00; stroke: #00ff00");
path = doc.GetElementById<SvgPath>("path1");
// default fill color is Black
Assert.AreEqual(System.Drawing.Color.Black, ((SvgColourServer)path.Fill).Colour);
Assert.AreEqual(System.Drawing.Color.Lime, ((SvgColourServer)path.Stroke).Colour);
doc = GenerateLexerTestFile("fill: #fff; stroke: 005577");
path = doc.GetElementById<SvgPath>("path1");
Assert.AreEqual(System.Drawing.Color.White, ((SvgColourServer)path.Fill).Colour);
// default stroke color is null (transparent)
Assert.IsNull(path.Stroke);
doc = GenerateLexerTestFile("fill:; stroke: #00557;");
path = doc.GetElementById<SvgPath>("path1");
Assert.AreEqual(System.Drawing.Color.Black, ((SvgColourServer)path.Fill).Colour);
Assert.IsNull(path.Stroke);
} }
/// <summary> /// <summary>
......
<svg xmlns="http://www.w3.org/2000/svg" width="1092" height="453"> <svg xmlns="http://www.w3.org/2000/svg" width="1092" height="453">
<style type="text/css"> <style type="text/css">
.plot-zero {
/*[REPLACE]*/
#footer }
{ </style>
/*[REPLACE]*/
}
</style>
<g transform="translate(40,20)" style="opacity: 1;"> <g transform="translate(40,20)" style="opacity: 1;">
<path class="plot-zero" d="M0,0 H1042" style="opacity: 0;"></path> <path class="plot-zero" id="path1" d="M0,0 H1042"></path>
<path class="plot-now" d="" style="opacity: 0;"></path> <path class="plot-now" d="" style="opacity: 0;"></path>
</g> </g>
<clipPath id="clip-view-2"> <clipPath id="clip-view-2">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment