Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wide characters in rustdoc: Fall-back to default CJK serif font on Windows is ugly #84035

Closed
ghost opened this issue Apr 9, 2021 · 11 comments
Closed
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@ghost
Copy link

ghost commented Apr 9, 2021

In Windows, browsers like Chrome and Firefox use legacy fonts as default serif font to render.
rustdoc uses its custom serif fonts, but these do not support CJK glyph, so the browser renders CJK characters as default one.

The problem is that the default serif font in Windows is so ugly and not clear.
The default sans-serif font looks just ok.

Take a look at this screenshot after matching the pixels on the monitor.

Why don't we just use sans-serif font for rustdoc? Or, we can use sans-serif fonts that look like serif font.

With Windows default serif font (batang.ttc):
Screenshot_2021-04-09 xingapi - Rust

With Noto Sans font (not serif):
Screenshot_2021-04-09 xingapi - Rust(2)

@ghost
Copy link
Author

ghost commented Apr 9, 2021

I'm using Windows 10 20H2 (Korean) and Firefox 87.0 with clean installation.

@ghost
Copy link
Author

ghost commented Apr 9, 2021

The label would be T-rustdoc, but I cannot add it.

@estebank estebank added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Apr 9, 2021
@ghost ghost changed the title CJK characters with Windows default serif fonts in doc are ugly and not clear Use serif font or serif like sans-serif font in rustdoc for multilingual legibility Apr 9, 2021
@workingjubilee
Copy link
Member

In Windows, browsers like Chrome and Firefox use legacy fonts as default serif font to render.
rustdoc uses its custom serif fonts, but these do not support CJK glyph, so the browser renders CJK characters as default one.

The problem is that the default serif font in Windows is so ugly and not clear.
The default sans-serif font looks just ok.

Take a look at this screenshot after matching the pixels on the monitor.

Why don't we just use sans-serif font for rustdoc? Or, we can use sans-serif fonts that look like serif font.

Huh. I have a recently installed Windows, and on both Firefox and Edge, I see:
image

This looks much more similar to your second image. I wonder if #83156 or #82315 affected this? Or maybe it is because I do not have batang.ttc installed? Windows says the only Korean font I have is "Malgun Gothic". Having a good CJK default is ideal, so I am very interested in finding out exactly what is going on here.

@workingjubilee workingjubilee added the A-rustdoc-ui Area: Rustdoc UI (generated HTML) label Apr 9, 2021
@ghost ghost changed the title Use serif font or serif like sans-serif font in rustdoc for multilingual legibility Use serif font or enable sans-serif font for CJK characters Apr 9, 2021
@ghost
Copy link
Author

ghost commented Apr 9, 2021

Legacy fonts like batang.tcc maybe bundled in Korean Windows.

@ghost
Copy link
Author

ghost commented Apr 9, 2021

"Malgun Gothic" (malgun.ttf) is default sans-serif font for Korean, so your browser maybe rendered that font instead of batang.tcc.

@workingjubilee
Copy link
Member

workingjubilee commented Apr 9, 2021

Oh I see, that makes sense. So because it can't find a Korean serif font, it might have used a Korean sans serif font.
Checking... yep, Firefox says that it is using Malgun Gothic instead on https://docs.rs/xingapi/0.2.6/xingapi/, and obviously "have no meh-looking Korean serif fonts already installed" is not really a reasonable expectation.
image

@ghost
Copy link
Author

ghost commented Apr 11, 2021

BTW, user-defined custom theme can solve this issue for crate-level. Pass --extend-css argument to rustdoc with custom css.

For example,

@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300&display=swap");

body {
  font-family: "Noto Sans KR", sans-serif;
  line-height: 1.5;
}

pre.rust.rust-example-rendered {
  line-height: 1.4;
}

@ghost ghost changed the title Use serif font or enable sans-serif font for CJK characters Wide characters in rustdoc: Fall-back to default CJK serif font on Windows is ugly Apr 11, 2021
@jsha
Copy link
Contributor

jsha commented Apr 13, 2021

Would it work to add Noto Sans CJK as a custom font-face, and then include it in the fallback list, like:

body {
	font: 16px/1.4 "Source Serif 4", "Noto Sans CJK", serif;
	...
}

@ghost
Copy link
Author

ghost commented Apr 13, 2021

@jsha Noto sans fonts that support CJK exist only for OpenType. Also its size is too big ;) (20MB)

So we should provide webfonts for each language instead of providing a CJK OpenType font.
For example, Noto Sans HK, JP, KR, SC, TC...

@workingjubilee
Copy link
Member

Noto Sans is quite adequate on a local installation, but that is indeed a fair amount of MB to transfer.

My understanding is that most docs in KR are going to be almost 100% using Hangul characters and very rarely if ever use characters from the rest of the CJK character set, is that correct? There would most certainly be a huge difference between that and a font that loads Japanese characters, which I would expect to cover 2000~3000 kanji, and the SC or TC fonts which would have to cover as many as 5000 hanzi.

@ghost
Copy link
Author

ghost commented Apr 14, 2021

@workingjubilee Yes, norwadays chinese characters are rarely used in korean. I had never seen chinese characters in software docs so they are not necessary for rustdoc.

JohnTitor added a commit to JohnTitor/rust that referenced this issue May 26, 2021
Avoid CJK legacy fonts in Windows

As metioned in rust-lang#84035, the default serif CJK font in Windows is meh-looking.
To avoid this, we should use sans-serif font or provide CJK glyph supported font in `rustdoc.css`.
@ghost ghost closed this as completed May 26, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-ui Area: Rustdoc UI (generated HTML) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants