Skip to content

Fix duplicate faces when loading fonts from a directory - #754

Open
ChrisJr404 wants to merge 1 commit into
linebender:mainfrom
ChrisJr404:fontique-dedup-load-fonts-from-paths
Open

Fix duplicate faces when loading fonts from a directory#754
ChrisJr404 wants to merge 1 commit into
linebender:mainfrom
ChrisJr404:fontique-dedup-load-fonts-from-paths

Conversation

@ChrisJr404

Copy link
Copy Markdown

Fixes #683.

load_fonts_from_paths kept a single families map for the whole scan and never cleared it, then re-merged the entire map into self.families on every callback, so each face got re-added on later callbacks. On top of that it re-scanned the whole file with scan_memory even though scan_paths had already parsed the font, which multiplied the duplicates further for collection (.ttc) files.

This registers the font that scan_paths already handed us directly and gives each callback its own accumulator, so every face lands exactly once. register_fonts still scans the memory blob it is given, but now goes through the same per-font registration path.

Added a regression test that loads the system font directory and checks that no family ends up with a duplicate face (same source and index). It is gated the same way as the existing make_shared_matches_local test and returns early when no font directory is present.

`load_fonts_from_paths` shared a single accumulator across every scanned
font and never cleared it, and each callback re-scanned the whole file,
so every face was re-registered on later callbacks (and multiplied further
for collection files). Register the font that `scan_paths` already parsed
directly instead of re-scanning, giving each callback its own accumulator.
@ChrisJr404
ChrisJr404 force-pushed the fontique-dedup-load-fonts-from-paths branch from 6a92cfa to 90fd270 Compare August 26, 2026 03:10
@DJMcNab

DJMcNab commented Aug 26, 2026

Copy link
Copy Markdown
Member

Welcome! Unfortunately this code is a little bit outside of my wheelhouse to review quickly.

However, I'd just like to understand your workflow here - we have a recently introduced PR template, which you haven't followed. What tool did you use the open this PR? It might be worth reporting to them that they didn't surface the PR template properly

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.

Fontique: duplication and redundant re-scanning in load_fonts_from_paths

2 participants