JDK-8260687 : Inherited font size is smaller than expected when using StyleSheet to add styles
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 11,15,17
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-01-30
  • Updated: 2021-02-18
  • Resolved: 2021-02-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 17
17 b10Fixed
Related Reports
Relates :  
Relates :  
Description
After the JDK-8257664 fix, the font size inherited from body is different from the font size from inline style declaration.

The bug is only reproducible when JEditorPane.W3C_LENGTH_UNITS is in effect and when the CSS properties are added to StyleSheet from HTMLEditorKit.

If the font-size property is declared in <style> element of the HTML or in style attribute of <body> element, it works as expected.
Comments
Changeset: 2e610f53 Author: Stanimir Stamenkov <stanio@yahoo.com> Committer: Alexey Ivanov <aivanov@openjdk.org> Date: 2021-02-15 16:16:50 +0000 URL: https://git.openjdk.java.net/jdk/commit/2e610f53
15-02-2021

As stated in the PR https://github.com/openjdk/jdk/pull/2515 this bug is not new, JDK-8257664 just uncovered a new case. The modified test case where the first paragraph is <p style="font-size: 100%">100% from body</p> fails on JDK 15, 17 and JDK 11 with the following message: java.lang.RuntimeException: The font size is different with w3cUnits: Percentage: 16 vs. Inherited: 43 vs. Explicit: 43 java.lang.RuntimeException: The font size is different with stdUnits: Percentage: 43 vs. Inherited: 16 vs. Explicit: 16 See screenshot BodyInheritedFontSize std.png taken with running JDK 15. Thus, both modes with and without JEditorPane.W3C_LENGTH_UNITS fail. I'm removing regression labels.
12-02-2021

I have written an automatic test for this bug: https://github.com/aivanov-jdk/jdk/commits/JDK-8260687 I haven't raised a separate PR because the fix to this bug is current included in JDK-8231286.
04-02-2021

The attached test case app HtmlFontSizeGUITest.java is based on HtmlFontSizeTest.java from JDK-8231286. With the fix of JDK-8231286 applied, the difference between ���inherited from body��� and ���16pt paragraph��� is not so significant but still noticeable. If you comment out the lines StyleSheet styleSheet = kit.getStyleSheet(); styleSheet.addRule("body { font-family: sans-serif; font-size: 16pt; }"); and use either variant of HTML_TEXT: + "<head><style> body { font-size: 16pt } </style></head>\n" //+ "<body style=\"font-size: 16pt\">\n" + "<body>\n" or //+ "<head><style> body { font-size: 16pt } </style></head>\n" + "<body style=\"font-size: 16pt\">\n" //+ "<body>\n" then the font size of the first two paragraphs will be the same.
30-01-2021