-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
8285308: Win: Japanese logical fonts are drawn with wrong size #8329
Conversation
👋 Welcome back tnakamura! A progress list of the required criteria for merging this PR into |
Webrevs
|
Hmm. I am surprised that the glyphs are actually bigger. Did you come to understand the exact mechanism (steps) And whilst you tested linux & mac it is a shared code change so it is another reason to understand .. And are you sure you can't write a test ? Even something that uses heuristics around the metrics ? |
With JEP 400, the default charset may differ from the platform encoding, which is the case like this on Windows (mac & Linux won't be affected as they already use UTF-8 natively) and the mitigation here looks fine to me. But the real issue here to me is why the font size gets bigger depending on the encoding (windows-31j vs. UTF-8)? |
Thank you for the comments, @prrace @naotoj The bigger fonts are caused by the behavior of RichEdit component. I was able to recreate the similar behavior with a native application. I attached the code and the screen shot to JBS. RichEdit seems to use fallback font if English font (Arial, for example) was set for Japanese text. It could show Japanese, but its size was not perfect. So, we need to set a proper font. NG case (Java18): "Arial 9pt" with ANSI_CHARSET was used.
OK, I moved the fix to Windows part. I need to change setEncoding method to protected, because "encoding" value was used in the constructor.
Sorry, I tried some ways, but I couldn't. It tightly binds with OS settings. A pre-submit test was failed once, but passed after rerun. |
Hmm. I'm not sure I'm seeing what you see in the native app. Also JDK - in theory - controls the exact fonts that are used even in a TextField. I'd like to see this resolved but I'm still not feeling like I have a sufficient understanding. |
@prrace Java code: These codes displayed the exact same glyphs. Screen shot was attached in JBS.
Well, I think TextField sets only one font (HFONT) via So, we need to pick up a proper font from fontconfig file. Expected native call: |
The following diff seems to choose the right font:
This diff intends to choose the |
I've been looking at that exact line since I think it is what we'd use in the new default locale I suspect it is a lot safer to do what Toshio is doing but I just want to understand the mechanism. |
Hi @prrace In Japanese until Java 17,
In Japanese after Java 18, textInputCharset is "DEFAULT_CHARSET".
When the first one was changed to "japanese", it was used (mapped "MS Gothic,SHIFTJIS_CHARSET" or "MS Mincho,SHIFTJIS_CHARSET").
So, I tried to modify
|
@naotoj the print statements are mine that I added I supposed this is all I need to do to make the JDK use the right settings ? |
I believe this is only reproducible on Japanese Windows, where the system locale is set to Japanese. You can emulate this by |
Ah, because even in the JDK context the behaviour of the native Text Control in this respect is determined in part by the system locale, not just the JDK's idea of locale .. |
It looks to me as if we specify a latin font as the text component font, some windows fall back behaviour insists Naoto suggested : This did't work for me because it isn't picking up that line anyway So what I see is that MS Mincho isn't even in the list of names it is considering ! I see Toshio says he saw the UTF-8 entry being used, but I don't see that. Toshio is right that what matters here for the native text component is what is picked up in The helper method for getTextComponentFontName() is findFontWithCharset() That has a bit of a questionable behaviour in that it returns the last font in the then in both cases we'd get Times and still have the problem So this fix is a "band aid" on the problem that in the UTF 8 locale we don't seem to be picking UPDATE: pilot error on my part - I set lang to jp .. not ja .. So back to just the encoding case .. Regarding what Toshio pointed out that we can't have both |
Hi @prrace Yes, my system also picked up "UTF-8.ja" line. "ja" can be specified by locale data, such as "-Duser.language=ja". However, I was not able to recreate the wrong size issue on the system which changed the primary language from English to Japanese. There may be differences between pure Japanese Windows and English Windows changed the primary language to Japanese. Unicode (UTF-8) is language independent. So, we need to use a locale data.
"alphabetic/default" assigned to "DEFAULT_CHARSET", but it's only used on this line.
"alphabetic" assigned to "ANSI_CHARSET". So, if we had "DEFAULT_CHARSET", nothing was matched. Then, the first one was used. (WFontConfiguration.java, l.165) |
Yes, so did I after I fixed my typo.
I definitely can reproduce this on my "English" windows by changing the system locale.
If you mean those changes you have in this latest diff then I was thinking of something like that .. although not exactly. I'll also adjust fontconfig file and test some environments I can prepare. I'm not sure what fontconfig changes you are thinking of.
Yes, I think we have issues there I'd like to look closely at. Really, I am at the point where I'd like to say "thank you for drawing this to our attention, but I'd prefer to do this fix myself" I can forsee a bunch of follow up work that we might want to do over time. |
OK, I'll leave it to you. |
Japanese logical fonts are drawn with wrong size since Java 18.
It's triggered by JEP 400, UTF-8 by Default.
sun.awt.FontConfiguration
(andsun.awt.windows.WFontConfiguration
) seems to expect the native encoding instead of the default encoding. This patch changes to use native encoding.Tested: jdk_desktop on Windows, Linux, and macOS
Progress
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/8329/head:pull/8329
$ git checkout pull/8329
Update a local copy of the PR:
$ git checkout pull/8329
$ git pull https://git.openjdk.java.net/jdk pull/8329/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 8329
View PR using the GUI difftool:
$ git pr show -t 8329
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/8329.diff