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
Font size conversion issue using Style in JTextPane with HTML #165
Comments
As far as I've found out it is related to
If I add to your example: textPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.FALSE); I get "Font size 12 set but retrieved: 12" using both of Metal and FlatLaf. So it appears Metal and FlatLaf use different defaults for that property, but I'm still not sure why: textPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE); would affect: // Set font size 12
StyleConstants.setFontSize(basicStyle, fontSize);
// Immediately retrieve it. It is 10 with Flatlaf
final int retrievedFontSize = StyleConstants.getFontSize(basicStyle); given the font size is set explicitly to that style. Happens with both Metal and FlatLaf so I suspect it's not a FlatLaf problem. |
There's some styleConstantsValueToCSSValue transformations happening in the StyleConstants.setFontSize(basicStyle, fontSize); sets a size which is closest to a set of predefined sizes like You may also use: System.out.println(((HTMLDocument) textPane.getStyledDocument()).getStyleSheet()); to compare the "default" styles with |
So, the behavior appears the same as with other L&Fs when setting |
Thanks a lot for your replies. I think the main problem is that bug in OpenJDK that you also found now, but I guess I was hoping that there may be a way to work around this from FlatLaf. Setting I agree with your conclusion that this is not a FlatLaf bug. Thanks for looking at it. |
I can notice this also happening with e.g. JLabel using HTML inside. Sometimes the size also changes randomly when the component is re-rendered |
Hi,
I have found an issue related to font sizes when I use Styles within HTML documents. Below you find a small program that reproduces this. Basically, what happens is that if I set the font size for a Style, and then retrieve it, I do not always get the same value back, and this can cause very tiny fonts in the text pane, given a font size. The main reason is probably a bug in OpenJDK that I link to below (in short, different conversion tables are used to convert to and from points to CSS size in the StyleSheet class), but perhaps something can be done in Flatlaf.
A side note: Even if I use really ugly hacks to use the same conversion tables, a given font size seems smaller in the text pane than the rest of the application.
Link to bug: https://bugs.openjdk.java.net/browse/JDK-7022164?focusedCommentId=12231004&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel
Small program that reproduces the issue below (couldn't get the code formatting good, sorry). The font size 12 is set on a Style, but when retrieving it, it is 10. The same font size is set on the text pane in another panel and that shows how size 12 should look I think. Comment out the setLookAndFeel call and this problem disappears (on my Win 10 at leats).
Cheers,
Sam
Oh by the way, I really, really like this LAF. Good job!
The text was updated successfully, but these errors were encountered: