8256019: JLabel HTML text does not support translucent text colors#1158
8256019: JLabel HTML text does not support translucent text colors#1158prsadhuk wants to merge 3 commits intoopenjdk:masterfrom
Conversation
|
👋 Welcome back psadhukhan! A progress list of the required criteria for merging this PR into |
| color[i] = color[i].strip(); | ||
| } | ||
| col = new Color(Integer.parseInt(color[0]), Integer.parseInt(color[1]), | ||
| Integer.parseInt(color[2]), (int)(Float.parseFloat(color[3])*255)); |
There was a problem hiding this comment.
It seems OceanTheme in Metal L&F supports only rgb
ColorUIResource CONTROL_TEXT_COLOR = new PrintColorUIResource(0x333333, Color.BLACK)
so even when Color(r,g,b,a) is used, it creates rgb color and not rgba
so alpha is obtained and passed separately.
There was a problem hiding this comment.
I have already mentioned it here.
There was a problem hiding this comment.
But in what place we parse "rgb(...)"? it does not seem mentioned in this method and does not depend on the c.getForeground()?
There was a problem hiding this comment.
It is parsed in Parser.java#parseAttributeValue() which is being called from this method via kit.read().
It also parses rgba() and store it but JDK does not seem to support rgba() in CSS.java and also SwingUtilities2.displayPropertiesToCSS() which is being called prior to html parsing so alpha needs to be parsed separately.
Webrevs
|
| else if (str.startsWith("rgb(")) { | ||
| color = parseRGB(str); | ||
| } else if (str.startsWith("rgba(")) { | ||
| color = parseRGBA(str); |
There was a problem hiding this comment.
Probably we need to update the spec for StyleSheet.stringToColor()
| */ | ||
| public static View createHTMLView(JComponent c, String html) { | ||
| BasicEditorKit kit = getFactory(); | ||
| int beginIndex = html.indexOf("rgba("); |
There was a problem hiding this comment.
Don't we need to implement this parsing similarly to rgb()? somewhere inside kit.createDefaultDocument() or where we parse rgb()?
There was a problem hiding this comment.
The problem is the alpha color not being present in c.getForeground() so we need to parse alpha here to pass the value to displayPropertiesToCSS(). I have already mentioned it below.
There was a problem hiding this comment.
As far as I understand the only place where we decode rgb() is CSS.stringToColor and that code missing the rgba() case.
Just to double-check.
If the test case TestTranslucentLabelText will be modified to use rgb() instead of rgba() then the color which was set by the user to the Component will be ignored, and the correct color from the rgb() will be used. So it does not matter that c.getForeground() contains some opaque color, it is ignored, why the similar case for rgba() does not work in the same way?
There was a problem hiding this comment.
Yes, seems like overkill last time which is not needed. Reverted back unneeded code.
|
any further comments? |
| * @test | ||
| * @bug 8256019 | ||
| * @summary Verifies if JLabel HTML text support translucent text colors | ||
| * @run main/manual TestTranslucentLabelText |
There was a problem hiding this comment.
Is it necessary to make this test manual? probably we can just draw the label to the buffered image and check resulted content?
There was a problem hiding this comment.
I tried before making it manual but could not effectively do that.
|
@Kizune please review |
|
@prsadhuk This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 520 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
|
@prsadhuk 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! |
|
/integrate |
|
@prsadhuk Since your change was applied there have been 885 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 44c8379. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Issue is a JLabel with a translucent foreground color properly renders plain text, but with HTML text, the alpha component is discarded and the text is rendered using an opaque color.
As per https://www.w3schools.com/cssref/func_rgba.asp, CSS supports rgba() to support alpha and render translucent text color
but support for rgba() is not present in JDK html text rendering.
Added support for rgba() to render translucent text color.
Progress
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/1158/head:pull/1158$ git checkout pull/1158