Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5367f0b

Browse files
authoredOct 26, 2021
Rollup merge of #90232 - konan8205:master, r=GuillaumeGomez
rustdoc: Use TTF based font instead of OTF for CJK glyphs to improve readability Due to Windows' implementation of font rendering, OpenType fonts can be distorted. So the existing font, Noto Sans KR, is not very readable on Windows. This PR improves readability of Korean glyphs on Windows. ## Before ![원1](https://user-images.githubusercontent.com/11029378/138592394-16b15787-532d-4421-a5eb-ed85675290fa.png) ## After ![원2](https://user-images.githubusercontent.com/11029378/138592409-f3a440ee-f0fc-40e4-9561-42c479439c9f.png) The fonts included in this PR are licensed under the SIL Open Font License and generated with these commands: ```sh pyftsubset NanumBarunGothic.ttf \ --unicodes=U+AC00-D7AF,U+1100-11FF,U+3130-318F,U+A960-A97F,U+D7B0-D7FF \ --output-file=NanumBarunGothic.ttf.woff --flavor=woff ``` ```sh pyftsubset NanumBarunGothic.ttf \ --unicodes=U+AC00-D7AF,U+1100-11FF,U+3130-318F,U+A960-A97F,U+D7B0-D7FF \ --output-file=NanumBarunGothic.ttf.woff2 --flavor=woff2 ``` r? `@GuillaumeGomez`
2 parents 90b3a84 + 9e00501 commit 5367f0b

9 files changed

+61
-35
lines changed
 

‎src/librustdoc/html/render/write_shared.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ static FILES_UNVERSIONED: Lazy<FxHashMap<&str, &[u8]>> = Lazy::new(|| {
3939
"SourceCodePro-Semibold.ttf.woff" => static_files::source_code_pro::SEMIBOLD,
4040
"SourceCodePro-It.ttf.woff" => static_files::source_code_pro::ITALIC,
4141
"SourceCodePro-LICENSE.txt" => static_files::source_code_pro::LICENSE,
42-
"noto-sans-kr-regular.woff2" => static_files::noto_sans_kr::REGULAR2,
43-
"noto-sans-kr-regular.woff" => static_files::noto_sans_kr::REGULAR,
44-
"noto-sans-kr-LICENSE.txt" => static_files::noto_sans_kr::LICENSE,
42+
"NanumBarunGothic.ttf.woff2" => static_files::nanum_barun_gothic::REGULAR2,
43+
"NanumBarunGothic.ttf.woff" => static_files::nanum_barun_gothic::REGULAR,
44+
"NanumBarunGothic-LICENSE.txt" => static_files::nanum_barun_gothic::LICENSE,
4545
"LICENSE-MIT.txt" => static_files::LICENSE_MIT,
4646
"LICENSE-APACHE.txt" => static_files::LICENSE_APACHE,
4747
"COPYRIGHT.txt" => static_files::COPYRIGHT,

‎src/librustdoc/html/static/css/rustdoc.css

+6-6
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@
7777

7878
/* Avoid using legacy CJK serif fonts in Windows like Batang. */
7979
@font-face {
80-
font-family: 'Noto Sans KR';
81-
src: url("noto-sans-kr-regular.woff2") format("woff2"),
82-
url("noto-sans-kr-regular.woff") format("woff");
80+
font-family: 'NanumBarunGothic';
81+
src: url("NanumBarunGothic.ttf.woff2") format("woff2"),
82+
url("NanumBarunGothic.ttf.woff") format("woff");
8383
font-display: swap;
84-
unicode-range: U+AC00-D7AF, U+3130-318F, U+1100-11FF, U+A960-A97F, U+D7B0-D7FF;
84+
unicode-range: U+AC00-D7AF, U+1100-11FF, U+3130-318F, U+A960-A97F, U+D7B0-D7FF;
8585
}
8686

8787
* {
@@ -108,7 +108,7 @@ html {
108108
/* General structure and fonts */
109109

110110
body {
111-
font: 16px/1.4 "Source Serif 4", "Noto Sans KR", serif;
111+
font: 16px/1.4 "Source Serif 4", NanumBarunGothic, serif;
112112
margin: 0;
113113
position: relative;
114114
padding: 10px 15px 20px 15px;
@@ -196,7 +196,7 @@ div.impl-items > div:not(.docblock):not(.item-info),
196196
.content ul.crate a.crate, a.srclink,
197197
/* This selector is for the items listed in the "all items" page. */
198198
#main > ul.docblock > li > a {
199-
font-family: "Fira Sans", Arial, sans-serif;
199+
font-family: "Fira Sans", Arial, NanumBarunGothic, sans-serif;
200200
}
201201

202202
.content ul.crate a.crate {

‎src/librustdoc/html/static/fonts/noto-sans-kr-LICENSE.txt ‎src/librustdoc/html/static/fonts/NanumBarunGothic-LICENSE.txt

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
Copyright 2014, 2015 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries.
1+
Copyright (c) 2010, NAVER Corporation (https://www.navercorp.com/),
22

3-
This Font Software is licensed under the SIL Open Font License, Version 1.1.
3+
with Reserved Font Name Nanum, Naver Nanum, NanumGothic, Naver NanumGothic,
4+
NanumMyeongjo, Naver NanumMyeongjo, NanumBrush, Naver NanumBrush, NanumPen,
5+
Naver NanumPen, Naver NanumGothicEco, NanumGothicEco, Naver NanumMyeongjoEco,
6+
NanumMyeongjoEco, Naver NanumGothicLight, NanumGothicLight, NanumBarunGothic,
7+
Naver NanumBarunGothic, NanumSquareRound, NanumBarunPen, MaruBuri
48

5-
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
9+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
10+
This license is copied below, and is also available with a FAQ at:
11+
http://scripts.sil.org/OFL
612

713

814
-----------------------------------------------------------
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

‎src/librustdoc/html/static_files.rs

+29-9
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,35 @@ crate mod source_code_pro {
160160
crate static LICENSE: &[u8] = include_bytes!("static/fonts/SourceCodePro-LICENSE.txt");
161161
}
162162

163-
crate mod noto_sans_kr {
164-
/// The file `noto-sans-kr.woff`, the Regular variant of the Noto Sans KR font.
165-
crate static REGULAR: &[u8] = include_bytes!("static/fonts/noto-sans-kr-regular.woff");
166-
167-
/// The file `noto-sans-kr.woff2`, the Regular variant of the Noto Sans KR font.
168-
crate static REGULAR2: &[u8] = include_bytes!("static/fonts/noto-sans-kr-regular.woff2");
169-
170-
/// The file `noto-sans-kr-LICENSE.txt`, the license text of the Noto Sans KR font.
171-
crate static LICENSE: &[u8] = include_bytes!("static/fonts/noto-sans-kr-LICENSE.txt");
163+
/// Files related to the Nanum Barun Gothic font.
164+
///
165+
/// These files are used to avoid some legacy CJK serif fonts in Windows.
166+
///
167+
/// Note that the Noto Sans KR font, which was used previously but was not very readable on Windows,
168+
/// has been replaced by the Nanum Barun Gothic font. This is due to Windows' implementation of font
169+
/// rendering that distorts OpenType fonts too much.
170+
///
171+
/// The font files were generated with these commands:
172+
///
173+
/// ```sh
174+
/// pyftsubset NanumBarunGothic.ttf \
175+
/// --unicodes=U+AC00-D7AF,U+1100-11FF,U+3130-318F,U+A960-A97F,U+D7B0-D7FF \
176+
/// --output-file=NanumBarunGothic.ttf.woff --flavor=woff
177+
/// ```
178+
/// ```sh
179+
/// pyftsubset NanumBarunGothic.ttf \
180+
/// --unicodes=U+AC00-D7AF,U+1100-11FF,U+3130-318F,U+A960-A97F,U+D7B0-D7FF \
181+
/// --output-file=NanumBarunGothic.ttf.woff2 --flavor=woff2
182+
/// ```
183+
crate mod nanum_barun_gothic {
184+
/// The file `NanumBarunGothic.ttf.woff`, the Regular variant of the Nanum Barun Gothic font.
185+
crate static REGULAR: &[u8] = include_bytes!("static/fonts/NanumBarunGothic.ttf.woff");
186+
187+
/// The file `NanumBarunGothic.ttf.woff2`, the Regular variant of the Nanum Barun Gothic font.
188+
crate static REGULAR2: &[u8] = include_bytes!("static/fonts/NanumBarunGothic.ttf.woff2");
189+
190+
/// The file `NanumBarunGothic-LICENSE.txt`, the license text of the Nanum Barun Gothic font.
191+
crate static LICENSE: &[u8] = include_bytes!("static/fonts/NanumBarunGothic-LICENSE.txt");
172192
}
173193

174194
/// Files related to the sidebar in rustdoc sources.
+14-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
// This test checks that the correct font is used on module items (in index.html pages).
22
goto: file://|DOC_PATH|/test_docs/index.html
3-
assert-css: (".item-table .module-item a", {"font-family": '"Fira Sans", Arial, sans-serif'}, ALL)
4-
assert-css: (".item-table .docblock-short", {"font-family": '"Source Serif 4", "Noto Sans KR", serif'}, ALL)
3+
assert-css: (".item-table .module-item a", {"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'}, ALL)
4+
assert-css: (".item-table .docblock-short", {"font-family": '"Source Serif 4", NanumBarunGothic, serif'}, ALL)
55

66
// modules
7-
assert-css: ("#modules + .item-table .item-left a", {"font-family": '"Fira Sans", Arial, sans-serif'})
8-
assert-css: ("#modules + .item-table .item-right.docblock-short", {"font-family": '"Source Serif 4", "Noto Sans KR", serif'})
7+
assert-css: ("#modules + .item-table .item-left a", {"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'})
8+
assert-css: ("#modules + .item-table .item-right.docblock-short", {"font-family": '"Source Serif 4", NanumBarunGothic, serif'})
99
// structs
10-
assert-css: ("#structs + .item-table .item-left a", {"font-family": '"Fira Sans", Arial, sans-serif'})
11-
assert-css: ("#structs + .item-table .item-right.docblock-short", {"font-family": '"Source Serif 4", "Noto Sans KR", serif'})
10+
assert-css: ("#structs + .item-table .item-left a", {"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'})
11+
assert-css: ("#structs + .item-table .item-right.docblock-short", {"font-family": '"Source Serif 4", NanumBarunGothic, serif'})
1212
// enums
13-
assert-css: ("#enums + .item-table .item-left a", {"font-family": '"Fira Sans", Arial, sans-serif'})
14-
assert-css: ("#enums + .item-table .item-right.docblock-short", {"font-family": '"Source Serif 4", "Noto Sans KR", serif'})
13+
assert-css: ("#enums + .item-table .item-left a", {"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'})
14+
assert-css: ("#enums + .item-table .item-right.docblock-short", {"font-family": '"Source Serif 4", NanumBarunGothic, serif'})
1515
// traits
16-
assert-css: ("#traits + .item-table .item-left a", {"font-family": '"Fira Sans", Arial, sans-serif'})
17-
assert-css: ("#traits + .item-table .item-right.docblock-short", {"font-family": '"Source Serif 4", "Noto Sans KR", serif'})
16+
assert-css: ("#traits + .item-table .item-left a", {"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'})
17+
assert-css: ("#traits + .item-table .item-right.docblock-short", {"font-family": '"Source Serif 4", NanumBarunGothic, serif'})
1818
// functions
19-
assert-css: ("#functions + .item-table .item-left a", {"font-family": '"Fira Sans", Arial, sans-serif'})
20-
assert-css: ("#functions + .item-table .item-right.docblock-short", {"font-family": '"Source Serif 4", "Noto Sans KR", serif'})
19+
assert-css: ("#functions + .item-table .item-left a", {"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'})
20+
assert-css: ("#functions + .item-table .item-right.docblock-short", {"font-family": '"Source Serif 4", NanumBarunGothic, serif'})
2121
// keywords
22-
assert-css: ("#keywords + .item-table .item-left a", {"font-family": '"Fira Sans", Arial, sans-serif'})
23-
assert-css: ("#keywords + .item-table .item-right.docblock-short", {"font-family": '"Source Serif 4", "Noto Sans KR", serif'})
22+
assert-css: ("#keywords + .item-table .item-left a", {"font-family": '"Fira Sans", Arial, NanumBarunGothic, sans-serif'})
23+
assert-css: ("#keywords + .item-table .item-right.docblock-short", {"font-family": '"Source Serif 4", NanumBarunGothic, serif'})

0 commit comments

Comments
 (0)
Please sign in to comment.