Many True/OpenType fonts, like Noto Sans CJK ("notocjk") in this example, uses a pattern in "name" table where:
* name.fontFamily gives the full name (with style) of the font and Subfamily is always Regular
* name.preferredFamily gives the actual family name and Subfamily is the actual weight
Fontconfig doesn't seem to be capable of handling such a case. Specifically, given a config file which <prefer>s notocjk:
<family>Noto Sans CJK SC</family>
<family>Noto Sans CJK TC</family>
Fontconfig will produce a match like:
$ fc-match --verbose
Pattern has 38 elts (size 48)
family: "Noto Sans CJK SC"(s) "Noto Sans CJK SC DemiLight"(s)
familylang: "en"(s) "en"(s)
style: "DemiLight"(w) "Regular"(w)
stylelang: "en"(w) "en"(w)
fullname: "Noto Sans CJK SC DemiLight"(w)
Now here is the problem. By preferring the preferredFamily "Noto Sans CJK SC", fontconfig ended up also preferring "Noto Sans CJK SC DemiLight", and matched "Noto Sans CJK SC DemiLight" "Regular" for the implicit "Regular".
See https://bugs.launchpad.net/ubuntu/+source/language-selector/+bug/1468027 for a context of this problem.
Looks like it's something around src/fcfreetype.c:1408. Working on some duct tape.
I don't see why that happens. Ie, why is weight ignored? You are using master, right?
It's not ignored, it just mixed up font(sub)family and preferred(sub)family, from an outsider's perspective.
Just an initial wild guess without looking at the source:
When looking for "Noto Sans CJK SC" "Regular", fc looked at the name first and found "Noto Sans CJK SC" "Demilight", and then found a "Regular" on "Demilight", so it considered it a good match.
I am actually using 2.11.1, but well... I was reading the code for master on cgit.
Ubuntu 16.04 should be using 2.11.0. Oh let me change the version tag.
Noto Sans CJK Regular actually looks different from the rest -- its preferredSubfamily is omitted from "name".
That's ancient. That version did not support DemiLight. That's your issue. Update to something newer and it will all work.
*** This bug has been marked as a duplicate of bug 81453 ***
Still FYI, Noto CJK have made a different OS/2 weight mapping choices for Thin (Extralight?) that gives 250. That seems to be intended to workaround a Windows GDI 'bug' (or feature) that it generates faux bold for everything with OS/2 weight < 250.
This might need to be taken into account when dealing with OpenType/TrueType weights.
Regarding the "ancient" version... https://www.freedesktop.org/wiki/Software/fontconfig/ still points to 2.11.1. https://www.freedesktop.org/software/fontconfig/release/ gives 2.11.94 though. Perhaps someone forgot to update that page?
Oh I see. https://www.freedesktop.org/wiki/Software/fontconfig/Devel/.
Yeah, not the best updated project website...