Created
August 3, 2014 04:45
-
-
Save kidlj/f30e82c2c6f064990596 to your computer and use it in GitHub Desktop.
在Gentoo上配置Infinality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Infinality[1] 是一套 Linux 平台下通用字体渲染引擎 freetype 的补丁,它为 Linux 提供了近乎于 Windows 和 Mac 的字体渲染效果,特别是很好地解决了 Linux 下中文字体发虚的问题。本 wiki 提供了在 Gentoo Linux 下将微软雅黑字体配置出 Windows 7 渲染效果的方法。 | |
### 1. 字体准备 | |
安装宋体(SimSun)和微软雅黑(Microsoft YaHei)作为主要中文字体。实测文泉驿微米黑和文泉驿正黑在低分辨率下渲染效果不好,建议不用,最好删除。 | |
宋体和雅黑可以在微软系统里拷贝或者下载,具体为四个字体文件: `msyh.ttf`, `msyhbd.ttf`, `simsun.ttc`, `simsunb.ttf`. 然后将其放置在`~/.fonts/`目录下: | |
$ cd ~/.fonts | |
$ mkfontdir | |
$ mkfontscale | |
$ fc-cache -fv | |
另外还可以安装`croscorefonts`作为微软英文兼容替代字体。 | |
$ sudo emerge -av media-fonts/croscorefonts | |
### 2. 安装 infinality | |
给`media-libs/freetype`加上`infinality` USE, 并重新 emerge : | |
$ sudo emerge -av1 media-libs/freetype | |
这会自动依赖安装`fontconfig-infinality`和`eselect-infinality`. 如果没有请手动安装。 | |
### 3. 选择 freetype 渲染效果 | |
`eselect-infinality`包安装了几种预设渲染效果供 freetype 使用: | |
$ eselect lcdfilter set 14 | |
此处我选择 windows-7 效果,实测选哪个没有影响,只要给 freetype 打上`infinality` USE 就好。选 windows-7 吧。 | |
### 4. 配置 fontconfig | |
Fontconfig 是 Linux 下通用的字体选择程序,它既能配置字体的优先级,也能调整字体的渲染效果。Gentoo 提供了`eselect fontconfig`工具来方便地调整 fontconfnig 设置。 | |
上面提到的`fontconfig-infinality`安装了一堆预设 fontconfig 配置文件。你可以用`eselect infinality`命令来选择使用那种预先设置。特别应当注意的是,本wiki没有启用`fontconfig-infinality`安装进来的任何 fontconfig 配置文件,体现在`eselect fontconfig list`结果中就是没有启用`52-infinality.conf`条目(见下文),而采取的是自己定制`fonts.conf`的方法。这样做的原因是 infinality 预设的选项并不十分灵活,某些选项并不能满足自己的需要,而直接编辑这些配置文件并不可取,因为下次升级包的时候所有更改都将被覆盖。 | |
需要强调的是,开启`50-user.conf`代表启用自己定制的用户 fontconfig 设置。 | |
以下为`eselect fontconfig list`命令的输出,如有可能请尽量按照此列表开关配置文件。 | |
Available fontconfig .conf files (* is enabled): | |
[1] 10-autohint.conf | |
[2] 10-no-sub-pixel.conf | |
[3] 10-scale-bitmap-fonts.conf * | |
[4] 10-sub-pixel-bgr.conf | |
[5] 10-sub-pixel-rgb.conf * | |
[6] 10-sub-pixel-vbgr.conf | |
[7] 10-sub-pixel-vrgb.conf | |
[8] 10-unhinted.conf | |
[9] 11-lcdfilter-default.conf | |
[10] 11-lcdfilter-legacy.conf | |
[11] 11-lcdfilter-light.conf | |
[12] 20-unhint-small-dejavu-sans-mono.conf * | |
[13] 20-unhint-small-dejavu-sans.conf * | |
[14] 20-unhint-small-dejavu-serif.conf * | |
[15] 20-unhint-small-vera.conf * | |
[16] 25-unhint-nonlatin.conf | |
[17] 30-metric-aliases.conf * | |
[18] 30-urw-aliases.conf * | |
[19] 31-cantarell.conf * | |
[20] 40-nonlatin.conf | |
[21] 45-latin.conf * | |
[22] 49-sansserif.conf * | |
[23] 50-user.conf * | |
[24] 51-local.conf | |
[25] 52-infinality.conf | |
[26] 57-dejavu-sans-mono.conf * | |
[27] 57-dejavu-sans.conf * | |
[28] 57-dejavu-serif.conf * | |
[29] 60-latin.conf * | |
[30] 60-liberation.conf | |
[31] 62-croscore-arimo.conf * | |
[32] 62-croscore-cousine.conf * | |
[33] 62-croscore-symbolneu.conf * | |
[34] 62-croscore-tinos.conf * | |
[35] 63-source-pro.conf * | |
[36] 65-fonts-persian.conf * | |
[37] 65-khmer.conf | |
[38] 65-nonlatin.conf | |
[39] 69-unifont.conf * | |
[40] 70-no-bitmaps.conf | |
[41] 70-yes-bitmaps.conf | |
[42] 80-delicious.conf * | |
[43] 90-synthetic.conf * | |
[44] 99pdftoopvp.conf | |
### 5. 用户 fontconfig 配置文件 | |
以下内容请写于`~/.fonts.conf`或者`~/.config/fontconfig/fonts.conf`, 具体哪个请参考`/etc/fonts/conf.d/50-user.conf`文件。 前者为遗留支持,新版本的 fontconfig 使用后者。 | |
<?xml version='1.0'?> | |
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'> | |
<fontconfig> | |
<!-- ******************************************************** --> | |
<!-- ***************** ALIASES ****************************** --> | |
<!-- ******************************************************** --> | |
<!-- Default fonts - Linux Appearance --> | |
<alias> | |
<family>sans-serif</family> | |
<prefer> | |
<family>Arimo</family> | |
<family>DejaVu Sans</family> | |
<family>SimSun</family> | |
<family>Microsoft YaHei</family> | |
</prefer> | |
</alias> | |
<alias> | |
<family>serif</family> | |
<prefer> | |
<family>Tinos</family> | |
<family>DejaVu Serif</family> | |
<family>SimSun</family> | |
</prefer> | |
</alias> | |
<alias> | |
<family>monospace</family> | |
<prefer> | |
<family>Cousine</family> | |
<family>DejaVu Sans Mono</family> | |
</prefer> | |
</alias> | |
<!-- ******************************************************** --> | |
<!-- *************** RENDERING SETTINGS ********************* --> | |
<!-- ******************************************************** --> | |
<!-- basic settings --> | |
<match target="font"> | |
<edit name="rgba" mode="assign"> | |
<const>rgb</const> | |
</edit> | |
<edit name="autohint" mode="assign"> | |
<bool>false</bool> | |
</edit> | |
<edit name="hinting" mode="assign"> | |
<bool>true</bool> | |
</edit> | |
<edit name="antialias" mode="assign"> | |
<bool>true</bool> | |
</edit> | |
<edit name="hintstyle" mode="assign"> | |
<const>hintfull</const> | |
</edit> | |
<edit name="lcdfilter" mode="assign"> | |
<const>lcddefault</const> | |
</edit> | |
</match> | |
<!-- Microsoft Yahei specific settings --> | |
<match target="font"> | |
<test name="family"> | |
<string>Microsoft YaHei</string> | |
</test> | |
<edit name="rgba" mode="assign"> | |
<const>rgb</const> | |
</edit> | |
<edit name="autohint" mode="assign"> | |
<bool>false</bool> | |
</edit> | |
<edit name="hinting" mode="assign"> | |
<bool>true</bool> | |
</edit> | |
<edit name="antialias" mode="assign"> | |
<bool>true</bool> | |
</edit> | |
<edit name="hintstyle" mode="assign"> | |
<const>hintfull</const> | |
</edit> | |
<edit name="lcdfilter" mode="assign"> | |
<const>lcdlight</const> | |
</edit> | |
</match> | |
</fontconfig> | |
在`~/.config/fontconfig/.fonts.conf`文件里,第一段对字体优先级做了设置。其中特别设置了 SimSun 为 serif 和 sans-serif 字体,并且比雅黑优先。如果你想让雅黑优先,就在 sans-serif 那里把 SimSun 一行删掉。 | |
后边两段分别针对全部字体和微软雅黑渲染微调做了设置。这里全局开启`hintfull`和`lcddefault`, 然后对微软雅黑单独设置了`hintfull`和`lcdlight`, 因为我实测这种搭配雅黑最好看。你可以选择你自己的。 | |
另,配置后需重启应用程序(如 firefox)方可看到效果。 | |
另另,不要同时使用另一方字体微调软件(如 gnome-tweak-tool)配置字体,以免发生混乱。 | |
### 6. 一些注解 | |
本 wiki 所使用软件版本如下: | |
freetype-2.4.11 | |
fontconfig-2.10.92 | |
经测试,`freetype-2.5.3`会使 Terminology 中 Source Code Pro 字体渲染模糊,原因待查。 | |
另外我测试了 Google 和 Adobe 开源的中文字体 Source Han Sans,在 Linux 下的渲染效果依然不如微软雅黑,所以现在依然在用宋体和雅黑作为主力字体。我想等以后换个高分辨率的显示器效果会好很多吧。 | |
[1]: http://infinality.net |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment