Skip to content

Keep the collection index in fontconfig fallbacks - #3

Merged
omartelo merged 1 commit into
mainfrom
fix/fontconfig-fallback-collection-index
Oct 19, 2026
Merged

omartelo merged 1 commit into
mainfrom
fix/fontconfig-fallback-collection-index

Conversation

@omartelo

Copy link
Copy Markdown
Contributor

What

With fontconfig, a character the family lacks is looked up with fc-list :charset=X and ranked by fc-match -s monospace. Both named fonts by file alone, so a fallback inside a collection (.ttc) was drawn from the file's first font. The result was bold text, a font from another family in the same file, or a box when that first font lacked the character.

fc-match, fc-list and the ranking now ask for %{index}:%{file}, and one parser (parseFontRefs) reads all three. This finishes the collection-index fix from #2, which covered only the family's four styles.

Tests

  • TestAFontconfigFallbackIsItsFontInACollection builds a .ttc with bold at index 0 and regular at index 1, then points fontconfig at that directory alone. fontconfig ranks the regular first, but the old code returned index 0 (bold). The test fails without the fix.
  • TestParseFcListFiles is replaced by TestParseFontRefs, because the format the parser reads changed (contract changed). The new test also covers a path containing : and a line without an index.
  • TestFallbackLookupsRankAgainstMonospaceOnce only follows the new return type; the assertion is unchanged.
  • gofmt, go vet ./... and go test ./... pass. The font tests also pass with -count=20 and -race. go vet passes on linux, windows and the darwin library packages.

fc-list and the ranking against monospace named a font by file alone, so
a fallback in a collection was drawn from the file's first font: bold,
another family, or a box when that font lacked the character.
@omartelo
omartelo merged commit 3540155 into main Oct 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant