Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8292276

Add named colors from CSS Color Module Level 4

    XMLWordPrintable

Details

    • In Review
    • generic
    • generic

    Description

      A DESCRIPTION OF THE PROBLEM :
      In the Swing HTML package, we can't use most of the named colors from the CSS 4 Level recommendation. https://www.w3.org/TR/2022/CR-css-color-4-20220705/#named-colors.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Test the provided program with :
      - JDK without patch.
      - JDK patched (PR https://github.com/openjdk/jdk/pull/9825)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      With the patch, the two texts must be the same color cyan.
      ACTUAL -
      Without the patch, the first text is blakck, the second text is cyan.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.Dimension;
      import javax.swing.JEditorPane;
      import javax.swing.JFrame;
      import javax.swing.JScrollPane;
      import javax.swing.SwingUtilities;
      import javax.swing.text.Document;
      import javax.swing.text.html.HTMLEditorKit;
      import javax.swing.text.html.StyleSheet;

      public class CSSNamedColorTest{
        public static void main(String[] args){
          new CSSNamedColorTest();
        }
        
        public CSSNamedColorTest(){
          SwingUtilities.invokeLater(new Runnable(){
            public void run(){
              JEditorPane jEditorPane = new JEditorPane();
              jEditorPane.setEditable(false);
              JScrollPane scrollPane = new JScrollPane(jEditorPane);
              HTMLEditorKit kit = new HTMLEditorKit();
              jEditorPane.setEditorKit(kit);
              StyleSheet styleSheet = kit.getStyleSheet();
              styleSheet.addRule("body {color: #000; font-family:times; margin: 4px; }");
              styleSheet.addRule("#rgb {color: Cyan; font-family:times; margin: 4px; }");
              styleSheet.addRule("#nam {color: #00ffff;}");
              styleSheet.addRule("pre {font : 10px monaco; color : black; background-color : #fafafa; }");
              String htmlString = """
                                  <html>
                                     <body>
                                        <h1 id="rgb">Welcome ! using named cyan color</h1>
                                        <h1 id="nam">Welcome with hex cyan coded</h2>
                                        <p>The two lines must have the same color.</p>
                                        <p>First Welcome in black means that the named color is not implemented.</p>
                                     </body>
                                  </html>
                                  """;
              Document doc = kit.createDefaultDocument();
              jEditorPane.setDocument(doc);
              jEditorPane.setText(htmlString);
              JFrame jf = new JFrame("CSS named colors Test");
              jf.getContentPane().add(scrollPane, BorderLayout.CENTER);
              jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              jf.setSize(new Dimension(600,400));
              jf.setLocationRelativeTo(null);
              jf.setVisible(true);
            }
          });
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Other suggestions are available at https://github.com/scientificware/jdk/issues/12

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              aivanov Alexey Ivanov
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated: