Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Drawing.Color is possibly missing 8 colors #38244

Closed
HumanEquivalentUnit opened this issue Jun 22, 2020 · 26 comments
Closed

System.Drawing.Color is possibly missing 8 colors #38244

HumanEquivalentUnit opened this issue Jun 22, 2020 · 26 comments
Assignees
Labels
api-approved API was approved in API review, it can be implemented area-System.Drawing help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@HumanEquivalentUnit
Copy link
Contributor

HumanEquivalentUnit commented Jun 22, 2020

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:

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
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Drawing untriaged New issue has not been triaged by the area owner labels Jun 22, 2020
@ghost
Copy link

ghost commented Jun 22, 2020

Tagging subscribers to this area: @safern, @tannergooding
Notify danmosemsft if you want to be subscribed.

@safern safern added api-suggestion Early API idea and discussion, it is NOT ready for implementation and removed untriaged New issue has not been triaged by the area owner labels Jun 22, 2020
@safern
Copy link
Member

safern commented Jun 22, 2020

THanks @HumanEquivalentUnit -- this would be an API proposal because we need to add these new members to [KnownColor](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.knowncolor?view=net-5.0)

For new APIs we need to follow this process: https://github.com/dotnet/runtime/blob/97e553f5c3244b7df65ebfb7de3bb712081228cc/docs/project/api-review-process.md

So first we need to format the issue description to show that these are additions to KnownColor. Once the issue description is updated, we can mark it as api-ready-for-review and then it will be reviewed by the .NET API Reviewers.

@HumanEquivalentUnit
Copy link
Contributor Author

@safern I have rewritten the issue description from the API proposal template, as best as I can. I have limited C# experience, and am not sure what the full diff would look like, or whether System.Windows.Media.Colors needs to be involved/included either.

NB. If the .Net colors are not intended to track the CSS colors, then I am not strongly advocating to add these. Only if they are supposed to be identical, then it seems like a bug that they differ at all.

@safern
Copy link
Member

safern commented Jun 23, 2020

If the .Net colors are not intended to track the CSS colors

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.

@safern safern added api-ready-for-review and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Jun 23, 2020
@safern safern modified the milestones: Future, 6.0.0 Jun 23, 2020
@reflectronic
Copy link
Contributor

If KnownColor members are being added, static members should be added to Color as well.

@safern
Copy link
Member

safern commented Jun 24, 2020

If KnownColor members are being added, static members should be added to Color as well.

That is correct. Will add it to the description as well, thanks @reflectronic

@carlossanlop carlossanlop added api-ready-for-review API is ready for review, it is NOT ready for implementation and removed api-ready-for-review labels Jul 6, 2020
@terrajobst terrajobst added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for review, it is NOT ready for implementation labels Jul 21, 2020
@terrajobst
Copy link
Member

terrajobst commented Jul 21, 2020

Video

  • For better or worse, framework spelling is en-us.
  • If this would be parsing, supporting both grey and gray seems reasonable, but duplicating API surface to offer AE and BE feels wrong, so we don't feel we should be exposing those.
namespace System.Drawing
{
    public enum KnownColor
    {
        RebeccaPurple
    }
    public readonly struct Color : IEquatable<Color>
    {
        public static Color RebeccaPurple;
    }
}

@FireCubeStudios
Copy link
Contributor

i want to try implementing this

@danmoseley
Copy link
Member

@FireCubeStudios go for it!

@FireCubeStudios
Copy link
Contributor

ok so i can get it done this weekend and i will send a pull request in.

@FireCubeStudios
Copy link
Contributor

i added rebecca purple, but what to do with "grey", do i replace "gray" with "grey" or add both or add none? @HumanEquivalentUnit @terrajobst

@danmoseley
Copy link
Member

@FireCubeStudios my understanding of the post above is they only want Rebecca purple: the others would simply be duplicating existing "grAy" entries with parallel "grEy" which they don't think makes sense to expose in API. Anywhere we parse such colors we should accept both, but we should represent both of them with the "grAy" spelling in the API.

@saucecontrol
Copy link
Member

The thing about missing the 'Grey' spelling variants is that there are a lot of places where color name mappings are populated from the static properties on Color. There's an expectation that all W3C color names can be mapped through there, and that's not currently true.

Example from ColorConverter:

private static void FillConstants(Hashtable hash, Type enumType) {
MethodAttributes attrs = MethodAttributes.Public | MethodAttributes.Static;
PropertyInfo[] props = enumType.GetProperties();
for (int i = 0; i < props.Length; i++) {
PropertyInfo prop = props[i];
if (prop.PropertyType == typeof(Color)) {
MethodInfo method = prop.GetGetMethod();
if (method != null && (method.Attributes & attrs) == attrs) {
object[] tempIndex = null;
hash[prop.Name] = prop.GetValue(null, tempIndex);
}
}
}
}

@danmoseley
Copy link
Member

Ah, if there's an interop angle then possibly that should be revisited then. cc @safern @tannergooding who are area owners and will have a more interesting response than me.

@saucecontrol
Copy link
Member

Interestingly, LightGrey is special-cased in ColorTranslator, but the other grey shades are not:

// special case. Html requires LightGrey, but .NET uses LightGray
if (c.IsEmpty && string.Equals(htmlColor, "LightGrey", StringComparison.OrdinalIgnoreCase))
{
c = Color.LightGray;
}

@HumanEquivalentUnit
Copy link
Contributor Author

HumanEquivalentUnit commented Sep 26, 2020

There's an expectation that all W3C color names can be mapped through there

What do you have in mind - who expects, or where is it documented that way? My assumption was "the colour lists are very close, so they probably intend to be identical", but the review video above says .Net Framework used "web" colours as a convenient source for a colour list, but never intended to be in sync with them.

@tannergooding
Copy link
Member

cc @safern @tannergooding who are area owners and will have a more interesting response than me.

Given that these are largely the W3C color types, that we define other aliases such as aqua/cyan and fuchsia/magenta, and that we have existing special handling for at least one grey vs gray; 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).

FireCubeStudios added a commit to FireCubeStudios/runtime that referenced this issue Sep 28, 2020
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
FireCubeStudios added a commit to FireCubeStudios/runtime that referenced this issue Oct 2, 2020
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
FireCubeStudios added a commit to FireCubeStudios/runtime that referenced this issue Oct 2, 2020
Reverted the breaking changes in system.drawing.primivite ref.

the numbers of colors were restored back and i removed rebeccapurple.

dotnet#38244
FireCubeStudios added a commit to FireCubeStudios/runtime that referenced this issue Oct 4, 2020
I added rebeccapurple to the ref file with value 175.

RebeccaPurple was added with value 175 to the bottom of the enum.

dotnet#38244
FireCubeStudios added a commit to FireCubeStudios/runtime that referenced this issue Oct 9, 2020
I added rebeccapurple to theend of the file

RebeccaPurple was added to the bottom of the enum.

dotnet#38244
stephentoub pushed a commit to FireCubeStudios/runtime that referenced this issue Oct 23, 2020
Added Rebecca Purple color to System.Drawing.Color

Added RebeccaPurple (#663399) to KnownColorNames.cs, Color.cs, KnownColortable.cs and KnownColor.cs

dotnet#38244
stephentoub pushed a commit to FireCubeStudios/runtime that referenced this issue Oct 23, 2020
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
stephentoub pushed a commit to FireCubeStudios/runtime that referenced this issue Oct 23, 2020
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
stephentoub pushed a commit to FireCubeStudios/runtime that referenced this issue Oct 23, 2020
Reverted the breaking changes in system.drawing.primivite ref.

the numbers of colors were restored back and i removed rebeccapurple.

dotnet#38244
stephentoub pushed a commit to FireCubeStudios/runtime that referenced this issue Oct 23, 2020
I added rebeccapurple to the ref file with value 175.

RebeccaPurple was added with value 175 to the bottom of the enum.

dotnet#38244
stephentoub pushed a commit to FireCubeStudios/runtime that referenced this issue Oct 23, 2020
I added rebeccapurple to theend of the file

RebeccaPurple was added to the bottom of the enum.

dotnet#38244
FireCubeStudios added a commit to FireCubeStudios/runtime that referenced this issue Nov 2, 2020
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
FireCubeStudios added a commit to FireCubeStudios/runtime that referenced this issue Nov 4, 2020
Added a comment in KnownColorNames.cs stating that the array follows order of knowncolor enum. Also removed duplicate rebeccapurple entries

dotnet#38244
FireCubeStudios added a commit to FireCubeStudios/runtime that referenced this issue Nov 29, 2020
Added a comment in KnownColortable.cs stating that the code accounts for the system colors and new rebeccapurple color
dotnet#38244
@ghost ghost added in-pr There is an active PR which will close this issue when it is merged and removed in-pr There is an active PR which will close this issue when it is merged labels Dec 9, 2020
ghost pushed a commit that referenced this issue Dec 9, 2020
* 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

* 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.

#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.

#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.

#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.

#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.

#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

#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.

#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.

#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.

#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.

#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.

#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

#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

#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
#38244

Co-authored-by: Tanner Gooding <tagoo@outlook.com>
@akoeplinger
Copy link
Member

RebeccaPurple was added in #42785 (thanks @FireCubeStudios!).
Do we still think we want to address the gray vs. grey colors or should we close this issue?

@safern
Copy link
Member

safern commented Dec 9, 2020

Do we still think we want to address the gray vs. grey colors or should we close this issue?

I think we should add the aliases as @tannergooding mentioned.

@akoeplinger
Copy link
Member

Does this need to go through another round of API review then? In @terrajobst's comment only the RebeccaPurple change was approved: #38244 (comment)

@terrajobst
Copy link
Member

terrajobst commented Dec 10, 2020

@tannergooding

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:

I think that's a reasonable rationale and probably doesn't result in explosion. However, we should contain it here. I don't believe a general praxis of adding aliases for BE vs AE spelling makes any sense.

Another compromise would be to add the properties with AE but accept AE and BE when parsing.

@dotnet/fxdc, does anybody feel strongly here?

@bartonjs
Copy link
Member

bartonjs commented Jan 4, 2021

Another compromise would be to add the properties with AE but accept AE and BE when parsing.

does anybody feel strongly here?

I believe most, if not all, of the BCL is American English spelling, so I think my vote is for making the parser here support both while leaving IntelliSense consistent as American English (even though I usually spell grey with an e).

@tannergooding
Copy link
Member

I think supporting parsing both without exposing both would be reasonable. We can then chalk the existing duplicates up as legacy/back-compat

@safern safern added the help wanted [up-for-grabs] Good issue for external contributors label Jan 4, 2021
@safern
Copy link
Member

safern commented Jul 22, 2021

I'm going to close this as it fixed what was approved. If we want to add grey colors then we should open a new issue and should go through API Review

@safern safern closed this as completed Jul 22, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Aug 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-approved API was approved in API review, it can be implemented area-System.Drawing help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

No branches or pull requests