Bug 94505 - Writing name.preferredFamilyname of a font in <prefer> tag mixes up with name.font{,sub}Family
Summary: Writing name.preferredFamilyname of a font in <prefer> tag mixes up with name...
Status: RESOLVED DUPLICATE of bug 81453
Alias: None
Product: fontconfig
Classification: Unclassified
Component: library (show other bugs)
Version: 2.11
Hardware: Other All
: medium normal
Assignee: fontconfig-bugs
QA Contact: Behdad Esfahbod
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-11 23:17 UTC by Mingye Wang (Arthur2e5)
Modified: 2016-03-12 09:25 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Mingye Wang (Arthur2e5) 2016-03-11 23:17:36 UTC
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:

        <alias>
                <family>sans-serif</family>
                <prefer>
                        <family>Noto Sans CJK SC</family>
                        <family>Noto Sans CJK TC</family>
                </prefer>
        </alias>

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)
        fullnamelang: "en"(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.
Comment 1 Mingye Wang (Arthur2e5) 2016-03-12 03:24:45 UTC
Looks like it's something around src/fcfreetype.c:1408. Working on some duct tape.
Comment 2 Behdad Esfahbod 2016-03-12 03:56:51 UTC
I don't see why that happens.  Ie, why is weight ignored?  You are using master, right?
Comment 3 Mingye Wang (Arthur2e5) 2016-03-12 04:28:09 UTC
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.
Comment 4 Mingye Wang (Arthur2e5) 2016-03-12 04:31:11 UTC
Noto Sans CJK Regular actually looks different from the rest -- its preferredSubfamily is omitted from "name".
Comment 5 Behdad Esfahbod 2016-03-12 04:44:48 UTC
> 2.11.1

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 ***
Comment 6 Mingye Wang (Arthur2e5) 2016-03-12 05:00:45 UTC
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?
Comment 7 Mingye Wang (Arthur2e5) 2016-03-12 05:37:14 UTC
Oh I see. https://www.freedesktop.org/wiki/Software/fontconfig/Devel/.
Comment 8 Behdad Esfahbod 2016-03-12 09:25:53 UTC
Yeah, not the best updated project website...


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.