-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8260687: Inherited font size is smaller than expected when using StyleSheet to add styles #2515
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
Conversation
Honor the main StyleSheet.w3cLengthUnits setting at all times.
|
👋 Welcome back stanio! A progress list of the required criteria for merging this PR into |
Webrevs
|
|
Hi @stanio. Thank you for your new contribution. I have not run the build and tests for it yet. However, the suggested fix looks reasonable. I thought it was related to the way I propose that you copy the changes from my JDK-8260687 branch. There are two changes:
You can then add another |
…xpected when using StyleSheet to add styles
prsadhuk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix looks ok, it seems. Please also add the testcase given in JBS, or you can add your own.
aivanov-jdk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix looks good to me too. It passes the set of the four tests related to the recent fixes:
- javax/swing/text/html/CSS/8231286/HtmlFontSizeTest.java
- javax/swing/text/html/CSS/4765271/bug4765271.java
- javax/swing/text/html/StyleSheet/TestWrongCSSFontSize.java
- javax/swing/text/html/StyleSheet/8260687/BodyInheritedFontSize.java
I've just updated BodyInheritedFontSize.java on my JDK-8260687 branch to include your test case with font-size: 100%.
- Add <p style="font-size: 100%">...</p> element/case
It is important to have it before the <p>...</p> one, so it could
trigger the pre-existing problem;
- Replace StyleConstants.getFontSize() for GlyphView.getFont().getSize()
The former is unreliable as it doesn't explicitly send a StyleSheet
context and depends on generally unknown state of the
CSS.styleSheet.w3cLengthUnits the FontSize declaration has been
instantiated from. At the end it doesn't report the actual font
set to the view.
|
I have copied the changes from the aivanov-jdk/jdk@f9e997776fe4 branch earlier and made my revision to include the
|
I do not think the order matters. The paragraph which does not specify the font size and the paragraph which specifies it as 100% have the same size. This can be confirmed with another added check, does it make sense?
Does it not? I can't see it has much of difference: visually the views have different font sizes which is confirmed by the existing check. But the font size in all three cases is expected to be the same. |
aivanov-jdk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have copied the changes from the aivanov-jdk/jdk@f9e9977 branch earlier and made my revision to include the
font-size: 100%case. I have the following adjustments that don't appear included in @aivanov-jdk's latest change:• The
<p style="font-size: 100%">...</p>has to be before the<p>...</p>to trigger the pre-existing problem (f.e. in Java 11);I do not think the order matters. The paragraph which does not specify the font size and the paragraph which specifies it as 100% have the same size. This can be confirmed with another added check, does it make sense?
Okay, the order does matter, it produces different results. With percentage value first, one more scenario is covered.
The third comparison does not make sense. If the two not-equal-to conditions are false, fontSizeInherited != fontSizePercentage is also false.
test/jdk/javax/swing/text/html/StyleSheet/8260687/BodyInheritedFontSize.java
Outdated
Show resolved
Hide resolved
It doesn't matter just after the #1759 fix. If you try this with Java 11 or 15 you'll see the problem is present even before that fix. That's the point.
That's the point, what you see visually is what you get from |
|
Shouldn't you update copyright years in the headers of edited files? |
Sure! The copyright header in |
I don't know if I should. I'll do it if I'm told it is necessary. |
Should I update it like: "Copyright (c) 1997, 2021"? That is, update the second year, or should I add a new one: "Copyright (c) 1997, 2018, 2021"? |
|
@stanio 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 59 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. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@prsadhuk, @aivanov-jdk, @azuev-java) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
test/jdk/javax/swing/text/html/StyleSheet/TestWrongCSSFontSize.java
Outdated
Show resolved
Hide resolved
- Always save image capture to the current working directory on test failure; - Save successful image capture with '-capture' program argument; - Always save image capture with ".png" extension; - Use '-w3cUnits' program argument to control the test.w3cUnits flag.
|
I'd appreciate if you add me as contributor (for the test): |
|
/contributor add aivanov |
|
@stanio |
|
@aivanov-jdk, please tell me when I should |
I think we're good to go… |
prsadhuk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks @stanio for the contribution.
|
/integrate |
|
/sponsor |
|
@aivanov-jdk @stanio Since your change was applied there have been 59 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 2e610f5. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Proposed fix for JDK-8260687.
It is noted the issue appeared after the JDK-8257664 (PR #1759) fix landed but the underlying problem is present even before that as demonstrated by using the following HTML document variant:
with the program setup given in the ticket. The PR #1759 fix basically does just that – implies
font-size: 100%where nofont-sizespecified explicitly to ensure correctly computed font-size gets inherited when an ancestor specifies a percentage font-size different from100%(or1em) – otherwise the percentage is calculated and multiplied at every level of the inheritance, producing wrong results.The underlying problem is probably a combination of inconsistencies one may observe with the complex implementation of the
W3C_LENGTH_UNITSeditor property. Starting with only theHTMLDocument.styleSheetgets its internalStyleSheet.w3cLengthUnitsfield set up according to theJEditorPane.W3C_LENGTH_UNITSproperty. Thus when afont-size: 16ptrule is part of theHTMLEditorKit.styleSheetwhichw3cLengthUnitsgenerally remainsfalse– querying the font for it from that style sheet yields a different result from querying the same rule via theHTMLDocument.styleSheet:That's probably fine as one may programmatically create and add more style sheets to the
HTMLDocument.styleSheet. These style sheets may further turn out shared with multiple documents/editors with differentW3C_LENGTH_UNITSsettings.The next issue with the
W3C_LENGTH_UNITSimplementation, this PR proposes a fix for, is related to the current implementation ofStyleSheet.ViewAttributeSet.getAttribute():jdk/src/java.desktop/share/classes/javax/swing/text/html/StyleSheet.java
Lines 2810 to 2818 in 70b5b31
which in turn invokes
CSS.FontSize.toStyleConstants():jdk/src/java.desktop/share/classes/javax/swing/text/html/CSS.java
Lines 2195 to 2199 in 48c932e
One may notice the latter loses the
StyleSheetcontext necessary to properly resolvew3cLengthUnitsfromCSS.FontSize.getValue():jdk/src/java.desktop/share/classes/javax/swing/text/html/CSS.java
Lines 2049 to 2061 in 48c932e
This context is properly sent from
StyleSheet.getFont(), for example:jdk/src/java.desktop/share/classes/javax/swing/text/html/StyleSheet.java
Lines 913 to 914 in 70b5b31
I'll further add a test based on
BodyInheritedFontSize.javaalready given to JDK-8260687 – I just want to enhance it with the:testing the issue from a different angle as noted at the beginning of this PR description.
Progress
Issue
Reviewers
Contributors
<aivanov@openjdk.org>Download
$ git fetch https://git.openjdk.java.net/jdk pull/2515/head:pull/2515$ git checkout pull/2515