Fonts (简体中文)

From ArchWiki
Revision as of 17:13, 28 November 2012 by Flockyrocky (Talk | contribs) (更老的应用程序)

Jump to: navigation, search
翻译状态: 本文是英文页面 Fonts翻译,最后翻译时间:2012-10-11,点击这里可以查看翻译后英文页面的改动。

Tango-preferences-desktop-locale.png本页面需要更新翻译,内容可能已经与英文脱节。要贡献翻译,请访问简体中文翻译组Tango-preferences-desktop-locale.png

附注: please use the first argument of the template to provide more detailed indications.

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary end From Wikipedia:

A computer font (or font) is an electronic data file containing a set of glyphs, characters, or symbols such as dingbats.

字体类型

大多数当代电脑使用的不是点阵字体就是矢量字体。

点阵字体
每种字形的每种形式和每种尺寸的图像都由点或者像素组成的矩阵构成。由于位图的原故,点阵字体很难进行缩放,特定的点阵字体只能清晰地显示在相应的字号下。但对于 12-16px 这样小的汉字,点阵字体常常比其它类型的字体在屏幕上更好的显示效果。常见的点阵字体有 bdf,pcf,fnt,hbf 等格式。
矢量字体
使用贝塞尔曲线, 绘图指令和数学公式来描述每种字形,使得字体可以适应各种尺寸。

通用类型

  • bdf and bdf.gz – 点阵字体,“b”代表点阵,“d”代表布局,“f”代表形式,用gzip压缩 bdf
  • pcf and pcf.gz – 点阵字体,“p”代表可移植,“c”代表编译 “f”代表字体,用gzip压缩 pcf
  • psfpsfupsf.gz and psfu.gz – 点阵字体,“PC”,“s”代表屏幕,“f”代表字体,“PC”,“s”代表屏幕,“f”代表字体,“U”代表Unicode,用gzip压缩(不适用于X.Org)。
  • pfa and pfb – 矢量字体,“P”代表PostScript,“f”代表字体,“A”代表ASCII。“P”代表PostScript,“f”代表字体,“b”代表二进制。PostScript字体包含内嵌打印令。
  • ttf – outline,“T”rue“T”ype,“f”代表字体。作为PostScript字体的替代。
  • otf – outline,“O”pen“T”ype,“f”代表字体。带有PostScript打印指令的TrueType字体。

在多数情况下,TrueType和OpenType的技术差异可以忽略,一些带有ttf扩展的字体实际上是OpenType字体。

其它类型

排版程序“TeX”和配套的字体软件“Metafont”用它们自己的方法渲染字体。一些用于这两个程序的字体的文件后缀是*pk, *gf, mf and vf

“FontForge”, 一个字体编辑程序,可能用自己的格式来储存字体,例如sfd, “s”代表线条,“f”代表字体,“d”代表数据库。

SVG格式也有自己的字体描述方法

安装

你可以使用多种方法安装字体。

Pacman

有效的源中的字体和字体集可以使用pacman来安装。 可以使用以下方式查找字体:

$ pacman -Ss font

或者也可以只查找ttf字体:

$ pacman -Ss ttf

一些字体(例如Terminus)被安装在/usr/share/fonts/local中,这个路径默认没有被加入字体搜索路径中。通过在~/.xinitrc中加入以下命令将可以在X11中使用这些字体:

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

创建字体包

如果想让pacman能够管理你自己的字体,可以创建一个Arch软件包。这些包也可以在AUR中与社区成员分享. 以下是一个怎样创建软件包的基本样例。需要了解更多如何创建软件包的内容,请参考PKGBUILD.

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

build()
{
  mkdir -p $pkgdir/usr/share/fonts/TTF
  cp $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
}

手工安装字体

要安装不在源中的字体,推荐的方法请参考#创建字体包。这样使得pacman在以后能够移除或者更新它们。当然字体也可以通过手工方式安装。

要在系统范围内(对所有用户有效)安装字体,请将文件夹移动到 /usr/share/fonts/目录。要为单个用户安装字体,请使用 ~/.fonts/

同样你可能需要更新/etc/X11/xorg.conf/etc/xorg.conf来指明新目录。查找字符串FontPath以便在这些文件中找到正确的位置来插入你的新路径。查看#X.Org的字体以了解更多信息.

然后更新fontconfig的字体缓存:

$ fc-cache -vf

过老的应用程序

过老而不支持fontconfig的应用程序(例如GTK+ 1.x应用,及xfontsel),需要在字体目录创建索引:

$ mkfontscale
$ mkfontdir

或在一条命令中包含多于一个目录:

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

有时候X server可能会不能成功加载字体目录,这时你需要重新扫描fonts.dir文件:

# xset +fp /usr/share/fonts/misc # Inform the X server of new directories
# xset fp rehash                # Forces a new rescan

查询字体是否已经生效,可以使用:

$ xlsfonts | grep fontname

Pango Warnings

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"

Fonts with 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

Font packages

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.

Braille

International users

Arabic

Birman

Chinese, Japanese, Korean, Vietnamese

(Mainly) Chinese
  • ttf-twAUR -(繁體字)國字標準字體(楷書/宋體)母稿——中華民國教育部(AUR).
  • wqy-microheiAUR - 一种Sans-Serif风格的高质量CJK轮廓字体。"(AUR)
  • wqy-zenhei - 嵌入点阵宋体的黑体风格(sans-serif)中文轮廓字体(也支持部分日文和韩文).
  • ttf-arphic-ukai - 楷體 Kaiti (brush stroke) unicode TTFonts (建议开启抗锯齿)
  • ttf-arphic-uming - 明體 Mingti (打印) unicode TTFonts
  • opendesktop-fonts - 新宋 字体, 之前是 ttf-fireflysung 软件包
  • wqy-bitmapfont - 中文点阵宋体(serif)
  • ttf-hannom - 中文和越南文TrueType字体
Japanese
  • otf-ipafontAUR - Formal style Japanese Gothic (sans-serif) and Mincho (serif) fonts set; one of the highest quality open source font. Default of openSUSE-ja. (AUR)
  • 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).
  • 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 environment.
Korean

Cyrillic

Also see #Monospace, #Sans and #Serif

Greek

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)

Hebrew

  • culmusAUR - Nice collection of free Hebrew fonts

Indic

(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-font - Indic TrueType fonts from Fedora Project (containing Oriya Fonts and more) (AUR)

Khmer

Sinhala

Tamil

Thai

  • ttf-thai - Font covering glyphs for Thai

Tibetan

Math

Microsoft fonts

See MS Fonts.

Apple Mac OS X fonts

  • ttf-macAUR - Mac OS X TrueType fonts. (AUR)

Monospaced

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

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

TrueType

Bitmap

Sans-serif

Script

Serif

Unsorted

Console fonts

The console, meaning a terminal running with no X Window System, uses the ASCII character set as the default. This font and the keymap used are easily changed.

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

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

Previewing and testing

An organized library of images for previewing is available at http://alexandre.deverteuil.net/consolefonts/consolefonts.html.

Moreover, the user can use setfont to temporarily change the font and be able to consider its use as the default. The available glyphs or letters in the font can also be viewed as a table with the command showconsolefont.

If the newly changed font is not suitable, a return to the default font is done by issuing the command setfont without any arguments. If the console display is totally unreadable, this command will still work—the user just types in setfont while "working blind."

Note that setfont only works on the console currently being used. Any other consoles, active or inactive, remain unaffected.

Examples

Change the font. This example is distinctive:

$ setfont /usr/share/kbd/consolefonts/gr737b-9x16-medieval.psfu.gz

Or change the font to one with 512 glyphs and set the keymap to ISO 8859-5 using the -m option:

$ setfont /usr/share/kbd/consolefonts/LatArCyrHeb-16.psfu.gz -m 8859-5

Then issue commands that send text to the display, perhaps view a manpage and try vi or nano, and view the table of glyphs with the command, showconsolefont.

Return to the default font with:

$ setfont

Changing the default font

To change the default font, the FONT= and FONT_MAP= settings in /etc/vconsole.conf (this file may need to be created) must be altered. Again, the fonts can be found in /usr/share/kbd/consolefonts/ directory and keymaps can be found in the subdirectories of /usr/share/kbd/keymaps/.

Examples

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 like lat2-08...16. For the regions determined by 8859 specification, look at the Wikipedia. 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 keymap, for lat2-16 it will be:

FONT_MAP=8859-2

To use the specified font in early userspace, that is, early in the bootup process, add the consolefont hook to /etc/mkinitcpio.conf:

HOOKS="base udev autodetect pata scsi sata filesystems consolefont keymap"

Then rebuild the image:

# mkinitcpio -p linux
Note: The above steps must be repeated for each kernel if more than one kernel package is installed.

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 KMS#Early_KMS_start or other ways to setup your framebuffer before /etc/vconsole.conf gets applied.

Boot Error

If "Loading Console Font" fails at boot time, this is probably because you didn't choose a valid font during your Arch Linux install.

To get rid of this message, simply empty the CONSOLEFONT variable in /etc/rc.conf. It will fallback on default font at boot.

Fallback font order with 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 doesn't 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 monospaced as well. For more informations, have a look at the fontconfig manual.

Font alias

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.

2 英文字和中文字等宽

Merge-arrows-2.pngThis article or section is a candidate for merging with Font Configuration (简体中文).Merge-arrows-2.png

Notes: 配置方法应该放入字体配置页面. (Discuss in Talk:Fonts (简体中文)#)

TrueType 字体分成两种,一种是可变字距,也就是每个字符宽度不一样,比如 "x" 与 "i",这两个字符就不等宽,它是在每个字符中记录该字符的宽度,大多数的 TrueType 字体都是这种格式。

另一种就是固定字距。也就是每个字符宽度都一样,这样显示或打印時,用会有对齐效果,比较美观,在英语环境中,不会有任何问题,但是CJK 的等宽字体,包含『半角英数字符』与『全角 CJK 字符』,字体引擎会把全角字宽度套用在半角字上,造成半宽字看起来间距太大。

a. 让字体引擎(FreeType)取消CJK字体的指定宽度

	<match target="font">
                <test target="pattern" name="lang" compare="contains">
                        <string>zh</string>
                        <string>ja</string>
                        <string>ko</string>
                </test>
                <edit name="spacing">
                        <const>proportional</const>
                </edit>
                <edit name="globaladvance">
                		<bool>false</bool>
                </edit>
        </match>

3 字体替换

一些网页编写时候,对使用的字体预先设定,(如英文部分使用了simsun,使得英文显示很不美观)所以可以使用字体替换使得字体显示更美观。

a. 把Simsun , SimSun-18030 , AR PL ShanHeiSun Uni等这个几个中文字体的英文部分,用 Tahoma,Arial 等替换。

	<match target="pattern">
		<test name="family">
			<string>SimSun</string>
			<string>SimSun-18030</string>
			<string>AR PL ShanHeiSun Uni</string>
			<string>AR PL New Sung</string>
			<string>MingLiU</string>
			<string>PMingLiU</string>
		</test>
		<edit binding="strong" mode="prepend" name="family">
			<string>Tahoma</string>
			<string>Arial</string>
			<string>Verdana</string>
			<string>DejaVu Sans</string>
			<string>Bitstream Vera Sans</string>
		</edit>
	</match>

b. 把 AR PL ShanHeiSun Uni , AR PL New Sung 字体中12~16号的中文字用 WenQuanYi Bitmap Song 点阵字替换, WenQuanYi Bitmap Song 比 AR PL ShanHeiSun Uni , AR PL New Sung中的内嵌点阵更加完善,美观。


	<match target="pattern">
		<test name="family" qual="any">
			<string>AR PL ShanHeiSun Uni</string>
			<string>AR PL New Sung</string>
		</test>
		<test compare="more_eq" name="pixelsize" >
			<double>12</double>
		</test>
		<test compare="less_eq" name="pixelsize" >
			<double>16</double>
		</test>
		<edit name="family" mode="prepend" binding="strong">
			<string>WenQuanYi Bitmap Song</string>
		</edit>
	</match>

4 使用内嵌点阵字

a. 当字体有内嵌字体时,优先使用内嵌字体。

	<match target="font">
		<edit name="embeddedbitmap" mode="assign">
			<bool>true</bool>
		</edit>
	</match>

注意:libXft 还没有embeddedbitmap选项的支持。可以到这里得到libXft2.1.8.2的embeddedbitmap patch,通过ABS重新编译安装libXft 。

5 必须使用hinting的字体

a. 有些 CJK 字体要the byte code interpreter (hinting)才能正确的显示,因为这些字体使用了hinting的一些技术制作。常见的MingLiu 就是这类字体。


        <match target="font">
                <test name="family">
                        <string>MingLiU</string>
                        <string>PMingLiU</string>
                </test>
                <edit name="autohint">
                        <bool>false</bool>
                </edit>
                <edit name="hinting">
                        <bool>true</bool>
                </edit>
        </match>