Bug 157441 - Freetype2: autohinting's quality is worse for Chinese fonts.
Summary: Freetype2: autohinting's quality is worse for Chinese fonts.
Status: RESOLVED FIXED
: 162556 (view as bug list)
Alias: None
Product: SUSE Linux 10.1
Classification: openSUSE
Component: Basesystem (show other bugs)
Version: Beta 7
Hardware: Other Other
: P5 - None : Normal (vote)
Target Milestone: ---
Assignee: Mike Fabian
QA Contact: E-mail List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-11 16:04 UTC by Zhe Su
Modified: 2006-04-21 15:07 UTC (History)
3 users (show)

See Also:
Found By: Other
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
Screeshot shows FZSongTi rendering effect on different hinting styles. (466.47 KB, image/png)
2006-03-11 16:07 UTC, Zhe Su
Details
Fix for pitch problem with CJK fonts (2.12 KB, patch)
2006-03-14 09:29 UTC, Takashi Iwai
Details | Diff
ftview screenshot with new freetype2 library. (81.87 KB, image/png)
2006-03-14 09:53 UTC, Zhe Su
Details
New autofit patch backported from freetype2 cvs head. (93.79 KB, patch)
2006-03-14 15:52 UTC, Zhe Su
Details | Diff
autofit-takashi.png (77.40 KB, image/png)
2006-03-14 17:05 UTC, Mike Fabian
Details
autofit-upstream-cvs.png (67.70 KB, image/png)
2006-03-14 17:07 UTC, Mike Fabian
Details
new patch with correct code range. (93.77 KB, patch)
2006-03-15 02:55 UTC, Zhe Su
Details | Diff
freetype-new-hintfull.png (35.62 KB, image/png)
2006-04-03 13:40 UTC, Mike Fabian
Details
freetype-new-hintmedium.png (35.03 KB, image/png)
2006-04-03 13:41 UTC, Mike Fabian
Details
freetype-new-hintnone.png (34.91 KB, image/png)
2006-04-03 13:42 UTC, Mike Fabian
Details
freetype-old-hintfull.png (36.58 KB, image/png)
2006-04-03 13:44 UTC, Mike Fabian
Details
freetype-old-hintmedium.png (36.53 KB, image/png)
2006-04-03 13:45 UTC, Mike Fabian
Details
freetype-old-hintnone.png (97.31 KB, image/png)
2006-04-03 13:47 UTC, Mike Fabian
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zhe Su 2006-03-11 16:04:55 UTC
Since freetype 2.1.10, the old autohint module (patched by Akito) was replaced by new autofit module, however autofit is not good for CJK fonts. Though there are some patched for ft2 2.1.10 in our package (contributed by Takashi IWAI) to improve autofit for cjk font handling, the quality is still worse than old module, especially on the glyph width handling.

The attached screenshot shows the difference. There are three ftview windows in it, all load FZSongTi.

The top left window is autohinting off and bytecode hinting on, the top right window  is autohinting on, the bottom left window is hinting off.

You can see that if autohinting is on, the right side glyphs will be zigzag, it's not acceptable for Chinese users.

If without hinting, then glyphs will be fuzzy.

So, I suggest to turn off autohinting for Chinese fonts for now, until the autofit module is fixed to handle this issue correctly.

Putting the following code in suse-hinting.conf does this trick:

        <match target="font">
                <test name="family">
                        <string>FZSongTi</string>
                        <string>FZFangSong</string>
                        <string>FZKaiTi</string>
                        <string>FZHeiTi</string>
                        <string>FZKaiTiB</string>
                        <string>FZMingTiB</string>
                        <string>AR PL SungtiL GB</string>
                        <string>AR PL Mingti2L Big5</string>
                        <string>AR PL KaitiM GB</string>
                        <string>AR PL KaitiM Big5</string>
                </test>
                <edit name="autohint">
                        <bool>false</bool>
                </edit>
        </match>

Users can override this config in user config file if they don't like.
Comment 1 Zhe Su 2006-03-11 16:07:39 UTC
Created attachment 72418 [details]
Screeshot shows FZSongTi rendering effect on different hinting styles.
Comment 2 Mike Fabian 2006-03-13 13:52:25 UTC
The effect is the same for Japanese and Korean as well.

The hinting has an influence on the character spacing, therefore the
CJK characters which should all have the same width, don't have the
same width anymore after the hinting, therefore the lines in ftview
have different length.

If this is bad, than it is bad for Japanese and Korean as well and
we should probably use

        <match target="font">
                <test name="lang" compare="contains">
                        <string>ja</string>
                        <string>zh</string>
                        <string>ko</string>
                </test>
                <edit name="autohint" mode="assign">
                        <const>false</const>
                </edit>
        </match>


instead of doing this only for a few Chinese fonts.

Comment 3 Mike Fabian 2006-03-13 14:01:41 UTC
Apart from the problem with the spacing, I think that the glyphs
rendered with the autohinter look better than those rendered with the
autohinter turned off.

Comment 4 Mike Fabian 2006-03-13 15:10:21 UTC
I compared with freetype2-2.1.9 on SuSE Linux 9.3.  You are right, our
freetype2-2.1.9 package didn't have the problem with the CJK glyph
widths.

Comment 5 Takashi Iwai 2006-03-14 09:28:42 UTC
The patch below fixes the pitch problem with CJK glyphs.

The packages are found on mbuilt/bari-tiwai-12.
The baseline-correction (ft2-autofit-03-latin-baseline.diff) is disabled there since this seems to have many side effects.  (Note that ft2-autofit-01-* and 03 are slightly fixed)

The wavy rendering problem appears specially with IPA fonts.  Maybe a dedicated tuning would be necessary for them...
Comment 6 Takashi Iwai 2006-03-14 09:29:21 UTC
Created attachment 72726 [details]
Fix for pitch problem with CJK fonts
Comment 7 Zhe Su 2006-03-14 09:53:13 UTC
Created attachment 72728 [details]
ftview screenshot with new freetype2 library.

I tested the new package, but the issue is still there. The right side of glyphs is still zigzag (See screenshot).

btw, I noticed that there is a new afcjk module in freetype2 cvs head, which is based on akito's patch for 2.1.9. Unfortunately, the new afcjk module has similiar issue as well.

I just wonder whether we should back port the new module into our package and fix it, so that we can submit the fix back?
Comment 8 Mike Fabian 2006-03-14 11:01:35 UTC
Zhe Su> I tested the new package, but the issue is still there. The
Zhe Su> right side of glyphs is still zigzag (See screenshot).

As far as the width problem is concerned, I cannot see any difference between
the packages we currently have in STABLE and Takashi's packages
from mbuilt/bari-tiwai-12. When viewed with ftview, both
screen shots show exactly the same problem with the glyph widths.
Comment 9 Takashi Iwai 2006-03-14 11:03:52 UTC
It's because FZSonti has a strange unicode table...  A known problem?

Comment 10 Takashi Iwai 2006-03-14 11:10:03 UTC
Arphic fonts seem OK.
Comment 11 Mike Fabian 2006-03-14 11:18:20 UTC
Takashi Iwai> Arphic fonts seem OK.

Yes, indeed. What is the problem with the unicode table of FZSongTi?
Comment 12 Takashi Iwai 2006-03-14 11:36:53 UTC
Some unicode char ranges included in FZSonti are not covered by ft2.  For example, 0x33xx-0x4bxx, 0xaxxx, 0xe[78]xx, etc.  Adding the missing ranges should fix the problem.

Comment 13 Mike Fabian 2006-03-14 14:04:18 UTC
Changing Takashi's patch like this fixes the problem indeed:

diff -u /work/built/mbuild/bari-tiwai-12/ft2-autofit-02-cjk.diff ./ft2-autofit-02-cjk.diff
--- /work/built/mbuild/bari-tiwai-12/ft2-autofit-02-cjk.diff	2006-03-14 10:23:47.000000000 +0100
+++ ./ft2-autofit-02-cjk.diff	2006-03-14 14:37:01.000000000 +0100
@@ -402,9 +402,9 @@
 +
 +
 +static const AF_Script_UniRangeRec af_cjk_uniranges[] = {
-+	{0x3000, 0x31ff},
-+	{0x4e00, 0x9fff},
-+	{0xac00, 0xd7ff},
++	{0x3000, 0xd7ff},
++	{0xf900, 0xfaff},
++	{0xfe30, 0xfe6b},
 +	{0, 0},
 +};
 +
Comment 14 Mike Fabian 2006-03-14 14:10:00 UTC
Fixed package submitted to STABLE, closing as FIXED:

-------------------------------------------------------------------
Tue Mar 14 14:38:57 CET 2006 - mfabian@suse.de

- Bugzilla #157441: FZSongTi.ttf contains a lot more (CJK)-glyphs
  than most other fonts, therefore we have to expand the cjk range
  in Takashi Iwai's "ft2-autofit-02-cjk.diff" to render these
  glyphs correctly as well.
- Bugzilla #157441: don't apply ft2-autofit-03-latin-baseline.diff
  as it has some side effects.

----------------------------------------------------------------------
Comment 15 Zhe Su 2006-03-14 14:30:01 UTC
Actually, CJK code range is much wider than that. Below is the range table in afcjk.c from freetype2 cvs head:

  static const AF_Script_UniRangeRec  af_cjk_uniranges[] =
  {
    { 0x0100,  0xFFFF },
    { 0x2E80,  0x2EFF },  /* CJK Radicals Supplement */
    { 0x2F00,  0x2FDF },  /* Kangxi Radicals */
    { 0x3000,  0x303F },  /* CJK Symbols and Punctuation */
    { 0x3040,  0x309F },  /* Hiragana */
    { 0x30A0,  0x30FF },  /* Katakana */
    { 0x3100,  0x312F },  /* Bopomofo */
    { 0x3130,  0x318F },  /* Hangul Compatibility Jamo */
    { 0x31A0,  0x31BF },  /* Bopomofo Extended */
    { 0x31C0,  0x31EF },  /* CJK Strokes */
    { 0x31F0,  0x31FF },  /* Katakana Phonetic Extensions */
    { 0x3200,  0x32FF },  /* Enclosed CJK Letters and Months */
    { 0x3300,  0x33FF },  /* CJK Compatibility */
    { 0x3400,  0x4DBF },  /* CJK Unified Ideographs Extension A */
    { 0x4DC0,  0x4DFF },  /* Yijing Hexagram Symbols */
    { 0x4E00,  0x9FFF },  /* CJK Unified Ideographs */
    { 0xF900,  0xFAFF },  /* CJK Compatibility Ideographs */
    { 0xFE30,  0xFE4F },  /* CJK Compatibility Forms */
    { 0xFF00,  0xFFEF },  /* Halfwidth and Fullwidth Forms */
    { 0x20000, 0x2A6DF }, /* CJK Unified Ideographs Extension B */
    { 0x2F800, 0x2FA1F }, /* CJK Compatibility Ideographs Supplement */
    { 0,       0 }
  };

And I'm still wondering whether it's better to upgrade our freetype2 package to the latest cvs head. I found that many serious fixes are missing in our package.

I'll give you feedback as soon as I evaluate freetype2 cvs head.
Comment 16 Takashi Iwai 2006-03-14 14:34:09 UTC
The upgrade at this stage must be a fairly exception.  What we are allowed to do is to apply (minimal) backport patches.
Comment 17 Mike Fabian 2006-03-14 14:50:38 UTC
I also doubt that we will be allowed to update a very important, basic
package like freetype2 to CVS head now.  Who knows what will break
then?

If you find very important fixes in CVS head which obviously don't
break anything, we can apply them.

But please create new bugreports for each important fix.

(Closing this bugreport as FIXED).



Comment 18 Zhe Su 2006-03-14 15:02:05 UTC
I see.

I just tested freetype2 cvs head. The rendering effect of new autofit module looks better than our package.

I'll backport the new autofit module plus necessary fix to our package and report the patch to bugzilla asap.
Comment 19 Mike Fabian 2006-03-14 15:27:57 UTC
Thank you!
Comment 20 Zhe Su 2006-03-14 15:52:02 UTC
Created attachment 72808 [details]
New autofit patch backported from freetype2 cvs head.

The attached patch is backported from freetype2 cvs head. It makes autohinting rendering effect much better. This bug is also fixed by it.
Comment 21 Zhe Su 2006-03-14 15:54:27 UTC
Please test the new patch attached in comment #20. Old ft2-autofit-* patches are obsoleted by it.
Comment 22 Mike Fabian 2006-03-14 17:05:58 UTC
Created attachment 72830 [details]
autofit-takashi.png

screen shot with Takashi's autofit patches.
Comment 23 Mike Fabian 2006-03-14 17:07:02 UTC
Created attachment 72831 [details]
autofit-upstream-cvs.png

screen shot with the patch from upstream cvs.
Comment 24 Mike Fabian 2006-03-14 17:07:54 UTC
I think the screen shot with the patch from upstream CVS looks
a little bit better.
Comment 25 Mike Fabian 2006-03-14 17:19:33 UTC
Package with the patch from comment #20 submitted to STABLE.

Closing as FIXED.

-------------------------------------------------------------------
Tue Mar 14 18:16:30 CET 2006 - mfabian@suse.de

- Bugzilla #157441: instead of Takashi's patches, use a patch
  from upstream CVS which renders slightly better.

-------------------------------------------------------------------
Comment 26 Takashi Iwai 2006-03-14 17:25:27 UTC
Hmm, that patch handles the whole unicode range 0x0100-0xffff as CJK.
I don't know whether it's intentional or a typo.  I hope this won't have regressions for non-CJK letters.

Comment 27 Zhe Su 2006-03-15 02:55:51 UTC
Created attachment 72883 [details]
new patch with correct code range.

I think it's better to remove that range. Just tested and the rendering quality wasn't affected by removing it.

The new patch is attached, please apply.
Comment 28 Takashi Iwai 2006-03-15 10:15:14 UTC
Agreed to remove it.  At least, non-CJK/latin letters default to the old behavior.
Comment 29 Mike Fabian 2006-03-15 15:09:31 UTC
FIXED (submitted to STABLE):
-------------------------------------------------------------------
Wed Mar 15 16:02:12 CET 2006 - mfabian@suse.de

- Bugzilla #157441:  remove 0x0100-0xFFFF from CJK Unicode range,
  as it might cause side effects for non-CJK scripts.

-------------------------------------------------------------------
Comment 30 Dirk Mueller 2006-03-21 09:41:06 UTC
is this supposed to break non-chinese setups? my fonts look horrible with this patch applied. 
Comment 31 Zhe Su 2006-03-21 09:59:55 UTC
Can you post two screen shots (good and bad) and which font do you use?
Comment 32 Mike Fabian 2006-04-03 13:40:24 UTC
Created attachment 76171 [details]
freetype-new-hintfull.png
Comment 33 Mike Fabian 2006-04-03 13:41:43 UTC
Created attachment 76172 [details]
freetype-new-hintmedium.png
Comment 34 Mike Fabian 2006-04-03 13:42:47 UTC
Created attachment 76174 [details]
freetype-new-hintnone.png
Comment 35 Mike Fabian 2006-04-03 13:44:32 UTC
Created attachment 76176 [details]
freetype-old-hintfull.png
Comment 36 Mike Fabian 2006-04-03 13:45:42 UTC
Created attachment 76177 [details]
freetype-old-hintmedium.png
Comment 37 Mike Fabian 2006-04-03 13:47:03 UTC
Created attachment 76181 [details]
freetype-old-hintnone.png
Comment 38 Mike Fabian 2006-04-03 13:55:38 UTC
The screen shots from comment #32 to comment #37 are created with

    xfd -fa "Albany AMT"

and editing ~/.fonts.conf to try different values of "hintstyle", e.g.:

     <match target="font" >
      <edit mode="assign" name="hintstyle" >
       <const>hintfull</const>
      </edit>
     </match>

The screen shots "freetype-new-*" are created with freetype2 packages
with the bugzilla-157441-autofit-cjk-cvs.patch patch applied.

The screen shots "freetype-old-*" are created with freetype2 packages
with that patch *not* applied.

Examining the screen shots in detail (e.g. with xmag) shows that
the rendering for the hint styles "hintfull" and "hintnone" is
not changed at all.

But the rendering for the hintstyle "hintmedium" is changed.

Without the patch, "hintmedium" rendered *exactly* the same as
"hintfull". I guess this was a bug, I don't think "hintmedium"
should render the same as "hintfull".

With the patch, the result using "hintmedium" is somewhere between
"hintfull" and "hintnone" (but rather close to "hintnone").  This is
probably correct.

Comment 39 Mike Fabian 2006-04-03 13:59:22 UTC
*** Bug 162556 has been marked as a duplicate of this bug. ***
Comment 40 Mike Fabian 2006-04-03 16:31:19 UTC
fonts-config packages submitted to NOARCH which sets
hinstyle=hintfull as the default in /etc/fonts/suse-hinting.
Comment 41 Dan Winship 2006-04-05 16:04:06 UTC
Is there some trick to getting that package to work? I built a package with that change, installed it, and reran SuSEconfig.fonts, but my fonts still look ugly. (I even tried rm'ing /var/cache/fontconfig/* and ~/.fonts.cache-2 and running SuSEconfig.fonts again, but that didn't help.)
Comment 42 Mike Fabian 2006-04-21 09:33:02 UTC
The caches in /var/cache/fontconfig/* and ~/.fonts.cache-2 have no influence
on the hintstyle.
Comment 43 Mike Fabian 2006-04-21 09:38:04 UTC
Dan> Is there some trick to getting that package to work? I built a package with
Dan> that change, installed it, and reran SuSEconfig.fonts, but my fonts still look
Dan> ugly.

After running SuSEconfig.fonts with the new fonts-config package installed,
you should have

    
        <!--
            Using the autohinter, hintstyle=hintfull and anti-aliasing.
            This is a good default for most fonts.
        -->
        <match target="font">
                <edit name="autohint">
                        <bool>true</bool>
                </edit>
                <edit name="hintstyle">
                        <const>hintfull</const>
                </edit>
                <edit name="antialias">
                        <bool>true</bool>
                </edit>
        </match>

in /etc/fonts/suse-hinting.conf (close to the top of that file).

If it still doesn't work for you, I guess you have a ~/.fonts.conf
file in your home directory which changes the hintstyle again.  The
hintstule set in the user specific file ~/.fonts.conf has higher
priority and overrides the system default.

I'm closing this bug as FIXED again, feel free to reopen if your ~/.fonts.conf
is not the problem.

Comment 44 Dan Winship 2006-04-21 15:07:57 UTC
I don't have a fonts.conf, but I think my problem now is part of bug 104365.