runtime: System.Drawing.Color is possibly missing 8 colors
Background and Motivation
It appears that the System.Drawing.Color names are intended to track the CSS color names; if that is correct, there are some colors which need to be added. Two reasons for thinking the names are supposed to track CSS colors are:
-
The Documentation for System.Drawing.Color says “For more information about these colors, see Colors by Name.” which links to Mozilla’s documentation on CSS color names.
-
Pull Request https://github.com/dotnet/corefx/pull/41561 where one of the color values differed from the CSS value, and the .Net color value was changed to agree with CSS.
Proposed API
Affecting at least KnownColor.cs and KnownColorNames.cs and KnownColorTable.cs and Affecting at least Color.cs, the significant differences are the addition of the new RebeccaPurple color, and the variant spellings of grAy colors as grEy:
namespace System.Drawing
{
enum KnownColor
{
+ RebeccaPurple,
+ DarkGrey,
+ DarkSlateGrey,
+ DimGrey,
+ Grey,
+ LightGrey,
+ LightSlateGrey,
+ SlateGrey,
}
public readonly struct Color : IEquatable<Color>
{
+ public static Color RebeccaPurple;
+ public static Color DarkGrey;
+ public static Color DarkSlateGrey;
+ public static Color DimGrey;
+ public static Color Grey;
+ public static Color LightGrey;
+ public static Color LightSlateGrey;
+ public static Color SlateGrey;
}
}
Possibly related, System.Windows.Media.Colors
Usage Examples
using System.Drawing;
string text = String.Format(
"The CSS color 'RebeccaPurple' has Red component of {0}",
Color.RebeccaPurple.R);
Alternative Designs
I have not considered any particular designs, only intending to report this as a bug where the existing behaviour differs from the intended behaviour.
Risks
This will change the total number of items in the Color enum, and (depending on whether the new ones are added in order, or to the end) might change the existing color locations.
I think the missing color values are:
- RebeccaPurple
#663399 - DarkGrey
#a9a9a9 - DarkSlateGrey
#2f4f4f - DimGrey
#696969 - Grey
#808080 - LightGrey
#d3d3d3 - LightSlateGrey
#778899 - SlateGrey
#708090
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 26 (26 by maintainers)
Commits related to this issue
- Added Rebecca Purple Added Rebecca Purple color to System.Drawing.Color Added RebeccaPurple (#663399) to KnownColorNames.cs, Color.cs, KnownColortable.cs and KnownColor.cs #38244 — committed to FireCubeStudios/runtime by FireCubeStudios 4 years ago
- 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. #3... — committed to FireCubeStudios/runtime by FireCubeStudios 4 years ago
- 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 prev... — committed to FireCubeStudios/runtime by FireCubeStudios 4 years ago
- 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. #38244 — committed to FireCubeStudios/runtime by FireCubeStudios 4 years ago
- 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. #38244 — committed to FireCubeStudios/runtime by FireCubeStudios 4 years ago
- Added rebeccapurple to bottom of Knowncolors.cs I added rebeccapurple to theend of the file RebeccaPurple was added to the bottom of the enum. #38244 — committed to FireCubeStudios/runtime by FireCubeStudios 4 years ago
- Added Rebecca Purple Added Rebecca Purple color to System.Drawing.Color Added RebeccaPurple (#663399) to KnownColorNames.cs, Color.cs, KnownColortable.cs and KnownColor.cs #38244 — committed to FireCubeStudios/runtime by FireCubeStudios 4 years ago
- 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. #3... — committed to FireCubeStudios/runtime by FireCubeStudios 4 years ago
- 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 prev... — committed to FireCubeStudios/runtime by FireCubeStudios 4 years ago
- 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. #38244 — committed to FireCubeStudios/runtime by FireCubeStudios 4 years ago
- 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. #38244 — committed to FireCubeStudios/runtime by FireCubeStudios 4 years ago
- Added rebeccapurple to bottom of Knowncolors.cs I added rebeccapurple to theend of the file RebeccaPurple was added to the bottom of the enum. #38244 — committed to FireCubeStudios/runtime by FireCubeStudios 4 years ago
- 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 k... — committed to FireCubeStudios/runtime by FireCubeStudios 4 years ago
- 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 #38244 — committed to FireCubeStudios/runtime by FireCubeStudios 4 years ago
- 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 #38244 — committed to FireCubeStudios/runtime by FireCubeStudios 4 years ago
- Added Rebecca Purple (#42785) * Added Rebecca Purple Added Rebecca Purple color to System.Drawing.Color Added RebeccaPurple (#663399) to KnownColorNames.cs, Color.cs, KnownColortable.cs and KnownCo... — committed to dotnet/runtime by FireCubeStudios 4 years ago
I’m not sure if it has been our intention over the past, but I think it doesn’t hurt to add those colors if they help matching other frameworks with default colors.
Marked as ready for review.
I think supporting parsing both without exposing both would be reasonable. We can then chalk the existing duplicates up as legacy/back-compat
I think we should add the aliases as @tannergooding mentioned.
Given that these are largely the W3C color types, that we define other aliases such as
aqua/cyanandfuchsia/magenta, and that we have existing special handling for at least onegreyvsgray; I think it would be worthwhile to add the other aliases and just spec it out as explicitly mapping to the W3C color name/values defined for CSS: https://www.w3.org/wiki/CSS/Properties/color/keywords (the docs currently link to https://developer.mozilla.org/en-US/docs/Web/CSS/color_value in a couple places).i want to try implementing this