From 8138e4e244d776cc252dc11e9c2e72bb0c6de1e0 Mon Sep 17 00:00:00 2001 From: Sawraz-IS Date: Wed, 6 Aug 2025 13:57:49 +0600 Subject: [PATCH 1/2] DW-35: Align Color FromName with System.Drawing --- .gitignore | 4 ++ .../UnitTests/ColorFunctionality.cs | 23 ++++++ .../IronSoftware.Drawing.Common/Color.cs | 28 ++++++-- .../IronSoftware.Drawing.Common/KnownColor.cs | 69 +++++++++--------- .../KnownColors.cs | 72 ++++++++++--------- 5 files changed, 122 insertions(+), 74 deletions(-) diff --git a/.gitignore b/.gitignore index dfcfd56..d4f75d6 100644 --- a/.gitignore +++ b/.gitignore @@ -116,6 +116,10 @@ ipch/ # Visual Studio Trace Files *.e2e +# JetBrains IDE settings (e.g., IntelliJ, Rider, PyCharm) +.idea/ + + # TFS 2012 Local Workspace $tf/ diff --git a/IronSoftware.Drawing/IronSoftware.Drawing.Common.Tests/UnitTests/ColorFunctionality.cs b/IronSoftware.Drawing/IronSoftware.Drawing.Common.Tests/UnitTests/ColorFunctionality.cs index abe8e17..10cf8af 100644 --- a/IronSoftware.Drawing/IronSoftware.Drawing.Common.Tests/UnitTests/ColorFunctionality.cs +++ b/IronSoftware.Drawing/IronSoftware.Drawing.Common.Tests/UnitTests/ColorFunctionality.cs @@ -525,46 +525,69 @@ public void Should_Create_FromName() _ = color.R.Should().Be(255); _ = color.G.Should().Be(0); _ = color.B.Should().Be(0); + _ = color.IsKnownColor.Should().BeTrue(); color = Color.FromName("green"); _ = color.R.Should().Be(0); _ = color.G.Should().Be(128); _ = color.B.Should().Be(0); + _ = color.IsKnownColor.Should().BeTrue(); color = Color.FromName("blue"); _ = color.R.Should().Be(0); _ = color.G.Should().Be(0); _ = color.B.Should().Be(255); + _ = color.IsKnownColor.Should().BeTrue(); color = Color.FromName("yellow"); _ = color.R.Should().Be(255); _ = color.G.Should().Be(255); _ = color.B.Should().Be(0); + _ = color.IsKnownColor.Should().BeTrue(); color = Color.FromName("pink"); _ = color.R.Should().Be(255); _ = color.G.Should().Be(192); _ = color.B.Should().Be(203); + _ = color.IsKnownColor.Should().BeTrue(); color = Color.FromName("brown"); _ = color.R.Should().Be(165); _ = color.G.Should().Be(42); _ = color.B.Should().Be(42); + _ = color.IsKnownColor.Should().BeTrue(); color = Color.FromName("gray"); _ = color.R.Should().Be(128); _ = color.G.Should().Be(128); _ = color.B.Should().Be(128); + _ = color.IsKnownColor.Should().BeTrue(); color = Color.FromName("black"); _ = color.R.Should().Be(0); _ = color.G.Should().Be(0); _ = color.B.Should().Be(0); + _ = color.IsKnownColor.Should().BeTrue(); color = Color.FromName("orange"); _ = color.R.Should().Be(255); _ = color.G.Should().Be(165); _ = color.B.Should().Be(0); + _ = color.IsKnownColor.Should().BeTrue(); + + color = Color.FromName("RebeccaPurple"); + _ = color.A.Should().Be(255); + _ = color.R.Should().Be(102); + _ = color.G.Should().Be(51); + _ = color.B.Should().Be(153); + _ = color.IsKnownColor.Should().BeTrue(); + + color = Color.FromName("NotAColor"); + _ = color.A.Should().Be(0); + _ = color.R.Should().Be(0); + _ = color.G.Should().Be(0); + _ = color.B.Should().Be(0); + _ = color.IsKnownColor.Should().BeFalse(); } [FactWithAutomaticDisplayName] diff --git a/IronSoftware.Drawing/IronSoftware.Drawing.Common/Color.cs b/IronSoftware.Drawing/IronSoftware.Drawing.Common/Color.cs index 3600abe..004ad74 100644 --- a/IronSoftware.Drawing/IronSoftware.Drawing.Common/Color.cs +++ b/IronSoftware.Drawing/IronSoftware.Drawing.Common/Color.cs @@ -35,6 +35,12 @@ public partial class Color /// /// The red component value of this . public byte R { get; internal set; } + + /// + /// Gets a value indicating whether this structure is a predefined color. + /// + /// if this was created from a predefined color; otherwise, . + public bool IsKnownColor { get; internal set; } /// /// Construct a new . @@ -889,21 +895,31 @@ public static Color FromArgb(int argb) } /// - /// Creates a structure from the specified name of a predefined color. + /// Creates a structure from the name of a color. If the name is a predefined color, a known Color is returned. If the name is not a known color, a new Color with ARGB values of 0 is returned. /// - /// - /// + /// A string that is the name of a color. The comparison is case-insensitive. + /// + /// The that this method creates. If the color name is found, the corresponding known Color is returned; otherwise, a Color representing transparent black (A=0, R=0, G=0, B=0) is returned. + /// + /// + /// The returned will have its property set to if the name was found in the list of known colors, and otherwise. + /// public static Color FromName(string name) { if (!string.IsNullOrEmpty(name)) { if (KnownColors.ArgbByName.TryGetValue(name.ToLower(), out uint argb)) { - return FromArgb((int)argb); + Color knownColor = FromArgb((int)argb); + knownColor.IsKnownColor = true; + return knownColor; } } - - throw new InvalidOperationException($"{name} is unable to convert to {typeof(Color)} because it requires a suitable name."); + + // If name is not found, return a color with ARGB values of 0, and IsKnownColor set to false. + Color newColor = new Color(0, 0, 0, 0); + newColor.IsKnownColor = false; + return newColor; } /// diff --git a/IronSoftware.Drawing/IronSoftware.Drawing.Common/KnownColor.cs b/IronSoftware.Drawing/IronSoftware.Drawing.Common/KnownColor.cs index 5c000bb..705ad81 100644 --- a/IronSoftware.Drawing/IronSoftware.Drawing.Common/KnownColor.cs +++ b/IronSoftware.Drawing/IronSoftware.Drawing.Common/KnownColor.cs @@ -143,40 +143,41 @@ public enum KnownColor Plum = 138, PowderBlue = 139, Purple = 140, - Red = 141, - RosyBrown = 142, - RoyalBlue = 143, - SaddleBrown = 144, - Salmon = 145, - SandyBrown = 146, - SeaGreen = 147, - SeaShell = 148, - Sienna = 149, - Silver = 150, - SkyBlue = 151, - SlateBlue = 152, - SlateGray = 153, - Snow = 154, - SpringGreen = 155, - SteelBlue = 156, - Tan = 157, - Teal = 158, - Thistle = 159, - Tomato = 160, - Turquoise = 161, - Violet = 162, - Wheat = 163, - White = 164, - WhiteSmoke = 165, - Yellow = 166, - YellowGreen = 167, - ButtonFace = 168, - ButtonHighlight = 169, - ButtonShadow = 170, - GradientActiveCaption = 171, - GradientInactiveCaption = 172, - MenuBar = 173, - MenuHighlight = 174 + RebeccaPurple = 141, + Red = 142, + RosyBrown = 143, + RoyalBlue = 144, + SaddleBrown = 145, + Salmon = 146, + SandyBrown = 147, + SeaGreen = 148, + SeaShell = 149, + Sienna = 150, + Silver = 151, + SkyBlue = 152, + SlateBlue = 153, + SlateGray = 154, + Snow = 155, + SpringGreen = 156, + SteelBlue = 157, + Tan = 158, + Teal = 159, + Thistle = 160, + Tomato = 161, + Turquoise = 162, + Violet = 163, + Wheat = 164, + White = 165, + WhiteSmoke = 166, + Yellow = 167, + YellowGreen = 168, + ButtonFace = 169, + ButtonHighlight = 170, + ButtonShadow = 171, + GradientActiveCaption = 172, + GradientInactiveCaption = 173, + MenuBar = 174, + MenuHighlight = 175 } #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member } diff --git a/IronSoftware.Drawing/IronSoftware.Drawing.Common/KnownColors.cs b/IronSoftware.Drawing/IronSoftware.Drawing.Common/KnownColors.cs index 307cc9b..9b2f6bc 100644 --- a/IronSoftware.Drawing/IronSoftware.Drawing.Common/KnownColors.cs +++ b/IronSoftware.Drawing/IronSoftware.Drawing.Common/KnownColors.cs @@ -147,40 +147,41 @@ internal class KnownColors 0xFFDDA0DD, /* 138 - Plum */ 0xFFB0E0E6, /* 139 - PowderBlue */ 0xFF800080, /* 140 - Purple */ - 0xFFFF0000, /* 141 - Red */ - 0xFFBC8F8F, /* 142 - RosyBrown */ - 0xFF4169E1, /* 143 - RoyalBlue */ - 0xFF8B4513, /* 144 - SaddleBrown */ - 0xFFFA8072, /* 145 - Salmon */ - 0xFFF4A460, /* 146 - SandyBrown */ - 0xFF2E8B57, /* 147 - SeaGreen */ - 0xFFFFF5EE, /* 148 - SeaShell */ - 0xFFA0522D, /* 149 - Sienna */ - 0xFFC0C0C0, /* 150 - Silver */ - 0xFF87CEEB, /* 151 - SkyBlue */ - 0xFF6A5ACD, /* 152 - SlateBlue */ - 0xFF708090, /* 153 - SlateGray */ - 0xFFFFFAFA, /* 154 - Snow */ - 0xFF00FF7F, /* 155 - SpringGreen */ - 0xFF4682B4, /* 156 - SteelBlue */ - 0xFFD2B48C, /* 157 - Tan */ - 0xFF008080, /* 158 - Teal */ - 0xFFD8BFD8, /* 159 - Thistle */ - 0xFFFF6347, /* 160 - Tomato */ - 0xFF40E0D0, /* 161 - Turquoise */ - 0xFFEE82EE, /* 162 - Violet */ - 0xFFF5DEB3, /* 163 - Wheat */ - 0xFFFFFFFF, /* 164 - White */ - 0xFFF5F5F5, /* 165 - WhiteSmoke */ - 0xFFFFFF00, /* 166 - Yellow */ - 0xFF9ACD32, /* 167 - YellowGreen */ - 0xFFECE9D8, /* 168 - ButtonFace */ - 0xFFFFFFFF, /* 169 - ButtonHighlight */ - 0xFFACA899, /* 170 - ButtonShadow */ - 0xFF3D95FF, /* 171 - GradientActiveCaption */ - 0xFF9DB9EB, /* 172 - GradientInactiveCaption */ - 0xFFECE9D8, /* 173 - MenuBar */ - 0xFF316AC5, /* 174 - MenuHighlight */ + 0xFF663399, /* 141 - RebeccaPurple */ + 0xFFFF0000, /* 142 - Red */ + 0xFFBC8F8F, /* 143 - RosyBrown */ + 0xFF4169E1, /* 144 - RoyalBlue */ + 0xFF8B4513, /* 145 - SaddleBrown */ + 0xFFFA8072, /* 146 - Salmon */ + 0xFFF4A460, /* 147 - SandyBrown */ + 0xFF2E8B57, /* 148 - SeaGreen */ + 0xFFFFF5EE, /* 149 - SeaShell */ + 0xFFA0522D, /* 150 - Sienna */ + 0xFFC0C0C0, /* 151 - Silver */ + 0xFF87CEEB, /* 152 - SkyBlue */ + 0xFF6A5ACD, /* 153 - SlateBlue */ + 0xFF708090, /* 154 - SlateGray */ + 0xFFFFFAFA, /* 155 - Snow */ + 0xFF00FF7F, /* 156 - SpringGreen */ + 0xFF4682B4, /* 157 - SteelBlue */ + 0xFFD2B48C, /* 158 - Tan */ + 0xFF008080, /* 159 - Teal */ + 0xFFD8BFD8, /* 160 - Thistle */ + 0xFFFF6347, /* 161 - Tomato */ + 0xFF40E0D0, /* 162 - Turquoise */ + 0xFFEE82EE, /* 163 - Violet */ + 0xFFF5DEB3, /* 164 - Wheat */ + 0xFFFFFFFF, /* 165 - White */ + 0xFFF5F5F5, /* 166 - WhiteSmoke */ + 0xFFFFFF00, /* 167 - Yellow */ + 0xFF9ACD32, /* 168 - YellowGreen */ + 0xFFECE9D8, /* 169 - ButtonFace */ + 0xFFFFFFFF, /* 170 - ButtonHighlight */ + 0xFFACA899, /* 171 - ButtonShadow */ + 0xFF3D95FF, /* 172 - GradientActiveCaption */ + 0xFF9DB9EB, /* 173 - GradientInactiveCaption */ + 0xFFECE9D8, /* 174 - MenuBar */ + 0xFF316AC5, /* 175 - MenuHighlight */ }; internal static string[] Names = { @@ -325,6 +326,7 @@ internal class KnownColors "Plum", "PowderBlue", "Purple", + "RebeccaPurple", "Red", "RosyBrown", "RoyalBlue", @@ -404,10 +406,12 @@ public static Color FromKnownColor(KnownColor kc) if ((n <= 0) || (n >= ArgbValues.Length)) { c = Color.FromArgb(0); + c.IsKnownColor = false; } else { c = Color.FromArgb((int)ArgbValues[n]); + c.IsKnownColor = true; } return c; From 85c2ec54a8c48c4f87cd630da4c2602d56749d20 Mon Sep 17 00:00:00 2001 From: Sawraz-IS Date: Wed, 13 Aug 2025 11:30:44 +0600 Subject: [PATCH 2/2] DW-35: Fix IsKnownColor Issue --- .../UnitTests/ColorFunctionality.cs | 21 +- .../IronSoftware.Drawing.Common/Color.cs | 361 ++++++++++-------- .../KnownColors.cs | 31 +- 3 files changed, 246 insertions(+), 167 deletions(-) diff --git a/IronSoftware.Drawing/IronSoftware.Drawing.Common.Tests/UnitTests/ColorFunctionality.cs b/IronSoftware.Drawing/IronSoftware.Drawing.Common.Tests/UnitTests/ColorFunctionality.cs index 10cf8af..e64767a 100644 --- a/IronSoftware.Drawing/IronSoftware.Drawing.Common.Tests/UnitTests/ColorFunctionality.cs +++ b/IronSoftware.Drawing/IronSoftware.Drawing.Common.Tests/UnitTests/ColorFunctionality.cs @@ -19,18 +19,21 @@ public void Create_new_Color() Assert.Equal(25, color.R); Assert.Equal(25, color.G); Assert.Equal(25, color.B); + Assert.False(color.IsKnownColor); color = new Color("#800080"); Assert.Equal(255, color.A); Assert.Equal(128, color.R); Assert.Equal(0, color.G); Assert.Equal(128, color.B); + Assert.False(color.IsKnownColor); color = new Color("#F0F"); Assert.Equal(255, color.A); Assert.Equal(255, color.R); Assert.Equal(0, color.G); Assert.Equal(255, color.B); + Assert.False(color.IsKnownColor); InvalidOperationException ex = Assert.Throws(() => color = new Color("#F")); Assert.Equal($"#F is unable to convert to {typeof(Color)} because it requires a suitable length of string.", ex.Message); @@ -40,12 +43,14 @@ public void Create_new_Color() Assert.Equal(255, color.R); Assert.Equal(0, color.G); Assert.Equal(255, color.B); + Assert.False(color.IsKnownColor); color = new Color(255, 0, 255); Assert.Equal(255, color.A); Assert.Equal(255, color.R); Assert.Equal(0, color.G); Assert.Equal(255, color.B); + Assert.False(color.IsKnownColor); } [FactWithAutomaticDisplayName] @@ -55,21 +60,25 @@ public void Create_correct_color_from_system_defined() Assert.Equal(154, Color.YellowGreen.R); Assert.Equal(205, Color.YellowGreen.G); Assert.Equal(50, Color.YellowGreen.B); + Assert.True(Color.YellowGreen.IsKnownColor); Assert.Equal(255, Color.Violet.A); Assert.Equal(238, Color.Violet.R); Assert.Equal(130, Color.Violet.G); Assert.Equal(238, Color.Violet.B); + Assert.True(Color.Violet.IsKnownColor); Assert.Equal(0, Color.Transparent.A); Assert.Equal(255, Color.Transparent.R); Assert.Equal(255, Color.Transparent.G); Assert.Equal(255, Color.Transparent.B); + Assert.True(Color.Transparent.IsKnownColor); Assert.Equal(255, Color.Azure.A); Assert.Equal(240, Color.Azure.R); Assert.Equal(255, Color.Azure.G); Assert.Equal(255, Color.Azure.B); + Assert.True(Color.Azure.IsKnownColor); } [FactWithAutomaticDisplayName] @@ -82,6 +91,7 @@ public void Create_color_from_RGB() Assert.Equal(244, color.G); Assert.Equal(208, color.B); Assert.Equal("#FF40F4D0", color.ToString()); + Assert.False(color.IsKnownColor); color = Color.FromArgb(0, 64, 244, 208); @@ -90,7 +100,7 @@ public void Create_color_from_RGB() Assert.Equal(244, color.G); Assert.Equal(208, color.B); Assert.Equal("#0040F4D0", color.ToString()); - + Assert.False(color.IsKnownColor); } [FactWithAutomaticDisplayName] @@ -103,12 +113,14 @@ public void Create_color_from_ARGB() Assert.Equal(244, color.G); Assert.Equal(208, color.B); Assert.Equal("#6440F4D0", color.ToString()); + Assert.False(color.IsKnownColor); var color1 = Color.FromArgb(50, color); Assert.Equal(50, color1.A); Assert.Equal(64, color1.R); Assert.Equal(244, color1.G); Assert.Equal(208, color1.B); + Assert.False(color.IsKnownColor); } [FactWithAutomaticDisplayName] @@ -116,12 +128,15 @@ public void Get_Luminance_from_color() { Color color = Color.Black; Assert.Equal(0, color.GetLuminance()); + Assert.True(color.IsKnownColor); color = Color.Gray; Assert.Equal(50, color.GetLuminance()); + Assert.True(color.IsKnownColor); color = Color.White; Assert.Equal(100, color.GetLuminance()); + Assert.True(color.IsKnownColor); } [FactWithAutomaticDisplayName] @@ -133,6 +148,7 @@ public void Cast_System_Drawing_Color_from_Color() Assert.Equal(255, red.R); Assert.Equal(0, red.G); Assert.Equal(0, red.B); + Assert.False(red.IsKnownColor); drawingColor = System.Drawing.Color.FromArgb(255, 0, 255, 0); Color green = drawingColor; @@ -140,6 +156,7 @@ public void Cast_System_Drawing_Color_from_Color() Assert.Equal(0, green.R); Assert.Equal(255, green.G); Assert.Equal(0, green.B); + Assert.False(green.IsKnownColor); drawingColor = System.Drawing.Color.FromArgb(0, 0, 255); Color blue = drawingColor; @@ -147,6 +164,7 @@ public void Cast_System_Drawing_Color_from_Color() Assert.Equal(0, blue.R); Assert.Equal(0, blue.G); Assert.Equal(255, blue.B); + Assert.False(blue.IsKnownColor); int iColorCode = Convert.ToInt32("1e81b0", 16); drawingColor = System.Drawing.Color.FromArgb(iColorCode); @@ -155,6 +173,7 @@ public void Cast_System_Drawing_Color_from_Color() Assert.Equal(30, color.R); Assert.Equal(129, color.G); Assert.Equal(176, color.B); + Assert.False(color.IsKnownColor); } [FactWithAutomaticDisplayName] diff --git a/IronSoftware.Drawing/IronSoftware.Drawing.Common/Color.cs b/IronSoftware.Drawing/IronSoftware.Drawing.Common/Color.cs index 004ad74..19d8e24 100644 --- a/IronSoftware.Drawing/IronSoftware.Drawing.Common/Color.cs +++ b/IronSoftware.Drawing/IronSoftware.Drawing.Common/Color.cs @@ -11,6 +11,7 @@ namespace IronSoftware.Drawing /// public partial class Color { + private readonly bool _isKnownColor; /// /// Gets the alpha component value of this structure. @@ -35,12 +36,12 @@ public partial class Color /// /// The red component value of this . public byte R { get; internal set; } - + /// /// Gets a value indicating whether this structure is a predefined color. /// /// if this was created from a predefined color; otherwise, . - public bool IsKnownColor { get; internal set; } + public bool IsKnownColor => _isKnownColor; /// /// Construct a new . @@ -76,6 +77,8 @@ public Color(string colorcode) { throw NoConverterException(colorcode, null); } + + _isKnownColor = false; } /// @@ -92,6 +95,7 @@ public Color(int alpha, int red, int green, int blue) R = (byte)red; G = (byte)green; B = (byte)blue; + _isKnownColor = false; } /// @@ -107,6 +111,29 @@ public Color(int red, int green, int blue) R = (byte)red; G = (byte)green; B = (byte)blue; + _isKnownColor = false; + } + + /// + /// Construct a new from a packed ARGB integer value. + /// This constructor is intended for internal use when creating known colors, + /// ensuring the correct immutable state is set. + /// + /// + /// A 32-bit integer containing the alpha, red, green, and blue components in ARGB order. + /// The highest 8 bits represent the alpha component, followed by red, green, and blue. + /// + /// + /// Indicates whether the color is a predefined known color, used to control internal immutability behavior. + /// + internal Color(int argb, bool isKnownColor) + { + // This constructor is used internally to create known colors with the correct immutable flag. + A = (byte)(argb >> 24); + R = (byte)(argb >> 16); + G = (byte)(argb >> 8); + B = (byte)argb; + _isKnownColor = isKnownColor; } /// @@ -117,712 +144,712 @@ public Color(int red, int green, int blue) /// Gets a system-defined color that has an ARGB value of #F0F8FF. /// /// A representing a system-defined color. - public static readonly Color AliceBlue = new("#F0F8FF"); + public static readonly Color AliceBlue = FromKnownColor(KnownColor.AliceBlue); /// /// Gets a system-defined color that has an ARGB value of #FAEBD7. /// /// A representing a system-defined color. - public static readonly Color AntiqueWhite = new("#FAEBD7"); + public static readonly Color AntiqueWhite = FromKnownColor(KnownColor.AntiqueWhite); /// /// Gets a system-defined color that has an ARGB value of #00FFFF. /// /// A representing a system-defined color. - public static readonly Color Aqua = new("#00FFFF"); + public static readonly Color Aqua = FromKnownColor(KnownColor.Aqua); /// /// Gets a system-defined color that has an ARGB value of #7FFFD4. /// /// A representing a system-defined color. - public static readonly Color Aquamarine = new("#7FFFD4"); + public static readonly Color Aquamarine = FromKnownColor(KnownColor.Aquamarine); /// /// Gets a system-defined color that has an ARGB value of #F0FFFF. /// /// A representing a system-defined color. - public static readonly Color Azure = new("#F0FFFF"); + public static readonly Color Azure = FromKnownColor(KnownColor.Azure); /// /// Gets a system-defined color that has an ARGB value of #F5F5DC. /// /// A representing a system-defined color. - public static readonly Color Beige = new("#F5F5DC"); + public static readonly Color Beige = FromKnownColor(KnownColor.Beige); /// /// Gets a system-defined color that has an ARGB value of #FFE4C4. /// /// A representing a system-defined color. - public static readonly Color Bisque = new("#FFE4C4"); + public static readonly Color Bisque = FromKnownColor(KnownColor.Bisque); /// /// Gets a system-defined color that has an ARGB value of #000000. /// /// A representing a system-defined color. - public static readonly Color Black = new("#000000"); + public static readonly Color Black = FromKnownColor(KnownColor.Black); /// /// Gets a system-defined color that has an ARGB value of #FFEBCD. /// /// A representing a system-defined color. - public static readonly Color BlanchedAlmond = new("#FFEBCD"); + public static readonly Color BlanchedAlmond = FromKnownColor(KnownColor.BlanchedAlmond); /// /// Gets a system-defined color that has an ARGB value of #0000FF. /// /// A representing a system-defined color. - public static readonly Color Blue = new("#0000FF"); + public static readonly Color Blue = FromKnownColor(KnownColor.Blue); /// /// Gets a system-defined color that has an ARGB value of #8A2BE2. /// /// A representing a system-defined color. - public static readonly Color BlueViolet = new("#8A2BE2"); + public static readonly Color BlueViolet = FromKnownColor(KnownColor.BlueViolet); /// /// Gets a system-defined color that has an ARGB value of #A52A2A. /// /// A representing a system-defined color. - public static readonly Color Brown = new("#A52A2A"); + public static readonly Color Brown = FromKnownColor(KnownColor.Brown); /// /// Gets a system-defined color that has an ARGB value of #DEB887. /// /// A representing a system-defined color. - public static readonly Color BurlyWood = new("#DEB887"); + public static readonly Color BurlyWood = FromKnownColor(KnownColor.BurlyWood); /// /// Gets a system-defined color that has an ARGB value of #5F9EA0. /// /// A representing a system-defined color. - public static readonly Color CadetBlue = new("#5F9EA0"); + public static readonly Color CadetBlue = FromKnownColor(KnownColor.CadetBlue); /// /// Gets a system-defined color that has an ARGB value of #7FFF00. /// /// A representing a system-defined color. - public static readonly Color Chartreuse = new("#7FFF00"); + public static readonly Color Chartreuse = FromKnownColor(KnownColor.Chartreuse); /// /// Gets a system-defined color that has an ARGB value of #D2691E. /// /// A representing a system-defined color. - public static readonly Color Chocolate = new("#D2691E"); + public static readonly Color Chocolate = FromKnownColor(KnownColor.Chocolate); /// /// Gets a system-defined color that has an ARGB value of #FF7F50. /// /// A representing a system-defined color. - public static readonly Color Coral = new("#FF7F50"); + public static readonly Color Coral = FromKnownColor(KnownColor.Coral); /// /// Gets a system-defined color that has an ARGB value of #6495ED. /// /// A representing a system-defined color. - public static readonly Color CornflowerBlue = new("#6495ED"); + public static readonly Color CornflowerBlue = FromKnownColor(KnownColor.CornflowerBlue); /// /// Gets a system-defined color that has an ARGB value of #FFF8DC. /// /// A representing a system-defined color. - public static readonly Color Cornsilk = new("#FFF8DC"); + public static readonly Color Cornsilk = FromKnownColor(KnownColor.Cornsilk); /// /// Gets a system-defined color that has an ARGB value of #DC143C. /// /// A representing a system-defined color. - public static readonly Color Crimson = new("#DC143C"); + public static readonly Color Crimson = FromKnownColor(KnownColor.Crimson); /// /// Gets a system-defined color that has an ARGB value of #00FFFF. /// /// A representing a system-defined color. - public static readonly Color Cyan = new("#00FFFF"); + public static readonly Color Cyan = FromKnownColor(KnownColor.Cyan); /// /// Gets a system-defined color that has an ARGB value of #00008B. /// /// A representing a system-defined color. - public static readonly Color DarkBlue = new("#00008B"); + public static readonly Color DarkBlue = FromKnownColor(KnownColor.DarkBlue); /// /// Gets a system-defined color that has an ARGB value of #008B8B. /// /// A representing a system-defined color. - public static readonly Color DarkCyan = new("#008B8B"); + public static readonly Color DarkCyan = FromKnownColor(KnownColor.DarkCyan); /// /// Gets a system-defined color that has an ARGB value of #B8860B. /// /// A representing a system-defined color. - public static readonly Color DarkGoldenrod = new("#B8860B"); + public static readonly Color DarkGoldenrod = FromKnownColor(KnownColor.DarkGoldenrod); /// /// Gets a system-defined color that has an ARGB value of #A9A9A9. /// /// A representing a system-defined color. - public static readonly Color DarkGray = new("#A9A9A9"); + public static readonly Color DarkGray = FromKnownColor(KnownColor.DarkGray); /// /// Gets a system-defined color that has an ARGB value of #006400. /// /// A representing a system-defined color. - public static readonly Color DarkGreen = new("#006400"); + public static readonly Color DarkGreen = FromKnownColor(KnownColor.DarkGreen); /// /// Gets a system-defined color that has an ARGB value of #BDB76B. /// /// A representing a system-defined color. - public static readonly Color DarkKhaki = new("#BDB76B"); + public static readonly Color DarkKhaki = FromKnownColor(KnownColor.DarkKhaki); /// /// Gets a system-defined color that has an ARGB value of #8B008B. /// /// A representing a system-defined color. - public static readonly Color DarkMagenta = new("#8B008B"); + public static readonly Color DarkMagenta = FromKnownColor(KnownColor.DarkMagenta); /// /// Gets a system-defined color that has an ARGB value of #556B2F. /// /// A representing a system-defined color. - public static readonly Color DarkOliveGreen = new("#556B2F"); + public static readonly Color DarkOliveGreen = FromKnownColor(KnownColor.DarkOliveGreen); /// /// Gets a system-defined color that has an ARGB value of #FF8C00. /// /// A representing a system-defined color. - public static readonly Color DarkOrange = new("#FF8C00"); + public static readonly Color DarkOrange = FromKnownColor(KnownColor.DarkOrange); /// /// Gets a system-defined color that has an ARGB value of #9932CC. /// /// A representing a system-defined color. - public static readonly Color DarkOrchid = new("#9932CC"); + public static readonly Color DarkOrchid = FromKnownColor(KnownColor.DarkOrchid); /// /// Gets a system-defined color that has an ARGB value of #8B0000. /// /// A representing a system-defined color. - public static readonly Color DarkRed = new("#8B0000"); + public static readonly Color DarkRed = FromKnownColor(KnownColor.DarkRed); /// /// Gets a system-defined color that has an ARGB value of #E9967A. /// /// A representing a system-defined color. - public static readonly Color DarkSalmon = new("#E9967A"); + public static readonly Color DarkSalmon = FromKnownColor(KnownColor.DarkSalmon); /// /// Gets a system-defined color that has an ARGB value of #8FBC8B. /// /// A representing a system-defined color. - public static readonly Color DarkSeaGreen = new("#8FBC8B"); + public static readonly Color DarkSeaGreen = FromKnownColor(KnownColor.DarkSeaGreen); /// /// Gets a system-defined color that has an ARGB value of #483D8B. /// /// A representing a system-defined color. - public static readonly Color DarkSlateBlue = new("#483D8B"); + public static readonly Color DarkSlateBlue = FromKnownColor(KnownColor.DarkSlateBlue); /// /// Gets a system-defined color that has an ARGB value of #2F4F4F. /// /// A representing a system-defined color. - public static readonly Color DarkSlateGray = new("#2F4F4F"); + public static readonly Color DarkSlateGray = FromKnownColor(KnownColor.DarkSlateGray); /// /// Gets a system-defined color that has an ARGB value of #00CED1. /// /// A representing a system-defined color. - public static readonly Color DarkTurquoise = new("#00CED1"); + public static readonly Color DarkTurquoise = FromKnownColor(KnownColor.DarkTurquoise); /// /// Gets a system-defined color that has an ARGB value of #9400D3. /// /// A representing a system-defined color. - public static readonly Color DarkViolet = new("#9400D3"); + public static readonly Color DarkViolet = FromKnownColor(KnownColor.DarkViolet); /// /// Gets a system-defined color that has an ARGB value of #FF1493. /// /// A representing a system-defined color. - public static readonly Color DeepPink = new("#FF1493"); + public static readonly Color DeepPink = FromKnownColor(KnownColor.DeepPink); /// /// Gets a system-defined color that has an ARGB value of #00BFFF. /// /// A representing a system-defined color. - public static readonly Color DeepSkyBlue = new("#00BFFF"); + public static readonly Color DeepSkyBlue = FromKnownColor(KnownColor.DeepSkyBlue); /// /// Gets a system-defined color that has an ARGB value of #696969. /// /// A representing a system-defined color. - public static readonly Color DimGray = new("#696969"); + public static readonly Color DimGray = FromKnownColor(KnownColor.DimGray); /// /// Gets a system-defined color that has an ARGB value of #1E90FF. /// /// A representing a system-defined color. - public static readonly Color DodgerBlue = new("#1E90FF"); + public static readonly Color DodgerBlue = FromKnownColor(KnownColor.DodgerBlue); /// /// Gets a system-defined color that has an ARGB value of #B22222. /// /// A representing a system-defined color. - public static readonly Color Firebrick = new("#B22222"); + public static readonly Color Firebrick = FromKnownColor(KnownColor.Firebrick); /// /// Gets a system-defined color that has an ARGB value of #FFFAF0. /// /// A representing a system-defined color. - public static readonly Color FloralWhite = new("#FFFAF0"); + public static readonly Color FloralWhite = FromKnownColor(KnownColor.FloralWhite); /// /// Gets a system-defined color that has an ARGB value of #228B22. /// /// A representing a system-defined color. - public static readonly Color ForestGreen = new("#228B22"); + public static readonly Color ForestGreen = FromKnownColor(KnownColor.ForestGreen); /// /// Gets a system-defined color that has an ARGB value of #FF00FF. /// /// A representing a system-defined color. - public static readonly Color Fuchsia = new("#FF00FF"); + public static readonly Color Fuchsia = FromKnownColor(KnownColor.Fuchsia); /// /// Gets a system-defined color that has an ARGB value of #DCDCDC. /// /// A representing a system-defined color. - public static readonly Color Gainsboro = new("#DCDCDC"); + public static readonly Color Gainsboro = FromKnownColor(KnownColor.Gainsboro); /// /// Gets a system-defined color that has an ARGB value of #F8F8FF. /// /// A representing a system-defined color. - public static readonly Color GhostWhite = new("#F8F8FF"); + public static readonly Color GhostWhite = FromKnownColor(KnownColor.GhostWhite); /// /// Gets a system-defined color that has an ARGB value of #FFD700. /// /// A representing a system-defined color. - public static readonly Color Gold = new("#FFD700"); + public static readonly Color Gold = FromKnownColor(KnownColor.Gold); /// /// Gets a system-defined color that has an ARGB value of #DAA520. /// /// A representing a system-defined color. - public static readonly Color Goldenrod = new("#DAA520"); + public static readonly Color Goldenrod = FromKnownColor(KnownColor.Goldenrod); /// /// Gets a system-defined color that has an ARGB value of #808080. /// /// A representing a system-defined color. - public static readonly Color Gray = new("#808080"); + public static readonly Color Gray = FromKnownColor(KnownColor.Gray); /// /// Gets a system-defined color that has an ARGB value of #008000. /// /// A representing a system-defined color. - public static readonly Color Green = new("#008000"); + public static readonly Color Green = FromKnownColor(KnownColor.Green); /// /// Gets a system-defined color that has an ARGB value of #ADFF2F. /// /// A representing a system-defined color. - public static readonly Color GreenYellow = new("#ADFF2F"); + public static readonly Color GreenYellow = FromKnownColor(KnownColor.GreenYellow); /// /// Gets a system-defined color that has an ARGB value of #F0FFF0. /// /// A representing a system-defined color. - public static readonly Color Honeydew = new("#F0FFF0"); + public static readonly Color Honeydew = FromKnownColor(KnownColor.Honeydew); /// /// Gets a system-defined color that has an ARGB value of #FF69B4. /// /// A representing a system-defined color. - public static readonly Color HotPink = new("#FF69B4"); + public static readonly Color HotPink = FromKnownColor(KnownColor.HotPink); /// /// Gets a system-defined color that has an ARGB value of #CD5C5C. /// /// A representing a system-defined color. - public static readonly Color IndianRed = new("#CD5C5C"); + public static readonly Color IndianRed = FromKnownColor(KnownColor.IndianRed); /// /// Gets a system-defined color that has an ARGB value of #4B0082. /// /// A representing a system-defined color. - public static readonly Color Indigo = new("#4B0082"); + public static readonly Color Indigo = FromKnownColor(KnownColor.Indigo); /// /// Gets a system-defined color that has an ARGB value of #FFFFF0. /// /// A representing a system-defined color. - public static readonly Color Ivory = new("#FFFFF0"); + public static readonly Color Ivory = FromKnownColor(KnownColor.Ivory); /// /// Gets a system-defined color that has an ARGB value of #F0E68C. /// /// A representing a system-defined color. - public static readonly Color Khaki = new("#F0E68C"); + public static readonly Color Khaki = FromKnownColor(KnownColor.Khaki); /// /// Gets a system-defined color that has an ARGB value of #E6E6FA. /// /// A representing a system-defined color. - public static readonly Color Lavender = new("#E6E6FA"); + public static readonly Color Lavender = FromKnownColor(KnownColor.Lavender); /// /// Gets a system-defined color that has an ARGB value of #FFF0F5. /// /// A representing a system-defined color. - public static readonly Color LavenderBlush = new("#FFF0F5"); + public static readonly Color LavenderBlush = FromKnownColor(KnownColor.LavenderBlush); /// /// Gets a system-defined color that has an ARGB value of #7CFC00. /// /// A representing a system-defined color. - public static readonly Color LawnGreen = new("#7CFC00"); + public static readonly Color LawnGreen = FromKnownColor(KnownColor.LawnGreen); /// /// Gets a system-defined color that has an ARGB value of #FFFACD. /// /// A representing a system-defined color. - public static readonly Color LemonChiffon = new("#FFFACD"); + public static readonly Color LemonChiffon = FromKnownColor(KnownColor.LemonChiffon); /// /// Gets a system-defined color that has an ARGB value of #ADD8E6. /// /// A representing a system-defined color. - public static readonly Color LightBlue = new("#ADD8E6"); + public static readonly Color LightBlue = FromKnownColor(KnownColor.LightBlue); /// /// Gets a system-defined color that has an ARGB value of #F08080. /// /// A representing a system-defined color. - public static readonly Color LightCoral = new("#F08080"); + public static readonly Color LightCoral = FromKnownColor(KnownColor.LightCoral); /// /// Gets a system-defined color that has an ARGB value of #E0FFFF. /// /// A representing a system-defined color. - public static readonly Color LightCyan = new("#E0FFFF"); + public static readonly Color LightCyan = FromKnownColor(KnownColor.LightCyan); /// /// Gets a system-defined color that has an ARGB value of #FAFAD2. /// /// A representing a system-defined color. - public static readonly Color LightGoldenrodYellow = new("#FAFAD2"); + public static readonly Color LightGoldenrodYellow = FromKnownColor(KnownColor.LightGoldenrodYellow); /// /// Gets a system-defined color that has an ARGB value of #D3D3D3. /// /// A representing a system-defined color. - public static readonly Color LightGray = new("#D3D3D3"); + public static readonly Color LightGray = FromKnownColor(KnownColor.LightGray); /// /// Gets a system-defined color that has an ARGB value of #90EE90. /// /// A representing a system-defined color. - public static readonly Color LightGreen = new("#90EE90"); + public static readonly Color LightGreen = FromKnownColor(KnownColor.LightGreen); /// /// Gets a system-defined color that has an ARGB value of #FFB6C1. /// /// A representing a system-defined color. - public static readonly Color LightPink = new("#FFB6C1"); + public static readonly Color LightPink = FromKnownColor(KnownColor.LightPink); /// /// Gets a system-defined color that has an ARGB value of #FFA07A. /// /// A representing a system-defined color. - public static readonly Color LightSalmon = new("#FFA07A"); + public static readonly Color LightSalmon = FromKnownColor(KnownColor.LightSalmon); /// /// Gets a system-defined color that has an ARGB value of #20B2AA. /// /// A representing a system-defined color. - public static readonly Color LightSeaGreen = new("#20B2AA"); + public static readonly Color LightSeaGreen = FromKnownColor(KnownColor.LightSeaGreen); /// /// Gets a system-defined color that has an ARGB value of #87CEFA. /// /// A representing a system-defined color. - public static readonly Color LightSkyBlue = new("#87CEFA"); + public static readonly Color LightSkyBlue = FromKnownColor(KnownColor.LightSkyBlue); /// /// Gets a system-defined color that has an ARGB value of #778899. /// /// A representing a system-defined color. - public static readonly Color LightSlateGray = new("#778899"); + public static readonly Color LightSlateGray = FromKnownColor(KnownColor.LightSlateGray); /// /// Gets a system-defined color that has an ARGB value of #B0C4DE. /// /// A representing a system-defined color. - public static readonly Color LightSteelBlue = new("#B0C4DE"); + public static readonly Color LightSteelBlue = FromKnownColor(KnownColor.LightSteelBlue); /// /// Gets a system-defined color that has an ARGB value of #FFFFE0. /// /// A representing a system-defined color. - public static readonly Color LightYellow = new("#FFFFE0"); + public static readonly Color LightYellow = FromKnownColor(KnownColor.LightYellow); /// /// Gets a system-defined color that has an ARGB value of #00FF00. /// /// A representing a system-defined color. - public static readonly Color Lime = new("#00FF00"); + public static readonly Color Lime = FromKnownColor(KnownColor.Lime); /// /// Gets a system-defined color that has an ARGB value of #32CD32. /// /// A representing a system-defined color. - public static readonly Color LimeGreen = new("#32CD32"); + public static readonly Color LimeGreen = FromKnownColor(KnownColor.LimeGreen); /// /// Gets a system-defined color that has an ARGB value of #FAF0E6. /// /// A representing a system-defined color. - public static readonly Color Linen = new("#FAF0E6"); + public static readonly Color Linen = FromKnownColor(KnownColor.Linen); /// /// Gets a system-defined color that has an ARGB value of #FF00FF. /// /// A representing a system-defined color. - public static readonly Color Magenta = new("#FF00FF"); + public static readonly Color Magenta = FromKnownColor(KnownColor.Magenta); /// /// Gets a system-defined color that has an ARGB value of #800000. /// /// A representing a system-defined color. - public static readonly Color Maroon = new("#800000"); + public static readonly Color Maroon = FromKnownColor(KnownColor.Maroon); /// /// Gets a system-defined color that has an ARGB value of #66CDAA. /// /// A representing a system-defined color. - public static readonly Color MediumAquamarine = new("#66CDAA"); + public static readonly Color MediumAquamarine = FromKnownColor(KnownColor.MediumAquamarine); /// /// Gets a system-defined color that has an ARGB value of #0000CD. /// /// A representing a system-defined color. - public static readonly Color MediumBlue = new("#0000CD"); + public static readonly Color MediumBlue = FromKnownColor(KnownColor.MediumBlue); /// /// Gets a system-defined color that has an ARGB value of #BA55D3. /// /// A representing a system-defined color. - public static readonly Color MediumOrchid = new("#BA55D3"); + public static readonly Color MediumOrchid = FromKnownColor(KnownColor.MediumOrchid); /// /// Gets a system-defined color that has an ARGB value of #9370DB. /// /// A representing a system-defined color. - public static readonly Color MediumPurple = new("#9370DB"); + public static readonly Color MediumPurple = FromKnownColor(KnownColor.MediumPurple); /// /// Gets a system-defined color that has an ARGB value of #3CB371. /// /// A representing a system-defined color. - public static readonly Color MediumSeaGreen = new("#3CB371"); + public static readonly Color MediumSeaGreen = FromKnownColor(KnownColor.MediumSeaGreen); /// /// Gets a system-defined color that has an ARGB value of #7B68EE. /// /// A representing a system-defined color. - public static readonly Color MediumSlateBlue = new("#7B68EE"); + public static readonly Color MediumSlateBlue = FromKnownColor(KnownColor.MediumSlateBlue); /// /// Gets a system-defined color that has an ARGB value of #00FA9A. /// /// A representing a system-defined color. - public static readonly Color MediumSpringGreen = new("#00FA9A"); + public static readonly Color MediumSpringGreen = FromKnownColor(KnownColor.MediumSpringGreen); /// /// Gets a system-defined color that has an ARGB value of #48D1CC. /// /// A representing a system-defined color. - public static readonly Color MediumTurquoise = new("#48D1CC"); + public static readonly Color MediumTurquoise = FromKnownColor(KnownColor.MediumTurquoise); /// /// Gets a system-defined color that has an ARGB value of #C71585. /// /// A representing a system-defined color. - public static readonly Color MediumVioletRed = new("#C71585"); + public static readonly Color MediumVioletRed = FromKnownColor(KnownColor.MediumVioletRed); /// /// Gets a system-defined color that has an ARGB value of #191970. /// /// A representing a system-defined color. - public static readonly Color MidnightBlue = new("#191970"); + public static readonly Color MidnightBlue = FromKnownColor(KnownColor.MidnightBlue); /// /// Gets a system-defined color that has an ARGB value of #F5FFFA. /// /// A representing a system-defined color. - public static readonly Color MintCream = new("#F5FFFA"); + public static readonly Color MintCream = FromKnownColor(KnownColor.MintCream); /// /// Gets a system-defined color that has an ARGB value of #FFE4E1. /// /// A representing a system-defined color. - public static readonly Color MistyRose = new("#FFE4E1"); + public static readonly Color MistyRose = FromKnownColor(KnownColor.MistyRose); /// /// Gets a system-defined color that has an ARGB value of #FFE4B5. /// /// A representing a system-defined color. - public static readonly Color Moccasin = new("#FFE4B5"); + public static readonly Color Moccasin = FromKnownColor(KnownColor.Moccasin); /// /// Gets a system-defined color that has an ARGB value of #FFDEAD. /// /// A representing a system-defined color. - public static readonly Color NavajoWhite = new("#FFDEAD"); + public static readonly Color NavajoWhite = FromKnownColor(KnownColor.NavajoWhite); /// /// Gets a system-defined color that has an ARGB value of #000080. /// /// A representing a system-defined color. - public static readonly Color Navy = new("#000080"); + public static readonly Color Navy = FromKnownColor(KnownColor.Navy); /// /// Gets a system-defined color that has an ARGB value of #FDF5E6. /// /// A representing a system-defined color. - public static readonly Color OldLace = new("#FDF5E6"); + public static readonly Color OldLace = FromKnownColor(KnownColor.OldLace); /// /// Gets a system-defined color that has an ARGB value of #808000. /// /// A representing a system-defined color. - public static readonly Color Olive = new("#808000"); + public static readonly Color Olive = FromKnownColor(KnownColor.Olive); /// /// Gets a system-defined color that has an ARGB value of #6B8E23. /// /// A representing a system-defined color. - public static readonly Color OliveDrab = new("#6B8E23"); + public static readonly Color OliveDrab = FromKnownColor(KnownColor.OliveDrab); /// /// Gets a system-defined color that has an ARGB value of #FFA500. /// /// A representing a system-defined color. - public static readonly Color Orange = new("#FFA500"); + public static readonly Color Orange = FromKnownColor(KnownColor.Orange); /// /// Gets a system-defined color that has an ARGB value of #FF4500. /// /// A representing a system-defined color. - public static readonly Color OrangeRed = new("#FF4500"); + public static readonly Color OrangeRed = FromKnownColor(KnownColor.OrangeRed); /// /// Gets a system-defined color that has an ARGB value of #DA70D6. /// /// A representing a system-defined color. - public static readonly Color Orchid = new("#DA70D6"); + public static readonly Color Orchid = FromKnownColor(KnownColor.Orchid); /// /// Gets a system-defined color that has an ARGB value of #EEE8AA. /// /// A representing a system-defined color. - public static readonly Color PaleGoldenrod = new("#EEE8AA"); + public static readonly Color PaleGoldenrod = FromKnownColor(KnownColor.PaleGoldenrod); /// /// Gets a system-defined color that has an ARGB value of #98FB98. /// /// A representing a system-defined color. - public static readonly Color PaleGreen = new("#98FB98"); + public static readonly Color PaleGreen = FromKnownColor(KnownColor.PaleGreen); /// /// Gets a system-defined color that has an ARGB value of #AFEEEE. /// /// A representing a system-defined color. - public static readonly Color PaleTurquoise = new("#AFEEEE"); + public static readonly Color PaleTurquoise = FromKnownColor(KnownColor.PaleTurquoise); /// /// Gets a system-defined color that has an ARGB value of #DB7093. /// /// A representing a system-defined color. - public static readonly Color PaleVioletRed = new("#DB7093"); + public static readonly Color PaleVioletRed = FromKnownColor(KnownColor.PaleVioletRed); /// /// Gets a system-defined color that has an ARGB value of #FFEFD5. /// /// A representing a system-defined color. - public static readonly Color PapayaWhip = new("#FFEFD5"); + public static readonly Color PapayaWhip = FromKnownColor(KnownColor.PapayaWhip); /// /// Gets a system-defined color that has an ARGB value of #FFDAB9. /// /// A representing a system-defined color. - public static readonly Color PeachPuff = new("#FFDAB9"); + public static readonly Color PeachPuff = FromKnownColor(KnownColor.PeachPuff); /// /// Gets a system-defined color that has an ARGB value of #CD853F. /// /// A representing a system-defined color. - public static readonly Color Peru = new("#CD853F"); + public static readonly Color Peru = FromKnownColor(KnownColor.Peru); /// /// Gets a system-defined color that has an ARGB value of #FFC0CB. /// /// A representing a system-defined color. - public static readonly Color Pink = new("#FFC0CB"); + public static readonly Color Pink = FromKnownColor(KnownColor.Pink); /// /// Gets a system-defined color that has an ARGB value of #DDA0DD. /// /// A representing a system-defined color. - public static readonly Color Plum = new("#DDA0DD"); + public static readonly Color Plum = FromKnownColor(KnownColor.Plum); /// /// Gets a system-defined color that has an ARGB value of #B0E0E6. /// /// A representing a system-defined color. - public static readonly Color PowderBlue = new("#B0E0E6"); + public static readonly Color PowderBlue = FromKnownColor(KnownColor.PowderBlue); /// /// Gets a system-defined color that has an ARGB value of #800080. /// /// A representing a system-defined color. - public static readonly Color Purple = new("#800080"); + public static readonly Color Purple = FromKnownColor(KnownColor.Purple); /// /// Gets a system-defined color that has an ARGB value of #663399. /// /// A representing a system-defined color. - public static readonly Color RebeccaPurple = new("#663399"); + public static readonly Color RebeccaPurple = FromKnownColor(KnownColor.RebeccaPurple); /// /// Gets a system-defined color that has an ARGB value of #FF0000. /// /// A representing a system-defined color. - public static readonly Color Red = new("#FF0000"); + public static readonly Color Red = FromKnownColor(KnownColor.Red); /// /// Gets a system-defined color that has an ARGB value of #BC8F8F. /// /// A representing a system-defined color. - public static readonly Color RosyBrown = new("#BC8F8F"); + public static readonly Color RosyBrown = FromKnownColor(KnownColor.RosyBrown); /// /// Gets a system-defined color that has an ARGB value of #4169E1. /// /// A representing a system-defined color. - public static readonly Color RoyalBlue = new("#4169E1"); + public static readonly Color RoyalBlue = FromKnownColor(KnownColor.RoyalBlue); /// /// Gets a system-defined color that has an ARGB value of #8B4513. /// /// A representing a system-defined color. - public static readonly Color SaddleBrown = new("#8B4513"); + public static readonly Color SaddleBrown = FromKnownColor(KnownColor.SaddleBrown); /// /// Gets a system-defined color that has an ARGB value of #FA8072. /// /// A representing a system-defined color. - public static readonly Color Salmon = new("#FA8072"); + public static readonly Color Salmon = FromKnownColor(KnownColor.Salmon); /// /// Gets a system-defined color that has an ARGB value of #F4A460. /// /// A representing a system-defined color. - public static readonly Color SandyBrown = new("#F4A460"); + public static readonly Color SandyBrown = FromKnownColor(KnownColor.SandyBrown); /// /// Gets a system-defined color that has an ARGB value of #2E8B57. /// /// A representing a system-defined color. - public static readonly Color SeaGreen = new("#2E8B57"); + public static readonly Color SeaGreen = FromKnownColor(KnownColor.SeaGreen); /// /// Gets a system-defined color that has an ARGB value of #FFF5EE. /// /// A representing a system-defined color. - public static readonly Color SeaShell = new("#FFF5EE"); + public static readonly Color SeaShell = FromKnownColor(KnownColor.SeaShell); /// /// Gets a system-defined color that has an ARGB value of #A0522D. /// /// A representing a system-defined color. - public static readonly Color Sienna = new("#A0522D"); + public static readonly Color Sienna = FromKnownColor(KnownColor.Sienna); /// /// Gets a system-defined color that has an ARGB value of #C0C0C0. /// /// A representing a system-defined color. - public static readonly Color Silver = new("#C0C0C0"); + public static readonly Color Silver = FromKnownColor(KnownColor.Silver); /// /// Gets a system-defined color that has an ARGB value of #87CEEB. /// /// A representing a system-defined color. - public static readonly Color SkyBlue = new("#87CEEB"); + public static readonly Color SkyBlue = FromKnownColor(KnownColor.SkyBlue); /// /// Gets a system-defined color that has an ARGB value of #6A5ACD. /// /// A representing a system-defined color. - public static readonly Color SlateBlue = new("#6A5ACD"); + public static readonly Color SlateBlue = FromKnownColor(KnownColor.SlateBlue); /// /// Gets a system-defined color that has an ARGB value of #708090. /// /// A representing a system-defined color. - public static readonly Color SlateGray = new("#708090"); + public static readonly Color SlateGray = FromKnownColor(KnownColor.SlateGray); /// /// Gets a system-defined color that has an ARGB value of #FFFAFA. /// /// A representing a system-defined color. - public static readonly Color Snow = new("#FFFAFA"); + public static readonly Color Snow = FromKnownColor(KnownColor.Snow); /// /// Gets a system-defined color that has an ARGB value of #00FF7F. /// /// A representing a system-defined color. - public static readonly Color SpringGreen = new("#00FF7F"); + public static readonly Color SpringGreen = FromKnownColor(KnownColor.SpringGreen); /// /// Gets a system-defined color that has an ARGB value of #4682B4. /// /// A representing a system-defined color. - public static readonly Color SteelBlue = new("#4682B4"); + public static readonly Color SteelBlue = FromKnownColor(KnownColor.SteelBlue); /// /// Gets a system-defined color that has an ARGB value of #D2B48C. /// /// A representing a system-defined color. - public static readonly Color Tan = new("#D2B48C"); + public static readonly Color Tan = FromKnownColor(KnownColor.Tan); /// /// Gets a system-defined color that has an ARGB value of #008080. /// /// A representing a system-defined color. - public static readonly Color Teal = new("#008080"); + public static readonly Color Teal = FromKnownColor(KnownColor.Teal); /// /// Gets a system-defined color that has an ARGB value of #D2B48C. /// /// A representing a system-defined color. - public static readonly Color Thistle = new("#D8BFD8"); + public static readonly Color Thistle = FromKnownColor(KnownColor.Thistle); /// /// Gets a system-defined color that has an ARGB value of #FF6347. /// /// A representing a system-defined color. - public static readonly Color Tomato = new("#FF6347"); + public static readonly Color Tomato = FromKnownColor(KnownColor.Tomato); /// /// Gets a system-defined color that has an ARGB value of #00FFFFFF. /// /// A representing a system-defined color. - public static readonly Color Transparent = new("#00FFFFFF"); + public static readonly Color Transparent = FromKnownColor(KnownColor.Transparent); /// /// Gets a system-defined color that has an ARGB value of #40E0D0. /// /// A representing a system-defined color. - public static readonly Color Turquoise = new("#40E0D0"); + public static readonly Color Turquoise = FromKnownColor(KnownColor.Turquoise); /// /// Gets a system-defined color that has an ARGB value of #EE82EE. /// /// A representing a system-defined color. - public static readonly Color Violet = new("#EE82EE"); + public static readonly Color Violet = FromKnownColor(KnownColor.Violet); /// /// Gets a system-defined color that has an ARGB value of #F5DEB3. /// /// A representing a system-defined color. - public static readonly Color Wheat = new("#F5DEB3"); + public static readonly Color Wheat = FromKnownColor(KnownColor.Wheat); /// /// Gets a system-defined color that has an ARGB value of #FFFFFF. /// /// A representing a system-defined color. - public static readonly Color White = new("#FFFFFF"); + public static readonly Color White = FromKnownColor(KnownColor.White); /// /// Gets a system-defined color that has an ARGB value of #F5F5F5. /// /// A representing a system-defined color. - public static readonly Color WhiteSmoke = new("#F5F5F5"); + public static readonly Color WhiteSmoke = FromKnownColor(KnownColor.WhiteSmoke); /// /// Gets a system-defined color that has an ARGB value of #FFFF00. /// /// A representing a system-defined color. - public static readonly Color Yellow = new("#FFFF00"); + public static readonly Color Yellow = FromKnownColor(KnownColor.Yellow); /// /// Gets a system-defined color that has an ARGB value of #9ACD32. /// /// A representing a system-defined color. - public static readonly Color YellowGreen = new("#9ACD32"); + public static readonly Color YellowGreen = FromKnownColor(KnownColor.YellowGreen); /// /// Creates a structure from the specified 8-bit color values @@ -894,32 +921,52 @@ public static Color FromArgb(int argb) return new Color(colorCode); } + private static Color FromKnownColor(KnownColor kc) + { + return KnownColors.FromKnownColor(kc); + } + /// - /// Creates a structure from the name of a color. If the name is a predefined color, a known Color is returned. If the name is not a known color, a new Color with ARGB values of 0 is returned. + /// Creates a structure from the name of a color. /// - /// A string that is the name of a color. The comparison is case-insensitive. + /// A string that is the name of a predefined color. /// - /// The that this method creates. If the color name is found, the corresponding known Color is returned; otherwise, a Color representing transparent black (A=0, R=0, G=0, B=0) is returned. + /// The that this method creates. If the color name is found, + /// the corresponding known Color is returned; otherwise, a Color representing + /// transparent black (A=0, R=0, G=0, B=0) is returned. /// /// - /// The returned will have its property set to if the name was found in the list of known colors, and otherwise. + /// + /// This method mimics the behavior of System.Drawing.Color.FromName for compatibility. + /// Unlike previous versions, this method no longer throws an exception for unknown color names. + /// + /// + /// The property will be set to only if + /// the name matches a predefined color in the KnownColor enumeration. + /// + /// + /// Color name comparison is case-insensitive. Both "Red" and "red" will return the same color. + /// /// + /// + /// + /// Color red = Color.FromName("Red"); // Returns known red color, IsKnownColor = true + /// Color unknown = Color.FromName("Foo"); // Returns transparent black, IsKnownColor = false + /// + /// public static Color FromName(string name) { if (!string.IsNullOrEmpty(name)) { - if (KnownColors.ArgbByName.TryGetValue(name.ToLower(), out uint argb)) + // Lookup to get the KnownColor enum + if (KnownColors.KnownColorByName.TryGetValue(name.ToLower(), out KnownColor kc)) { - Color knownColor = FromArgb((int)argb); - knownColor.IsKnownColor = true; - return knownColor; + return FromKnownColor(kc); } } - - // If name is not found, return a color with ARGB values of 0, and IsKnownColor set to false. - Color newColor = new Color(0, 0, 0, 0); - newColor.IsKnownColor = false; - return newColor; + + // Return a new Color instance that is not a "known" color. + return new Color(0, 0, 0, 0); } /// diff --git a/IronSoftware.Drawing/IronSoftware.Drawing.Common/KnownColors.cs b/IronSoftware.Drawing/IronSoftware.Drawing.Common/KnownColors.cs index 9b2f6bc..8bb3153 100644 --- a/IronSoftware.Drawing/IronSoftware.Drawing.Common/KnownColors.cs +++ b/IronSoftware.Drawing/IronSoftware.Drawing.Common/KnownColors.cs @@ -364,6 +364,7 @@ internal class KnownColors }; private static Dictionary _argbByName = null; private static Dictionary _nameByArgb = null; + private static Dictionary _knownColorByName = null; internal static Dictionary ArgbByName { @@ -399,22 +400,34 @@ internal static Dictionary NameByArgb } } + internal static Dictionary KnownColorByName + { + get + { + if (_knownColorByName == null) + { + _knownColorByName = new Dictionary(); + for (int i = 0; i < Names.Length; ++i) + { + // The key is the lowercased name for case-insensitive matching + _knownColorByName[Names[i].ToLower()] = (KnownColor)i; + } + } + return _knownColorByName; + } + } + public static Color FromKnownColor(KnownColor kc) { - Color c; short n = (short)kc; if ((n <= 0) || (n >= ArgbValues.Length)) { - c = Color.FromArgb(0); - c.IsKnownColor = false; - } - else - { - c = Color.FromArgb((int)ArgbValues[n]); - c.IsKnownColor = true; + // For invalid KnownColor enum values, return transparent black, which is not a "known" color. + return new Color(0, 0, 0, 0); } - return c; + // Create a color and set its immutable IsKnownColor flag to true. + return new Color((int)ArgbValues[n], true); } public static string GetName(short kc)