rstudio / rstudio

RStudio is an integrated development environment (IDE) for R
https://posit.co/products/open-source/rstudio/
Other
4.65k stars 1.09k forks source link

Fallback font in RStudio code editor #9512

Open drizmiz opened 3 years ago

drizmiz commented 3 years ago

RStudio (Version 1.4.1717) on Ubuntu 20.04 uses an undesirable fallback font for Chinese that looks like STSong. I personally would consider it a bug, because this font is not what people usually expect on Ubuntu (and ugly). In editors like PyCharm and VSCode, this setting can be customized, and the default fallback font looks more natural.

What's worse, RStudio only supports mono fonts, and not all of them - for example, Noto Mono gets supported, but Noto Sans Mono CJK SC (the default font for Chinese on Ubuntu) just won't appear in the font list of RStudio. It means that even if I give up my favorite Fira Mono, I cannot select a font decent enough for Chinese characters displaying.

Roughly speaking, I hope RStudio can support fallback font setting, or at least change the default fallback font for Chinese on Ubuntu to Noto Sans Mono CJK SC or just something that looks good enough, if possible. Thanks.

chuxinyuan commented 1 year ago

Ubuntu 20.04 system, updated R 4.3.0 today, RStudio told me that the current version of RStudio does not support R's graphics engine version 16 while drawing in Rstudio-2022.0.0.1-554. So I updated RStudio to the latest 2023.03.0 Build 386. Except for Chinese characters, there was no difference in other aspects of use experience. However, no matter in the console,.r file or R Markdown editor, all Chinese fonts changed into sans-serif fonts, which was really ugly. How to change the Chinese font to Noto Serif CJK SC? Thanks!

chuxinyuan commented 1 year ago

@ronblum @mikebessuille Has the problem been noticed? It doesn't seem to be on any of the to-do lists. It's disappointing how few questions seem to get resolved here.

mikebessuille commented 1 year ago

@chuxinyuan Sorry for the silence. Sorry for the inconvenience this is causing. This is not on our near-term plans to fix, but we do have some longer-term plans for next year that will probably address this problem.

chuxinyuan commented 1 year ago

@mikebessuille In fact, it affects the user experience very much. I hope to make this problem a priority. I believe the font problem should be easily solved under Ubuntu because we have Noto Serief CJK SC

kevinushey commented 1 year ago

Part of the problem here (as I understand it) is that FontConfig does not actually think those fonts are monospace, and we use FontConfig on Linux to discover installed fonts. For example:

$ fc-list | grep "Noto Sans Mono CJK"
/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc: Noto Sans Mono CJK TC:style=Bold
/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc: Noto Sans Mono CJK SC:style=Bold
/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc: Noto Sans Mono CJK KR:style=Bold
/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc: Noto Sans Mono CJK HK:style=Bold
/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc: Noto Sans Mono CJK JP:style=Bold
/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc: Noto Sans Mono CJK SC:style=Regular
/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc: Noto Sans Mono CJK TC:style=Regular
/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc: Noto Sans Mono CJK HK:style=Regular
/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc: Noto Sans Mono CJK KR:style=Regular
/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc: Noto Sans Mono CJK JP:style=Regular

And yet:

$ fc-list :mono | grep "Noto Sans Mono"

For comparison:

$ fc-scan /usr/share/fonts/truetype/noto/NotoMono-Regular.ttf --brief
Pattern has 22 elts (size 32)
        family: "Noto Mono"(s)
        familylang: "en"(s)
        style: "Regular"(s)
        stylelang: "en"(s)
        fullname: "Noto Mono"(s)
        fullnamelang: "en"(s)
        slant: 0(i)(s)
        weight: 80(f)(s)
        width: 100(f)(s)
        spacing: 100(i)(s)
        foundry: "GOOG"(s)
        file: "/usr/share/fonts/truetype/noto/NotoMono-Regular.ttf"(s)
        index: 0(i)(s)
        outline: True(s)
        scalable: True(s)
        fontversion: 65536(i)(s)
        fontformat: "TrueType"(s)
        decorative: False(s)
        postscriptname: "NotoMono"(s)
        color: False(s)
        symbol: False(s)
        variable: False(s)

Compared with e.g.

Pattern has 22 elts (size 32)
        family: "Noto Sans Mono CJK HK"(s)
        familylang: "en"(s)
        style: "Regular"(s)
        stylelang: "en"(s)
        fullname: "Noto Sans Mono CJK HK"(s)
        fullnamelang: "en"(s)
        slant: 0(i)(s)
        weight: 80(f)(s)
        width: 100(f)(s)
        foundry: "GOOG"(s)
        file: "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc"(s)
        index: 9(i)(s)
        outline: True(s)
        scalable: True(s)
        fontversion: 131334(i)(s)
        capability: "otlayout:DFLT otlayout:cyrl otlayout:grek otlayout:hang otlayout:hani otlayout:kana otlayout:latn"(s)
        fontformat: "CFF"(s)
        decorative: False(s)
        postscriptname: "NotoSansMonoCJKhk-Regular"(s)
        color: False(s)
        symbol: False(s)
        variable: False(s)

I think the fact that the "spacing: 100(i)(s)" attribute is missing on these fonts is causing us to miss the fact that these fonts are monospace. As a workaround, we could probably just assume that any font with "Mono" in the name is a monospace font.

kevinushey commented 1 year ago

https://github.com/rstudio/rstudio/blob/e00def7f2c943984a06bb0eb92f5b00b11a274ef/src/node/desktop/src/main/gwt-callback.ts#L113-L115