序:
linux是社區搞出來, 商業應用也都是服務器場景。社區里又都是技術人員。字體又是細節。而且會英文早成了標配。所以沒有很多社區以外的人力來搞字體這個毫無回報的東西。
結果很自然的,裝linux桌面環境的幾個問題之一,就包括了字體。與字體相關的一般問題主要就是中文顯示問題。搞定了中文之后基本就不影響使用了。然后當你繼續使用下去之后,就會出現更高的要求,就是希望為了美觀要求而得到了一個好看的字體。
於是就會牽扯出,分辨率,等寬,高清等問題。但是沒關系,因為在搞定中文字體的時候,你已經學會了安裝各種各樣的字體。然后你就開始瘋狂的裝字體,微軟的,蘋果的,安卓的。文泉驛的。。。
那么突然問題就來了,你完全沒有辦法管理他們,也不知道他們的默認和優先關系。某一個時刻你發現,你的字體失控了。
嗯,以上,就是我此刻遇到的問題。我裝了多個字體之后,我的thunderbird中的中文並沒有如我預期般的使用 adobe-source-han-sans-cn 作為默認字體,而是不知道一個什么字體,每一撇一捺都在肆意生長。
零: 知識儲備
1. 聖教讀物
包括了truetype, opentype,bitmap的一般性科普,可以只閱讀前邊的一小部分。
2. 關於serif, sans serif, monospace Serif和Sans-serif字體的區別
3. 一個大 列表。常用的coding字體,按推薦強度排序。還能preview。
4. 名稱解釋:Anti-alisaing(抗鋸齒)
一: 高清屏下的tty
我有一個24寸2K的顯示器。ppi是400? 反正就是很牛逼啦。但是進入tty的時候,特別可怕。字特別的小,幾乎瞎掉了我的眼。我就這樣眼瞎繚亂的從裝arch開始一直到進入了X,在回頭去該tty的字體與字號。總之對於高清屏來說,linux tty的默認字體太小太小了。
可是當時,我並沒有寫blog的習慣,甚至連寫筆記的習慣都沒有。我還甚甚的以為自己做過的事情永遠不會忘記。此刻,我真的忘記了。我只直接,我裝了tty下的字體,並且做了一些忘記了是什么樣子的設置。嗯,只記得個大概,真的記不得細節。寫blog多重要。
首先,我裝了個字體。
/home/tong/Src/risinginfo/tss_sys/daemon/appdump [tong@TStation] [10:05] > pacman -Qs terminus local/terminus-font 4.40-2 Monospace bitmap font (for X11 and console)
然后,我設置了這個:
/home/tong/Src/risinginfo/tss_sys/daemon/appdump [tong@TStation] [11:51] > cat /etc/vconsole.conf FONT=ter-v32n
重啟(relogin ??),就設好了。
還有個命令,可以實時生效。好像是setfont,記不太清了。。。
/home/tong/Src/risinginfo/tss_sys/daemon/appdump [tong@TStation] [11:53] > man vconsole.conf /home/tong/Src/risinginfo/tss_sys/daemon/appdump [tong@TStation] [11:55] > man setfont
不過,所幸,我們還有邪教讀物,來重拾這部分知識。。。
二:中文顯示我用誰
之前裝過用過一陣子的文泉驛。已經卸載了,現在使用adobe。反正,都差不多吧,對於中文,能顯示我就滿意了。
/home/tong/Amazon [tong@TStation] [1:36] > pacman -Qs adobe-source local/adobe-source-han-sans-cn-fonts 1.004-1 Adobe Source Han Sans Subset OTF - Simplified Chinese OpenType/CFF fonts /home/tong/Amazon [tong@TStation] [1:36] >
三:編程字體很糾結
最開始的時候,在windows下面編程的時候,我的配置是:putty + 白色背景 + Courier New + 10號。一直用了好多年,始終是我的最愛。但是到了linux下面字變得很細,很模糊,於是就不用了。
Cousine(ttf-google-fonts-git),據說是courier new的替代品,這個包好大,正在裝,還沒用。
最近發現的是Terminus,就是前文提到的那一個。在高清屏KDE下konsole里(14號字)使用還是蠻不錯的。
驚喜的發現是,竟然在archcn的源里邊找到了ttf版本。不過ttf的雖然細膩,但是偏細長,我反而更喜歡bitmap的。
另外Cousine也很好,不過Terminus在筆記本的屏幕上,因為字號設置的比較小,且沒有那么細膩,所以並不好看。。。
/home/tong [tong@TStation] [2:02] > pacman -Qs Terminus-font-ttf local/terminus-font-ttf 4.40.1-1 Monospaced bitmap font designed for long work with computers (TTF version) /home/tong [tong@TStation] [2:02] >
上效果圖,一張:
再補一張bitmap terminus 14號,非加粗字體的:
四:到底要怎么管理字體
大多數主流軟件的font都是有fonts-conf進行管理的。包括了一系列fc開頭的軟件。
/home/tong [tong@TStation] [20:09] > fc- [tabtab...] fc-cache fc-cat fc-list fc-match fc-pattern fc-query fc-scan fc-validate
fonts-conf 讀配置文件,配置文件分4類:
1. ~/.fonts.conf, ~/.fonts.conf.d/, ~/.fontconfig/*.cache-* 這三類配置已經不推薦,在不久的將來也不會被兼容。
2. /etc/fonts/fonts.conf, /etc/fonts/conf.avail/ fonts.conf和conf.avail在軟件更新的時候會被覆蓋。不要做任何更改。
3. /etc/fonts/conf.d/, /etc/fonts/local.conf 系統全局配置。conf.d里面是從conf.avail中軟連接過去的。
4. $XDG_CONFIG_HOME/fontconfig/fonts.conf, $XDG_CONFIG_HOME/fontconfig/fonts.d, 用戶自定義配置。 在未設置環境變量的情況下,$XDG_CONFIG_HOME默認為 $HONE/.config. 參考內容一,參考內容二。
這還真的挺重要的我覺得,所以我覺得把這段貼出來:

$XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used. $XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used. $XDG_DATA_DIRS defines the preference-ordered set of base directories to search for data files in addition to the $XDG_DATA_HOME base directory. The directories in $XDG_DATA_DIRS should be seperated with a colon ':'. If $XDG_DATA_DIRS is either not set or empty, a value equal to /usr/local/share/:/usr/share/ should be used. $XDG_CONFIG_DIRS defines the preference-ordered set of base directories to search for configuration files in addition to the $XDG_CONFIG_HOME base directory. The directories in $XDG_CONFIG_DIRS should be seperated with a colon ':'. If $XDG_CONFIG_DIRS is either not set or empty, a value equal to /etc/xdg should be used. The order of base directories denotes their importance; the first directory listed is the most important. When the same information is defined in multiple places the information defined relative to the more important base directory takes precedent. The base directory defined by $XDG_DATA_HOME is considered more important than any of the base directories defined by $XDG_DATA_DIRS. The base directory defined by $XDG_CONFIG_HOME is considered more important than any of the base directories defined by $XDG_CONFIG_DIRS. $XDG_CACHE_HOME defines the base directory relative to which user specific non-essential data files should be stored. If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used. $XDG_RUNTIME_DIR defines the base directory relative to which user-specific non-essential runtime files and other file objects (such as sockets, named pipes, ...) should be stored. The directory MUST be owned by the user, and he MUST be the only one having read and write access to it. Its Unix access mode MUST be 0700.
所以,實際上用戶的配置位置為:$HOME/.config/fontconfig/* 目錄。而在實際系統中,即將被廢止的配置文件~/.fonts.conf 也正是指向該目錄的鏈接:
/home/tong [tong@TStation] [20:30] > ll .fonts.conf lrwxrwxrwx 1 tong tong 40 Sep 26 2015 .fonts.conf -> /home/tong/.config/fontconfig/fonts.conf /home/tong [tong@TStation] [20:32] >
調整了配置文件之后,運行 fc-cache 命令。新打開的程序就會使用新的字體了。
搞定了wps的問題之后,導致了thunderbird的中文問題。詳見:[daily][troubleshoot][archlinux][wps][font] wps文檔中的圖內容無法顯示中文 我現在的目的是,在配置文件中,調整系統默認的中文字體。
首先,我要知道當前的match順序。使用命令fc-match: 太長了,就不全貼出來了。說實話我也並不太會用這個命令:
[tong@T7:~] % fc-match -a serif > 1 [tong@T7:~] % fc-match -s serif > 11 [tong@T7:~]
然后,通過man手冊中提供的本地文檔 /usr/share/doc/fontconfig/fontconfig-user.html , 找到了這樣一段內容:
<!-- use WenQuanYi Zen Hei font when serif is requested for Chinese --> <match> <!-- If you don't want to use WenQuanYi Zen Hei font for zh-tw etc, you can use zh-cn instead of zh. Please note, even if you set zh-cn, it still matches zh. if you don't like it, you can use compare="eq" instead of compare="contains". --> <test name="lang" compare="contains"> <string>zh</string> </test> <test name="family"> <string>serif</string> </test> <edit name="family" mode="prepend"> <string>WenQuanYi Zen Hei</string> </edit> </match>
依葫蘆畫瓢,寫到用戶配置里,如下:
[tong@T7:~] % cat .config/fontconfig/fonts.conf

<?xml version="1.0"?><!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> <dir>~/.fonts</dir> <match> <test name="lang" compare="contains"> <string>zh</string> </test> <test name="family"> <string>serif</string> </test> <edit name="family" mode="prepend"> <string>Source Han Sans CN</string> </edit> </match> <match> <test name="lang" compare="contains"> <string>zh</string> </test> <test name="family"> <string>sans</string> </test> <edit name="family" mode="prepend"> <string>Source Han Sans CN</string> </edit> </match> <match> <test name="lang" compare="contains"> <string>zh</string> </test> <test name="family"> <string>mono</string> </test> <edit name="family" mode="prepend"> <string>Source Han Sans CN</string> </edit> </match> </fontconfig>
遺憾的是,並沒有用。
順便讀了這個,僅僅用來參考:http://www.cnblogs.com/youxia/p/linux004.html
依據聖教讀物,將配置再次做了修改如下:

<?xml version="1.0"?><!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> <dir>~/.fonts</dir> <alias> <family>serif</family> <prefer> <family>DejaVu Serif</family> <family>Source Han Sans CN</family> </prefer> </alias> <alias> <family>sans serif</family> <prefer> <family>DejaVu Sans</family> <family>Source Han Sans CN</family> </prefer> </alias> <alias> <family>sans</family> <prefer> <family>DejaVu Sans</family> <family>Source Han Sans CN</family> </prefer> </alias> <alias> <family>mono</family> <prefer> <family>DejaVu Sans Mono</family> <family>Source Han Sans CN</family> </prefer> </alias> </fontconfig>
配置生效,也達到了調整順序的目的(通過fc-match的結果與修改之前對比):

[tong@T7:~] % fc-match -a serif > 3 [tong@T7:~] % fc-match -s serif > 33 [tong@T7:~] % diff 1 3 8a9,15 > SourceHanSansCN-Regular.otf: "Source Han Sans CN" "Regular" > SourceHanSansCN-Normal.otf: "Source Han Sans CN" "Normal" > SourceHanSansCN-Light.otf: "Source Han Sans CN" "Light" > SourceHanSansCN-ExtraLight.otf: "Source Han Sans CN" "ExtraLight" > SourceHanSansCN-Medium.otf: "Source Han Sans CN" "Medium" > SourceHanSansCN-Bold.otf: "Source Han Sans CN" "Bold" > SourceHanSansCN-Heavy.otf: "Source Han Sans CN" "Heavy" 247d253 < SourceHanSansCN-Regular.otf: "Source Han Sans CN" "Regular" 363d368 < SourceHanSansCN-Normal.otf: "Source Han Sans CN" "Normal" 369d373 < SourceHanSansCN-Light.otf: "Source Han Sans CN" "Light" 372d375 < SourceHanSansCN-ExtraLight.otf: "Source Han Sans CN" "ExtraLight" 377d379 < SourceHanSansCN-Medium.otf: "Source Han Sans CN" "Medium" 527d528 < SourceHanSansCN-Bold.otf: "Source Han Sans CN" "Bold" 553d553 < SourceHanSansCN-Heavy.otf: "Source Han Sans CN" "Heavy" [tong@T7:~] % diff 11 33 1 ↵ 4a5 > SourceHanSansCN-Regular.otf: "Source Han Sans CN" "Regular" 14d14 < MSJH.TTC: "Microsoft JhengHei" "Normal" 79d78 < SourceHanSansCN-Regular.otf: "Source Han Sans CN" "Regular" [tong@T7:~]
[tong@T7:~] % fc-match -s serif|head -n 6 DejaVuSerif.ttf: "DejaVu Serif" "Book" DejaVuSerif-Bold.ttf: "DejaVu Serif" "Bold" DejaVuSerif-Italic.ttf: "DejaVu Serif" "Italic" DejaVuSerif-BoldItalic.ttf: "DejaVu Serif" "Bold Italic" SourceHanSansCN-Regular.otf: "Source Han Sans CN" "Regular" times.ttf: "Times New Roman" "Regular" [tong@T7:~] %
可是thunderbird的顯示依然不正確。這真的讓我很為難。。。
又改了一版,因為family名字寫錯了,serif生效了,另外的沒生效。認真閱讀/etc/fontconfig/fonts.conf文件,就會發現正確的名字。

<?xml version="1.0"?><!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> <dir>~/.fonts</dir> <alias> <family>serif</family> <prefer> <family>DejaVu Serif</family> <family>Source Han Sans CN</family> </prefer> </alias> <alias> <family>sans-serif</family> <prefer> <family>DejaVu Sans</family> <family>Source Han Sans CN</family> </prefer> </alias> <alias> <family>monospace</family> <prefer> <family>DejaVu Sans Mono</family> <family>Source Han Sans CN</family> </prefer> </alias> </fontconfig>
查看thunderbird,問題修正。:-)