Skip to content

8256019: JLabel HTML text does not support translucent text colors#1158

Closed
prsadhuk wants to merge 3 commits intoopenjdk:masterfrom
prsadhuk:JDK-8256019
Closed

8256019: JLabel HTML text does not support translucent text colors#1158
prsadhuk wants to merge 3 commits intoopenjdk:masterfrom
prsadhuk:JDK-8256019

Conversation

@prsadhuk
Copy link
Copy Markdown
Contributor

@prsadhuk prsadhuk commented Nov 11, 2020

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

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8256019: JLabel HTML text does not support translucent text colors

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/1158/head:pull/1158
$ git checkout pull/1158

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper bot commented Nov 11, 2020

👋 Welcome back psadhukhan! 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 openjdk bot added the rfr Pull request is ready for review label Nov 11, 2020
@openjdk
Copy link
Copy Markdown

openjdk bot commented Nov 11, 2020

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

  • swing

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.

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));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have already mentioned it here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But in what place we parse "rgb(...)"? it does not seem mentioned in this method and does not depend on the c.getForeground()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@mlbridge
Copy link
Copy Markdown

mlbridge bot commented Nov 11, 2020

Webrevs

else if (str.startsWith("rgb(")) {
color = parseRGB(str);
} else if (str.startsWith("rgba(")) {
color = parseRGBA(str);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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(");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't we need to implement this parsing similarly to rgb()? somewhere inside kit.createDefaultDocument() or where we parse rgb()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, seems like overkill last time which is not needed. Reverted back unneeded code.

@prsadhuk
Copy link
Copy Markdown
Contributor Author

prsadhuk commented Dec 2, 2020

any further comments?

* @test
* @bug 8256019
* @summary Verifies if JLabel HTML text support translucent text colors
* @run main/manual TestTranslucentLabelText
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it necessary to make this test manual? probably we can just draw the label to the buffered image and check resulted content?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried before making it manual but could not effectively do that.

@victordyakov
Copy link
Copy Markdown

@Kizune please review

@openjdk
Copy link
Copy Markdown

openjdk bot commented Dec 9, 2020

@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:

8256019: JLabel HTML text does not support translucent text colors

Reviewed-by: serb

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 master branch:

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 master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 9, 2020
@bridgekeeper
Copy link
Copy Markdown

bridgekeeper bot commented Jan 6, 2021

@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!

@prsadhuk
Copy link
Copy Markdown
Contributor Author

/integrate

@openjdk openjdk bot closed this Jan 13, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jan 13, 2021
@openjdk
Copy link
Copy Markdown

openjdk bot commented Jan 13, 2021

@prsadhuk Since your change was applied there have been 885 commits pushed to the master branch:

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.

@prsadhuk prsadhuk deleted the JDK-8256019 branch January 13, 2021 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integrated Pull request has been integrated swing [email protected]

Development

Successfully merging this pull request may close these issues.

3 participants