linebender / parley

Rich text layout library
Apache License 2.0
228 stars 28 forks source link

Skip adding font family as fallback if it has zero coverage for given script #182

Closed richardhozak closed 2 days ago

richardhozak commented 2 days ago

Fontconfig can be and is so in some distros, configured wrong. It can report fonts as a fallback for given language when in reality the font family has zero coverage for given language.

This change does preliminary coverage check for fonts loaded from fontconfig and skips font families that have zero coverage for given language it reports.

This PR also contains small fix for calculating coverage, where it could never match font with full coverage for multi-byte chars as computing coverage returns how many characters it matches but we compared it to number of bytes in a string.

Fixes #174

I've tested this on fresh install of PopOS where the font fallback for Arabic script failed and works with this change. I've also tested this on fresh install of Ubuntu 24.04 where fontconfig is configured correctly, fallback worked correctly without this change and still works correctly with this change.