amertkara / seaglass

Automatically exported from code.google.com/p/seaglass
0 stars 0 forks source link

Cannot show Chinese Character in JFrame title correctly. #45

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Use com.seaglasslookandfeel.SeaGlassLookAndFeel as look and feel
2.Set title on JFrame by value "简单例子" (Chinese Characters)
3.Show the JFrame will show four little blank box in 

What is the expected output? What do you see instead?
It should show four right shape for the four chinese characters instead of
four little blank box.

What version of the product are you using? On what operating system? What
JRE version?
I use version 0.1.7.2.2 of SeaGlassLookAndFeel.

Please provide any additional information below.
This is caused by following code in class SeaGlassLookAndFeel
    private Font getDefaultFont()
    {
        Font font = null;
        if(PlatformUtils.isMac())
            font = new Font("Lucida Grande", 0, 13);
        if(font == null)
            font = new Font("Lucida Sans Unicode", 0, 13);
        return font;
    }
The font "Lucida Sans Unicode" don't support Chinese character correctly.
Three suggestion for this problem:
1. Use system default font instead of "Lucida Sans Unicode"
2. Make default font name configurable
3. Change getDefaultFont() function to protected instead of private

Original issue reported on code.google.com by kua...@gmail.com on 30 Apr 2010 at 6:07

GoogleCodeExporter commented 9 years ago
btw: I use windows XP sp3.

Original comment by kua...@gmail.com on 30 Apr 2010 at 6:08

GoogleCodeExporter commented 9 years ago
Hi,
I stumbled upon something similar with some strange french characters.
Just as tip for you. Try the following:

UIManager.setLookAndFeel(new SeaGlassLookAndFeel());
UIManager.getDefaults().put("default-font", new Font("SansSerif", Font.PLAIN, 
13));

This will set the default font to the system default. I tested it and with this 
the
font does not look 100% perfect but at least it displays all characters.

Hope this helps,
- Rossi

Original comment by rosstaus...@googlemail.com on 1 Jun 2010 at 5:17

GoogleCodeExporter commented 9 years ago
Sorry the property name is wrong it is "defaultFont"

Original comment by rosstaus...@googlemail.com on 1 Jun 2010 at 5:18

GoogleCodeExporter commented 9 years ago
The work around does not the thing 100% because some other fonts get derive 
smaller
fonts from the defaultFont before the user has the a chance to set the default
(progress bar, slider, ...).

To solve this you would have to copy the class DerivedFont from the
NimbusDefaults.class and then set the derived fonts like this in 
SeaglassLookAndFeel:

d.put(p + ".font", new DerivedFont("defaultFont", -2.f, null, null));

This will resolve the font lazy when it is access for the first time. This 
gives the
user the chance to set a new defaultFont property.

Have fun,
- Rossi

Original comment by rosstaus...@googlemail.com on 1 Jun 2010 at 5:24

GoogleCodeExporter commented 9 years ago
Hi, 
Me again. I invested some more time into this. I would like to provide a patch 
that
will hopefully improve the font resolving in case a user wants to override the 
L&F
default font. The patch ensures that all fonts are loaded lazy to allow the user
overriding it with something like this:

UIManager.setLookAndFeel(new SeaGlassLookAndFeel());
UIManager.getLookAndFeelDefaults().put("defaultFont", new Font("SansSerif",
Font.PLAIN, 13));

I think it would be good to add a section to the usage documentation and explain
people what they need to do if they have problems with foreign languages that 
are not
rendered correctly with the Lucida font family.

Have fun,
- Rossi

Original comment by rosstaus...@googlemail.com on 6 Jun 2010 at 6:18

Attachments:

GoogleCodeExporter commented 9 years ago
Hi, Rossi
Nice to see your response.
Thanks a lot for your effort and time.

The last way you mentioned is great for the problem I've encountered. Just one 
question, which release this patch will be patched into the library? I'm eager 
to see this happen :-)

Now, I copy one of the code and modify the default font name. Hope this 
feature(font lazy load) can be implemented into the library as soon as possible.

And one suggestion, why not 
3. Change getDefaultFont() function to protected instead of private. In this 
way, I can subclass it and solve the problem.
This should be the simplest way to solve the problem. Just want hear your 
explanation again. It's very valuable for me to understand the library and some 
design thought.

Original comment by kua...@gmail.com on 8 Jun 2010 at 10:48

GoogleCodeExporter commented 9 years ago
Hello Kuaima,
First of all please note that I'm not an offical Developer of this project 
therefore I can not give you any guarantee if and when the patch will be 
integrated. 
But I think it is very likely that this will happen soon.

In the current implementation the getDefaultFont() method is called in the 
constructor. It is not adviseable to override a method that is called in a 
constructor, but with the patch applied it would be possible to make the method 
protected, because then the method is no longer called from the constructor.

I think the "offical way" of changing L&F settings is to push them into the 
defaults map.

Lets wait what Kathryn Huxtable (the project owner) thinks about this.

Have fun,
- Rossi

Original comment by rosstaus...@googlemail.com on 8 Jun 2010 at 4:02

GoogleCodeExporter commented 9 years ago
I *am* an official developer and I think we'll be reconsidering the way we set 
fonts. I was trying to get a consistent look across platforms, but you're 
right, Chinese characters are an issue. I *did* select a Unicode font, so the 
characters should be there, but if it's not working we need to fix it.

When I apply a fix, I'll note it and ask for testers.

Are you members of the Sea Glass Google Group?

Original comment by kahuxtable on 8 Jun 2010 at 5:21

GoogleCodeExporter commented 9 years ago
Hi Kathryn,
I think there is no good way to "fix" this. The Lucida font is a very good 
selection because it is wide spread and cover a lot of glyphs of the unicode 
range (Arabic, Roman, Cyrillic, Hebrew, Thai and Greek). 
There is no nice looking font that will cover all glyphs and will be 
widespread. I think you should stick with it and give the user an clear defined 
API to override this or to fall back to the system default "SansSerif" if he 
needs to do so. This is mainly an issue for chinese and some other asian 
countries.

Yes I'm monitoring the news group and lets move the discussion there.

-Rossi

Original comment by rosstaus...@googlemail.com on 8 Jun 2010 at 5:51

GoogleCodeExporter commented 9 years ago
Issue 43 has been merged into this issue.

Original comment by kahuxtable on 2 Jul 2010 at 5:29

GoogleCodeExporter commented 9 years ago
I've chosen a modification of Rossi's suggestion in comment 9 to solve this. We 
will use Lucida Grande on the Mac because it's the standard Mac font. 
Otherwise, we will use the JRE's "Dialog" font, and if we can't find it, the 
"SansSerif" font.

This fixes the problem with Chinese characters.

The test case TestFrame.java in the seaglass-demo project displays this.

Original comment by kahuxtable on 5 Jul 2010 at 1:39