Linux 字体微调 - windows 效果版
时间:2006-08-03
来源:互联网
作者:quanliking
转载请注明:来自 http://www.linuxsir.org
适用范围:针对 LCD 用户,CRT 用户做少量修改。
实验系统:Debian\Ubuntu,其它发行版应该也适用。
目的:使 linux 下的字体显示达到和 windows 下一样的效果。
一、必须掌握的概念 DPI (以下讨论先避免 sub-pixle 子像素渲染技术,以免混淆)
看过无数流行的汉化或字体美化的文章,往往存在一个致命伤,即忽略了 DPI 这个重要概念,因此是不完整的。
DPI 原来是印刷上的记量单位,意思是每个英寸上,所能印刷的网点数(Dot Per Inch)。但随着数字输入,输出设备快速发展,大多数的人也将数字影像的解析度用DPI表示,但较为严谨的人可能注意到,印刷时计算的网点(Dot)和电脑显示器的显示像素(Pixel)并非相同,所以较专业的人士,会用PPI(Pixel Per Inch)表示数字影像的解析度,以区分二者。而在本文中我们约定两个概念可以互换,即 DPI 就是 PPI。
参考: Coming to Terms with DPI, PPI and Size
问题一: dpi 和我们的 LCD 屏有什么关系呢?
把眼睛凑近屏幕,容易发现我们的屏幕是由一个个小方格组成,我们称这些方格为像素,LCD 中有个术语叫屏幕的 native resolution(物理解析度),指的的就是屏幕所包含的像素数量,比如我的 TFT LCD 14" native resolution 为 1024x768,即水平由 1024 个像素组成,垂直由 768 个像素组成。通常让我们的 LCD 工作在 native resolution,成像效果最好。
通过控制像素的开关和色彩的组合来显示我们需要的图像,但不要忽略了屏幕像素的数量是有限的,所以往往在低解析度的显示设备上看到的图像并不十分清晰,比如在观察白底黑字(或黑底白字)的文字时,文字的边缘有尖锐的锯齿状(阶梯状),长时间观看,眼睛很容易疲乏,这也就是很多人喜欢看纸制书籍的一个重要原因,制作精良的纸张,它包含的“像素”可以达到很高,边缘看起来非常的流畅。
问题二: 有什么办法可以解决或缓解上述缺陷呢?
除了通过各种辅助技术(hinting,anti-alias,sub-pixel,etc.)改善成像效果外,最快捷的途径是换一台高解析度(高分屏或高 dpi) 的屏幕,简单说像素越精细越好。
讲到这里你可能很关心自己的屏幕的 dpi 具体为多少?(拿去和别人炫耀 :)
到这里找找看有没有你的 LCD dpi 信息: http://www.prismo.ch/comparisons/notebook.php
问题三: 如果找不到,如何来手工计算?
找把尺子,把 LCD 屏可视区域的宽和高量一下,比如我的屏幕 width = 287 mm = 28.7 cm,height = 215 mm = 21.5 cm
换算比例: 1 cm = 0.39 inch, 1 inch = 2.54 cm
水平 dpi = 水平 resolution * 2.54 / width = 1024 * 2.54 / 28.7 = 90.6
垂直 dpi = 垂直 resolution * 2.54 / height = 768 * 2.54 / 21.5 = 90.7
故我的 dpi 大概为 90x90,在某些机子上水平 dpi 和 垂直 dpi 会不相当,这是很正常的。
问题四: 下面我们看看自己的单个像素具体有多大?
术语: pixel pitch - 像素间距,即单个像素的水平宽度,类似于 CRT 的 dot pitch(点距)
我的 TFT 14" 1024x768
pixel pitch = 28.7 / 1024 = 0.028 cm = 0.28 mm
而一台 T43 高分屏 SXGA+ 14" 1400x1050, pixel pitch = 0.2047 mm
可以看出 SXGA+ 14" 要精细的多。羡慕啊!
问题五: 我要显示一个 px = 12 的文字,实际看起来会有多大?
术语: [color=red]px(pixel size) - 显示单个文字需要的水平像素数量
实际大小 = px * pixel pitch
TFT 14" 1024x768: 12 * 0.28 = 3.36 mm
SXGA+ 14" 1400x1050: 12 * 0.20 = 2.4 mm
看到这里高分屏的用户应该明白为什么同样是 12 px 的 SimSun 点阵字体(bitmap font),在自己的屏幕上看起来要小很多,因为你的 pixel pitch 小。pixel pitch 小不是更好么?
不是不好,而是字太小了,看起来太累,为了保护你的视力,你应该选择大一些的 px。
但要注意中文点阵字体提供商并没有为每个 px 制作点阵汉字,因为中文点阵都是手工绘制的,需要很高的专业技能,非常耗时,故一般只绘制最常用的 px,而且点阵的一个最大的缺点就是不能够缩放,每个点阵汉字的每一个像素都是事先安排好的,缩放后打乱了原有的布局,比如出现破碎,高高低低之类的现象,使字体变得非常丑陋。
好在 winxp 带的 simsun.ttc 除了 outline 字体外,还包含了丰富的点阵,ppem(pixels per em)分别为 12px, 13px, 14px, 15px, 16px, 18px,你可以根据你的需要选择。例如选择 16px:
实际大小 = 16 * 0.20 = 3.2 mm,这样看起来和 14" TFT 上的 12 px 字就差不多大小了。
当然因为 ppem 不同(或 px 不同),绘制点阵字体时的空间自由度也不同,出来的点阵效果也不同,而且竖线横线比划一般都只占用一个像素宽度,在高分屏上 16px 看起来会有细胳膊细腿的感觉,这也就是为什么不少人会觉得 12px 在 14" 1024x768 上会比较好看,比较符合东方人对中文的审美观。
要注意,由于点阵字体以上的缺陷,通常用在低解析度的屏幕上,现在随着技术的发展,屏幕解析度逐步提高,越来越流行使用 outline 字体,这种字体可以随意的缩放,而不影响形状,现在高分屏用户可以尝试用黑体,如 mac os 带的华文细黑或微软新出的雅黑,黑体比划很粗,适合一部分人的审美观,在大屏幕上效果比较好。
问题六:既然 dpi 都不一样,我要去和别人讨论字体大小,如何讲清楚该字体究竟有多大呢?
真是一个难题,显然用 pixel 这个相对度量去讨论是不合适的,谁也说不清。所以这里我们引入另外一个重要单位 point(磅)。
1 point = 1/72 inch
这里的 inch 就是实际生活中使用的 inch。没错 point 才是绝对度量,比如一个 9 point(9磅)的字的实际大小:
9 * 1/72 = 1/8 inch = 1/8 * 2.54 cm = 3.175 mm
这样的话,大家才能从同一个标准出发讨论问题。所以你看到 MS office word 里的 size,都是以 point 为单位的。
注意,不同家族的字体,如 Arial 和 Verdana 字体,由于设计思路不同,同样磅值的字,看起来 Verdana 感觉要大一些。
Arial VS Verdana
不要让 windows 蒙蔽了你的眼睛!
由于显示器市场的混乱,不同产品 dpi 都不同,为了统一,windows 默认设置 dpi 为 96。注意这里的 dpi 不是你机器的实际 dpi,而是 windows 给你强加上去的。
统一的 96 dpi 有它的优点,因为市面上大多数的显示器 dpi 和这个值接近,而且大多数人都是用 wndows 来设计网页,因此无形中 96dpi 成了一个 de facto 上的标准。但缺点也是很明显的,设计师在 96 dpi 显示器上设计的网页到了 120 dpi 的机器上看起来可能效果会差强人意。所以现在有人建议设置 em 值,这个已经超出我的知识范围。
问题七:你在自己机器上看到的 9 point 还是 9 point 大么?
初看这句话好像自相矛盾,难不成 1 != 1 了!小学老师欺骗了俺?!
别着急!因为你打开 MS word,字体设置栏里看到的 9 point 字,很可能是错误的信息。
假如你运气很好,你的机器实际 dpi 刚好为 96 dpi,那么恭喜你,你没受骗,你看到的是正确信息,如果你的实际 dpi 和 96 相差比较大,那么你看到的是虚假信息。为什么这么讲呢?
我们来做几道小学数学题:
文字在 LCD 上成像,不管是 bitmap font 还是 outline 字体,最终都是以像素绘制。
比方我有一台实际 96 dpi 的 LCD,我要显示一个 9 point 大小的字,我们来看看具体需要多少像素 px?
换算公式: px = pt * dpi / 72
96 dpi, 9 pt: px = 9 * 96 / 72 = 12
操作系统水平要用 12 个像素来描绘该字。
屏幕上看起来有多大?
12 * pixel pitch
假如我通过各种手段人为的把 dpi 改成了 72,来算一下需要的像素值 px?
72 dpi, 9 pt: px = 9 * 72 / 72 = 9
屏幕大小:9 * pixel pitch
注意 pixel pitch 是不变的,计算方法见上文。
现在操作系统就以 9 个像素给你描绘该字,显然比 12 像素描绘出来的小。
这也就是为什么很多人抱怨 Debian/Ubuntu 下默认的 75 dpi ,设置为 9 ponit 的字会看起来比 windows 96 dpi 下小的多的缘故。
此时最可能发生的做法就是,把 9 point 改成更高的 point,而不知其实是 dpi 在跟你开玩笑呢!正确做法,应该先调整好系统 dpi,使之接近你的实际 dpi。
再结合高分屏来讨论一下。
问题八: 同样显示一个 9 point 字(即实际大小一样),显然在 TFT 上需要描绘该字的像素比较少,因为像素个头比较大,而在 SXGA+ 上用来描绘的像素多,个头细,哪个会看起来更漂亮些呢?
我猜你会毫不犹豫选择后者,好比用一个高 dpi 的数码相机拍摄同一个场景,拍出来的效果比低 dpi 要好的多。
但我只能部分同意,还要看你选择的是哪种字体。
如果你正在使用 outline 字体,它是可以任意缩放的,明显同样大小在 SXGA+ 上的表现要好很多,即字体边缘更加光滑流畅,好比在一张好的和画布上作画。
点阵字体要分情况讨论,不要忘了点阵字体是不能缩放的,而且 px 并不完整,只绘制了一些最常用的 px。
例如:
拿两台实际 dpi 分别为 96 和 72 的机器来讨论,同样显示 9 point 的点阵汉字。
上面已经计算过,dpi 96 要用 12 px, dpi 72 要用 9 px 绘制该字。
而使用的字体只带了 9px, 10px, 11px, 13px,14px,15px .....,恰好没提供 12px。
此时 96 dpi 机器上的 9 point 汉字,将会非常丑陋,因为此时的 12px 点阵是机器为你合成的,现在的 AI 还没那么智能,远没达到和人类一样的审美能力。就好比一台高性能手机,可惜不在服务器,任你本事多强,也无用武之地,多郁闷啊!
而 72 dpi 的机器,9 point 刚好落在 9px,此时的字体比划端端正正,自然效果会好的多。
以上的讨论也正说明了点阵字体的缺点,很不灵活。
所以在后面的讨论中,对于 outline 字体,我们用 point size 讨论, 直观方便。而对于 simsun 内嵌的点阵(bitmap font)会用 pixel size 来控制比较好,因为用 point size 的话,还要进行换算,看看是否刚好落在特定的 px,而换算要用到 dpi,个人的实际 dpi 又不尽相同,事先没法得知,故用 point size 是不合适的。
总结一下,dpi 在这里就像是一个桥梁,将 point size 转化为需要的 pixel size。
听了这么多,你也累了,休息一下吧!然后我们一起来实践一下,注意 Linux 将会有多个需要调整 dpi 的地方,希望你能区分清楚。
1、告诉 X server 你的实际 dpi
Debian/Ubuntu 下 X server 默认会使用 75 dpi,可以通过以下命令查看你的 X server 的 dpi 设置:
$ xdpyinfo |grep resolution resolution: 75x75 dots per inch
Mozilla DPI-related Font Size Issues on Unix
Solving the Linux DPI Puzzle
引用其中的几句话,简单看一下有哪几种和它们的优先级:
How the XFree86 and Xorg servers calculate DPI The DPI of the X server is determined in the following manner: 1. The -dpi command line option has highest priority. 2. If this is not used, the DisplaySize setting in the X config file is used to derive the DPI, given the screen resolution. 3. If no DisplaySize is given, the monitor size values from DDC are used to derive the DPI, given the screen resolution. 4. If DDC does not specify a size, 75 DPI is used by default. You can check what DPI your X server is set to by running xdpyinfo | grep resolution in a terminal window. |
As above, if this works, but at less than 100% satisfaction, tweak the number lower or higher to suit your preference. If possible, use a number that is a multiple of 6, or even 12, as numbers that aren't sometimes result in annoying rounding errors that cause adjacent bitmap font sizes to not increment and decrement linearly. |
$ vi /etc/X11/xorg.conf 加入 Section "Monitor" ...... DisplaySize 287 215 # 1024x768 90dpi ...... EndSection
重启 X 后,生效。以 gdm 为例:
$ /etc/init.d/gdm restart
$ xdpyinfo |grep dimensions dimensions: 1024x768 pixels (289x217 millimeters) $ xdpyinfo |grep resolution resolution: 90x90 dots per inch
2、fontconfig/xft
对于传统的程序或系统,使用 legacy x font server,简称 xfs,那么上面的做法应该已经足够,但对于现在的程序来说,通常使用 fontconfig/xft,还得做进一步的工作。
Unfortunately, variations in the implementations of X mean display size reconciliation as above won't be a solution on every system. Failure here seems to be common on newer systems using fontconfig instead of legacy xfs |
$ vi /etc/fonts/local.conf 或 vi ~/.fonts.conf 加入 <!-- Target dots per inch --> <match target="pattern"> <edit name="dpi" mode="assign" > <double>90</double> </edit> </match>
fontconfig 中 pixel size 的计算过程
据我实践,kde Qt3 程序会使用该值,包括 kdm,用该值来控制 Qt3 程序的字体 dpi 比较方便。
3、dpi in gonome
GNOME also offers an interface to set the Xft DPI. If "gnome-settings-daemon" is running, this will advertise the DPI value set in the gnome-font-properties dialog to GNOME applications via XSETTINGS, and set the Xft.dpi X resource. Any Qt application started after gnome-settings-daemon is running will use the Xft.dpi value configured by GNOME. |
操作方法,在 gnome 的字体功能面板 dpi 设置栏里输入 90,就可以了,你可以根据喜好,进行微调,马上能见到效果。
查看 Xft.dpi 值,方法如下:
$ xrdb -query ...... Xft.antialias: 1 Xft.dpi: 90.00000 Xft.hinting: 1 Xft.hintstyle: hintfull Xft.rgba: rgb
细节:
如果 gnome 中的 dpi 和 X server 中的不同,而且相差很大,比如一个 120,一个 90。那么你在登录到 gnome 那一瞬间,会发现开始菜单的字体一下子变大,原因是最开始时 gnome-settings-daemon 还没运行。
4、字体大小不等,dpi 惹得祸
如果你在使用 kde 或 fvwm 之类,而又没有运行 gnome-font-properties,那么你会发现同样是 9 point 字,gtk2 程序和 Qt3 程序的显示大小不同。例如你打开 gnome terminal 和 kde terminal 比较一下。
解决方法:
$ vi ~/.Xresources
Xft.dpi: 90
如果你 dpi 设置遇到问题或有关术语不清楚,请看参考链接:
Mozilla DPI-related Font Size Issues on Unix
Solving the Linux DPI Puzzle
FAQVideoModes
Monitor Tech Guide
Toward a standard font size interval system
二、安装 MS core fonts
即然讲的是实现和 Windows 一样的效果,而我却叽哩咕噜讲了一大堆 dpi,你也听烦了,听会音乐,暂时把 dpi 丢在一边。我们开始一些机械劳动。
1、字体下载
其它发行版,请到这里下载:
Microsoft's TrueType core fonts
Debian/Ubuntu:
$ apt-get install msttcorefonts
分别是:
Andale Mono, Arial, Comic Sans MS, Courier New, Georgia
Impact, Times New Roman, Trebuchet MS, Verdana, Webdings
先来分分类:
无衬线字体(San Serif):
Arial 和 Verdana 作为无衬线字体的经典代表,是我们平时浏览 Web 是最常见的字体,在小字体下都有很好的表现,但是 Verdana 字符间隔(spacing)比较大,在浏览某些网页时,会出现布局混乱的现象,故我们把 Arial 作为我们的主字体。Trebuchet MS 也是比较常见的页面字体。
见: The Scourge of Arial
衬线字体 (Serif):
Georgia 和 Times New Roman 都是比较美观的衬线字体,Georgia 和 Verdana 都出自字体巨匠 Matthew Carter 之手,并由 Monotype's hinting 专家 Tom Rickner 润色,具有很优雅的外观,故同样选择作为我们的主字体。
见: Georgia & Verdana Typefaces designed for the screen
等宽字体 (monotype):
Courier New 和 Adobe 的 Courier 有很像的外观,在终端下有非常好的表现,适合编程故选为我们的主字体。
卡通字体
Comic_Sans_MS 很休闲,也非常出名的卡通字体,可以用来装饰桌面等,有时候作为页面字体,也有很好的可读性。
见: Comic Sans Cafe
界面字体 (UI):
Tahoma 一直以来都是 MS 很多主线产品的 UI 字体,在小字下也有很优秀的表现,故选为我们的主字体,不过由于版权问题,MS 并不提供 Tahoma 免费下载,故不包含在核心字体包里。
简体中文字体:
winxp 带的 simsun.ttc 是一个 truetype 字体集,包括 SimSun(宋体)和 NSimSun(新宋体),它们的中文部分完全一样,唯一不同在于英文部分,NSimSun 的英文是等宽的。不过它们所带的英文衬线字体并不美观,我们在下面将用到字体替换技术,替换成我们喜欢的英文字体。
选择 simsun,除了它是 winxp 的默认字体外,另一个重要原因是带有丰富的点阵字体,在特定的 px 下有非常锐利的外观,所带点阵有效像素(ppem) 分别为 12,13,14,15,16,18,不仅制作规整专业,而且方方正正,很适合一般人的习惯。当然点阵字体的缺点也很明显,不像 Outline 字体可以随意缩放,点阵字体的每个像素都是人为安排的,缩放后打乱了整体结构,会变得非常丑陋。不过不要担心,我会很详细的讲解如何显示特定像素大小的点阵。
注意如果没有必要,请不要使用 simsun18030.ttc 或 vista 中的 simsun.ttc,因为 simsun18030.ttc 所带的点阵只有 12,14,16 三种 ppem,而且没有 xp 中 simsun.ttc 的点阵设计美观,而 vista 中的 simsun.ttc 就好比 simsun18030.ttc 的缩小版,除了字符集小一点外,我没看出区别来,故不要被这些名字所迷惑。
见: simsun - 微軟宋體 TrueType 字型
繁体中文字体:
mingliu.ttc 同样是 truetype 字符集,包含 MingLiU(细明体)和 PMingLiU(新细明体),这里刚好和 simsun 倒一下,MingLiU 的英文部分是才是等宽的,所带的 ppem 分别为 11,12,13,15,16,20。一个需要注意的地方是 mingliu 使用了 hinting 技术,必须打开 freetype2 中的 BYTECODE INTERPRETER,否则在某些字号下,字体会整个破碎掉。而使用 bytecode 会涉及到一些专利问题,引用 firefly 大虾的话:
宋体和 Freetype2 有什么关系呀? (新)宋体、楷体_GB2312使用 bytecode 组字法,与一般的 TrueType 格式不一样,一般的 TrueType 是存放“笔划”,所以字型引擎只要依照笔划指引,就可以绘出字形,而 bytecode 则是一些虚拟指令(类似 java 的虚拟指令),这时候,字型引擎就必须化身为一个解译器,来解释并执行这些虚拟指令,就像 JVM 一样,bytecode 的好处是减少字型档案的大小。 bytecode 有三个部份为 Apple 专利,正是因为这个缘故,freetype2 预设并未打开这个 bytecode 解译功能,所以当遇到了 bytecode 组字的字型时,就会不正常(破碎),幸好此类字型不常见,有个好消息是:freetype unstable 版已经避开了 Apple 专利部份,而且预设也是开启 bytecode 解译功能,可见专利问题已解决了(猜测),所以才会预设开启。 |
参考链接:
mingliu - 微軟細明體 TrueType 字型
Freetype 主页关于 Apple 专利的说明
如果你看不到上述网页效果,很正常,因为你还安装完成。
$ mkdir /usr/share/fonts/truetype/winxp
同时在 /etc/X11/xorg.conf 中加入该路径,好让 legacy X font server 找到是上述四个新添加字体。
$ vi /etc/X11/xorg.conf FontPath "/usr/share/fonts/truetype/winxp"
答案是一般不用了,因为在 Debian/Ubuntu 中有 defoma 帮我们管理字体,而 defoma 会自动在 /etc/X11/xorg.conf 中添加自己的字体路径:
# path to defoma fonts FontPath "/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType"
$ /var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType# ls -al |grep Arial lrwxrwxrwx 1 root root 55 2006-08-02 20:06 Arial_Black.ttf -> /usr/share/fonts/truetype/msttcorefonts/Arial_Black.ttf lrwxrwxrwx 1 root root 61 2006-08-02 20:05 Arial_Bold_Italic.ttf -> /usr/share/fonts/truetype/msttcorefonts/Arial_Bold_Italic.ttf lrwxrwxrwx 1 root root 54 2006-08-02 20:06 Arial_Bold.ttf -> /usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf lrwxrwxrwx 1 root root 56 2006-08-02 20:05 Arial_Italic.ttf -> /usr/share/fonts/truetype/msttcorefonts/Arial_Italic.ttf lrwxrwxrwx 1 root root 49 2006-08-02 20:05 Arial.ttf -> /usr/share/fonts/truetype/msttcorefonts/Arial.ttf
这里要注意区分 fontconfig 和 xfs,它们在你的系统中是共存的,可以简单用新旧两代字体系统来区分。
重启 X, 使之生效。
2、建立字体缓存
$ sudo fc-cache -fv
它会搜索在 /etc/fonts/fonts.conf 指定的字体路径或你自定义的字体路径中的任何 fontconfig 可识别的格式:
<!-- Font directory list --> <dir>/usr/share/fonts</dir> <dir>/usr/share/X11/fonts</dir> <dir>/usr/local/share/fonts</dir> <dir>~/.fonts</dir>
3、两个很有用的命令
1) fc-list
让我们看看刚装的 MS core fonts
$ fc-list : family foundry spacing |grep monotype Andale Mono:spacing=100:foundry=monotype Arial:foundry=monotype Arial Black:foundry=monotype Impact:foundry=monotype Courier New:spacing=100:foundry=monotype Times New Roman:foundry=monotype $ fc-list : family foundry spacing |grep microsoft Verdana:foundry=microsoft Georgia:foundry=microsoft Tahoma:foundry=microsoft Comic Sans MS:foundry=microsoft Webdings:foundry=microsoft Trebuchet MS:foundry=microsoft $ fc-list : family foundry spacing |grep SimSun SimSun,宋体:spacing=90:foundry=unknown NSimSun,新宋体:spacing=90:foundry=unknown quanli@tpr50-ubuntu:~/fonts$ fc-list : family foundry spacing |grep MingLiU PMingLiU,新細明體:foundry=dynalab MingLiU,細明體:spacing=90:foundry=dynalab
很容易看出 MS 的很多字体都不是它自己制作的,而是委托其它专业字体公司,如 monotype 完成制作,然后获取授权。简单说就是付过钱的。
这里的数字 90 代表 dual-width(双宽度),100 表示 mono-width(等宽),没有默认为 0 表示 proportional (不等宽)。
终端字体最好用等宽字体,可以看出我们选择的 Courier New 就是英文等宽字体,spacing=100。
而中文字体如 SimSun,NSimSun,MingLiU 都是双宽度字体,spacing=90,字体渲染引擎 Freetype2 在处理这些双宽度亚洲字体时会出现错误,故我们在后面的配置中要涉及这个问题。
2) fc-match
如果我们要看到单个字体的具体信息
$ fc-match -v Tahoma Pattern 31 of 32 file: "/usr/share/fonts/myfonts/winxp/tahoma.ttf"(s) scalable: FcTrue(s) slant: 0(i)(s) prefer_bitmap: FcTrue(w) rgba: 1(i)(w) rh_prefer_bitmaps: FcTrue(w) size: 12(f)(s) fontversion: 209060(i)(s) weight: 80(i)(s) family: "Tahoma"(s) familylang: "en"(s) antialias: FcFalse(w) outline: FcTrue(s) foundry: "microsoft"(s) dpi: 90(f)(s) stylelang: "ca"(s) style: "Normal"(s) lang: aa|ab|af|ar|ast|ava|ay|az|az-ir|ba|bam|be|bg|bi|bin|br|bs|bua|ca|ce|ch|chm|co|cs|cu|cv|cy|da|de|el|en|eo|es|et|eu|fa|fi|fj|fo|fr|ful|fur|fy|ga|gd|gl|gn|gv|ha|haw|he|ho|hr|hu|ia|ibo|id|ie|ik|io|is|it|kaa|ki|kk|kl|ku|ku-ir|kum|kv|kw|ky|la|lb|lez|lt|lv|mg|mh|mi|mk|mo|mt|nb|nds|nl|nn|no|ny|oc|om|os|pl|ps-af|ps-pk|pt|rm|ro|ru|sah|sco|se|sel|sh|sk|sl|sm|sma|smj|smn|sms|so|sq|sr|sv|sw|tg|th|tk|tn|to|tr|ts|tt|tw|tyv|ug|uk|ur|uz|ven|vi|vo|vot|wa|wen|wo|xh|yap|yi|yo|zu(s) fontformat: "TrueType"(s) width: 100(i)(s) charset: set(s) index: 0(i)(s) pixelsize: 15(f)(s) capability: "otlayout:arab otlayout:cyrl otlayout:hebr otlayout:latn otlayout:thai"(s) verticallayout: FcFalse(s) hinting: FcTrue(w) autohint: FcFalse(w) embeddedbitmap: FcTrue(w) scale: 1(f)(s) hintstyle: 3(i)(w) globaladvance: FcTrue(s)
$ fc-match -v SimSun Pattern 30 of 32 file: "/usr/share/fonts/truetype/msttcorefonts/arial.ttf"(s) ......
看到这里聪明的你一定学会了如何给 fc-list 添加你想看到的参数,同时不要忘了看一下 man。
如果你想学到更多关于 fontconfig 的知识,请看下面链接:
fonts-conf - English Version
fonts-conf - traditional Chinese translation
三、字体配置
该是我们开始对字体进行微调的时候了!Go go ...
1) $ sudo dpkg-reconfigure fontconfig
Select Native if you mostly use Bitstream Vera (the default in Debian) or any of the Microsoft fonts. Select Autohinter if you mostly use other TrueType fonts. Select None if you want blurry text. How should fonts be tuned for the screen? Native Autohinter None
解释一下 Native 表示使用字体自带的 hinting 信息,Autohinter 顾名思义采用 freetype 的 autohint 来机器生产 hint 信息。none 则不使用以上任何一种 hint,通常的结果就是字体更模糊。
选择 Native 的原因是 MS 的 truetype 都带有非常漂亮的 hinting,那什么是 hinting 呢?
The "mathematically correct" pixels for character outlines scaled to a given size and resolution are often unaesthetic or illegible. Hinting is the name for the set of techniques for restoring, as far as possible, their aesthetics and legibility. ...... Each glyph in the font contains its own little hint program, with which the control points of the outlines can be manipulated just prior to rasterization in any way the hint programmer desires. In practice, this means that the outline is carefully distorted by each glyph's hinting instructions to surround only those pixels that produce the desired bitmap image. |
常用的英文符号或其它欧州字符并不是很多,因此可以花很多的时间来给它们手工或其它方式添加 hinting,其中不同的字号大小,不同的字体风格,如 roman,bold,italic,需要进行单独调整,非常费时,从而提供最佳的效果,当然还是那句老话,只有更好,没有最好。
一般来说,hinting 比 autohint 要效果好的多,但对于一些免费字体,用 autohint 反倒是效果更好,原因可能是 Freetype 的设计者对这些字体做了优化。
中文字体由于为数众多,而且字型复杂,为每个字型添加 hinting,显然不实际,也做不好,故很少带 hinting 的。
本文的下文将围绕 hinting 这个主角展开。
见: TrueType Hinting
Rendering text at a subpixel level generally makes it look a bit better on flat (LCD) screens, but can show color artifacts on CRT screens. The "Automatic" choice will enable it only if a LCD screen is detected. screens. The "Automatic" choice will enable it only if a LCD screen is detected. Automatic Always Never
sub-pixel 技术(暂略)
见: [url="http://www.grc.com/cleartype.htm"]Sub-Pixel Font Rendering Technology[/url]
sub-pixel 开关可以单独对每个字体进行的,个人建议是全局开 sub-pixel,而对于中文字体关闭 sub-pixel,对于英文字体根据喜好,有选择性的关闭。
By default, only outline fonts are used by applications which support fontconfig. Outline fonts are fonts which scale well to various sizes. In contrast, bitmapped fonts are often lower quality. Enabling this option will affect the systemwide default; this and many other fontconfig options may be enabled or disabled on a per-user basis. Enable bitmapped fonts by default?
确定以后,它还会为我们作一次 fc-cache,故前面 fc-cache 可以不做。
现在看看 dpkg-reconfigure fontconfig 到底为我们做了什么,背地里的行为我看不到,我只发现多了这么两个软链接:
ubuntu:/etc/fonts/conf.d# ls -al total 32 drwxr-xr-x 2 root root 4096 2006-08-03 22:41 . drwxr-xr-x 3 root root 4096 2006-08-03 19:11 .. lrwxrwxrwx 1 root root 32 2006-08-03 22:41 20-debconf-sub-pixel.conf -> /etc/fonts/conf.d/sub-pixel.conf lrwxrwxrwx 1 root root 33 2006-08-03 22:41 30-debconf-no-bitmaps.conf -> /etc/fonts/conf.d/no-bitmaps.conf -rw-r--r-- 1 root root 250 2006-05-19 14:44 autohint.conf -rw-r--r-- 1 root root 306 2006-05-19 14:44 no-bitmaps.conf -rw-r--r-- 1 root root 257 2006-05-19 14:44 no-sub-pixel.conf -rw-r--r-- 1 root root 256 2006-05-19 14:44 sub-pixel.conf -rw-r--r-- 1 root root 247 2006-05-19 14:44 unhinted.conf -rw-r--r-- 1 root root 296 2006-05-19 14:44 yes-bitmaps.conf
在 /etc/fonts/fonts.conf 里包含了 /etc/fonts/conf.d 这个路径,故它会 Load 里面的配置。
如果 dpkg-reconfigure fontconfig 只为我们做了这么一点工作,那么该命令是完全没有必要运行的。我们后面的工作可比这个复杂的多。我在这里主要是为了起推波助澜的作用,同时也作为一部分全局设置。如果你喜欢清清爽爽一个配置文件的话,你可以删掉软链接,直接都写在一个文件中去。
关于 Ubuntu 中的 fontconfig-voodoo 命令,其实就是帮你写了一个不痛不痒的 fontconfig 配置文件。比如:
$ fontconfig-voodoo -l ja_JP ko_KR none zh_CN zh_HK zh_SG zh_TW ubuntu:/etc/fonts# fontconfig-voodoo -s zh_CN -f 多了 language-selector.conf -> /usr/share/language-selector/fontconfig/zh_CN
ubuntu:/etc/fonts# fontconfig-voodoo -s none -f language-selector.conf -> /usr/share/language-selector/fontconfig/none
不要去修改 /etc/fonts/fonts.conf,因为它很可能在以后升级过程中被替换掉,为了不让你辛苦配置好的文件付诸东流,我们把配置写到 /etc/fonts/local.conf,可以被每位用户读到,当然你也可以写到 ~/.fonts.conf,但要注意如果使用 kde, 每次在 kde 控制中心设置字体后,kde 都会自动创建 ~/.fonts.conf,如果已经存在则在最底下加上它的配置,从而可能覆盖或影响到你的配置,这种做法在我看来是很讨厌的。好在 /etc/fonts/local.conf 是在 ~/.fonts.conf 后被 fontconfig 读取,具有更高的优先级,所以放在这里最合适。
因为配置会很长,故我分三个文件:
local.conf 负责全局配置,本身被 fonts.conf 读取,
msttcorefonts.conf 负责 MS core fonts,被 local.conf 读取,
cjk.conf 负责中日韩字体,被 local.conf 读取。
任何 fontconfig 配置文件,都被包含在 XML 结构之中:
<?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <fontconfig> ... </fontconfig>
给使用 fontconfig 的程序设定目标 dpi,程序包括 kdm, kde 等:
<!-- Target dots per inch --> <match target="pattern"> <edit name="dpi" mode="assign" > <double>90</double> </edit> </match>
<!-- Mark common families with their generics so we'll get something reasonable --> <!-- Serif faces --> <alias> <family>Georgia</family> <family>Times New Roman</family> <family>SimSun</family> <family>PMingLiU</family> <default><family>serif</family></default> </alias> <!-- Sans-serif faces --> <alias> <family>Arial</family> <family>Tahoma</family> <family>Verdana</family> <family>Trebuchet MS</family> <family>Comic Sans MS</family> <family>Arial Unicode MS</family> <default><family>sans-serif</family></default> </alias> <!-- Monospace faces --> <alias> <family>Courier New</family> <family>Andale Mono</family> <family>NSimSun</family> <family>MingLiU</family> <default><family>monospace</family></default> </alias>
<!-- Provide required aliases for standard names --> <alias> <family>serif</family> <prefer> <family>Georgia</family> <family>Times New Roman</family> <family>SimSun</family> <family>PMingLiU</family> </prefer> </alias> <alias> <family>sans-serif</family> <prefer> <family>Arial</family> <family>Verdana</family> <family>Trebuchet MS</family> <family>Comic Sans MS</family> <family>SimSun</family> <family>PMingLiU</family> <family>Arial Unicode MS</family> </prefer> </alias> <alias> <family>monospace</family> <prefer> <family>Courier New</family> <family>Andale Mono</family> <family>NSimSun</family> <family>MingLiU</family> </prefer> </alias>
道理很简单,比如 Georgia 没有中文字型,会向下匹配查找,直到找到第一个中文字型,即 SimSun。这里要注意的地方是,如果你还放了其它中文字体或日文韩文等,一定要加到 pMingLiU 的后面,否则会先使用这些字体里的相同字型,到时界面很丑陋,可别哭啊!
同样 Arial 虽然为 sans-serif 字型,但同样没带中文字型,故使用 SimSun 和 PMingLiU 来补充。
而 NSimSun 和 MingLiU 都是等宽字型,故作为终端字体配合 Courier New 使用。
其实还有个字体叫 Arial Unicode MS,在 Office 2k/xp 里可以找到,带有很全的 Unicode 编码,包括 CJK,是一个很好的补充字体,为了不增加劳动量,我在这里就一撇带过了。
设置 3 个常见 Adobe 字体家族的可接受字体
<!-- Use MS core fonts provides metric and shape compatible fonts for these 3 Adobe families. --> <alias> <family>Times</family> <accept><family>Times New Roman</family></accept> </alias> <alias> <family>Helvetica</family> <accept><family>Arial</family></accept> </alias> <alias> <family>Courier</family> <accept><family>Courier New</family></accept> </alias>
xfonts-100dpi xfonts-75dpi
分别包含 100 和 75 dpi 的字体 for X,里面包括了 Times, Helverica, Courier 这三个字体家族,但它们都是 pcf bitmap 字体格式,而且只包含部分字体大小,最重要的是 pcf 并非很有效的字体格式,在读取时要整个读入内存,故一般体积比较小,而 truetype 是非常先进的字体格式,支持字体部分读取,效率很高。而且 MS 提供的以上三种 turetype 字体都是 outline 字体,可以随意缩放。故我一般直接将上面两个包删除,因为我根本用不到它们。如果你觉得它们有用,比如你觉得 Courier 作为终端字体更好看,那么你保留它们。关于如何删除系统字体,而不影响依赖关系,有兴趣的朋友,可以在文章的最后看到。
见: pcf 的效率
包含 cjk.conf 和 msttcorefonts.conf 文件
<!-- Load Chinese customization file --> <include ignore_missing="yes">./cjk.conf</include> <!-- Load MS core font customization file --> <include ignore_missing="yes">./msttcorefonts.conf</include>
对于核心字体的配置是本文的重点,是实现和 windows 一样显示效果的关键。
很多人在处理英文字体的时候,都会很草率的进行,比如将低于某个数值的字体关闭 Anti-alias(反锯齿),其它开 AA。这种做法在许多场合效果并不理想。因为 MS 的 truetype 在做 hinting 时,是针对不同大小,不同风格做不同的处理,而非一锤子买卖。
在这方面我不得不说 MS 做得很仁义,我们来看看 MS 提供的
Core fonts Quick reference table
font name smoothing and hinting* smoothed hinted both Arial 0 - 6 7 - 13 14+ Arial Bold 0 - 6 7 - 8 9+ Arial Italic 0 - 6 7 - 13 14+ Arial Bold Italic 0 - 6 7 - 8 9+ Arial Black 0 - 6 7 - 12 13+
smoothed 即 Anti-alias
hinted 即 hinting
both 即 Anti-alias + hinting
(注意字体版本不同,信息和上面可以有所出入。)
可以很清楚的看到 Arial 和 Arial Bold 的不同,对于不同分格做了不同优化。写到这里明眼人已经看出我取这个文章题目的原因,我所有的诡计已被识破,黔驴技穷了。
如果上面没有的字体,如何找呢?一般 MS 提供的字体都会自带此类信息,而且 MS 提供了一个工具来帮助你更加简单的查看字体信息。
Font properties extension, version 2.1
如果你没有 windows,或你懒得一个个去看,你可以查看我收集的数据。如下:
Font Name version smoothed hinted both Andale Mono 2.00 0-6 7-20 21+ Arial 2.82 0-6 7-13 14+ Arial Black 2.35 0-6 7-12 13+ Arial Bold 2.82 0-6 7-8 9+ Arial Bold Italic 2.82 0-6 7-8 9+ Arial Italic 2.82 0-6 7-13 14+ Comic Sans MS 2.10 0-6 7-11 12+ Comic Sans MS Bold 2.10 0-6 7-8 9+ Courier New 2.82 0-6 7-27 28+ Courier New Bold 2.82 0-6 7-11 12+ Courier New Bold Italic 2.82 0-6 7-12 13+ Courier New Italic 2.82 0-6 7-27 28+ Georgia 2.05 0-6 7-12 13+ Georgia Bold 2.05 0-6 7-12 13+ Georgia Bold Italic 2.05 0-6 7-12 13+ Georgia Italic 2.05 0-6 7-12 13+ Impact 2.35 0-6 7-16 17+ Times New Roman 2.82 0-6 7-13 14+ Times New Roman Bold 2.82 0-6 7-10 11+ Times New Roman Bold Italic 2.82 0-6 7-13 14+ Times New Roman Italic 2.82 0-6 7-15 16+ Trebuchet MS 1.22 0-6 7-12 13+ Trebuchet MS Bold 1.22 0-6 7-8 9+ Trebuchet MS Bold Italic 1.22 0-6 7-8 9+ Trebuchet MS Italic 1.22 0-6 7-12 13+ Verdana 2.35 0-6 7-12 13+ Verdana Bold 2.35 0-6 7-12 13+ Verdana Bold Italic 2.35 0-6 7-12 13+ Verdana Italic 2.35 0-6 7-12 13+ Webdings 1.03 0-6 7-21 22-1536 1537+ Tahoma 3.09 0-6 7-12 13+ Tahoma Bold 3.09 0-6 7-12 13+ SimSun 3.03 0-6 7-18 19+ MingLiU 5.03 0-6 7-36 37+ Others: Arial Unicode MS 1.01 0-6 7-18 19+ MS 雅黑 0.72 0-6 7-17 18+ MS 雅黑 Bold 0.72 0-6 7-13 14+ Segoe UI 0.98 0-6 7-14 15+ Segoe UI Bold 0.98 0-6 7-14 15+ Segoe UI Italic 0.96 0-6 7-14 15+ Segoe UI Bold Italic 0.95 0-6 7-14 15+
$ vi /etc/fonts/msttcorefonts.conf <?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> <!-- /etc/fonts/msttcorefonts.conf file to configure system font access --> <fontconfig> ...... </fontconfig>
<!-- default : smoothed and hinted --> <match target="font" > <test name="foundry" qual="any" > <string>monotype</string> <string>microsoft</string> </test> <edit name="antialias" mode="assign" > <bool>true</bool> </edit> <edit name="autohint" mode="assign" > <bool>false</bool> </edit> <edit name="hinting" mode="assign" > <bool>true</bool> </edit> <edit name="hintstyle" mode="assign" > <const>hintfull</const> </edit> </match>
<!-- For point size less equal than 6 : only smoothed --> <match target="font" > <test name="foundry" qual="any" > <string>monotype</string> <string>microsoft</string> </test> <test name="size" compare="less_eq" > <double>6</double> </test> <edit name="antialias" mode="assign" > <bool>true</bool> </edit> <edit name="autohint" mode="assign" > <bool>false</bool> </edit> <edit name="hinting" mode="assign" > <bool>false</bool> </edit> </match>
篇幅关系,只举几个特例:
<!-- Arial Regular --> <match target="font" > <test name="family" > <string>Arial</string> </test> <test name="weight" compare="eq"> <const>regular</const> </test> <test name="slant" compare="eq" > <const>roman</const> </test> <test name="size" compare="more_eq" > <double>7</double> </test> <test name="size" compare="less_eq" > <double>13</double> </test> <edit name="antialias" mode="assign" > <bool>false</bool> </edit> <edit name="autohint" mode="assign" > <bool>false</bool> </edit> <edit name="hinting" mode="assign" > <bool>true</bool> </edit> <edit name="hintstyle" mode="assign" > <const>hintfull</const> </edit> </match>
再来个
<!-- Times New Roman Bold Italic --> <match target="font" > <test name="family" > <string>Times New Roman</string> </test> <test name="weight" compare="eq"> <const>bold</const> </test> <test name="slant" compare="eq" > <const>italic</const> </test> <test name="size" compare="more_eq" > <double>7</double> </test> <test name="size" compare="less_eq" > <double>13</double> </test> <edit name="antialias" mode="assign" > <bool>false</bool> </edit> <edit name="autohint" mode="assign" > <bool>false</bool> </edit> <edit name="hinting" mode="assign" > <bool>true</bool> </edit> <edit name="hintstyle" mode="assign" > <const>hintfull</const> </edit> </match>
fontconfig-user
如果某种风格的字体由于开了 sub-pixel,造成边缘花花绿绿,让你很不舒服,你可以单独的关闭它,插入以下语句:
... <edit name="rgba" mode="assign"> <const>none</const> </edit> ...
3) CJK 字型
老规矩:
[code]
$ vi /etc/fonts/cjk.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<!-- /etc/fonts/mscorefont.conf file to configure CJK font access -->
<fontconfig>
......
</fontconfig>
CJK 双宽度纠正
<!-- The dual-width Asian fonts (spacing=dual) are not rendered correctly, apparently FreeType forces all widths to match. Trying to disable the width forcing code by setting globaladvance=false alone doesn't help. As a brute force workaround, also set spacing=proportional, i.e. handle them as proportional fonts: --> <match target="font" > <test target="pattern" name="lang" compare="contains" > <string>zh</string> <string>ja</string> <string>ko</string> </test> <test name="spacing" compare="eq"> <const>dual</const> </test> <edit name="spacing" mode="assign" > <const>proportional</const> </edit> <edit name="globaladvance" mode="assign" > <bool>false</bool> </edit> </match>
<!-- English portion substitution --> <match target="pattern" > <test name="family" > <string>SimSun</string> <string>PMingLiU</string> </test> <edit name="family" mode="prepend" binding="strong" > <string>Arial</string> </edit> </match> <match target="pattern" > <test name="family" > <string>NSimSun</string> <string>MingLiU</string> </test> <edit name="family" mode="prepend" binding="strong" > <string>Courier New</string> </edit> </match>
以下是 SimSun/NSimSun,PMingLiU/MingLiU 微调,原则是存在点阵就优先使用点阵,否则选择 Outline 字体
<!-- SimSun/PMingLiU, NSimSun/MingLiU global setting --> <match target="font" > <test qual="any" name="family" compare="eq" > <string>SimSun</string> <string>NSimSun</string> <string>PMingLiU</string> <string>MingLiU</string> </test> <edit name="rgba" mode="assign"> <const>none</const> </edit> <edit name="antialias" mode="assign" > <bool>true</bool> </edit> <edit name="autohint" mode="assign" > <bool>false</bool> </edit> <edit name="hinting" mode="assign" > <bool>true</bool> </edit> <edit name="hintstyle" mode="assign" > <const>hintfull</const> </edit> <edit name="embeddedbitmap" mode="assign" > <bool>true</bool> </edit> </match>
<!-- Enable embedded bitmap fonts --> <match target="font" > <test qual="any" name="family" compare="eq" > <string>SimSun</string> <string>NSimSun</string> </test> <test name="pixelsize" compare="more_eq" > <double>12</double> </test> <test name="pixelsize" compare="less_eq" > <double>18</double> </test> <edit name="antialias" mode="assign" > <bool>false</bool> </edit> </match> <match target="font" > <test qual="any" name="family" compare="eq" > <string>SimSun</string> <string>NSimSun</string> </test> <test name="pixelsize" compare="eq" > <double>17</double> </test> <edit name="antialias" mode="assign" > <bool>true</bool> </edit> </match>
下面对 PMingLiU/MingLiU 做同样的处理,包含的点阵分别为 px = 11、12、13、15、16、20
<match target="font" > <test qual="any" name="family" compare="eq" > <string>MingLiU</string> <string>PMingLiU</string> </test> <test name="pixelsize" compare="more_eq" > <double>11</double> </test> <test name="pixelsize" compare="less_eq" > <double>16</double> </test> <edit name="antialias" mode="assign" > <bool>false</bool> </edit> </match> <match target="font" > <test qual="any" name="family" compare="eq" > <string>MingLiU</string> <string>PMingLiU</string> </test> <test name="pixelsize" compare="eq" > <double>14</double> </test> <edit name="antialias" mode="assign" > <bool>true</bool> </edit> </match>
为不带粗体的中文字体机器合成粗体
<!-- Synthetic emboldening for Chinese fonts that do not have bold face available --> <match target="font" > <test name="family" compare="contains" > <string>Song</string> <string>Sun</string> <string>Kai</string> <string>Ming</string> </test> <test target="pattern" name="weight" compare="more_eq"> <int>180</int> </test> <edit name="embolden" mode="assign" > <bool>true</bool> </edit> </match>
如果你觉得合成的粗体不过好看,可以用其它黑体/圆体之类来替换,可以增加下面的语句
<!-- Substitude Bold part of SimSun with other font --> <!-- <match target="pattern"> <test qual="any" name="family" > <string>SimSun</string> <string>NSimSun</string> </test> <test name="weight" compare="more" > <const>medium</const> </test> <edit name="family" mode="assign" > <string>其它字体</string> </edit> </match> -->
只要简单拷贝该字体到我们的字体路径下,然后 $ sudo fc-cache -fv,就 OK 了。
<match target="font" > <test qual="any" name="family" compare="eq" > <string>Microsoft YaHei</string> </test> <edit name="rgba" mode="assign"> <const>none</const> </edit> <edit name="antialias" mode="assign" > <bool>true</bool> </edit> <edit name="autohint" mode="assign" > <bool>false</bool> </edit> <edit name="hinting" mode="assign" > <bool>true</bool> </edit> <edit name="hintstyle" mode="assign" > <const>hintfull</const> </edit>
配置文件我已经在附件中给出,写累了,休息一下,看看反馈意见。
按本文配置好后,到下面链接比较一下效果:
Micorsoft Recommended fonts
觉得不错,贴个图我看看,哪里不清楚,同样贴图让我知道,如果配置文件哪里写的不理想,应该怎么改更好,也让我学习一下,比如我用的是英文界面,中文界面我还没测试。觉得太烂了,也别骂我,水平实在有限。
顺便提一下 Ubuntu 中的 firefox,一定要关闭 PANGO
$ vi /etc/firefox/firefoxrc
MOZ_DISABLE_PANGO=1
附件更新时间2006.08.08.21.28
未完待续
SimSun点阵测试.html.bz2 (311 字节, 808 次查看) | |
msttcorefonts.conf-2006.08.06.19.35.bz2 (1.1 KB, 1465 次查看) | |
local.conf-2006.08.08.21.28.bz2 (1.2 KB, 1516 次查看) | |
cjk.conf-2006.08.08.21.28.bz2 (1.9 KB, 1368 次查看) |
作者: quanliking 发布时间: 2006-08-03
我觉得使用screen这个词更准确点。
作者: pupilzeng 发布时间: 2006-08-03
而这东西的优先级应该高于 X 的配置文件吧。
有好像有矛盾:-\
作者: dlz_cn 发布时间: 2006-08-03
作者: pupilzeng
初一看标题,还以为win是MS Windows呢?
我觉得使用screen这个词更准确点。 |
作者: quanliking 发布时间: 2006-08-03
作者: dlz_cn
debian 的 gdm 启动的 X 直接用了 -dpi 96 这个参数。
而这东西的优先级应该高于 X 的配置文件吧。 有好像有矛盾:-\ |
为了更好说清楚,我来两张截图,分别通过 gnome 字体控制面板调节 dpi,看它对 kde 程序和 gnome 程序的影响。
我们看它们的菜单栏。90dpi 下两者菜单字体大小是一样的。gnome 程序在 dpi 120 下菜单栏字体变得硕大无比,而 kde 程序则纹丝不动。很好说明了 gnome 自带 dpi 设置的微妙之处。
当然标题栏都是受 gnome 窗体管理器控制的,不要搞混。
gnome-dpi90.png (175.9 KB, 2216 次查看) | |
gnome-dpi120.png (170.2 KB, 1806 次查看) |
作者: quanliking 发布时间: 2006-08-03
有人要问了,那 kde 的 dpi 本身又是受谁控制的呢?
答案是受 fontconfig 控制。
看截图,这里我将 fontconfig 设置成 120 dpi, gnome 字体控制面板还是 90 dpi,出现了和上一帖完全相反的效果,这里 kde 程序菜单字体硕大无比,而且正文字体大小也发生了变化。
我一再强调 dpi 的重要性,是有根据的,因为这是一个最最容易混淆的概念。
总结一下,也就是说最主要有五个 dpi:
1) legacy X font server (xfs) 一个,我想老式的程序会用到它,一些新程序,如 gdm 也会用到它。
2) fontconfig 一个,kdm,kde 程序会读取它,其它使用 fontconfig 的程序也可能读取它。
3) gnome 单独占一个,控制 gtk2 程序字体大小。
4) firefox 也能独立控制自己的 dpi,用于控制 firefox 界面和网页字体大小。
5) 最后 konqueror 的 dpi 好像是固定的 100 左右。
fontconfig-dpi120.png (146.1 KB, 1447 次查看) |
作者: quanliking 发布时间: 2006-08-03
:)
作者: linuxcpp 发布时间: 2006-08-04
笔记本,14'LCD, debian,使用 GDM+KDE+FireFox,
刚装上X系统,进KDE,字体很小,要在KDE 的控制中心设字体为12以上,但是一复制 W2K 的 simsun.ttf tahoma.ttf 之后,字体就变大了,只要设置 9,
也装过 GNOME,一样的 xorg 文件,GNOME的 还是小,在KDE 和 GNOME 里界面文字大小不一, 烦,删了GNOME.
现在KDE里界面字体是9,比 W2K里的 8大,如果设成8又比W2K里的8小...
在FireFox 里,字体又是一套,什么 12,14,16 的, 还有屏幕分辨率, 什么 72,96,自定义 之类的都试过,乱七八糟, 总是设置不了跟 IE一样, 一样的M$的宋体,设成12好像小一点,网页上的下划线跟字粘在一起,13又大一点,IE里刚好一行的文字,变成两行,第二行只有一个字..
怒,现在只用 wine 运行 IE.
作者: windwiny 发布时间: 2006-08-04
作者: windwiny
这个.....以前搞这个真麻烦
笔记本,14'LCD, debian,使用 GDM+KDE+FireFox, 刚装上X系统,进KDE,字体很小,要在KDE 的控制中心设字体为12以上,但是一复制 W2K 的 simsun.ttf tahoma.ttf 之后,字体就变大了,只要设置 9, 也装过 GNOME,一样的 xorg 文件,GNOME的 还是小,在KDE 和 GNOME 里界面文字大小不一, 烦,删了GNOME. 现在KDE里界面字体是9,比 W2K里的 8大,如果设成8又比W2K里的8小... 在FireFox 里,字体又是一套,什么 12,14,16 的, 还有屏幕分辨率, 什么 72,96,自定义 之类的都试过,乱七八糟, 总是设置不了跟 IE一样, 一样的M$的宋体,设成12好像小一点,网页上的下划线跟字粘在一起,13又大一点,IE里刚好一行的文字,变成两行,第二行只有一个字.. 怒,现在只用 wine 运行 IE. |
我的屏也是 14" , 1024x768,你提到的问题我刚好都会提到,也曾经遇到,我敢保证你能看到比 wine 里的 IE 更好的效果。字体微调真的是个很痛苦的过程,概念真的很多很乱,所以我希望我的经验能给大伙带来不算是解惑,能节约一点时间也好吧。
作者: quanliking 发布时间: 2006-08-04
作者: linuxcpp
期待下文
:) |
作者: quanliking 发布时间: 2006-08-04
作者: fallen 发布时间: 2006-08-04
作者: faxian 发布时间: 2006-08-04
很好
作者: ecserver 发布时间: 2006-08-04
作者: windwiny 发布时间: 2006-08-04
作者: quanliking 发布时间: 2006-08-04
作者: quanliking
不矛盾, x server 和 gnome 的 dpi 设置是分开的,也就是说进了 gnome 后,可以通过 gnome 字体面板控制 gtk2 程序的 dpi。默认 96 是采用和 windows
... 我们看它们的菜单栏。90dpi 下两者菜单字体大小是一样的。gnome 程序在 dpi 120 下菜单栏字体变得硕大无比,而 kde 程序则纹丝不动。很好说明了 gnome 自带 dpi 设置的微妙之处。 当然标题栏都是受 gnome 窗体管理器控制的,不要搞混。 |
“gdm 启动脚本用默认就存在的 '-dpi 96' 和 xorg.conf 里面你修改的 dpi(90) 设置”。这一对设置我认为是矛盾的。启动脚本中的参数是拥有最高的优先级的,你这样设置竟然还能是 xdpyinfo 输出的 dpi 为 90,让我感到非常疑惑。
还有这一段
<edit name="embeddedbitmap" mode="assign" > <bool>true</bool> </edit> <edit name="prefer_bitmap" mode="assign" > <bool>true</bool> </edit> <edit name="rh_prefer_bitmaps" mode="assign" > <bool>true</bool> |
还有一个观点和你的不一样。
我个人的看法,对于显示器这种低分辨率的设备,dpi 的概念实际意义非常的有限。和打印机上的 dpi 意义更无法等同。电脑显示器上我们看到的永远是相对的大小,相让显示的字体接近我们给定的参数的实际大小在运作上不切实际。
举个例子:
同是 1024x768 的分辨率,一个是 10‘ 的 lcd,一个是 15 的 lcd。两者都按照实际的 dpi(ppi) 设置。假设现在有一份文档在屏幕上显示,而且此时 15‘ 的 lcd 刚刚好能完全显示。那么这个时候 10' 的 lcd 能显示多少呢?稍加计算就知道它只能显示 (10 / 15) ^ 2 ,一半文档的大小都不到。显然这样的做法非常的不合理。
我非常赞同上面你引文中一篇文章的观点:
DPI applies well to printing, but not well to the screen. If I project my laptop display on a screen for a presentation, the theoretical DPI has clearly changed, but I do not want all of my fonts to suddenly change with it. DPI values for computer screens are simply convention and not meaningful.
个人见解,欢迎指教:-)
加句废话:你的 MSN 还用吗,怎么老见不到人:-\
作者: dlz_cn 发布时间: 2006-08-04
首先如果没有可重现性,肯定没有写这个的必要。
“gdm 启动脚本用默认就存在的 '-dpi 96' 和 xorg.conf 里面你修改的 dpi(90)设置”。这一对设置我认为是矛盾的。启动脚本中的参数是拥有最高的优先级的,你这样设置竟然还能是 xdpyinfo 输出的 dpi 为 90,让我感到非常疑惑。 |
root@tpr50-ubuntu:/etc# grep '96' /etc/init.d/ -R /etc/init.d/alsa-utils: unmute_and_set_level "PCM,1" "80%" # E.g., ess1969 /etc/init.d/bittorrent:PORT=6969 /etc/init.d/mountall.sh: # Accept 96 (32/mount failure + 64/some mount succeeded) root@tpr50-ubuntu:/etc# grep '96' /etc/gdm/ -R root@tpr50-ubuntu:/etc#
gdm 启动脚本用默认就存在的 '-dpi 96' |
你这样设置竟然还能是 xdpyinfo 输出的 dpi 为 90,让我感到非常疑惑。 |
root@tpr50-ubuntu:/etc# xdpyinfo |grep resolution resolution: 90x90 dots per inch root@tpr50-ubuntu:/etc# xdpyinfo |grep dimension dimensions: 1024x768 pixels (289x217 millimeters)
DisplaySize 287 215 # 1024x768 90dpi
而且我的 gdm Options 的字体和用户名输入框的字体大小明显发生变化。
具体我还得找找资料学习一下,看看里面的运作情况。
<edit name="embeddedbitmap" mode="assign" > <bool>true</bool> </edit> <edit name="prefer_bitmap" mode="assign" > <bool>true</bool> </edit> <edit name="rh_prefer_bitmaps" mode="assign" > <bool>true</bool> |
debian 和 ubuntu 官方的 fontconfig 都不支持这些设置,你写这个有何用?
我个人的看法,对于显示器这种低分辨率的设备,dpi 的概念实际意义非常的有限。和打印机上的 dpi 意义更无法等同。电脑显示器上我们看到的永远是相对的大小,相让显示的字体接近我们给定的参数的实际大小在运作上不切实际。
同是 1024x768 的分辨率,一个是 10‘ 的 lcd,一个是 15 的 lcd。两者都按照实际的 dpi(ppi)设置。假设现在有一份文档在屏幕上显示,而且此时 15‘ 的 lcd 刚刚好能完全显示。那么这个时候 10' 的 lcd 能显示多少呢?稍加计算就知道它只能显示 (10 / 15) ^ 2 ,一半文档的大小都不到。显然这样的做法非常的不合理。
DPI applies well to printing, but not well to the screen. If I project my laptop display on a screen for a presentation, the theoretical DPI has clearly changed, but I do not want all of my fonts to suddenly change with it. DPI values for computer screens are simply convention and not meaningful. |
很抱歉,好几个问题都没回答清楚,我的知识有限。给点时间让我多想想。不过讨论问题,真的有点像是头脑风暴,让你不停的正视你害怕的东西,多谢。
dlz_cn 兄,我的 msn : [email protected] ,上面人很少,所以很少用,很长时间我几乎没上网聊过天,见谅了。
作者: quanliking 发布时间: 2006-08-05
http://www.microsoft.com/typography/...ts/default.htm
如果你用我的方法设置好 dpi, 然后打开字体控制面板,和截图里的字比比大小,当然字体要一样,看看是否一样大。
我把自己的和微软网页上的图放在一块,你比较一下。
刚才改了一下 firefox 的 dpi, 发现结果完全一样,这个比较太糟糕了,firefox 有自己的一套,所以有点误导。还是上面说的放到 gnome 字体面板里去比较,更容易说明问题,而且调 gnome 的 dpi 也很简单
microsoft-arial.gif (7.5 KB, 187 次查看) | |
microsoft-arial-italic.gif (8.1 KB, 148 次查看) | |
quanli-arial.png (78.8 KB, 169 次查看) | |
quanli-arial-italic.png (89.5 KB, 128 次查看) |
作者: quanliking 发布时间: 2006-08-05
quanli-vs-microsoft-24pt-90dpi.jpg (163.1 KB, 360 次查看) | |
quanli-vs-microsoft-24pt-75dpi.jpg (160.5 KB, 314 次查看) |
作者: quanliking 发布时间: 2006-08-05
作者: troyme 发布时间: 2006-08-05
实际上这样截图出来的大小是一样的,当然我改成 120 结果就不同了。
Debian GDM 的这个设置在 /usr/share/gdm/defaults.conf 里面。
Ubuntu 好像对这个设置有特殊的处理,/etc/gdm/ 里面找不到的话,去 /usr/share/gdm 找找吧。关于命令行参数优先级最高的问题,你的引文中也提到的。
至于那几个 fontconfig 的设置 , embeddedbitmap 下个版本的 fontconfig 会引入的。
rh_prefer_bitmaps 则是 redhat 自己的补丁所至,好像从 rh9 的时候就开始用了。
DPI 的问题其实我想表达的就是:
屏幕上显示实际的大小意义不大,有个统一的固定的 dpi 值,调整好各个东西的相对大小就可以了。而这个正是现在大多数人所习惯的一种情况,我前面举的例子则违背了这个习惯。同样的分辨律,却带来不一样的可视范围,一般用户都不会认同的。”
作者: dlz_cn 发布时间: 2006-08-05
支持楼主。
作者: xw_xiao 发布时间: 2006-08-05
root@tpr50-ubuntu:/usr/share/gdm# ls BuiltInSessions gdmchooser.glade gdmphotosetup.glade gdmsetup.glade themes
例1:
比如一个多用户主机,用户甲开了 gnome,用户乙开了其它桌面,我想用户甲如果要设置 自己 gtk2 程序的 dpi,不至于会影响到用户乙的界面吧 !
例2:
多显主机,在 xorg.conf 中可以为每台 monitor 指定 Displaysize(即 dpi),也可以让 X server 自动侦测。应该也能说明部分问题。
gnome 相当于位于 X server 的上层建筑,有自己的自由度。就像是 firefox 同样可以设定自己的 dpi 一样。反倒是 kde 在这方面做得不够好,要去改动 fontconfig 配置文件。
至于那几个 fontconfig 的设置 , embeddedbitmap 下个版本的 fontconfig 会引入的。 rh_prefer_bitmaps 则是 redhat 自己的补丁所至,好像从 rh9 的时候就开始用了。
DPI 的问题其实我想表达的就是: 屏幕上显示实际的大小意义不大,有个统一的固定的 dpi 值,调整好各个东西的相对大小就可以了。而这个正是现在大多数人所习惯的一种情况,我前面举的例子则违背了这个习惯。同样的分辨律,却带来不一样的可视范围,一般用户都不会认同的。”
“调整好各个东西的相对大小就可以了。”部分同意,但这句话本身也是相对的。
如果是提供一个统一的 UI 界面,那完全应该是相对大小的,不然没法统一。就像是大家看不同机器上的 windows,它们的 UI 界面都是差不多的。
但比如说我要看一个文档,却让我看相对大小的文字(其实这里用到的是 pixel 的概念),那么我是无法接受的。为什么呢?
因为我在 15" 寸的屏幕上看到的是正常大小,到了 10" 屏看到的确是蚂蚁大小的文字,不能接受。
我肯定要调整文字到我习惯的大小,如 12pt,这样才能正常阅读,当然可能文档会超出屏幕显示范围。
再举个好玩的例子,如果机器们的 dpi 都没调好,我倒机器甲上看文字,要得到12pt,可能调到 9 pt 就差不多实际的 12pt 大了,而到了机器乙,我可能调到 15pt 才能达到实际的 12pt。久而久之,我会很郁闷,到底我看到的是否是 12pt,我每次看之前,都得带把尺子,先量一下才能放心的观看,因为屏幕给我都是一些虚假信息。有些人更惨了,可能他们一开始用的机器 dpi 设置就是错误的,所以他们心目中的 12pt 大小一开始就错了,这时候尺子也不管用了,实在太混乱了。当然这个例子夸张了点,但是我想作为用户,我是有权力知道正确的信息的。
还是那句话 1 point = 1/72 inch,这个是绝对的。
新版的 windows, vista 采用的都是 outline 字体,可以任意缩放,逐渐淘汰点阵字体, 而且在高分屏大屏幕才能得到良好的显示效果,我想 96 dpi 的时代将很快会过去,以后会如何,我不知道
作者: quanliking 发布时间: 2006-08-05
如果linux的字体显示能达到windows的水平,
我就天天使用linux桌面了。
作者: sofire 发布时间: 2006-08-06
作者: faxian 发布时间: 2006-08-06
或者你在 mozilla 里把中文的最小字体改为 12。
假如你正在用 firefox,在 /etc/firefox/firefoxrc 里加一句:
MOZ_DISABLE_PANGO=1
不然可能你的英文都会是 AA 的效果,而不受 fontconfig 的影响。
作者: quanliking 发布时间: 2006-08-06
比例字体:无衬线 16,
衬线 :times new roman
无衬线 :arial
等宽字体:curier new 16
最小字体为14,
不过/etc/gtk-2.0/gtkrc中设置 tahoma,simsun 11
这应该不相干吧
作者: faxian 发布时间: 2006-08-06
等我把完整的配置文件,贴上来,你再试试看。
还有,我的配置是 AA + hinting 和 单独 hinting 混编的。
顺便把你的配置告诉我一下。
贴张 slashdot 的抓图。
slashdot.png (125.8 KB, 434 次查看) |
作者: quanliking 发布时间: 2006-08-06
作者: faxian 发布时间: 2006-08-06
感谢感谢
呵呵
不过好像链接下不了啊
楼主检查一下
作者: linuxcpp 发布时间: 2006-08-06
作者: quanliking 发布时间: 2006-08-06
效果很好,粗体也有了.也试了msttcorefonts.conf,
感觉英文很"干瘦",

繁体我用的是firefly newsung.
以前打开网页或翻页是cpu占用率很高,现在好多了,看来还真是字体的问题.
非常感谢.
这么大,怎么显示缩略图?
作者: faxian 发布时间: 2006-08-06
因为是 hinting + AA 和 only hinting 混编的,故在正常大小一般都只开 hinting。
比如第一张图,simsun 用的是点阵,而英文部分却开了 AA。小字开了 AA 后感觉边缘有点脏兮兮的,不是很协调,而且 AA 是一种灰阶技术,会使边缘模糊掉,不够黑的感觉,所以我个人还是比较喜欢小字只开 hinting。
干瘦的感觉是因为,竖线一般只占一个像素,在 LCD 上看起来会比较瘦,而在 CRT 上,由于散焦,反倒是效果比较好,感觉就像是开了 AA。
如果用我的英文配置,对于稍大字,配置里都是开 AA 的,你可以用 Ctl + - 调整大小,可以很容易看出变化。
下午发现配置文件有几个地方不正确或没不理想,改了一下,晚上再替换附件里的。
firefly newsung 不知道英文部分效果如何,如果不好,我可以在配置文件里把它的英文替换成别的。
作者: quanliking 发布时间: 2006-08-06
还发先了个问题:中文斜体不好看.
firefly newsung英文部分还可以,我知道怎么替换.谢谢,
等你改了配置我再试试看.
pic4.jpg (6.9 KB, 61 次查看) |
作者: faxian 发布时间: 2006-08-06
dpi应该是96吧?
firefox里的字体我不会调
应该怎么设置最好啊?
我也不会评价如何
请大家说说
firfox_fonts_select.png (43.0 KB, 131 次查看) | |
linuxsir_chs.png (181.5 KB, 68 次查看) | |
linuxsir_code.png (109.7 KB, 111 次查看) | |
firefox_cht.png (159.4 KB, 116 次查看) | |
firefox-slashdot.png (179.0 KB, 83 次查看) |
作者: linuxcpp 发布时间: 2006-08-06
不过感觉ya hei 开了AA不是很好看啊
当然我没在windows下试过是什么效果
还有一个问题
一时想不起来了:(
scim-yahei.png (5.8 KB, 92 次查看) |
作者: linuxcpp 发布时间: 2006-08-06
http://www.prismo.ch/comparisons/notebook.php
dpi = 1400*2.54/28.65 =124
怎么会是 96 呢!
firefox 的暴力调法:
在 url 里输入 about:config
然后找到 browse.display.screen_resolution 输入 124
重启 firefox
我想你的 firefox 肯定没关 PANGO,因为你的英文都是 AA 的,fontconfig 里的效果都出不来。
方法是在 /etc/firefox/firefoxrc 里加入
MOZ_DISABLE_PANGO=1
重启 firefox
雅黑一定要个头够大才好看,你把输入法字体调大,就知道好了。
你先做完这些,看看效果,我再帮你调调。
作者: quanliking 发布时间: 2006-08-06
也许是习惯吧
作者: faxian 发布时间: 2006-08-06
作者: faxian
你说的有道理,不过英文小字只开hinting的话,效果不如winxp.
还发先了个问题:中文斜体不好看. firefly newsung英文部分还可以,我知道怎么替换.谢谢, 等你改了配置我再试试看. |
如果你喜欢开 AA,也没问题,个人喜好不同,这样英文配置文件简单多了,不过记得要加上 hinting,因为用的是 MS truetype 字体。
作者: quanliking 发布时间: 2006-08-06
如我把 Comic Sans MS + 微软雅黑合在一块,看附件截图里的标题,字调得很大。
顺便把输入法雅黑掩饰一下。
最后看看 Courier New 在终端的表现。
yahei+comic.png (130.5 KB, 321 次查看) |
作者: quanliking 发布时间: 2006-08-06
我在运行 dpkg-reconfigure fontconfig
时并没有出现提示窗口
而只是回显了下面的信息
[linuxcpp@root~]$ sudo dpkg-reconfigure fontconfig Cleaning up font configuration of fontconfig... Cleaning up category cid.. Cleaning up category truetype.. Cleaning up category type1.. Updating font configuration of fontconfig... Cleaning up category cid.. Cleaning up category truetype.. Cleaning up category type1.. Updating category type1.. Updating category truetype.. Updating category cid.. Regenerating fonts cache... done.
其中除了那个10-defoma.conf那个链接是原来有的
其它两个链接都是我手动建的
效果就是我上面帖的图
我不记得怎么让dpkg-reconfigure fontconfig有选择界面了
哪位能提醒我怎么设置?
lrwxrwxrwx 1 root root 39 2006-07-05 16:42 10-defoma.conf -> /var/lib/defoma/fontconfig.d/fonts.conf lrwxrwxrwx 1 root root 14 2006-08-06 13:28 20-debconf-sub-pixel.conf -> sub-pixel.conf lrwxrwxrwx 1 root root 15 2006-08-06 13:28 30-debconf-no-bitmaps.conf -> no-bitmaps.conf -rw-r--r-- 1 root root 250 2006-06-06 17:00 autohint.conf -rw-r--r-- 1 root root 306 2006-06-06 17:00 no-bitmaps.conf -rw-r--r-- 1 root root 257 2006-06-06 17:00 no-sub-pixel.conf -rw-r--r-- 1 root root 256 2006-06-06 17:00 sub-pixel.conf -rw-r--r-- 1 root root 597 2006-07-06 13:47 ttf-arphic-ukai -rw-r--r-- 1 root root 1627 2006-07-06 13:47 ttf-arphic-uming -rw-r--r-- 1 root root 247 2006-06-06 17:00 unhinted.conf -rw-r--r-- 1 root root 296 2006-06-06 17:00 yes-bitmaps.conf
作者: linuxcpp 发布时间: 2006-08-06
作者: faxian 发布时间: 2006-08-06
的选择 low
然后再
$ dpkg-reconfigure fontconfig
不过不用做也行,为了方便我已经把它们写到 local.conf
作者: quanliking 发布时间: 2006-08-06
作者: quanliking
我感觉把 fc-match 搞定,不管那种中英文的组合都能调出来。
如我把 Comic Sans MS + 微软雅黑合在一块,看附件截图里的标题,字调得很大。 顺便把输入法雅黑掩饰一下。 最后看看 Courier New 在终端的表现。 |
这个不是serif的字体吗?
我感觉没有monaco好看
嘿嘿
作者: linuxcpp 发布时间: 2006-08-06
作者: faxian 发布时间: 2006-08-06
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28