Xorg字體配置 (簡體中文)

 

X的字體配置和美化

See the Xorg Font Documentation for full details.
See the FreeType2 Project Page for details on the freetype X.org Module.
See Optimal Use of Fonts on Linux for more information about fonts in Linux.

xorg.conf模塊

  • freetype - 爲True Type (ttf, ttc), Type1 (pfa, pfb), CID (cid), CFF, Open Type, 點陣bitmap (bdf, pcf, snf), Windows (fnt), PFR, 和 Type42 字體提供支持
  • type1 - 爲Type1 (pfa, pfb) 和CID (cid) 字體提供支持
  • speedo - 支持Bitstream Speedo (spd) 字體
  • xtt - 爲True Type (ttf, ttc) 字體提供支持 (conflicts with freetype)
  • bitmap - 提供bitmap (bdf, pcf, snf) 的支持

如你所看到的,freetype提供了所有的支持.補充說明一點,xtt(或許應該是xft,這裏依據原文)於freetype有衝突.

X.org字體路徑和/etc/fonts/配置目錄

xorg.conf字體路徑

xorg.conf裏面的字體路徑是給非xft字體用的. 爲大多數字體在這裏指定路徑是值得的. 那些不支持xft的程序會尋找X的字體路徑.我個人來說,我在這裏填寫最少的字體路徑-僅僅爲了xterm和那一類程序使用.

/etc/fonts/配置目錄

/etc/fonts下的配置文件 (fonts.conf and local.conf)是用來配置字體的(Xft fonts). fonts.conf 不應該被更改, 如果要更改應該改local.conf(系統全局) 或者 ~/.fonts.conf (用戶自定義). 在/etc/fonts/conf.d目錄下的文件都是以一個數字開頭,還有.conf結尾的一個軟鏈接.

在fonts.conf列出的目錄會爲字體配置而被fc-cache掃描 (/usr/share/fonts 和 ~/.fonts). 所有的字體都應該放在這些文件夾內. 如果安裝一個新字體,運行fc-cache -fv會讓改變生效.

 

添加新字體

當新字體被添加後,它們不過是系統裏面的一些文件. 必須使用一些工具來告訴系統新字體已經被安裝了.

/usr/bin/fc-cache

這樣將會更新系統字體緩存, 當然是假設新字體能夠被配置文件找到 (看上一節關於/etc/fonts部分)

/usr/bin/mkfontscale
/usr/bin/mkfontdir
ln -s /usr/X11R6/lib/X11/fonts/encodings/encodings.dir encodings.dir

這幾個工具需要在含有新字體的目錄內運行. mkfontscale創建一個fonts.scale文件, mkfontdir 則創建一個fonts.dir文件. 這兩個文件被X服務所使用, 也僅僅需要當字體通過X.org的字體路徑使用的時候運行.而encodings的軟鏈接允許X服務使用這些新字體(支持相關編碼情況下).所有這些完成後, 你會發現這個字體目錄下有3個新文件 : fonts.scale, fonts.dir, and encodings.dir.

fc-list和xlsfont工具

這兩個工具將在命令行下用不同方式列出所有可用字體. fc-list將列出所有配置過的字體,而xlsfont則會列出所有的X字體. 如果同時使用grep效果會非常好,例如: "xlsfonts || grep -i bitstream" 可以看到所有可用的bitstream字體.

一些字體的下載

Goodies

LCD的ClearType補丁

http://bbs.archlinux.org/viewtopic.php?id=33955

我的字體像屎一樣難看.我都配置好了,但是好像是我缺少好看字體.

建議你從pacman安裝如下包來解決:

pacman -S ttf-ms-fonts ttf-cheapskate artwiz-fonts

另外一個方法是刪除75/100dpi包然後安裝Bitstream Vera.後者提供漂亮的等寬終端字體,也能是瀏覽網頁字體更好看(至少是firefox裏面這樣):

pacman -Rns xorg-fonts-75dpi xorg-fonts-100dpi
pacman -S ttf-bitstream-vera

補充:中文用戶,安裝如下任意一箇中文字體,帶有很全的GBK字符集,需要打開community倉庫

pacman -S wqy-bitmapfont	文泉驛點陣字體
pacman -S wqy-zenhei 文泉驛正黑字體

我有一些針對Gtk 2.2和以下版本編譯的程序,字體仍然看起來很垃圾.

的確這個會發生.現在的Gtk程序默認開啓了xft支持, 但是2.2字體以前就沒有這樣了. 也許這些程序應該升級到一個針對新Gtk的新版本了. 如果那不可能,那麼就添加 export GDK_USE_XFT=1 到全局設置文件 (/etc/profile, /etc/profile.d/gnome.sh, ~/.xinitrc, 等,任選一個) 將會爲老程序啓用xft的支持.

我有的老的Qt基礎的程序有同樣的問題.

同上, 添加 export QT_XFT=true.

在用KDE桌面的時候,Gtk程序字體太小.

安裝gtk-qt-engine:

pacman -Sy gtk-qt-engine
  • 更改Gtk程序字體大小:`Control Center' -> `Appearance & Themes' -> `GTK Styles and Fonts'.

bytecode interpreter讓我字體看起來很醜,但是我已經把它編譯進去了,我需要重新編譯麼?

完全不需要. 只是Freetype內部的自動微調(auto-hinting)關閉了. 在某些distros(也許可以翻譯成源)裏面, bytecode interpreter 被編譯進去而且默認開啓了. 這樣造成bytecode interpreter 替代了freetype的自動微調(autohinter) (這還是開發者比較得意的地方). 指定自動微調開啓, 添加下面的段到/etc/fonts/local.conf 或者 ~/.fonts.conf

     <match target="pattern">
<edit name="autohint" mode="assign">
<bool>true</bool>
</edit>
</match>

或者改變 /etc/fonts/conf.d目錄, 即從conf.avail做一個10-autohint.conf的軟鏈接到這裏. 如下(第二個命令需要有超級用戶權限).

cd /etc/fonts/conf.d
ln -s ../conf.avail/10-autohint.conf

問題: 我不明白,bytecode interpreter 會和自動微調(autohinter)衝突都有段時間了,所以我不知道爲什麼有人想要自動微調. 回答: 因爲 bytecode interpreter 在2.3分支(branch)裏面支持相當不好 . 這裏有一個論壇帖子是關於這個的: http://bbs.archlinux.org/viewtopic.php?id=29976 那上面的代碼讓我的字體好看很多. 儘管我重啓效果就會失效,我也不知道爲什麼.

自動微調(Autohint)運行的很好,但是我的字體的粗體就不行了,我怎樣能針對粗體關閉它?

自動微調可以讓字體很好看,但是有時也讓字體變太寬. 特別是字體爲粗體模式時尤其嚴重. 幸好你可以爲粗體關閉微調,而爲其他字體模式保留.

  • First turn on autohinter (see above) and add the following to ~/.fonts.conf
     <match target="font">
<test name="weight" compare="more">
<const>medium</const>
</test>
<edit name="autohint" mode="assign">
<bool>false</bool>
</edit>
</match>

我有一個使用DVI數據線的TFT/DFP/LCD顯示器,字體看起來模糊不清晰

這是CRT和非CTR渲染的不同造成的. 爲了解決這個問題,你應該開啓次像素(sub-pixel)渲染. 編輯~/[[[.fonts.conf]]] 文件. 添加下面一小段開啓用. 說明:這樣並沒有顯示質量的提高,只是做了CRT顯示器完成的一部分額外工作(NOTE that this will do nothing but a minor amount of extra work on CRTs and does not improve the display quality). 這裏 const可能的值是- rgb, bgr, vrgb, bgrv, 等.

< !-- Enable sub-pixel rendering -->
<match target="font" >
<edit mode="assign" name="rgba" >
<const>rgb</const>
</edit>
</match>

我不希望我的字體在某些字號下反鋸齒(或者叫邊緣模糊 AA Antialiase).

一份例子是/etc/fonts/local.conf文件. 推薦這樣做, 當然就像次像素渲染那一節一樣寫. 如果有任何改變,就應該改變 compare="less_eq" , 和<int>12</int>區域 - 這分別是渲染強弱和點大小.

     <match target="pattern">
<test qual="any" name="size" compare="less_eq">
<int>12</int>
</test>
<edit name="antialias" mode="assign"><bool>false</bool></edit>
</match>

我使用MS的TrueType字體(verdana),想針對看起來有鋸齒的大號字體開啓反鋸齒.

     <?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
     <match target="font" >
<test compare"more" name"size" qual="any" >
<double>12</double>
</test>
<edit mode"assign" name"antialias" >
<bool>true</bool>
</edit>
</match>
     <match target="font" >
<test compare"more" name"pixelsize" qual="any" >
<double>17</double>
</test>
<edit mode"assign" name"antialias" >
<bool>true</bool>
</edit>
</match>
</fontconfig>

我想安裝更多字體.

保存你的字體到一個目錄然後到~/[[[.fonts.conf]]]添加路徑

    < !-- Additional font directories -->
<dir>/path/to/dir</dir>

我希望我的字體大小符合我的DPI設置.

照下面編輯~/[[[.fonts.conf]]]. 這個設置應該適合你xorg.conf裏面的Dpi,或者startx命令. 使用xdpyinfo來查看你目前的DPI設置. 大多數人適合或者正在使用96或者100的值.應該依照這個文檔Xorg DisplaySize/DPI來改變X的DPI值

     <match target="pattern">
<edit name="dpi" mode="assign"><double>100</double></edit>
</match>

我不喜歡 <某個字體>希望用<另一個字體>替代它

最可靠的辦法是同上面一樣添加一段XML段落到 ~/.fonts.conf. 這會讓Bitstream Vera Sans取代Helvetica:

<match target="pattern" name="family" >
<test name="family" qual="any" >
<string>Helvetica</string>
</test>
<edit mode="assign" name="family" >
<string>Bitstream Vera Sans</string>
</edit>
</match>

 

一個另類的辦法是設置"更喜歡"字體,但這僅僅在原始字體不存在的時候生效,這樣你設置的字體才能生效:

 

     < !-- Replace Helvetica with Bitstream Vera Sans Mono -->
< !-- Note, an alias for Helvetica should already exist in default conf files -->
<alias>
<family>Helvetica</family>
<prefer><family>Bitstream Vera Sans Mono</family></prefer>
<default><family>fixed</family></default>
</alias>

我有一堆不想要的噁心的像素字體(pixel fonts)

只有兩個字體你需要一定保留,否則X服務無法啓動:'cursor' 和 'fixed', 他們都在/usr/share/fonts/misc目錄. 如果你不想要除此之外所有的像素字體, 你可以刪除那個目錄下多數文件, 除了cursor.pcf.gz和所有類似9x18.pcf.gz或者9x18-ISO8859-1.pcf.gz. 我刪除所有不需要字體後,misc目錄還有大約337個文件, 所以如果你比這個數字少,那麼在重啓X之前你最好是還原刪除的問題件.

譯者補充:

  • 我試過這種方法,不過我的文件是可以更少的,只需要保留cursor.pcf.gz和類似6x13- Iso8859-[1-10].pcf.gz就行了,沒有實驗能不能更少,其實沒有必要刪除這麼多,系統還是會剩下某個字號的fiexd字體,可以利用上面提到的字體替換方法替換成你喜歡字體,避免任何程序調用.
  • 如夠你刪除了所有文件,但是沒有備份,那麼可以
pacman -S xorg-fonts-misc

來重新安裝這個字體,否則你的X是不能啓動的,當然也可以解壓你cache文件夾下相應包.

  • 這種方法對於opera的中文字體難看問題有一定程度的解決

我的點陣字體被禁用了,我想使用它們.

默認的, fontconfig 2.3.2-4和更高版本會禁用點陣(bitmap)字體. 這個設置是被/etc/fonts/conf.d/10-no-bitmaps.conf管理的, 在更高版本里面是/etc/fonts/conf.d/10-bitmaps.conf. 啓用點陣字體而且在升級fontconfig後也保持, 建立一個軟鏈接從yes-bitmaps.conf到10-bitmaps.conf, 覆蓋no-bitmaps.conf.

爲沒有粗斜體的字體構造粗體和斜體

Freetype已經具備這樣的能力,但是如果不是程序要求,是不會這樣作的 - 也就是說它自己無論如何也不會給正常字體添加粗斜體樣式. 要是用這些樣式,你需要手動編輯/usr/share/fonts/fonts.cache-1 (保留一份你的修改,因爲fc-cache的更新會覆蓋它). 假設你有一個字體叫Dupree:

     "dupree.ttf" 0 "Dupree:style=Regular:slant=0:weight=80:width=100:foundry=unknown:index=0:outline=True:....

複製這一行, 把 style=Regular改成style=Bold或者其他樣式. 同時爲斜體更改 slant=0slant=100 , 爲粗體更改weight=80weight=200 (粗斜體則都更改):

     "dupree.ttf" 0 "Dupree:style=Bold Italic:slant=100:weight=200:width=100:foundry=unknown:index=0:outline=True:....

添加必須的設置到~/.fonts.conf:

     <match target="font">
<test name="family" qual="any">
<string>Dupree</string>
<!-- other fonts here .... -->
</test>
<test compare="more_eq" name="weight"><int>140</int></test>
<edit mode="assign" name="embolden"><bool>true</bool></edit>
</match>
<match target="font">
<test name="family" qual="any">
<string>Dupree</string>
<!-- other fonts here .... -->
</test>
<test compare="more_eq" name="slant"><int>80</int></test>
<edit mode="assign" name="matrix">
<times>
<name>matrix</name>
<matrix>
<double>1</double><double>0.2</double>
<double>0</double><double>1</double>
</matrix>
</times>
</edit>
</match>

(注意,現在你就能使用粗體了 - 或者把他們變得更粗)

~/.fonts.conf

一個網絡開發者的.~/.fonts.conf,是論壇上來的. 備份你現有的這是,嘗試一下.

 <?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">

<!-- the cathectic LCD tweaks, from linuxquestions.org,
http://www.linuxquestions.org/questions/showthread.php? postid=1361098#post1361098 -->

<fontconfig>

<!-- Disable sub-pixel rendering.
X detects it anyway, and if you set this as well, it just looks really horrible -->
<match target="font" >
<edit mode="assign" name="rgba" >
<const>none</const>
</edit>
</match>
<match target="font" >
<edit mode="assign" name="hinting">
<bool>true</bool>
</edit>
</match>
<match target="font" >
<edit mode="assign" name="hintstyle">
<const>hintfull</const>
</edit>
</match>

<!-- The first part of the 'magic.'
This makes the fonts start to look nice,
but some of the shapes will be distorted, so hinting is needed still -->
<match target="font" >
<edit mode="assign" name="antialias">
<bool>true</bool>
</edit>
</match>

<!-- Autohinter is not turned on automatically.
Only disable this if you have recompiled Freetype with the bytecode interpreter,
which is run automatically.<br /> -->
<match target="pattern" >
<edit mode="assign" name="autohint">
<bool>true</bool>
</edit>
</match>
<match target="font">
<test name="weight" compare="more">
<const>medium</const>
</test>
<edit name="autohint" mode="assign">
<bool>false</bool>
</edit>
</match>
<!-- Helvetica is a non true type font, and will look bad.
This replaces it with whatever is the default sans-serif font -->
<match target="pattern" name="family" >
<test name="family" qual="any" >
<string>Helvetica</string>
</test>
<edit mode="assign" name="family" >
<string>sans-serif</string>
</edit>
</match>
<dir>~/.fonts</dir>
</fontconfig>
http://blog.chinaunix.net/u2/71976/showart_1892342.html
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章