字母、数字、汉字、符号等,是一种抽象实体。
单个「字符」的具体表达,一个字可有多个不同的字形。
原则上 Unicode 中只对字,而非字形编码。
印刷行业中,指某一整套具有同样样式和尺码的字形,如一整套中易宋体 5 号字、一整套 9 磅 Helvetica 粗体字。
若干个「字型」在若干个尺寸上的集合。
随着计算机字体 (computer font) 的普及,可缩放的矢量字体的出现使得「字型」与「字体」的界限逐渐模糊,现今这两个概念在数字排印领域越来越多地被当做同义词使用。
「书体」- 宋体、仿宋体、黑体等…
例如 Windows 自带的「宋体」实为「中易宋体」。
| 无衬线字体 | |
|---|---|
| 衬线字体 | |
| 衬线 |

HTML 中的 <pre>、<code> 标签常使用等宽字体。
本质上是点阵图片的集合。
是向量图的集合,用 Bézier 曲线描述字形,适合缩放。


font-family: 宋体; 「宋体」定义在何处?
按 OpenType 规范,字体的名称信息存在 name 表中。
| ID | 含义 |
|---|---|
| 1 | Font Family name (Family) |
| 2 | Font Subfamily name (Style) |
| 4 | Full font name (Full) |
| 6 | PostScript name |
| 16 | Preferred Family |
| 17 | Preferred Subfamily |
| 18 | Compatible Full (OS X only) |
| 21 | WWS Family Name |
| 22 | WWS Subfamily Name |
| … | |
| Name Type | Chinese - PRC | English - United States |
|---|---|---|
| Family | 宋体 | SimSun |
| Style | Regular | Regular |
| Full | 宋体 | SimSun |
| PostScript name | 宋体 | SimSun |
| Name Type | Chinese - PRC | English - United States |
|---|---|---|
| Family | Adobe 黑体 Std R | Adobe Heiti Std R |
| Style | Regular | Regular |
| Full | AdobeHeitiStd-Regular | |
| Preferred Family | Adobe 黑体 Std | Adobe Heiti Std |
| Preferred Subfamily | R | R |
| PostScript name | AdobeHeitiStd-Regular | AdobeHeitiStd-Regular |
用哪个?
| 中文 | 英文 | |||||
|---|---|---|---|---|---|---|
| Family | Pref. Family | Full | Family | Pref. Family | Full | |
| IE 6~8 | ✓ | ✓ | ✓ | |||
| IE 9, IE 10 PP2 | ✓ | ✓ | * | |||
| Firefox 3.6 | ✓ | ✓ | ✓ | |||
| Firefox 4 + | ✓ | ✓ | ||||
| :( | ✓ | :( | ||||
| Chrome 18 | ✓ | ✓ | * | |||
| Safari 5 Win | ✓ | ✓ | ✓ | |||
| Opera 11 | ✓ | :( | ||||
Firefox 4+ 下字体只要有 Preferred Family,就无法通过 Family 匹配。
* 从「SimSun」来看应该是可以通过英文 Family 匹配的,这里的原因尚不明。
body {
font-family: Helvetica, Arial, sans-serif;
}
影响默认值、fallback 值因素:OS 相关机制、浏览器配置、charset、lang 属性、font-family 中之前项的值…

fontconfig:fontconfig 组织网/
WebKit settings 中可设定各个 generic family 的默认值。
访问 about:config 后筛选出的 font 相关项中包含不同语言下 generic families 的默认值。
opera:config#CSSGenericFontFamily
normal | italic | oblique | inherit
italic 为单独设计的斜体字体,而 oblique 则由普通字体变形而成。
normal | small-caps | inherit
允许使用同字体的大写字母缩小而成(甚至不缩小亦被允许)。
normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit
| 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | |
|---|---|---|---|---|---|---|---|---|---|
| IE 6 | Regular | Bold | |||||||
| IE 7-9, 10 PP2 | Regular | Semibold | Bold | ||||||
| Firefox 3.6 | Regular | Bold | |||||||
| Firefox 4 + | Regular | Semibold | Bold | ||||||
| Chrome 18 | Regular | Bold | |||||||
| Opera 11 | Regular | Bold | |||||||
| Safari 5 Win | Regular | Bold | |||||||
<absolute-size> | <relative-size> | <length> | <percentage> | inherit
xx-small | x-small | small | medium | large | x-large | xx-large
对对应于 HTML 的字体大小 1–7
larger | smaller
body {
font-family: Tahoma, sans-serif;
font-style: italic;
font-weight: bold;
}
(假设系统中已安装 Tahoma Regular 和 Tahoma Bold)
实际匹配过程 (WebKit):
font-family 没有设定中文字体时,汉字应该怎么显示?
p {
font-family: Helvetica;
}
p {
font-family: Helvetica, serif;
}
两者有什么不同?

p.foo { font-family: Helvetica, Times; }
p.bar { font-family: Helvetica, serif; } 其中的汉字均会 fallback 为「华文黑体」。
p { font-family: Helvetica, serif; } 其中的汉字字体会根据 serif 选择为「华文宋体」。
p.alpha { font-family: Times, Helvetica; }
p.beta { font-family: Helvetica, Times; }
p.gamma { font-family: Helvetica, serif; } 其中前两条的汉字字体都会 fallback 为「华文黑体」,第三条为默认 serif「华文宋体」。OS X 下这几个浏览器具体表现可参考此图

"Lucida Grande", Verdana, "Hiragino Sans GB", "Microsoft YaHei", sans-serif;除 font-synthesis 和 font features 外的新内容都是从 CSS 2 删除的内容
增加了一个字重数值-样式名的对照表供参考:
normal | ultra-condensed | extra-condensed | condensed | semi-condensed | semi-expanded | expanded | extra-expanded | ultra-expanded | inherit
用来选择字体的伸缩程度

<number> | none | inherit
aspect value:字体的 x-height 与 font-size 的比例
字体发生 fallback 以后,aspect value 可能会不一致,这个属性用来调整 font-size 使得不同字体的 x-height 保持一致,取值为需要的 aspect value 值。效果参见示意图

none | [ weight || style ]
默认 weight style
@font-face {
descriptor: value;
descriptor: value;
…
}
descriptor 与 CSS 属性不同,用来「描述」Web font 而非「选择」。
* 这里添加的规则将影响字体的渲染结果,但不影响字体选择。
是一系列字体资源的列表,优先使用 UA 能够使用的第一个资源,每个资源项后的文件类型描述可选。
src: url(fonts/simple.ttf);
src: url(basic.woff) format("woff"),
url(fonts/basic.ttf) format("opentype");

truetype 和 opentype 同义
读取本地字体
src: local(Baidu), // try local font first
url(baidu.ttf) format("opentype");
对于 OpenType 和 TrueType 字体,仅匹配 PostScript name (ID 6) 或 full font name (ID 4),且不支持 localized 名称。
@font-face {
font-family: BBCBengali;
src: url(fonts/BBCBengali.ttf) format("opentype");
unicode-range: U+00-FF, U+980-9FF;
}
已被主流浏览器支持
IE 9 以前仅支持 EOT 字体,浏览器兼容性可参考这里:caniuse 商业网/#feat=fontface。
中文环境下的应用场景?
更好地利用字体的的原生功能,提供更丰富的样式

下标 vs. 拟合下标

合字 (ligatures)


中文也有「合字」

小型大写字

数字样式
更多请参考 Font feature properties
Normalize-OpenType.css: kennethormandy 商业网/journal/normalize-opentype-css/

