Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Before this change, a font is considered monospace if
fontdb
flags itas such.
fontdb
checks thepost
table for this property.But some fonts don't set that property there.
Most notably, "Noto Sans Mono" is among these fonts. Monospace as
a property is said to be communicated in other places like
OS/2
'spanose
, but that's not set in the Noto font either.Loosely based on a
fontconfig
function calledFcFreeTypeSpacing()
, this commit adds an additional check againstfonts that are not set as
monospaced
byfontdb
. The horizontaladvances of all glyphs of a cmap unicode table are checked to see
if they are monospace. Proportionality with double-width and
treble-width advances is taken into consideration. Treble width
advances exist in the aforementioned Noto font.
The checks should be efficient, but the overhead is not in the noise.
So these extra checks are only run if the "monospace_fallback" crate
feature is enabled.
This change also requires library users to check monospacity with
FontSystem::is_monospace()
instead ofFaceInfo::monospaced
fromfontdb
to be in-sync with cosmic-text's view. This requirement wasprobably coming in the future anyway for when cosmic-text adds support
for variable fonts.
This depends on harfbuzz/ttf-parser#174 for making the check more efficient.
How many fonts have this issue?
Running this on my system returns 220 such fonts:
Sorted output:
All of these font files come from Archlinux packages. Most matches belong to Monaspace. But others include "Noto Sans Mono", "Noto Sans SignWriting", "ProggyCleanTTSZ", and Monoisome (a part of Monoid).
Performance Considerations
Timings listed in seconds are (pre_cache, caching, total). Caching timings are noisy a little bit.
No mono_proportional check
With mono_proportional check
So, with 220 extra fonts detected, only ~0.04s is spent on mono_proportional checking, and ~0.11s is spent on caching the extra fonts.