Display the Chinese font correctly with English locale in Ubuntu

Every time after upgrading Ubuntu, it just broke something from working correctly.

This time in Ubuntu 12.10, I found that it broke the Chinese (also Japanese) font display in non-CJK locales. It looks like this:

Try this link by yourself: http://www.ubuntu.com/download

Ubuntu 12.10 Chinese fonts

Even you don't read Chinese, I think you can see that the Chinese font display is really, really, really ugly. So, how happened?

After reading the source code and the recently changes of Language Support (language-selector), I finally figured out the problem. The problem is, Language Support still has bug about dealing the CJK display.

In Ubuntu 12.10, Language Support just installed all the config files for CJK: 69-language-selector-ja-jp.conf, 69-language-selector-zh-cn.conf and others.

Then how does it display the font correctly? It uses the "test" command in the configs.

See the content of 69-language-selector-zh-cn.conf , there're some <test></test> blocks like this:

    &lt;test name="lang"&gt;

        &lt;string&gt;zh-cn&lt;/string&gt;

    &lt;/test&gt;

It is saying that if the language is zh-CN, then display the Chinese font following the config. So the problem comes: English locale will never return the "zh-cn" test result, so at English locale, it will always display the ugly Chinese font. The same thing will happen in Japanese too.

So how to fix it? I think a totally re-factoring of Language Support application is needed, it should add support for real language display order, just like what OS X does. By now, if I put the 「汉语(中国)(Chinese)」 behind the English, it just became gray!

Ubuntu Language support

What's the lucky, there's always a quick and dirty way to fix this problem. By removing the <test></test> blocks in the 69-language-selector-zh- cn.conf, everything will work correctly.

Finally, Chinese and English fonts are both looking beautiful in Ubuntu, that's the way Ubuntu should behavir.

Ubuntu 12.10 Chinese fonts 02

As an internaiontal operating system, Ubuntu still has a lot of work to do. I hope the future release won't break this kind of things.

Hope this post is useful to you :)

<推广> 本站推荐使用使用 BandwagonHost 来搭建自己的虚拟主机和相关网络服务。

12 Comments

are both looking beautifully(all of the .. look beautiful), behavir, internaiontal, useful *to* you... :P

TualatriX 回复 @Iven

Thanks for the correction.

But should I use "all" here? There're two things.

Iven 回复 @TualatriX

Er, you're right. "Both" is better.

依云 回复 @Iven

useful /to/ you? /for/ you?

我的居然没这问题。

Kevin276

Very good !! Thanks!!

csslayer

I think you should make a copy of 69-XXX file, to avoid that file being overwritten while upgrading system.

abellong

I haven't got this problem with the <test></test> block. I set "English" not "English (United States)" the first place in "Language for menus and windows", use ubuntu 12.10 now

autoxbc

这个问题的本质应该是,在一个 UTF-8 编码的页面中,出现的一段 CJK 字符到底应该被当作哪种文字来对待,如果明明是一段中文,系统却认为是日文,调用了日文字体来渲染,同时日文字体里刚好含有大量的汉字,那么含有的汉字被显示成日文字体中的字型,剩下的部分日文字体没有,fallback 到中文字体,自然会出现两种字型混杂大小浓淡不一的结果。

就我自己的使用经验,系统总是优先去使用日文字体的。不负责任的推测一下,在 English locale 下去读日文,日本的使用者就不会遇到这个问题。如果有人怀疑,可以把那段文字复制到任何一个编辑器里,然后优先给编辑器指定一个日文字体,就会立刻重现这个效果,每个字的浓淡变化分毫不差。如果还看不出来的话,试着把字号一级一级调大到某个值就很明显了。

那么问题显然是,现有的字体机制中,有什么办法可以脱离操作系统的 locale 设定,单独的识别出一段 CJK 字符的种类?没有的话这个问题就无解,碰巧有些机制优先用中文字体的话,表面上我们这边没问题了,日文就一定有麻烦了。

csslayer 回复 @autoxbc

也许只是单纯的因为按照 ja_JP zh_CN 的字母序所以是日文优先……

一个文本编辑器内,你打着字,字体就变了……是很不科学的……很久以前我刚开始用linux的时候,就无比纠结gedit里面怎么打着字一段字体就变了……

浏览器的话,还至少可以用网页语言猜猜。

依云 回复 @csslayer

All web pages should use "lang" and/or "xml:lang" :D

这个是老大难问题了,这么多年过来了,基本上每次装完系统都得这么搞一下……哎CJK用户真可怜

Leave a Comment