顾轶灵
字母、数字、汉字、符号等,是一种抽象实体。
单个「字符」的具体表达,一个字可有多个不同的字形。
印刷行业中,指某一整套具有同样样式和尺码的字形,如一整套中易宋体 5 号字、一整套 9 磅 Helvetica 粗体字。
若干个「字型」在若干个尺寸上的集合。
随着计算机字体 (computer font) 的普及,可缩放的矢量字体的出现使得「字型」与「字体」的界限逐渐模糊,现今这两个概念在数字排印领域越来越多地被当做同义词使用。
「书体」- 宋体、仿宋体、黑体等…
例如 Windows 自带的「宋体」实为「中易宋体」。
| 无衬线字体 | |
|---|---|
| 衬线字体 | |
| 衬线 |
<pre>、<code> 标签常使用等宽字体。本质上是点阵图片的集合。
是向量图的集合,用 Bézier 曲线描述字形,适合缩放。


font-familyfont-stylefont-variantfont-weightfont-sizefontfont-family 名字;font-style, font-variant, …);font-family;font-family 无法匹配,UA 分配默认字体;font-familyfont-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 中之前项的值…可参考玉伯的实验。
WebKit settings 中可设定各个 generic family 的默认值。
访问 about:config 后筛选出的 font 相关项中包含不同语言下 generic families 的默认值。
opera:config#CSSGenericFontFamily
font-stylenormal | italic | oblique | inherit
italic 为单独设计的斜体字体,而 oblique 则由普通字体变形而成。
font-variantnormal | small-caps | inherit
允许使用同字体的大写字母缩小而成(甚至不缩小亦被允许)。
font-weightnormal | 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 | |||||||
font-size<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;
}
实际匹配过程 (WebKit):
font-family 是否支持 localized names?font-family 是否支持 Preferred Family?font-style / font-weight / font-variation 不满足时是否需要拟合?font-family 匹配失败 fallback 时默认字体的选择是否有讲究?font-family 没有设定中文字体时,汉字应该怎么显示?
p {
font-family: Helvetica;
}
p {
font-family: Helvetica, serif;
}

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"> 可缓解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;
arial,sans-serifArial,sans-serifarialsimsun"微软雅黑","黑体"Simsunarial,"微软雅黑","黑体""方正隶书简体","Microsoft Yahei"tahoma,arial,"Hiragino Sans GB",\5b8b\4f53,sans-serifarialverdana,arialMicrosoft YaHei, Hiragino Sans GBmicrosoft yahei"Microsoft YaHei,\5B8B\4F53"SimSunverdana"tahoma,arial,\5b8b\4f53,sans-serif""宋体","Arial Narrow",HELVETICA"\5B8B\4F53",arial,sans-serifTahoma,ArialTahomaTahoma,"微软雅黑","MicrosoftYahei","宋体"Tahoma,"宋体"Arial"Microsoft Yahei"arial, simsun"\u7039\u5b29\u7d8b",arial,sans-seriffont-familyfont-weightfont-stretchfont-stylefont-variantfont-sizefont-size-adjustfontfont-synthesis@font-face除 font-synthesis 和 font features 外的新内容都是从 CSS 2 删除的内容
font-familyfont-family 匹配的字体名称:Family (ID 1), Preferred Family (ID 16), WWS Family (ID 21)font-weight增加了一个字重数值-样式名的对照表供参考:
100 - Thin200 - Extra Light (Ultra Light)300 - Light400 - Normal500 - Medium600 - Semi Bold (Demi Bold)700 - Bold800 - Extra Bold (Ultra Bold)900 - Black (Heavy)font-stretchnormal | ultra-condensed | extra-condensed | condensed | semi-condensed | semi-expanded | expanded | extra-expanded | ultra-expanded | inherit
用来选择字体的伸缩程度

font-size-adjust<number> | none | inherit
aspect value:字体的 x-height 与 font-size 的比例
字体发生 fallback 以后,aspect value 可能会不一致,这个属性用来调整 font-size 使得不同字体的 x-height 保持一致,取值为需要的 aspect value 值。效果参见示意图。
font-synthesisnone | [ weight || style ]
默认 weight style
@font-face@font-face {
descriptor: value;
descriptor: value;
…
}
descriptor 与 CSS 属性不同,用来「描述」Web font 而非「选择」。
@font-facefont-familysrcfont-stylefont-weightfont-stretchunicode-rangefont-variant *font-feature-settings ** 这里添加的规则将影响字体的渲染结果,但不影响字体选择。
src是一系列字体资源的列表,优先使用 UA 能够使用的第一个资源,每个资源项后的文件类型描述可选。
src: url(fonts/simple.ttf);
src: url(basic.woff) format("woff"),
url(fonts/basic.ttf) format("opentype");
src读取本地字体
src: local(Baidu), // try local font first
url(baidu.ttf) format("opentype");
unicode-range@font-face {
font-family: BBCBengali;
src: url(fonts/BBCBengali.ttf) format("opentype");
unicode-range: U+00-FF, U+980-9FF;
}
@font-face已被主流浏览器支持
IE 9 以前仅支持 EOT 字体,浏览器兼容性可参考这里。
中文环境下的应用场景?
更好地利用字体的的原生功能,提供更丰富的样式
font-variant-position
font-variant-position
font-variant-caps
font-variant-numeric
更多请参考 Font feature properties
- EOF -