Skip to content

Commit d21fe17

Browse files
Added Rebecca Purple (dotnet#42785)
* Added Rebecca Purple Added Rebecca Purple color to System.Drawing.Color Added RebeccaPurple (#663399) to KnownColorNames.cs, Color.cs, KnownColortable.cs and KnownColor.cs dotnet#38244 * Added RebeccaPurple to UnitTest and Ref Added RebeccaPurple color to the UnitTest and to the ref Added RebeccaPurple a,r,g,b value to unittest in System.Drawing.Primitive. Also updated the ref. dotnet#38244 * Added RebeccaPurple to the system.drawing.primitive ref Added RebeccaPurple color to the System.Drawing.Primitive ref file. "RebeccaPurple = 141" was added. I updated the other colors to their previous number by one. dotnet#38244 * Reverted breaking changes in drawing.primitive ref Reverted the breaking changes in system.drawing.primivite ref. the numbers of colors were restored back and i removed rebeccapurple. dotnet#38244 * Added RebeccaPurple to the ref I added rebeccapurple to the ref file with value 175. RebeccaPurple was added with value 175 to the bottom of the enum. dotnet#38244 * Added rebeccapurple to bottom of Knowncolors.cs I added rebeccapurple to theend of the file RebeccaPurple was added to the bottom of the enum. dotnet#38244 * Added Rebecca Purple Added Rebecca Purple color to System.Drawing.Color Added RebeccaPurple (#663399) to KnownColorNames.cs, Color.cs, KnownColortable.cs and KnownColor.cs dotnet#38244 * Added RebeccaPurple to UnitTest and Ref Added RebeccaPurple color to the UnitTest and to the ref Added RebeccaPurple a,r,g,b value to unittest in System.Drawing.Primitive. Also updated the ref. dotnet#38244 * Added RebeccaPurple to the system.drawing.primitive ref Added RebeccaPurple color to the System.Drawing.Primitive ref file. "RebeccaPurple = 141" was added. I updated the other colors to their previous number by one. dotnet#38244 * Reverted breaking changes in drawing.primitive ref Reverted the breaking changes in system.drawing.primivite ref. the numbers of colors were restored back and i removed rebeccapurple. dotnet#38244 * Added RebeccaPurple to the ref I added rebeccapurple to the ref file with value 175. RebeccaPurple was added with value 175 to the bottom of the enum. dotnet#38244 * Added rebeccapurple to bottom of Knowncolors.cs I added rebeccapurple to theend of the file RebeccaPurple was added to the bottom of the enum. dotnet#38244 * Fixed some of the requested changes with ordering of Enum Removed a comment in "knowncolor.cs" and moved rebeccapurple to match enum order. moved rebeccapurple in knowncolortable.cs, color.cs, and knowncolornames.cs dotnet#38244 * Removed duplicates and added a comment Added a comment in KnownColorNames.cs stating that the array follows order of knowncolor enum. Also removed duplicate rebeccapurple entries dotnet#38244 * Fixing up the handling of RebeccaPurple * Added a comment to explain changes Added a comment in KnownColortable.cs stating that the code accounts for the system colors and new rebeccapurple color dotnet#38244 Co-authored-by: Tanner Gooding <[email protected]>
1 parent 53c1619 commit d21fe17

File tree

6 files changed

+54
-20
lines changed

6 files changed

+54
-20
lines changed

src/libraries/Common/src/System/Drawing/KnownColor.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ enum KnownColor
2121

2222
// 0 - reserved for "not a known color"
2323

24-
// "System" colors
24+
// "System" colors, Part 1
2525
ActiveBorder = 1,
2626
ActiveCaption,
2727
ActiveCaptionText,
@@ -49,7 +49,7 @@ enum KnownColor
4949
WindowFrame,
5050
WindowText,
5151

52-
// "Web" Colors
52+
// "Web" Colors, Part 1
5353
Transparent,
5454
AliceBlue,
5555
AntiqueWhite,
@@ -192,14 +192,16 @@ enum KnownColor
192192
Yellow,
193193
YellowGreen,
194194

195-
// New system color additions in Visual Studio 2005 (.NET Framework 2.0)
196-
195+
// "System" colors, Part 2
197196
ButtonFace,
198197
ButtonHighlight,
199198
ButtonShadow,
200199
GradientActiveCaption,
201200
GradientInactiveCaption,
202201
MenuBar,
203-
MenuHighlight
202+
MenuHighlight,
203+
204+
// "Web" colors, Part 2
205+
RebeccaPurple,
204206
}
205207
}

src/libraries/Common/src/System/Drawing/KnownColorTable.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ internal static class KnownColorTable
1010
// All non system colors (in order of definition in the KnownColor enum).
1111
private static readonly uint[] s_colorTable = new uint[]
1212
{
13+
// First contiguous set.
14+
1315
0x00FFFFFF, // Transparent
1416
0xFFF0F8FF, // AliceBlue
1517
0xFFFAEBD7, // AntiqueWhite
@@ -151,6 +153,10 @@ internal static class KnownColorTable
151153
0xFFF5F5F5, // WhiteSmoke
152154
0xFFFFFF00, // Yellow
153155
0xFF9ACD32, // YellowGreen
156+
157+
// Second contiguous set.
158+
159+
0xFF663399, // RebeccaPurple
154160
};
155161

156162
internal static Color ArgbToKnownColor(uint argb)
@@ -163,7 +169,14 @@ internal static Color ArgbToKnownColor(uint argb)
163169
{
164170
if (s_colorTable[index] == argb)
165171
{
166-
return Color.FromKnownColor((KnownColor)(index + (int)KnownColor.Transparent));
172+
var knownColor = KnownColor.Transparent + index;
173+
// Handles the mismatching of the RebeccaPurple color with ButtonFace color ("System" colors, Part 2)
174+
if (knownColor > KnownColor.YellowGreen)
175+
{
176+
knownColor += (int)KnownColor.RebeccaPurple - (int)KnownColor.ButtonFace;
177+
}
178+
179+
return Color.FromKnownColor(knownColor);
167180
}
168181
}
169182

@@ -173,11 +186,16 @@ internal static Color ArgbToKnownColor(uint argb)
173186

174187
public static uint KnownColorToArgb(KnownColor color)
175188
{
176-
Debug.Assert(color > 0 && color <= KnownColor.MenuHighlight);
189+
Debug.Assert(color > 0 && color <= KnownColor.RebeccaPurple);
190+
191+
if (Color.IsKnownColorSystem(color))
192+
{
193+
return GetSystemColorArgb(color);
194+
}
177195

178-
return Color.IsKnownColorSystem(color)
179-
? GetSystemColorArgb(color)
180-
: s_colorTable[(int)color - (int)KnownColor.Transparent];
196+
return color < KnownColor.ButtonFace
197+
? s_colorTable[(int)color - (int)KnownColor.Transparent]
198+
: s_colorTable[(int)color - (int)KnownColor.RebeccaPurple + ((int)KnownColor.YellowGreen - (int)KnownColor.WindowText)];
181199
}
182200

183201
#if FEATURE_WINDOWS_SYSTEM_COLORS

src/libraries/System.Drawing.Primitives/ref/System.Drawing.Primitives.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ namespace System.Drawing
135135
public static System.Drawing.Color PowderBlue { get { throw null; } }
136136
public static System.Drawing.Color Purple { get { throw null; } }
137137
public byte R { get { throw null; } }
138+
public static System.Drawing.Color RebeccaPurple { get { throw null; } }
138139
public static System.Drawing.Color Red { get { throw null; } }
139140
public static System.Drawing.Color RosyBrown { get { throw null; } }
140141
public static System.Drawing.Color RoyalBlue { get { throw null; } }
@@ -366,6 +367,7 @@ public enum KnownColor
366367
GradientInactiveCaption = 172,
367368
MenuBar = 173,
368369
MenuHighlight = 174,
370+
RebeccaPurple = 175,
369371
}
370372
[System.ComponentModel.TypeConverterAttribute("System.Drawing.PointConverter, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
371373
public partial struct Point : System.IEquatable<System.Drawing.Point>

src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ namespace System.Drawing
248248

249249
public static Color Purple => new Color(KnownColor.Purple);
250250

251+
public static Color RebeccaPurple => new Color(KnownColor.RebeccaPurple);
252+
251253
public static Color Red => new Color(KnownColor.Red);
252254

253255
public static Color RosyBrown => new Color(KnownColor.RosyBrown);
@@ -301,7 +303,6 @@ namespace System.Drawing
301303
public static Color Yellow => new Color(KnownColor.Yellow);
302304

303305
public static Color YellowGreen => new Color(KnownColor.YellowGreen);
304-
305306
//
306307
// end "web" colors
307308
// -------------------------------------------------------------------
@@ -372,7 +373,7 @@ private Color(long value, short state, string? name, KnownColor knownColor)
372373
public bool IsSystemColor => IsKnownColor && IsKnownColorSystem((KnownColor)knownColor);
373374

374375
internal static bool IsKnownColorSystem(KnownColor knownColor)
375-
=> (knownColor <= KnownColor.WindowText) || (knownColor > KnownColor.YellowGreen);
376+
=> ((knownColor >= KnownColor.ActiveBorder) && (knownColor <= KnownColor.WindowText)) || ((knownColor >= KnownColor.ButtonFace) && (knownColor <= KnownColor.MenuHighlight));
376377

377378
// Used for the [DebuggerDisplay]. Inlining in the attribute is possible, but
378379
// against best practices as the current project language parses the string with
@@ -464,7 +465,7 @@ public static Color FromArgb(int alpha, Color baseColor)
464465
public static Color FromArgb(int red, int green, int blue) => FromArgb(byte.MaxValue, red, green, blue);
465466

466467
public static Color FromKnownColor(KnownColor color) =>
467-
color <= 0 || color > KnownColor.MenuHighlight ? FromName(color.ToString()) : new Color(color);
468+
color <= 0 || color > KnownColor.RebeccaPurple ? FromName(color.ToString()) : new Color(color);
468469

469470
public static Color FromName(string name)
470471
{

src/libraries/System.Drawing.Primitives/src/System/Drawing/KnownColorNames.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ namespace System.Drawing
77
{
88
internal static class KnownColorNames
99
{
10+
// Names of all colors (in order of definition in the KnownColor enum).
1011
private static readonly string[] s_colorNameTable = new string[]
1112
{
13+
// "System" colors, Part 1
1214
"ActiveBorder",
1315
"ActiveCaption",
1416
"ActiveCaptionText",
@@ -35,6 +37,8 @@ internal static class KnownColorNames
3537
"Window",
3638
"WindowFrame",
3739
"WindowText",
40+
41+
// "Web" Colors, Part 1
3842
"Transparent",
3943
"AliceBlue",
4044
"AntiqueWhite",
@@ -176,18 +180,23 @@ internal static class KnownColorNames
176180
"WhiteSmoke",
177181
"Yellow",
178182
"YellowGreen",
183+
184+
// "System" colors, Part 2
179185
"ButtonFace",
180186
"ButtonHighlight",
181187
"ButtonShadow",
182188
"GradientActiveCaption",
183189
"GradientInactiveCaption",
184190
"MenuBar",
185-
"MenuHighlight"
191+
"MenuHighlight",
192+
193+
// "Web" colors, Part 2
194+
"RebeccaPurple",
186195
};
187196

188197
public static string KnownColorToName(KnownColor color)
189198
{
190-
Debug.Assert(color > 0 && color <= KnownColor.MenuHighlight);
199+
Debug.Assert(color > 0 && color <= KnownColor.RebeccaPurple);
191200
return s_colorNameTable[unchecked((int)color) - 1];
192201
}
193202
}

src/libraries/System.Drawing.Primitives/tests/ColorTests.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public class ColorTests
130130
new object[] {"Plum", 255, 221, 160, 221},
131131
new object[] {"PowderBlue", 255, 176, 224, 230},
132132
new object[] {"Purple", 255, 128, 0, 128},
133+
new object[] {"RebeccaPurple", 255, 102, 51, 153},
133134
new object[] {"Red", 255, 255, 0, 0},
134135
new object[] {"RosyBrown", 255, 188, 143, 143},
135136
new object[] {"RoyalBlue", 255, 65, 105, 225},
@@ -532,7 +533,7 @@ public void FromKnownColor(string name, int alpha, int red, int green, int blue)
532533
[Theory]
533534
[InlineData((KnownColor)(-1))]
534535
[InlineData((KnownColor)0)]
535-
[InlineData(KnownColor.MenuHighlight + 1)]
536+
[InlineData(KnownColor.RebeccaPurple + 1)]
536537
public void FromOutOfRangeKnownColor(KnownColor known)
537538
{
538539
Color color = Color.FromKnownColor(known);
@@ -556,7 +557,7 @@ public void ToKnownColorMatchesButIsNotKnown(KnownColor known)
556557
[Theory]
557558
[InlineData((KnownColor)(-1))]
558559
[InlineData((KnownColor)0)]
559-
[InlineData(KnownColor.MenuHighlight + 1)]
560+
[InlineData(KnownColor.RebeccaPurple + 1)]
560561
public void FromOutOfRangeKnownColorToKnownColor(KnownColor known)
561562
{
562563
Color color = Color.FromKnownColor(known);
@@ -588,7 +589,7 @@ public void IsSystemColorFalseOnMatching(KnownColor known)
588589
[Theory]
589590
[InlineData((KnownColor)(-1))]
590591
[InlineData((KnownColor)0)]
591-
[InlineData(KnownColor.MenuHighlight + 1)]
592+
[InlineData(KnownColor.RebeccaPurple + 1)]
592593
public void IsSystemColorOutOfRangeKnown(KnownColor known)
593594
{
594595
Color color = Color.FromKnownColor(known);
@@ -612,7 +613,7 @@ public void IsKnownColorMatchFalse(KnownColor known)
612613
[Theory]
613614
[InlineData((KnownColor)(-1))]
614615
[InlineData((KnownColor)0)]
615-
[InlineData(KnownColor.MenuHighlight + 1)]
616+
[InlineData(KnownColor.RebeccaPurple + 1)]
616617
public void IsKnownColorOutOfRangeKnown(KnownColor known)
617618
{
618619
Color color = Color.FromKnownColor(known);
@@ -683,7 +684,8 @@ public void GetHashCodeForUnknownNamed()
683684
KnownColor.SeaShell, KnownColor.Sienna, KnownColor.Silver, KnownColor.SkyBlue, KnownColor.SlateBlue,
684685
KnownColor.SlateGray, KnownColor.Snow, KnownColor.SpringGreen, KnownColor.SteelBlue, KnownColor.Tan,
685686
KnownColor.Teal, KnownColor.Thistle, KnownColor.Tomato, KnownColor.Turquoise, KnownColor.Violet,
686-
KnownColor.Wheat, KnownColor.White, KnownColor.WhiteSmoke, KnownColor.Yellow, KnownColor.YellowGreen
687+
KnownColor.Wheat, KnownColor.White, KnownColor.WhiteSmoke, KnownColor.Yellow, KnownColor.YellowGreen,
688+
KnownColor.RebeccaPurple
687689
}.Select(kc => new object[] { kc }).ToArray();
688690

689691
[DllImport("user32.dll", SetLastError = true)]

0 commit comments

Comments
 (0)