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

JDK-8292276 : Add named colors from CSS Color Module Level 4 #9825

Conversation

scientificware
Copy link
Contributor

@scientificware scientificware commented Aug 10, 2022

This is referenced in Java Bug Database as

This is tracked in JBS as

Adds missing color names, defined by CSS Level 4, in CSS.java :
CSS Color Module Level 4
W3C Candidate Recommendation Snapshot, 5 July 2022
7.1 Named Colors

Designed from : ScientificWare JDK-8292276 : Add named colors from CSS Color Module Level 4


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change requires a CSR request matching fixVersion 23 to be approved (needs to be created)

Issue

  • JDK-8292276: Add named colors from CSS Color Module Level 4 (Enhancement - P3)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/9825/head:pull/9825
$ git checkout pull/9825

Update a local copy of the PR:
$ git checkout pull/9825
$ git pull https://git.openjdk.org/jdk.git pull/9825/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 9825

View PR using the GUI difftool:
$ git pr show -t 9825

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/9825.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Aug 11, 2022

👋 Welcome back scientificware! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Aug 11, 2022

@scientificware The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Aug 11, 2022
@prsadhuk
Copy link
Contributor

First and foremost, you need to add JBS id 8292276 into the PR title. Also, please add a jtreg testcase which should fail before your fix and pass after.I guess JBS has a reproducer which can be made into a jtreg testcase, of which you can see several examples in jdk/test/javax/swing directory.

@scientificware scientificware changed the title Adds to CSS.java the missing color names. JDK-8292276 : Adds to CSS.java the missing color names. Aug 12, 2022
@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 12, 2022
@scientificware scientificware changed the title JDK-8292276 : Adds to CSS.java the missing color names. JDK-8292276 : Missing color names in CSS. Aug 12, 2022
CSS Color Module Level 4
W3C Candidate Recommendation Snapshot, 5 July 2022
[7.1 Named Colors](https://www.w3.org/TR/css-color-4/#named-color)
- Updates, Copyright year.
- Adds relative imports.
- Replaces, if ... then ... else statements with a Map called "colorNamed".
  Code is more readable and easy to maintain.
  After tests, TreeMap seems slower than Map. Results are available at #12 (comment).

Warning : The Previous JDK CSS Orange Color is different from CSS Color Recommendation.
@SWinxy
Copy link
Contributor

SWinxy commented Aug 16, 2022

Hey there. The current implementation creates a new Color object for each invocation of stringToColor (with the exception of "" because we want to keep developers on their toes). Using a Map will not create new Color objects for each invocation, which may explain why your results show Map as the most performant. This is technically a change in behavior, and technically not wanted.

To get around this, you can do new Color(c.getRed(), c.getGreen(), c.getBlue()) from the map, or--what I would prefer--to use an enhanced switch statement to create the colors.

One thing I'd request is to have stringToColor return in the branches, rather than setting the placeholder Color color; object. Things like this irk me. As in (using the map):

static Color stringToColor(String str) {
        if (str == null) {
            return null;
        } else if (str.length() == 0) {
            return Color.black;
        } else if (str.startsWith("rgb(")) {
            return parseRGB(str);
        } else if (str.startsWith("rgba(")) {
            return parseRGBA(str);
        } else if (str.charAt(0) == '#') {
            return hexToColor(str);
        } else if (colorNamed.containsKey(str.toLowerCase(Locale.ROOT))) {
            return colorNamed.get(str.toLowerCase(Locale.ROOT));
        } else {
            return hexToColor(str);
        }
    }

In general, good PR. I'd be interested to know the perf results when the behavior is unchanged, and if the enhanced switch would win out.

@scientificware
Copy link
Contributor Author

scientificware commented Aug 16, 2022

@SWinxy Thanks for comments. After reading them, I realize the Big Mistake !
I Shouldn't create a new object but rather return an existing one.

That was in my intention. All the code is already available here, I wrote it because I expected to move this logic to Color.java and return an Color instance like the Color.black in the existing code.

~~All color declarations are ready. ~~

The Map will be something like :

static TreeMap<String, Color> colorNamed = new TreeMap<String, Color>(
        Map.ofEntries(
            Map.entry("aliceblue", ALICE_BLUE),
            ...
            Map.entry("yellowgreen", YELLOW_GREEN)
        );            

Do you validate this approach ?

I think, I misinterpreted your message !

But could you tell me witch method you prefer, I wrote 4 for tests at scientificware#12

  • One classic with if ... then ... else
  • Another with switch ... case
  • One with TreeMap.
  • And le last with Map.

@scientificware
Copy link
Contributor Author

scientificware commented Aug 16, 2022

@SWinxy

I'd be interested to know the perf results when the behavior is unchanged, and if the enhanced switch would win out.
The results are also in my repository, the current implementation is

  • five times slower than the worst of other implementations
  • and eight times slower than the switch case implementation.

This concern only named Colors. For RGB and Hex, the code is the same than I think there is no change.
What I test :

  • 1 000 repetitions of 1 000 fixed random list of color names.
  • All tested implementations give the same result for only one RGB, RGBA and Hex because their logics are unchanged.

@openjdk openjdk bot removed the rfr Pull request is ready for review label Aug 16, 2022
Adds a jtreg test case that fails before JDK-8292276 patch and passes after.
Test the Cyan color name.
Cyan is the missing color name that originates the PR JDK8292276 : Missing Color NamesIn CSS.
Cyan name, as most color names Colors defined in CSS Color Module Level 4, is not referenced in CSS.java.
This test fails, if getAttribute doesn't return a cyan Color Object.
When a color name is missing getAttribute returns a black Color Object.
@SWinxy
Copy link
Contributor

SWinxy commented Aug 16, 2022

That's a bit sus for the enhanced switch statement to be significantly slower (7.5x more time than the map). Your methodology still shows that you aren't creating new objects for each invocation and returning the same objects each time. Is that accurate to your performance table?

@scientificware
Copy link
Contributor Author

scientificware commented Aug 17, 2022

Yes @SWinxy, you're right. Map and TreeMap implementations return the same object. Therefore comparisons with the current implemention or switch case solution are not relevant. I going to add a test result with Map + your workaround.

Presently, the switch case solution is the best in respect of the current behaviors you want to preserve.

I integrated all your comments but yesterday, I was busy with the test case and other propositions that could content you. I take time to found the best solution because there are other places in swing html package where such optimisation would be interresting, especially in view factories.

@scientificware
Copy link
Contributor Author

@SWinxy All my apologies, I skipped testing CASE + RGB implementation. I posted it but not tested (previous results were about CASE + Hex.
I updated my table including your workaround suggestion.

  • The results of CASE + RGB are still under Map.
  • But Map + your workaround gives good results.

All the stringToColor codes are available, feel free to make a test.

@SWinxy
Copy link
Contributor

SWinxy commented Aug 22, 2022

I mean I think I would prefer the switch over a map (it looks nicer to me). My crude tests showed that the switch is indeed slower, breaking my conception that switch statements are the peak of performance. Other than this request, I have no further comments.

@scientificware
Copy link
Contributor Author

scientificware commented Aug 22, 2022

@SWinxy Thanks for your reviews and confirmation tests.
Do you notice that the switch ... case is also two times slower than my "handmade" binary tree using if ... else ! A problem in the implementation of switch ... case ?

@openjdk openjdk bot added the rfr Pull request is ready for review label Aug 27, 2022
    - by correcting orange definition,
    - by adding 132 missing color names,
      - including transparent keyword
      - but excluding currentcolor keyword.
    - by treating RGB and Hex notations in insensitive case mode.
This commit modifies stringToColor method which has no modifier, so only usages are limited to :
    - its Class.
    - The inner Class ColorValue also without modifier uses it through the method to return the Color Object
    - its Package.
    - stringToColor is also used by javax.swing.text.html.StyleSheet stringToColor method to publicly return the Color Object.
    - conclusion : since Color Object is publicly exposed, one can't change method behavior. This preventing to return a constant Color excepted for the existing String.isEmpty argument.
Refactoring resolving color value and align it with 5.7. Resolving Values Values) will be treated in another PR. Extends JDK-8149631 rgb(...) CSS color values are not parsed properly.
Un caractère de retour à la ligne s'est immiscer dans le nom du dossier.
@openjdk openjdk bot added rfr Pull request is ready for review and removed rfr Pull request is ready for review labels Sep 7, 2022
@aivanov-jdk
Copy link
Member

Swing supports CSS1 only, it defines color names for 16 colors:

The suggested list of keyword color names is: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow. These 16 colors are taken from the Windows VGA palette, and their RGB values are not defined in this specification.

Would the addition of color names from CSS4 give a wrong impression that Swing implements CSS4?

@scientificware
Copy link
Contributor Author

scientificware commented Aug 17, 2023

@prrace and @aivanov-jdk #15262, #10317 and #9825 (this PR) are independant. That's why I planed to treat them separatly. It is also easier to test performance.

Yes, all affect the result of the stringToColor method but they are unrelated except for the stringToColor comments which need to be updated.

stringToColor is public only in StyleSheet.java but not in CSS.java. Using it directly with an unparsed string can be problematic if the string contains extra spaces. In fact this method is waiting for a parsed string.

In jshell, compare the following results :

import javax.swing.text.html.StyleSheet;
StyleSheet ss = new StyleSheet();

ss.stringToColor("#fe1ab5"); \\ rgb(254,26,181)
ss.stringToColor(" #fe1ab5"); \\ null
ss.stringToColor("rgb(254,26,181)"); \\ rgb(254,26,181)
ss.stringToColor(" rgb(254,26,181)"); \\ null
ss.stringToColor("rgb (254,26,181)");  \\ null

import javax.swing.text.AttributeSet;

AttributeSet as = ss.getDeclaration("color: rgb (254,26,181);"); \\ null

May be we can write it like that :

    static public Color stringToColor(String string) {
        StyleSheet ss = new StyleSheet();
        AttributeSet as = ss.getDeclaration("color: %s;".formatted(string));
        return CSS.stringToColor(as.getAttribute(COLOR).toString());
    }

@prrace
Copy link
Contributor

prrace commented Aug 17, 2023

@prrace and @aivanov-jdk #15262, #10317 and #9825 (this PR) are independant. That's why I planed to treat them separatly. It is also easier to test performance.

Not sure I see that to be the case.

Yes, all affect the result of the stringToColor method but they are unrealated except for the stringToColor comments which need to be updated.

They are not just "comments", they are Java SE API specification.
If you push code that does anything different, that's a problem - it can't wait to be "updated in a later fix".

stringToColor is public only in StyleSheet.java but not in CSS.java.

But the one in Stylesheet is merely a wrapper around the one in CSS
public Color stringToColor(String string) {
return CSS.stringToColor(string);
}

Basically at the very least you need to merge the two we asked you to merge.
I'll requote below what Alexey and I said in Feb
No one has looked at it enough to decide about the other one yet.

===
This specification change seems to be dependent on the change in implementation proposed in
#10317
JDK-8293776 : Adds CSS 4 and 8 digits hex coded Color
And BTW if you implemented that change on its own, it would not be spec compliant.

I think it best to WITHDRAW that other PR and absorb it in this PR

Also you should in the doc include the spec link.
spec limits what it will convert. I think

Initially, it looked as if handling these issues separately was a good idea. Now that we know that the specification of a public needs updating, which requires a CSR, it is better to have everything ready: named colors, hex-parsers, rgb() and rgba() parsers. The spec refers to all the cases. If one is missing, the method is not compliant to its specification.

Amending the implementation one by one would require updating the spec and reviewing the CSR. Thus, having everything ready in one larger PR makes more sense

=====

# Conflicts:
#	src/java.desktop/share/classes/javax/swing/text/html/CSS.java
@openjdk
Copy link

openjdk bot commented Aug 17, 2023

⚠️ @scientificware This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch> where <project> is the name of another project in the OpenJDK organization (for example Merge jdk:master).

@prrace
Copy link
Contributor

prrace commented Oct 6, 2023

/csr

@prrace
Copy link
Contributor

prrace commented Oct 6, 2023

Sorry, slow in getting back to this. I ran our test suite against this change.
The only problem was that a TCK test failed. It is a negative test which was checking that only the color strings specified to be supported worked. That test will be updated by the TCK team as a result of the CSR which we need to file anyway.
I'll create the CSR for you and populate it.

CSR here https://bugs.openjdk.org/browse/JDK-8317690.

@openjdk
Copy link

openjdk bot commented Oct 6, 2023

@prrace an approved CSR request is already required for this pull request.

Copy link
Contributor

@prrace prrace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there's a pre-existing mess here and I hope we can address it here
since it clearly needs addressing.

The existing spec. of StyleSheet.stringToColor() is clear that if what is
passed in doesn't match what it supports - it returns null.

/**
* Converts a color string such as "RED" or "#NNNNNN" to a Color.
* Note: This will only convert the HTML3.2 color strings
* or a string of length 7;
* otherwise, it will return null.
*
* @param string color string such as "RED" or "#NNNNNN"
* @return the color
*/
public Color stringToColor(String string) {
return CSS.stringToColor(string);
}

However since at least JDK 7 the CSS.stringToColor() method that is called says
/**
* Convert a color string such as "RED" or "#NNNNNN" or "rgb(r, g, b)"
* to a Color.
*/

And indeed it does.

But the HTML 3.2 spec says NOTHING about that last format.

So this has been out of compliance forever.

Here's a program run with JDK 8 that per spec should return null f
import javax.swing.text.html.StyleSheet;

public class StringToColor {
public static void main(String[] args) {
StyleSheet ss = new StyleSheet();
Color c = ss.stringToColor("rgb(50 50 50)");
System.out.println(c);

}
}

~/jdk8/Contents/Home/bin/java StringToColor
java.awt.Color[r=50,g=50,b=50]

Next in this fix https://bugs.openjdk.org/browse/JDK-8256019 for JDK 17
"rgba" support was added making it even further out of compliance.
The test and use case there did not make any direct use of StyleSheet.
it just passed HTML text to Swing.
So I expect this was overlooked (although there's a comment in the bug
report that this didn't appear to be specified which isn't true).
Perhaps the same is how rgb() got in too.

We need to rectify as much of this as we can.
I don't propose to go back to earlier releases and undo changes
to match the spec. and we can't go back and update the spec. either.
So its probably something we need to live with.

The update proposed here should go a very long way to addressing
this disconnect, bringing the spec. into alignment with existing
implementation.

But I think rather than just referencing the CSS spec, it should
be explicit in what it supports unless it implements EVERY SINGLE THING
that spec says. And clearly it does not !

Now we also have this PR #15262
which so far as I can tell is intended to bring the CSS support for rgb/rgba
into alignment with the CSS spec. So clearly that PR needs to be merged
into this one. I KNOW we already merged another PR into here but this
whole thing needs to be ONE PR.
We can't put spec implementation later and we can't put implementation
which (further!) contradicts the spec.

Then when we get all of these together I need to see that it really
implements what the spec. says and if it doesn't we'll need to
call out what is supported.
And either way the spec. would benefit from at least some examples
of each case, as to what are valid values for r,g,b and a.

@scientificware
Copy link
Contributor Author

PR JDK-8294090 #15262 is closed. Its content will be merged in this PR after applying requiered changes.

- rename the list of string test.

CSS.java :
- correct a wrong index.
- Add a subset of RGB and RGBA tests.
- Rename the color which doesn't belong to CSS-COLOR-4 specification.
@scientificware
Copy link
Contributor Author

Hex3468DigitsColor.java, this test is no longer useful. All tests are now included in MissingColorNames.java.

I'll remove it.

// Remove the next line after merging JDK-8294090 : Aligns the CSS <rgb()> and <rgba()> function behaviours #15262.
{"rgb(12 24 200)", "ff0c18c8"}
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep an empty line at the end of the files.

- Catches the Color Illegal Argument Exception and appends it to the result summary.
- Uncomments rgb tests.
- Update source code declaration in documentation comments and specifications.
- Typo in an argument.
@scientificware
Copy link
Contributor Author

scientificware commented Oct 13, 2023

  • Test output after the patch.
    No Exception.
  • Test output before the patch.
    Exception in thread "main" java.lang.RuntimeException: Failed.
            [aliceblue is not supported] 
            [antiquewhite is not supported] 
            [aquamarine is not supported] 
            [azure is not supported] 
            [beige is not supported] 
            [bisque is not supported] 
            [blanchedalmond is not supported] 
            [blueviolet is not supported] 
            [brown is not supported] 
            [burlywood is not supported] 
            [cadetblue is not supported] 
            [chartreuse is not supported] 
            [chocolate is not supported] 
            [coral is not supported] 
            [cornflowerblue is not supported] 
            [cornsilk is not supported] 
            [crimson is not supported] 
            [cyan is not supported] 
            [darkblue is not supported] 
            [darkcyan is not supported] 
            [darkgoldenrod is not supported] 
            [darkgray is not supported] 
            [darkgreen is not supported] 
            [darkgrey is not supported] 
            [darkkhaki is not supported] 
            [darkmagenta is not supported] 
            [darkolivegreen is not supported] 
            [darkorange is not supported] 
            [darkorchid is not supported] 
            [darkred is not supported] 
            [darksalmon is not supported] 
            [darkseagreen is not supported] 
            [darkslateblue is not supported] 
            [darkslategray is not supported] 
            [darkslategrey is not supported] 
            [darkturquoise is not supported] 
            [darkviolet is not supported] 
            [deeppink is not supported] 
            [deepskyblue is not supported] 
            [dimgray is not supported] 
            [dimgrey is not supported] 
            [dodgerblue is not supported] 
            [firebrick is not supported] 
            [floralwhite is not supported] 
            [forestgreen is not supported] 
            [gainsboro is not supported] 
            [ghostwhite is not supported] 
            [gold is not supported] 
            [goldenrod is not supported] 
            [greenyellow is not supported] 
            [grey is not supported] 
            [honeydew is not supported] 
            [hotpink is not supported] 
            [indianred is not supported] 
            [indigo is not supported] 
            [ivory is not supported] 
            [khaki is not supported] 
            [lavender is not supported] 
            [lavenderblush is not supported] 
            [lawngreen is not supported] 
            [lemonchiffon is not supported] 
            [lightblue is not supported] 
            [lightcoral is not supported] 
            [lightcyan is not supported] 
            [lightgoldenrodyellow is not supported] 
            [lightgray is not supported] 
            [lightgreen is not supported] 
            [lightgrey is not supported] 
            [lightpink is not supported] 
            [lightsalmon is not supported] 
            [lightseagreen is not supported] 
            [lightskyblue is not supported] 
            [lightslategray is not supported] 
            [lightslategrey is not supported] 
            [lightsteelblue is not supported] 
            [lightyellow is not supported] 
            [limegreen is not supported] 
            [linen is not supported] 
            [magenta is not supported] 
            [mediumaquamarine is not supported] 
            [mediumblue is not supported] 
            [mediumorchid is not supported] 
            [mediumpurple is not supported] 
            [mediumseagreen is not supported] 
            [mediumslateblue is not supported] 
            [mediumspringgreen is not supported] 
            [mediumturquoise is not supported] 
            [mediumvioletred is not supported] 
            [midnightblue is not supported] 
            [mintcream is not supported] 
            [mistyrose is not supported] 
            [moccasin is not supported] 
            [navajowhite is not supported] 
            [oldlace is not supported] 
            [olivedrab is not supported] 
         -> [ orange wrong RGB code ] expected ffffa500, returned ffff8000
            [orangered is not supported] 
            [orchid is not supported] 
            [palegoldenrod is not supported] 
            [palegreen is not supported] 
            [paleturquoise is not supported] 
            [palevioletred is not supported] 
            [papayawhip is not supported] 
            [peachpuff is not supported] 
            [peru is not supported] 
            [pink is not supported] 
            [plum is not supported] 
            [powderblue is not supported] 
            [rebeccapurple is not supported] 
            [rosybrown is not supported] 
            [royalblue is not supported] 
            [saddlebrown is not supported] 
            [salmon is not supported] 
            [sandybrown is not supported] 
            [seagreen is not supported] 
            [seashell is not supported] 
            [sienna is not supported] 
            [skyblue is not supported] 
            [slateblue is not supported] 
            [slategray is not supported] 
            [slategrey is not supported] 
            [snow is not supported] 
            [springgreen is not supported] 
            [steelblue is not supported] 
            [tan is not supported] 
            [thistle is not supported] 
            [tomato is not supported] 
            [transparent is not supported] 
            [turquoise is not supported] 
            [violet is not supported] 
            [wheat is not supported] 
            [whitesmoke is not supported] 
            [yellowgreen is not supported] 
            [#f should return null] 
            [#f0 should return null] 
         -> [ #f12a wrong RGB code ] expected aaff1122, returned ff00f12a
            [#f0f10 should return null] 
            [#f0f1092 should return null] 
         -> [ #ff1122aa wrong RGB code ] expected aaff1122, returned ffff1122
         -> [ #f0f10928 wrong RGB code ] expected 28f0f109, returned fff0f109
            [f0f10928 is not supported] 
            [#f0f109289 should return null] 
            [ffffffff is not supported] 
         -> [ rgb(12 24 200 / 82%) wrong RGB code ] expected d10c18c8, returned ff0c18c8
         -> [ rgb(12 24 200 / 0.82) wrong RGB code ] expected d10c18c8, returned ff0c18c8
         -> [ rgb(12 24 200 / -210) wrong RGB code ] expected 000c18c8, returned ff0c18c8
         -> [ rgb(15% 60% 49%) wrong RGB code ] expected ff26997d, returned ff26997c
         -> [ rgb(15% 60% 49% / 82%) wrong RGB code ] expected d126997d, returned ff26997c
         -> [ rgb(15%, 60%, 49% / 82%) wrong RGB code ] expected d126997d, returned ff26997c
         -> [ rgb(0.14  60% 52.3 / 0.98) wrong RGB code ] expected fa009934, returned ff009934
         -> [ rgb(none none none / none) wrong RGB code ] expected 00000000, returned ff000000
         -> [ rgb(none none none/none) wrong RGB code ] expected 00000000, returned ff000000
         -> [ rgb(none none 30) wrong RGB code ] expected ff00001e, returned ff1e0000
         -> [ rgb(none 20 none) wrong RGB code ] expected ff001400, returned ff140000
         -> [ rgb(10 50 13% / 50%) wrong RGB code ] expected 800a3221, returned ff0a3221
         -> [ rgb(10 50 13% // 50%) wrong RGB code ] expected ff000000, returned ff0a3221
         -> [ rgb(10 50,, 13% // 50%) wrong RGB code ] expected ff000000, returned ff0a3221
         -> [ rgb(10 50 ,, 13% // 50%) wrong RGB code ] expected ff000000, returned ff0a3221
         -> [ rgb(1.2e1 0.24e2 2e2) wrong RGB code ] expected ff0c18c8, returned ff010100
         -> [ rgb(1200e-2 2400e-2 200000e-3) wrong RGB code ] expected ff0c18c8, returned ffff00ff
         -> [ rgb(1200E-2 2400E-2 200000E-3) wrong RGB code ] expected ff0c18c8, returned ffff00ff
         -> [ rgb(120560.64646464632469823160676064670646798706406464098706464097970906464067e-4 2400E-2 200000e-3) wrong RGB code ] expected ff0c18c8, returned ffff00ff
         -> [ rgba(12 24 200) wrong RGB code ] expected ff0c18c8, returned c18c8
         -> [ rgba(12 24 200%) wrong RGB code ] expected ff0c18ff, returned c18ff
         -> [ rgba(-1 24 200%) wrong RGB code ] expected ff0018ff, returned 18ff
         -> [ rgba(300 24 28) wrong RGB code ] expected ffff181c, returned ff181c
         +> [ rgba(12 24 200 / 82%) illegal argument ] d10c18c8 Color parameter outside of expected range: Alpha
         -> [ rgba(12, 24, 200) wrong RGB code ] expected ff0c18c8, returned c18c8
         +> [ rgba(12, 24, 200, 210) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
         +> [ rgba(12, 24, 200 , 210) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
         +> [ rgba(12 , 24 , 200 , 210) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
         +> [ rgba(   12  ,      24 ,   200 ,             210  ) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
         +> [ rgba(12 ,24, 200 ,210) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
         +> [ rgba(12,24,200,210) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
         -> [ rgba(15% 60% 49%) wrong RGB code ] expected ff26997d, returned 26997d
         +> [ rgba(15% 60% 49% / 82%) illegal argument ] d126997d Color parameter outside of expected range: Alpha
         +> [ rgba(15%, 60%, 49% / 82%) illegal argument ] d126997d Color parameter outside of expected range: Alpha
         -> [ rgba(none none none) wrong RGB code ] expected ff000000, returned 0
         -> [ rgba(none none 30) wrong RGB code ] expected ff00001e, returned 1e0000
         -> [ rgba(none 20 none) wrong RGB code ] expected ff001400, returned 140000
         -> [ rgba(10 none none) wrong RGB code ] expected ff0a0000, returned a0000
         -> [ rgba(none none none) wrong RGB code ] expected ff000000, returned 0
         +> [ rgba(10 50 13% / 50%) illegal argument ] 800a3221 Color parameter outside of expected range: Alpha
         +> [ rgba(10 50 13% // 50%) illegal argument ] ff000000 Color parameter outside of expected range: Alpha
         +> [ rgba(10 50,, 13% // 50%) illegal argument ] ff000000 Color parameter outside of expected range: Alpha
         +> [ rgba(10 50 ,, 13% // 50%) illegal argument ] ff000000 Color parameter outside of expected range: Alpha
         +> [ rgba(1.2e1 0.24e2 2e2) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
         -> [ rgba(1200e-2 2400e-2 200000e-3) wrong RGB code ] expected ff0c18c8, returned ff00ff
         -> [ rgba(1200E-2 2400E-2 200000E-3) wrong RGB code ] expected ff0c18c8, returned ff00ff
         -> [ rgba(120560.64646464632469823160676064670646798706406464098706464097970906464067e-4 2400E-2 200000e-3) wrong RGB code ] expected ff0c18c8, returned ff00ff
          at MissingColorNames.main(MissingColorNames.java:67)
    

Copy link
Contributor

@prrace prrace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm testing the change as is, results TBD but there are few things to be updated here.

* <li><a href="https://www.w3.org/TR/css-color-4/#rgb-functions">`rgb()` and `rgba()`
* functions</a></li>
* </ul>
* as specified by the <a href="https://www.w3.org/TR/css-color-4/">CSS Color Module Level 4</a>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this PR : https://github.com/openjdk/jdk/pull/13360/files
We have the new {@SPEC .. } tag whereever we reference an external spec.
So you should add it here too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think that in the public class doc of CSS.java which talks about CSS1, you need to add a comment
"Additionally, the color strings from CSS 4 are supported" and again point to the spec.

public static void main(String[] args) {
StringBuilder result = new StringBuilder();
boolean passed = true;
StyleSheet styleSheet = new StyleSheet();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MissingColorNames test makes this one look very sparse.
can we please cover all the supported patterns and have negative tests too.

@prrace
Copy link
Contributor

prrace commented Oct 23, 2023

Hmm ..
I'm seeing the test fail

% java MissingColorNames
Exception in thread "main" java.lang.RuntimeException: Failed.
-> [ rgb(12 24 200 / 82%) wrong RGB code ] expected d10c18c8, returned ff0c18c8
-> [ rgb(12 24 200 / 0.82) wrong RGB code ] expected d10c18c8, returned ff0c18c8
-> [ rgb(12 24 200 / -210) wrong RGB code ] expected 000c18c8, returned ff0c18c8
-> [ rgb(15% 60% 49%) wrong RGB code ] expected ff26997d, returned ff26997c
-> [ rgb(15% 60% 49% / 82%) wrong RGB code ] expected d126997d, returned ff26997c
-> [ rgb(15%, 60%, 49% / 82%) wrong RGB code ] expected d126997d, returned ff26997c
-> [ rgb(0.14 60% 52.3 / 0.98) wrong RGB code ] expected fa009934, returned ff009934
-> [ rgb(none none none / none) wrong RGB code ] expected 00000000, returned ff000000
-> [ rgb(none none none/none) wrong RGB code ] expected 00000000, returned ff000000
-> [ rgb(none none 30) wrong RGB code ] expected ff00001e, returned ff1e0000
-> [ rgb(none 20 none) wrong RGB code ] expected ff001400, returned ff140000
-> [ rgb(10 50 13% / 50%) wrong RGB code ] expected 800a3221, returned ff0a3221
-> [ rgb(10 50 13% // 50%) wrong RGB code ] expected ff000000, returned ff0a3221
-> [ rgb(10 50,, 13% // 50%) wrong RGB code ] expected ff000000, returned ff0a3221
-> [ rgb(10 50 ,, 13% // 50%) wrong RGB code ] expected ff000000, returned ff0a3221
-> [ rgb(1.2e1 0.24e2 2e2) wrong RGB code ] expected ff0c18c8, returned ff010100
-> [ rgb(1200e-2 2400e-2 200000e-3) wrong RGB code ] expected ff0c18c8, returned ffff00ff
-> [ rgb(1200E-2 2400E-2 200000E-3) wrong RGB code ] expected ff0c18c8, returned ffff00ff
-> [ rgb(120560.64646464632469823160676064670646798706406464098706464097970906464067e-4 2400E-2 200000e-3) wrong RGB code ] expected ff0c18c8, returned ffff00ff
-> [ rgba(12 24 200) wrong RGB code ] expected ff0c18c8, returned c18c8
-> [ rgba(12 24 200%) wrong RGB code ] expected ff0c18ff, returned c18ff
-> [ rgba(-1 24 200%) wrong RGB code ] expected ff0018ff, returned 18ff
-> [ rgba(300 24 28) wrong RGB code ] expected ffff181c, returned ff181c
+> [ rgba(12 24 200 / 82%) illegal argument ] d10c18c8 Color parameter outside of expected range: Alpha
-> [ rgba(12, 24, 200) wrong RGB code ] expected ff0c18c8, returned c18c8
+> [ rgba(12, 24, 200, 210) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
+> [ rgba(12, 24, 200 , 210) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
+> [ rgba(12 , 24 , 200 , 210) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
+> [ rgba( 12 , 24 , 200 , 210 ) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
+> [ rgba(12 ,24, 200 ,210) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
+> [ rgba(12,24,200,210) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
-> [ rgba(15% 60% 49%) wrong RGB code ] expected ff26997d, returned 26997d
+> [ rgba(15% 60% 49% / 82%) illegal argument ] d126997d Color parameter outside of expected range: Alpha
+> [ rgba(15%, 60%, 49% / 82%) illegal argument ] d126997d Color parameter outside of expected range: Alpha
-> [ rgba(none none none) wrong RGB code ] expected ff000000, returned 0
-> [ rgba(none none 30) wrong RGB code ] expected ff00001e, returned 1e0000
-> [ rgba(none 20 none) wrong RGB code ] expected ff001400, returned 140000
-> [ rgba(10 none none) wrong RGB code ] expected ff0a0000, returned a0000
-> [ rgba(none none none) wrong RGB code ] expected ff000000, returned 0
+> [ rgba(10 50 13% / 50%) illegal argument ] 800a3221 Color parameter outside of expected range: Alpha
+> [ rgba(10 50 13% // 50%) illegal argument ] ff000000 Color parameter outside of expected range: Alpha
+> [ rgba(10 50,, 13% // 50%) illegal argument ] ff000000 Color parameter outside of expected range: Alpha
+> [ rgba(10 50 ,, 13% // 50%) illegal argument ] ff000000 Color parameter outside of expected range: Alpha
+> [ rgba(1.2e1 0.24e2 2e2) illegal argument ] ff0c18c8 Color parameter outside of expected range: Alpha
-> [ rgba(1200e-2 2400e-2 200000e-3) wrong RGB code ] expected ff0c18c8, returned ff00ff
-> [ rgba(1200E-2 2400E-2 200000E-3) wrong RGB code ] expected ff0c18c8, returned ff00ff
-> [ rgba(120560.64646464632469823160676064670646798706406464098706464097970906464067e-4 2400E-2 200000e-3) wrong RGB code ] expected ff0c18c8, returned ff00ff
at MissingColorNames.main(MissingColorNames.java:70)

@scientificware
Copy link
Contributor Author

scientificware commented Oct 23, 2023

The test fails because the content of JDK-8294090 #15262 has not been merged into this PR.

@scientificware
Copy link
Contributor Author

scientificware commented Oct 23, 2023

Actually, JDK-8294090 #15262 successfully parses expressions like rgba(12 24 200%) but the CSS spec doesn't allow mixing numbers and percentages in R, G and B components. I am correcting this.

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 20, 2023

@scientificware This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 18, 2023

@scientificware This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the /open pull request command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client-libs-dev@openjdk.org csr Pull request needs approved CSR before integration rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

8 participants