Fonts (正體中文)

From ArchWiki
Revision as of 09:46, 25 January 2014 by Plesry (Talk | contribs)

Jump to: navigation, search

Tango-preferences-desktop-locale.pngThis article or section needs to be translated.Tango-preferences-desktop-locale.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:Fonts (正體中文)#)

摘自維基百科

電腦字型 (computer font),或稱字型 (font),是包含字 (glyph)、字元或符號 (如 dingbats) 的電子檔案資料。」

注意,某些字型的授權有訂定合理使用限制。

字型格式

現今電腦所使用的字型中,絕大部分屬於點陣 (bitmap) 或輪廓 (outline)資料格式。

點陣字型
由點 (像素) 陣列構成的圖像,代表每種字樣、大小的字 (glyph)。
輪廓字型
又稱作向量 (vector) 字型。使用貝茲曲線 (Bézier curve)、繪圖指引和數學公式描繪每個字,產生的字元可以縮放至任意大小。

常見副檔名

  • bdf, bdf.gz – 點陣字型,bitmap distribution format 的縮寫,以及用 gzip 壓縮的 bdf
  • pcf, pcf.gz – 點陣字型,portable compiled font 的縮寫,以及用 gzip 壓縮的 pcf
  • psf, psfu, psf.gz, psfu.gz – 點陣字型,PC screen font 與 PC screen font Unicode 的縮寫,以及用 gzip 壓縮的版本 (跟 X.Org 不相容)
  • pfa, pfb – 輪廓字型,PostScript font ASCII 與 PostScript font binary 的縮寫。PostScript 字型內建印表機指令。
  • ttf – 輪廓字型,TrueType font 的縮寫。原本設計為 PostScript 字型的替代品。
  • otf – 輪廓字型,OpenType font 的縮寫。TrueType 附帶 PostScript 排版指令。

TrueType 與 OpenType 的技術差異,在大部分的用途之下可被忽略。某些 OpenType 字型使用了 ttf 副檔名。

其他格式

排版程式 TeX 與字型軟體 Metafont 有它們自己算繪字元的方法。這兩個程式使用的字型副檔名有 *pk, *gf, mfvf

FontForge 字型編輯程式會將字型存為自己的文字檔格式 sfd,這是 spline font database 的縮寫。

SVG 格式也有一套自己的字型描述方法。

安裝

安裝字型的方式有很多種。

Pacman

透過 pacman 可以安裝啟用軟體庫的字型。使用以下指令搜尋可供使用的字型:

$ pacman -Ss font

或只搜尋 ttf 字型:

$ pacman -Ss ttf

某些字型,像是 terminus-font,會安裝在 /usr/share/fonts/local,這個目錄預設沒有被加進字型路徑。將以下內容加入 ~/.xinitrc,就可以在 X11 使用這類字型:

xset +fp /usr/share/fonts/local
xset fp rehash

如果執行第一行指令後出現以下錯誤

$ xset +fp /usr/share/fonts/local/
xset:  bad font path element (#0), possible causes are:
    Directory does not exist or has wrong permissions
    Directory missing fonts.dir
    Incorrect font server address or syntax

需要執行

# cd /usr/share/fonts/local;mkfontdir

建立軟體包

您應該將管理字型的工作交給 pacman。字型可以打包成一份 Arch 軟體包,還可以透過 AUR 和社群分享。這裡有一個建立基本軟體包的範例。若想要更了解如何組建軟體包,請閱讀 PKGBUILD

pkgname=ttf-fontname
pkgver=1.0
pkgrel=1
pkgdesc="custom fonts"
arch=('any')
depends=('fontconfig' 'xorg-font-utils')
source=("http://someurl.org/$pkgname.tar.bz2")
install=$pkgname.install

package() {
  install -d "$pkgdir/usr/share/fonts/TTF"
  cp -dpr --no-preserve=ownership "$srcdir/$pkgname/"*.ttf "$pkgdir/usr/share/fonts/TTF/"
}

這份 PKGBUILD 假定字型為 TrueType 類型。之後還必須建立一份安裝檔案 (ttf-fontname.install) 更新字型快取:

post_install() {
  echo -n "Updating font cache... "
  fc-cache -fs >/dev/null
  mkfontscale /usr/share/fonts/TTF /usr/share/fonts/Type1
  mkfontdir /usr/share/fonts/TTF /usr/share/fonts/Type1
  echo "done"
}

post_upgrade() {
  post_install
}

post_remove() {
  post_install
}

若需要更方便的 ttf 字型建立方式,可以使用 AUR 提供的 makefontpkgAUR

手動安裝

要為系統新增一個軟體庫未收錄的字型,建議方法是#建立軟體包。採用這個方式讓 pacman 之後能夠移除或升級字型。不過您也可以用手動的方式安裝字型。

若要將字型安裝到系統 (讓所有使用者都能使用),將字型資料夾移至 /usr/share/fonts/ 目錄。如果只要為單一使用者安裝字型,則改移至 ~/.fonts/ 目錄。

要讓 X 伺服器可以直接載入字型 (不使用「字型伺服器」),需要將新增字型的所在目錄加為 FontPath 項目。這個項目位在您的 Xorg 設定檔案 (例如 /etc/X11/xorg.conf/etc/xorg.conf) 的 Files 區。更多詳細資訊請參閱#讓字型搭配 X.Org

接著更新 fontconfig 字型快取:

$ fc-cache -vf

手動安裝:進階方式

如果您有特殊的字型收集需求:使用商業字型、使用不同格式的字型、安裝/移除字型檔相當頻繁,或只是希望可以更能夠控制存取自己的字型資源,那就相當適合用手動的方式來安裝維護字型。採用這種方案會獲得很多好處:

  • 避免重複安裝不同版本、格式的同一種字型家族 (一個常見原因是算繪問題)。
  • 字型可使用多個非標準的實體來源 (例如額外的硬碟、分割區)。
  • 避免依賴隱晦又佔體積的本地字型來源 (例如 TeX Live & 09-texlive-fonts.conf,或是從 AUR 抓下來的某個字型集合);您可能只需要其中 5 種字型,卻連帶安裝其它 55 種不需要的字型。
  • 避免字型算繪問題,因為您的 fontconfig 設定檔已被調成和與安裝在系統的那份不同的格式。
  • 只要觀察主字型目錄下的內容,就能夠確定系統上有哪種格式的字型家族可供應用程式使用。您不需要複雜、佔用大量資源的字型管理程式;gtk2fontsel 和基本的指令工具 (如 fontconfig 軟體包下的 fc-query) 就可以將這件差事辦得又快又好。
  • 當您安裝或升級單一字型,所有應用程式都可以使用該版本,包含 LaTeX 相關軟體。
  • 有必要的話,可以快速啟用 / 停用某個字型家族,因為您知道它們在哪個目錄下 (除錯時很好用)。
  • 不需擔心有任何多餘的 /etc/fonts/conf.avail/nn-foo.conf fontconfig 檔案會潛在跟您的算繪設定起衝突 (特別是當您使用自訂的字型設定與修補過的函式庫)。
  • 長遠來看,可以省下那些因軟體包管理者的失誤,解決問題和清除衝突所浪費的寶貴時間。

實作上有幾種方式,有必要的話可由任何軟體包管理員採用。以下所舉出的實作方式相當有效率,即使字型數目眾多也相當安全。

  • 我們要將字型來源位置 (例如 /usr/share/fonts.avail:這是我們要存放字型的位置) 和包含字型家族軟連結的目錄 (/usr/share/fonts) 給分隔開來。
  • 將每個字型家族分別放在一個明確命名的子目錄下。命名規則必須一致且明確,例如這樣:
<ttf|otf|t1>-<字型作者或組織(選用)>-<字型家族名稱>

字型來源目錄的內容會長得像這樣:

$ ls /usr/share/fonts.avail

/usr/share/fonts.avail/otf-heuristica
/usr/share/fonts.avail/ttf-liberation
/usr/share/fonts.avail/ttf-ms-arial
...
  • 我們不會動到 TeX Live 的字型目錄,以避免 LaTeX 軟體發生任何問題。既然我們可以使用多個位置,我們將在 /usr/share/fonts 建立軟連結,讓應用程式可以存取特定的字型家族:
# cd /usr/share/fonts
# ln -s ../fonts.avail/otf-heuristica .
# ln -s /opt/texlive/texmf-dist/fonts/truetype/public/opensans ttf-texlive-open.sans

結果如下:

$ ls /usr/share/fonts

ttf-liberation        -> ..fonts.avail/ttf-liberation
ttf-ms-arial          -> ..fonts.avail/ttf-ms-arial
otf-heuristica        -> ..fonts.avail/otf-heuristica
otf-texlive-tex.gyre  -> /opt/texlive/texmf-dist/fonts/opentype/public/tex-gyre
ttf-texlive-open.sans -> /opt/texlive/texmf-dist/fonts/truetype/public/opensans
...

最後,依照慣例執行:

# fc-cache && mkfontscale && mkfontdir

TeX Live Wiki 文章內也有一個類似做法,比較簡單,但較適用於單一使用者的情境,而非全域設定。

舊版應用程式

對於不支援 fontconfig 的舊版應用程式 (例如 GTK+ 1.x 應用程式和 xfontsel),必須在字型目錄下建立索引:

$ mkfontscale
$ mkfontdir

或者,用一行指令將多個資料夾包含進來:

$ for dir in /font/dir1/ /font/dir2/; do xset +fp $dir; done && xset fp rehash

有時候 X 伺服器會無法成功載入字型資料夾,這時您需要重新掃描所有 fonts.dir 檔案:

# xset +fp /usr/share/fonts/misc # 告知 X 伺服器新的目錄
# xset fp rehash                # 強制進行新的掃描

檢查字型是否被包含進來:

$ xlsfonts | grep fontname

Pango 警告訊息

When Pango is in use on your system it will read from fontconfig to sort out where to source fonts.

(process:5741): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type='PangoRenderFc', script='common'
(process:5741): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type='PangoRenderFc', script='latin'

If you are seeing errors similar to this and/or seeing blocks instead of characters in your application then you need to add fonts and update the font cache. This example uses the ttf-liberation fonts to illustrate the solution and runs as root to enable them system-wide.

# pacman -S ttf-liberation
  -- output abbreviated, assumes installation succeeded -- 

# fc-cache -vfs
/usr/share/fonts: caching, new cache contents: 0 fonts, 3 dirs
/usr/share/fonts/TTF: caching, new cache contents: 16 fonts, 0 dirs
/usr/share/fonts/encodings: caching, new cache contents: 0 fonts, 1 dirs
/usr/share/fonts/encodings/large: caching, new cache contents: 0 fonts, 0 dirs
/usr/share/fonts/util: caching, new cache contents: 0 fonts, 0 dirs
/var/cache/fontconfig: cleaning cache directory   
fc-cache: succeeded

You can test for a default font being set like so:

# fc-match
LiberationMono-Regular.ttf: "Liberation Mono" "Regular"

讓字型搭配 X.Org

In order for Xorg to find and use your newly installed fonts, you must add the font paths to /etc/X11/xorg.conf (another X.Org configuration file may work too).

Here is an example of the section that must be added to /etc/X11/xorg.conf. Add or remove paths based on your particular font requirements.

# Let X.Org know about the custom font directories
Section "Files"
    FontPath    "/usr/share/fonts/100dpi"
    FontPath    "/usr/share/fonts/75dpi"
    FontPath    "/usr/share/fonts/cantarell"
    FontPath    "/usr/share/fonts/cyrillic"
    FontPath    "/usr/share/fonts/encodings"
    FontPath    "/usr/share/fonts/local"
    FontPath    "/usr/share/fonts/misc"
    FontPath    "/usr/share/fonts/truetype"
    FontPath    "/usr/share/fonts/TTF"
    FontPath    "/usr/share/fonts/util"
EndSection

終端機字型

The virtual console uses the kernel built-in font and ASCII character set by default, but both can be easily changed.

A console font is limited to either 256 or 512 characters. Available fonts are saved in /usr/share/kbd/consolefonts/ directory.

Keymaps, the connection between the key pressed and the character used by the computer, are found in the subdirectories of /usr/share/kbd/keymaps/.

預覽和測試

提示: An organized library of images for previewing is available: Linux console fonts screenshots.

The available glyphs or letters in the font can also be viewed as a table with using showconsolefont:

$ showconsolefont

The setfont utility may be used to temporarily change the font, so that the user can consider its use as the default. Just pass the name of the font (they are located in /usr/share/kbd/consolefonts/):

$ setfont Lat2-Terminus16

Optionally, you can specify character set to be used using the -m option:

$ setfont Lat2-Terminus16 -m 8859-2

If the newly changed font is not suitable, a return to the default font with the following command (even if the console display is totally unreadable, this command will still work - just type the command "blindly"):

$ setfont
註記: setfont only works on the console currently being used. Any other consoles, active or inactive, remain unaffected.

更改預設字型

The FONT and FONT_MAP variables in /etc/vconsole.conf are used to change the default font.

For displaying characters such as Č, ž, đ, š or Ł, ę, ą, ś using the font lat2-16.psfu.gz:

FONT=lat2-16

It means that second part of ISO/IEC 8859 characters are used with size 16. You can change font size using other values (e.g. lat2-08). For the regions determined by 8859 specification, look at the Wikipedia table. You can use a Terminus font which is recommended if you work a lot in console without X server. ter-216b for example is latin-2 part, size 16, bold. ter-216n is the same but normal weight. Terminus fonts have sizes up to 32.

Now, set the proper font mapping, for lat2-16 it will be:

FONT_MAP=8859-2

To use the specified font in early userspace, use the keymap hook in /etc/mkinitcpio.conf. See Mkinitcpio#HOOKS for more information.

If the fonts seems to not change on boot, or change only temporarily, it is most likely that they got reset when graphics driver was initialized and console was switched to framebuffer. To avoid this, load your graphics driver earlier. See for example Kernel Mode Setting#Early KMS start, [1] or other ways to setup your framebuffer before /etc/vconsole.conf is applied.

字型軟體包

This is a selective list that includes many font packages from the AUR along with those in the official repositories. Fonts are tagged "Unicode" if they have wide Unicode support, see the project or Wikipedia pages for detail.

Github user Ternstor has created a python script that generates PNG images of all fonts in extra, community and the AUR so you can preview all the fonts below.

盲文點字

非英語系使用者

Applications and browsers select and display fonts depending upon fontconfig preferences and available font glyph for Unicode text. To list installed fonts for a particular language, issue a command fc-list :lang="two letter language code". For instance, to list installed Arabic fonts or fonts supporting Arabic glyph:

$ fc-list :lang=ar | cut -d: -f1
/usr/share/fonts/TTF/FreeMono.ttf
/usr/share/fonts/TTF/DejaVuSansCondensed.ttf
/usr/share/fonts/truetype/custom/DroidKufi-Bold.ttf
/usr/share/fonts/TTF/DejaVuSansMono.ttf
/usr/share/fonts/TTF/FreeSerif.ttf

To properly render fonts for multilingual websites like Wikipedia or this Arch Linux wiki, install these packages: ttf-freefont, ttf-arphic-uming, ttf-baekmuk

阿拉伯文和烏爾都文

緬甸文

中日韓越

中文 (為主)
  • ttf-twAUR - Kai and Song traditional Chinese font from the Ministry of Education of Taiwan (AUR).
  • wqy-microhei - A Sans-Serif style high quality CJKV outline font.
  • wqy-zenhei - Hei Ti Style (sans-serif) Chinese Outline font embedded with bitmapped Song Ti (also supporting Japanese (partial) and Korean characters).
  • ttf-arphic-ukai - Kaiti (brush stroke) Unicode font (enabling anti-aliasing is suggested)
  • ttf-arphic-uming - Mingti (printed) Unicode font
  • opendesktop-fonts - New Sung font, previously is ttf-fireflysung package
  • wqy-bitmapfont - Bitmapped Song Ti (serif) Chinese font
  • ttf-hannom - Chinese and Vietnamese TrueType font
日文
  • otf-ipafont - Formal style Japanese Gothic (sans-serif) and Mincho (serif) fonts set; one of the highest quality open source font. Default of openSUSE-ja.
  • ttf-vlgothicAUR - Japanese Gothic fonts. Default of Debian/Fedora/Vine Linux (AUR)
  • ttf-mplusAUR - Modern Gothic style Japanese outline fonts. It includes all of Japanese Hiragana/Katakana, Basic Latin, Latin-1 Supplement, Latin Extended-A, IPA Extensions and most of Japanese Kanji, Greek, Cyrillic, Vietnamese with 7 weights (proportional) or 5 weights (monospace). (AUR)
  • ttf-ipa-monaAUR, ttf-monapoAUR - Japanese fonts to show 2channel Shift JIS art properly. (AUR)
  • ttf-sazanami - Japanese free TrueType font. This is outdated and not maintained any more, but may be defined as a fallback font on several environments.
韓文

西里爾文

Also see #Monospaced, #Sans-serif and #Serif

希臘文

Almost all Unicode fonts contain the Greek character set (polytonic included). Some additional font packages, which might not contain the complete Unicode set but utilize high quality Greek (and Latin, of course) typefaces are:

  • otf-gfsAUR - Selection of OpenType fonts from the Greek Font Society (AUR)
  • ttf-mgopenAUR - Professional TrueType fonts from Magenta (AUR)

希伯來文

  • culmusAUR - Nice collection of free Hebrew fonts (AUR)

印地文

(This one contains a "look of disapproval" that might be more to your liking than the bdf-unifont one mentioned elsewhere in this document)
  • lohit-fontsAUR - Indic TrueType fonts from Fedora Project (containing Oriya Fonts and more) (AUR)

高棉文

僧伽羅文

塔米爾文

藏文

數學

Microsoft 字型

See MS Fonts.

Apple Mac OS X 字型

  • ttf-mac-fontsAUR - Mac OS X TrueType fonts
  • ttf-macAUR - Mac OS X TrueType fonts (This package does not come with the ttf fonts (only the otf fonts), they have to be provided on their own.

等寬

Here are some suggestions. Every user has their own favorite, so experiment to find yours. If you are in a hurry, you read Dan Benjamin's blog post: Top 10 Programming Fonts.

Here is a long list of fonts by Trevor Lowing: http://www.lowing.org/fonts/.

TrueType

點陣

無襯線

Script

襯線

未分類

X11 的字型採用順序

Fontconfig automatically chooses a font that matches the current requirement. That is to say, if one is looking at a window containing English and Chinese for example, it will switch to another font for the Chinese text if the default one does not support it.

Fontconfig lets every user configure the order they want via $XDG_CONFIG_HOME/fontconfig/fonts.conf. If you want a particular Chinese font to be selected after your favorite Serif font, your file would look like this:

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<alias>
   <family>serif</family>
   <prefer>
     <family>Your favorite Latin Serif font name</family>
     <family>Your Chinese font name</family>
   </prefer>
 </alias>
</fontconfig>

You can add a section for Sans-serif and monospace as well. For more informations, have a look at the fontconfig manual.

字型別名

In Linux there are several font aliases which represent other fonts in order that applications may use similar fonts. The most common aliases are: serif for a font of the serif type (e.g. DejaVu Serif); sans-serif for a font of the sans-serif type (e.g. DejaVu Sans); and monospace for a monospaced font (e.g. DejaVu Sans Mono). However, the fonts which these aliases represent may vary and the relationship is often not shown in font management tools such as those found in KDE and other desktop environments.

To reverse an alias and find which font it is representing, run:

$ fc-match monospace
DejaVuSansMono.ttf: "DejaVu Sans Mono" "Book"

In this case DejaVuSansMono.ttf is the font represented by the monospace alias.

小提示

從官方軟體庫安裝字型

您可以將官方軟體倉庫有提供的字型全部抓下來安裝。

所有字型
# pacman -S $(pacman -Ssq font)
所有 TrueType 字型
# pacman -S $(pacman -Ssq ttf)

應用程式專用的字型快取

Matplotlib (python-matplotlibpython2-matplotlib) 使用自己的字型快取,因此更新字型後記得移除 $HOME/.matplotlib/fontList.cache,這樣它才會再產生一次快取並找到新字型 [2]

另請參閱