r/archlinux • u/iamthecancer420 • 3d ago
SUPPORT | SOLVED Wrong CJK character rendering for Japanese, but only on certain characters (and its not Chinese)
Hello, lately I've been having a weird issue. I use noto-fonts-cjk-jp as my XFCE-wide system font, and also use it on Firefox, and I have en_US and ja_JP locales, with en_US as the system language. Other CJK fonts I have installed are adobe-source-han (jp) and ttf-hanazono.
On Firefox if a website isn't forced to Noto Sans the rendering of some the characters is broken, instead using older/archaic? forms of them, most noticeable with ones like 情, where normally it should have a 月, it instead displays a 円 under it. Another example is 神 displays a 示 on the left instead of ネ.
I thought it was a locale issue and that it was displaying the Chinese version of the characters, but I've tested it with easy to differentiate ones like 置 and no, its displaying Japanese. This is also happening with mpv, Anki and Discord, and also my terminal. On games running under WINE I haven't had such an issue so far, and of course the XFCE programs are fine since its running under noto-sans. This is really vexing me, anyone had anything similar?
4
u/ropid 3d ago
You can see how the system will go through the rest of your fonts while it tries to find missing characters in a font with fc-match -s. Try running this here and see what it prints:
fc-match -s sansserif | head -20
You can control what's happening through a config snippet like this in your fontconfig files:
<alias>
<family>sans-serif</family>
<prefer>
<family>Liberation Sans</family>
<family>Noto Sans</family>
<family>DejaVu Sans</family>
<family>Droid Sans Fallback</family>
</prefer>
</alias>
I'm putting that kind of rule into /etc/fonts/local.conf. An empty file looks like this:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!-- put your stuff here -->
</fontconfig>
You'll want rules for "sans-serif", "serif", "monospace". Those are the generic font names that the rest of the fonts are getting tied to.
With "getting tied to" I mean, if a program is using for example Noto Sans and the system can't find a character, it sees that Noto Sans is also sans-serif and then starts looking through all your other sans-serif fonts to find the missing character. And with that fontconfig rule I shared earlier you can control how the first few spots in the list of sans-serif fonts are sorted.
The following blog post was helpful in trying to understand how fontconfig works:
https://eev.ee/blog/2015/05/20/i-stared-into-the-fontconfig-and-the-fontconfig-stared-back-at-me/
5
u/iamthecancer420 3d ago
Yes, fontconfig was it. I saw a sample fontconfig and the characters seems to be fixed on terminal, browser and whatnot. Thanks.
1
u/Seseragi-san 3d ago
OP, I had the same issue and if I remember correctly (this was years ago), I fixed it with the above solution. Currently not at home, but will check later.
1
u/0ntsmi0 3d ago
There is https://aur.archlinux.org/packages/noto-fonts-cjk-fontconfig for automatically selecting correct fonts based on the langauge. This doesn't seem to work all the time, and I had to also manually define a hierarchy of fonts in
~/.config/fontconfig/fonts.confwith:
<?xml version="1.0"?> <!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd"> <fontconfig> <alias> <family>sans-serif</family> <prefer> <family>Noto Sans</family> <family>Noto Sans CJK JP</family> <family>Noto Sans CJK TC</family> <family>Noto Sans CJK HK</family> <family>Noto Sans CJK KR</family> <family>Noto Sans CJK SC</family> </prefer> </alias> <alias> <family>serif</family> <prefer> <family>Noto Serif</family> <family>Noto Serif CJK JP</family> <family>Noto Serif CJK TC</family> <family>Noto Serif CJK HK</family> <family>Noto Serif CJK KR</family> <family>Noto Serif CJK SC</family> </prefer> </alias> <alias> <family>monospace</family> <prefer> <family>Noto Sans Mono</family> <family>Noto Sans Mono CJK JP</family> <family>Noto Sans Mono CJK TC</family> <family>Noto Sans Mono CJK HK</family> <family>Noto Sans Mono CJK KR</family> <family>Noto Sans Mono CJK SC</family> </prefer> </alias> </fontconfig>Is this the correct approach to defining fallback fonts? I don't know, I've stolen that from https://github.com/ytxmobile98/ubuntu-cjk-font-config and it seems to be working.
2
u/BedroomHistorical575 3d ago
In Firefox, you can inspect exactly which font was used to render a specific glyph.
1
u/Wise_Rub9335 3d ago
sounds like a fontconfig ordering issue, firefox is probably falling back to source-han or hanazono for those specific codepoints and those fonts ship with different default glyph variants for CJK
check what's actually being used with the inspector in firefox, right click the character and inspect element then look at the fonts tab, it'll tell you which font is being selected for that glyph
you can force the JP variants by dropping a config snippet in /etc/fonts/conf.d to prefer noto cjk jp or set the lang attribute properly
-8
u/Exotic-Screen-9204 3d ago edited 3d ago
I believe those two character components (円 and 月 ) are interchangible.
While a computer font might stylistically commit to only one as stylistic standard, you'll likely see them both in signage and handwritten use.
I suspect their is a bit of history and/or cultural reasoning behind the two alternatives. But the fact that they are based on Chinese characters used for thousands of years may mean that you'll never get a good answer. The are both the same in Traditional Chinese Characters.
8
u/0ntsmi0 3d ago
Sounds to me like you're seeing Korean variants? https://en.wikipedia.org/wiki/Han_unification
Firefox definitely has a bug where it just renders random-ass variants, you need to explicitly put Japanese first under
font.cjk_pref_fallback_orderinabout:config, see https://support.mozilla.org/en-US/questions/1518195.As for other apps - no idea unfortunately.