Repository navigation
Resolve font families without fontconfig - #2
Merged
Merged
Conversation
On Windows, macOS and a Linux without fc-match, New, NewSplit and NewDiffView read the fonts in the platform's font directories, match the family by the name each font carries and fall back to them for characters the family lacks. Add ErrFontNotFound and deprecate ErrNoFontconfig, which New no longer returns.
fc-match names a font in a collection by file and index, and the index was dropped, so every style of a family in a .ttc came from the file's first font.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
New,NewSplitandNewDiffViewresolved a family name only through fontconfig'sfc-match, so on Windows and macOS (and a Linux without fontconfig) they failed withErrNoFontconfig.%WINDIR%\Fonts,%LOCALAPPDATA%\Microsoft\Windows\Fonts/System/Library/Fonts,/Library/Fonts,~/Library/Fontsfc-matchis missing"monospace"maps to a per-platform list (Cascadia Mono, Consolas, Courier New on Windows; Menlo, Monaco, Courier New on macOS). The OS seams are build-tagged files (internal/glyphs/fontdirs_*.go). Pure Go, no new dependency..ttc) are now addressed by file and index, so Menlo's bold and italic work on macOS.ErrFontNotFound;ErrNoFontconfigis deprecated, sinceNewno longer returns it.fc-match's collection index was dropped, so every style of a family in a.ttccame from the file's first font. NowfcMatchasks for%{index}:%{file}.Cost: the scan keeps only names (~180 KB), about 0.1 s for 1,400 fonts on the first
New. A character no font covers costs about 0.1 s once per process. Limits are written down indocs/ceilings.md.Tests
ErrFontNotFound. The first test fails onmain..ttcand checks that bold resolves to index 1; it fails without the fix.gofmt,go vet ./...andgo test ./...pass. The font tests also pass with-raceand-count=20.go build ./...andgo vet ./.... darwin passes for every library package;cmd/godemirror-demoandinternal/shotneed cgo for Gio and fail just as they do onmain.Not run on real Windows or macOS hardware yet.
Not in this PR
The fontconfig fallback lookup (
fc-list/fc-match -s) still uses only the file path. A covering font that is not the first in its.ttcis skipped and the character is drawn as a box.