Skip to content

Commit

Permalink
重新撰写 chrome 字体替换为雅黑样式
Browse files Browse the repository at this point in the history
  • Loading branch information
ywzhaiqi committed Sep 10, 2014
1 parent bd09cc5 commit d294df3
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Font/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# 字体替换为雅黑

### 我目前在用的样式 firefox(2014年9月5日)
## 我目前在用的样式

**首先需要设置浏览器字体为 Microsoft YaHei UI 或微软雅黑**
Chrome 的字体替换详见 [chrome_font.md](chrome_font.md)

### firefox 下的样式

**首先需要设置浏览器字体为** Microsoft YaHei UI 或微软雅黑

```css
@namespace url(http://www.w3.org/1999/xhtml);
Expand Down Expand Up @@ -52,7 +56,10 @@

### 补充说明

**特别注意:** firefox 和 chrome 的字体方式不一样,最好使用 2 个不同的样式

- 字体替换只对设置了字体的有效,而百度搜索页面默认无字体,firefox 会调用默认的字体设置。
- 如果字体为 Arial 或 Verdana,其中中文部分 firefox 会使调用默认的衬线字体,而 chrome 不会。例如 [百度贴吧](http://tieba.baidu.com/p/3285422775?pn=2) 的翻页部分,chrome 需要额外的替换 Verdana 中文部分为雅黑样式。

### 测试页面

Expand Down
173 changes: 173 additions & 0 deletions Font/chrome_font.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
Chrome 的字体替换为雅黑
=====================

参考 [替换字体的中文部分为雅黑](https://chrome.google.com/webstore/detail/enpkigfhoabjjjonanmddidnnahopmcn) 扩展

- 这个扩展由于缺少了替换 Consolas 等字体的英文部分,所以会在 [github](https://github.com/ywzhaiqi/userscript/blob/master/DoubanDownloadSearch.user.js) 的网站显示 Courier New,而不是 Consolas。
- 如果用了 Mactype 可能会出现**斜体**渲染不正常的情况。

```css
/* 替换简体(中文部分)*/
@font-face { font-family: "Simsun"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "NSimsun"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Simhei"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "宋体"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "新宋体"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "黑体"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
/* 替换简体(英文部分)*/
@font-face { font-family: "Simsun"; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face { font-family: "NSimsun"; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face { font-family: "Simhei"; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face { font-family: "宋体"; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face { font-family: "新宋体"; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face { font-family: "黑体"; unicode-range: U+0-2E7F; src: local("Segoe UI"); }

/* 替换繁体(中文部分) */
@font-face {font-family: "MingLiU"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face {font-family: "PMingLiU"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face {font-family: "Microsoft JhengHei"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face {font-family: "DFKai-SB"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face {font-family: "細明體"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face {font-family: "新細明體"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face {font-family: "微軟正黑體"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face {font-family: "標楷體"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
/* 替换繁体(英文部分) */
@font-face {font-family: "MingLiU"; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face {font-family: "PMingLiU"; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face {font-family: "Microsoft JhengHei"; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face {font-family: "DFKai-SB"; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face {font-family: "細明體"; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face {font-family: "新細明體"; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face {font-family: "微軟正黑體"; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face {font-family: "標楷體"; unicode-range: U+0-2E7F; src: local("Segoe UI"); }

/* 替换常见英文字体(中文部分) */
@font-face { font-family: "Arial"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Arial Black"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Tahoma"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Times New Roman"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Times"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Times CY"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Trebuchet MS"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Verdana"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Segoe UI"; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
/* 替换常见英文字体(英文部分) */
@font-face { font-family: "Arial"; unicode-range: U+0-2E7F; src: local("Arial"); }
@font-face { font-family: "Arial Black"; unicode-range: U+0-2E7F; src: local("Arial Black"); }
@font-face { font-family: "Tahoma"; unicode-range: U+0-2E7F; src: local("Tahoma"); }
@font-face { font-family: "Times New Roman"; unicode-range: U+0-2E7F; src: local("Times New Roman"); }
@font-face { font-family: "Times"; unicode-range: U+0-2E7F; src: local("Times"); }
@font-face { font-family: "Times CY"; unicode-range: U+0-2E7F; src: local("Times CY"); }
@font-face { font-family: "Trebuchet MS"; unicode-range: U+0-2E7F; src: local("Trebuchet MS"); }
@font-face { font-family: "Verdana"; unicode-range: U+0-2E7F; src: local("Verdana"); }
@font-face { font-family: "Segoe UI"; unicode-range: U+0-2E7F; src: local("Segoe UI"); }

/* 替换常见的等宽字体(中文部分) */
@font-face { font-family: Consolas; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: Courier New; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: Georgia; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: Helvetica; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: Helvetica Neue; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: Lucida Console; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: Monaco; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: Palatino Linotype; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
/* 替换常见的等宽字体(英文部分) */
@font-face { font-family: Consolas; unicode-range: U+0-2E7F; src: local("Consolas"); }
@font-face { font-family: Courier New; unicode-range: U+0-2E7F; src: local("Courier New"); }
@font-face { font-family: Georgia; unicode-range: U+0-2E7F; src: local("Georgia"); }
@font-face { font-family: Helvetica; unicode-range: U+0-2E7F; src: local("Helvetica"); }
@font-face { font-family: Helvetica Neue; unicode-range: U+0-2E7F; src: local("Helvetica Neue"); }
@font-face { font-family: Lucida Console; unicode-range: U+0-2E7F; src: local("Lucida Console"); }
@font-face { font-family: Monaco; unicode-range: U+0-2E7F; src: local("Monaco"); }
@font-face { font-family: Palatino Linotype; unicode-range: U+0-2E7F; src: local("Palatino Linotype"); }


/* 上面所有的加上粗体(Chrome 需要) */
/* 替换简体(中文部分)*/
@font-face { font-family: "Simsun"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "NSimsun"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Simhei"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "宋体"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "新宋体"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "黑体"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
/* 替换简体(英文部分)*/
@font-face { font-family: "Simsun"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face { font-family: "NSimsun"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face { font-family: "Simhei"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face { font-family: "宋体"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face { font-family: "新宋体"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face { font-family: "黑体"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Segoe UI"); }

/* 替换繁体(中文部分) */
@font-face {font-family: "MingLiU"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face {font-family: "PMingLiU"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face {font-family: "Microsoft JhengHei"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face {font-family: "DFKai-SB"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face {font-family: "細明體"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face {font-family: "新細明體"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face {font-family: "微軟正黑體"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face {font-family: "標楷體"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
/* 替换繁体(英文部分) */
@font-face {font-family: "MingLiU"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face {font-family: "PMingLiU"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face {font-family: "Microsoft JhengHei"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face {font-family: "DFKai-SB"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face {font-family: "細明體"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face {font-family: "新細明體"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face {font-family: "微軟正黑體"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Segoe UI"); }
@font-face {font-family: "標楷體"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Segoe UI"); }

/* 替换常见英文字体(中文部分) */
@font-face { font-family: "Arial"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Arial Black"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Tahoma"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Times New Roman"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Times"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Times CY"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Trebuchet MS"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Verdana"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: "Segoe UI"; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
/* 替换常见英文字体(英文部分) */
@font-face { font-family: "Arial"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Arial"); }
@font-face { font-family: "Arial Black"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Arial Black"); }
@font-face { font-family: "Tahoma"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Tahoma"); }
@font-face { font-family: "Times New Roman"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Times New Roman"); }
@font-face { font-family: "Times"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Times"); }
@font-face { font-family: "Times CY"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Times CY"); }
@font-face { font-family: "Trebuchet MS"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Trebuchet MS"); }
@font-face { font-family: "Verdana"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Verdana"); }
@font-face { font-family: "Segoe UI"; font-weight: bold; unicode-range: U+0-2E7F; src: local("Segoe UI"); }

/* 替换常见的等宽字体(中文部分) */
@font-face { font-family: Consolas; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: Courier New; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: Georgia; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: Helvetica; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: Helvetica Neue; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: Lucida Console; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: Monaco; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
@font-face { font-family: Palatino Linotype; font-weight: bold; unicode-range: U+2E80-FFFF; src: local("Microsoft YaHei UI"), local("Microsoft YaHei"); }
/* 替换常见的等宽字体(英文部分) */
@font-face { font-family: Consolas; font-weight: bold; unicode-range: U+0-2E7F; src: local("Consolas"); }
@font-face { font-family: Courier New; font-weight: bold; unicode-range: U+0-2E7F; src: local("Courier New"); }
@font-face { font-family: Georgia; font-weight: bold; unicode-range: U+0-2E7F; src: local("Georgia"); }
@font-face { font-family: Helvetica; font-weight: bold; unicode-range: U+0-2E7F; src: local("Helvetica"); }
@font-face { font-family: Helvetica Neue; font-weight: bold; unicode-range: U+0-2E7F; src: local("Helvetica Neue"); }
@font-face { font-family: Lucida Console; font-weight: bold; unicode-range: U+0-2E7F; src: local("Lucida Console"); }
@font-face { font-family: Monaco; font-weight: bold; unicode-range: U+0-2E7F; src: local("Monaco"); }
@font-face { font-family: Palatino Linotype; font-weight: bold; unicode-range: U+0-2E7F; src: local("Palatino Linotype"); }
```

### 测试

[多种字体预览页面](http://lifesinger.github.io/lab/2011/default-fonts/),请在关闭 Tampermonkey(TM) 的基础上打开此页面(TM 在 iframe 多的页面会让内存飙升)

首先需要了解 `sans-serif` 为无衬线字体, `serif` 为衬线字体,在设置中可直接设置。

chrome 的规则(不考虑编码错误的问题)

- 无、sans-serif、serif 会调用默认的设置。
- `font-family: arial;` 会调用 Arial 和 宋体。
- `font-family: arial, '微软雅黑', sans-serif;` 会调用 Arial 和 雅黑。
- `font-family: arial, '宋体', sans-serif;` 会调用 Arial 和 宋体。
- `font-family: times, sans-serif;` 会调用 Times New Roman 和 雅黑。

0 comments on commit d294df3

Please sign in to comment.