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

Avoid CJK legacy fonts in Windows #84048

Merged
merged 7 commits into from May 26, 2021
Merged

Avoid CJK legacy fonts in Windows #84048

merged 7 commits into from May 26, 2021

Conversation

ghost
Copy link

@ghost ghost commented Apr 10, 2021

As metioned in #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.

@rust-highfive
Copy link
Collaborator

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ollie27 (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 10, 2021
@ghost ghost changed the title Fall-back to sans-serif to avoid CJK legacy characters in Windows Fall-back to sans-serif to avoid CJK legacy fonts in Windows Apr 10, 2021
@the8472
Copy link
Member

the8472 commented Apr 10, 2021

This would also affect fallback for all non-CJK text and I assume serif was chosen intentionally.
Wouldn't it be better to define a custom @font-family with
src: local(sans-serif) that is scoped to CJK-specific unicode ranges or something like that?

@ghost
Copy link
Author

ghost commented Apr 10, 2021

@the8472 I tried to impl that like

@font-face {
    font-family: 'CJK';
    src: local(sans-serif);
    unicode-range: U+4E00-9FFF;
}

body {
  font: 16px/1.4 "Source Serif Pro", "CJK", serif;
}

but neither src: local(sans-serif) nor src: sans-serif works.

Unknown descriptor ‘src: local(sans-serif);’ in @font-face rule.  Skipped to next declaration.
Unknown descriptor ‘sans-serif’ in @font-face rule.  Skipped to next declaration.

@ghost
Copy link
Author

ghost commented Apr 10, 2021

Adding Windows CJK sans-serif fonts to font-family manually can also solve this problem.

@the8472
Copy link
Member

the8472 commented Apr 10, 2021

Ah too bad, you're right this can't work. The spec says

Just as an @font-face rule specifies the characteristics of a single font within a family, the unique name used with local() specifies a single font, not an entire font family.


Adding Windows CJK sans-serif fonts to font-family manually can also solve this problem.

Depending on which unicode ranges those fonts cover they might suffer from a similar problem as switching the fallback. But with specific fonts the unicode-range approach might work.

@ghost
Copy link
Author

ghost commented Apr 10, 2021

Does adding a Windows font to font-family cause a license problem? I'm not sure about this.

@workingjubilee
Copy link
Contributor

That sounds implausible, as long as we are not distributing it. The software is licensed to installers like Microsoft for distribution to installees, and the browser is the one "using" the font, not us. Rather, we are merely giving an ignorable direction to use something if it is convenient: the browser could ignore this direction due to license concerns if it saw fit.

But if it was a license violation, the existing use of Arial would be a license violation also, and I am not aware of anyone trying to sue what must be half of the entire English-speaking internet for mentioning Arial in their CSS "without a license".

@ghost
Copy link
Author

ghost commented Apr 19, 2021

Could someone add T-rustdoc label?

@GuillaumeGomez GuillaumeGomez added A-rustdoc-ui Area: rustdoc UI (generated HTML) T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Apr 19, 2021
@GuillaumeGomez
Copy link
Member

r? @GuillaumeGomez

@GuillaumeGomez
Copy link
Member

Can you add screenshots to show us the comparison (before/after) please?

@ghost
Copy link
Author

ghost commented May 14, 2021

Comparison between serif and sans-serif in Windows

before 100% (batang.ttc):

before

after 100% (malgun.ttf):

after

before 140% (batang.ttc):

before-140

after 140% (malgun.ttf):

after-140

before 150% (batang.ttc):

before-150

after 150% (malgun.ttf):

after-150

@GuillaumeGomez
Copy link
Member

I guess it's fine; Just to be sure: cc @jsha

@jsha
Copy link
Contributor

jsha commented May 14, 2021

I don't think this is the right solution. I think we should do the alternate thing @ghost proposes:

or provide CJK glyph supported font in rustdoc.css.

We discussed that a bit over in #84035 (comment). As @ghost pointed out, the overall Noto Sans CJK is only available in OpenType, and it's too big (20MB). So I think we should add a stanza particularly for Noto Sans KR, and ship the font. Separately, somebody should check if the default JP, SC, TC, fonts have a similar problem, and we can apply a similar fix if so.

My reasoning for preferring this approach: The fallback font is displayed while the custom font is loading. For English text, this change would mean showing a sans-serif font, and then replacing it with "Source Serif 4", which would result in more of a visual shift.

Shipping the nice font that we want to use for Korean is consistent with the approach we use for English text: we want to make sure the docs people have taken the time to write are displayed in a consistent, beautiful font. And also it's hard know what the default fallback fonts are on various different systems, which makes it hard to select a set of fallbacks that is good for all systems and all languages.

@workingjubilee
Copy link
Contributor

Can we fallback to system sans serif on KR specifically?

I believe that such would be the appropriate minimal PR.
I should note that based on my experience with JP<->EN localization, I saw serif and sans serif in roughly equal proportions, but it was not on browser tech so I can't say for sure if the web platform we use changes anything.

@ghost ghost changed the title Fall-back to sans-serif to avoid CJK legacy fonts in Windows Avoid CJK legacy fonts in Windows May 15, 2021
@jsha
Copy link
Contributor

jsha commented May 15, 2021

This latest seems like a good approach to me! One question: Why does Malgun Gothic need a unicode-range property while Yu Gothic does not?

@ghost
Copy link
Author

ghost commented May 15, 2021

This latest seems like a good approach to me! One question: Why does Malgun Gothic need a unicode-range property while Yu Gothic does not?

Even Chinese characters with the same code might have different shapes depending on the font for each language (CN, JP, ...). So I decided to apply it only to Korean.

Can we fallback to system sans serif on KR specifically?

I've tried to implementing that, but since unicode-range with local font is seems to be ignored it may affect other language fonts. so I'm gonna just add Noto Sans KR font.

@jsha
Copy link
Contributor

jsha commented May 15, 2021

Can you indicate the origin and license of the font file in the commit message? And if the license requires that a license notice be distributed alongside, commit that as well.

@ghost
Copy link
Author

ghost commented May 15, 2021

https://fonts.google.com/attribution

@jsha
Copy link
Contributor

jsha commented May 15, 2021

Thanks! There's also a slightly unintuitive thing: The various static files are bundled into the rustdoc binary at compile time (src/librustdoc/html/static_files.rs) and written to the target directory at run time (src/librustdoc/html/render/write_shared.rs). We need to also add the license file in those places.

@jsha
Copy link
Contributor

jsha commented May 15, 2021

This looks good to me. I'll take some time for others to weigh in before giving an r+, and would like to do some testing later this weekend. Thanks for your work on it.

@workingjubilee
Copy link
Contributor

There are at least two major ways to render Chinese characters for Chinese alone (often given as zh-CN and zh-TW).

I've tried to implementing that, but since unicode-range with local font is seems to be ignored it may affect other language fonts. so I'm gonna just add Noto Sans KR font.

Alas. That seems weird, but this is probably for the best then.

@rust-log-analyzer

This comment has been minimized.

@ghost
Copy link
Author

ghost commented May 20, 2021

Could someone approve the workflow?

@GuillaumeGomez
Copy link
Member

I'll let @jsha handle it considering he's the expert here.

r? @jsha

@rust-highfive rust-highfive assigned jsha and unassigned GuillaumeGomez May 20, 2021
@jsha
Copy link
Contributor

jsha commented May 26, 2021

Tested this and it looks good to me! I confirmed Noto Sans KR is correctly applied on pages with Korean characters, and is not loaded on pages that don't have Korean characters. Thanks so much for implementing, @ghost

@bors r+

@bors
Copy link
Contributor

bors commented May 26, 2021

📌 Commit 8a2d663 has been approved by jsha

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 26, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request May 26, 2021
Rollup of 12 pull requests

Successful merges:

 - rust-lang#84048 (Avoid CJK legacy fonts in Windows)
 - rust-lang#85529 (doc: clarify Mutex::try_lock, etc. errors)
 - rust-lang#85590 (Fix bootstrap using host exe suffix for cargo)
 - rust-lang#85610 (Fix pointer provenance in <[T]>::copy_within)
 - rust-lang#85623 (Remove stray .stderr files)
 - rust-lang#85645 (Demote `ControlFlow::{from|into}_try` to `pub(crate)`)
 - rust-lang#85647 (Revert "Move llvm submodule updates to rustbuild")
 - rust-lang#85666 (Document shared_from_cow functions)
 - rust-lang#85668 (Fix tasklist example in rustdoc book.)
 - rust-lang#85672 (Move stability attribute for items under the `ip` feature)
 - rust-lang#85699 (Update books)
 - rust-lang#85701 (Update cargo)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0264f4f into rust-lang:master May 26, 2021
@rustbot rustbot added this to the 1.54.0 milestone May 26, 2021
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) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants