FcPatternGetWithBinding() doesn't work as expected?
FcPatternGetWithBinding() was added back in 2017. The original intention of this API was to allow Skia and WebKit to replace a bunch of seriously gnarly code designed to guess whether a strong or weak alias was followed during font matching. According to the Fontconfig documentation, the difference between strong and weak is that strong matches family before language while weak matches after language:
The canonical font pattern is finally matched against all available fonts. The distance from the pattern to the font is measured for each of several properties: foundry, charset, family, lang, spacing, pixelsize, style, slant, weight, antialias, rasterizer and outline. This list is in priority order -- results of comparing earlier elements of this list weigh more heavily than later elements.
There is one special case to this rule; family names are split into two bindings; strong and weak. Strong family names are given greater precedence in the match than lang elements while weak family names are given lower precedence than lang elements. This permits the document language to drive font selection when any document specified font is unavailable.
So Skia and WebKit are probably abusing this distinction, but in practice this strategy has worked pretty well to allow us to do some font matching while still mostly respecting the ordering of fonts in a font-family
directive. More rationale for this here.
Anyway, FcPatternGetWithBinding() was added specifically for use by WebKit and Skia, but neither of us actually ever got around to ever trying to use it, until yesterday. Oops. I tried it and found that every match is reported as using a strong binding, which isn't useful. I asked Akira about this:
Hmm, apparently there are some tasks we need to fix in fontconfig. There was some logic that needed to be changed when it was added. so I'm sorry but it won't return FcValueBindingStrong for an exact-matched family name and FcValueBindingWeak for others so far.
Also, there is no strict meaning for binding in the returned FcPattern more than the precedence on matching. If we are going to change fontconfig like what WebKit does, we may need to change it much more. Please open an issue for that. Let's keep track of the progress there.
I'm not sure whether this actually makes sense or not, though, since what WebKit and Skia are doing is maybe too different from how the bindings work? Maybe a different API would make more sense instead? Even if the binding was not always reported as strong, it isn't clear what WebKit or Skia should do if the function were to return Same, for example. Our logic assumes the only two options are Strong and Weak.
I ran a Debian codesearch, which indicates that no open source projects are currently using FcPatternGetWithBinding().