Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 Improve the reliability of web font matching #122

Merged
merged 1 commit into from
May 17, 2024

Conversation

tmdvs
Copy link
Member

@tmdvs tmdvs commented May 17, 2024

With #118 we patched google web font downloading to fix a breaking change on Google's end.

However, the font matching wasn't the most reliable, as we attempted to match against file names rather than the family and style names from the font file itself. I've refactored this to use the more reliable latter. However, the downside is downloading each font file for the family. The previous implementation did this but as a single ZIP file. Given fonts are typically very small, and ZIPing them appears to make a negligible difference, I've gone for a slight bandwidth increase for better reliability/conversion results.

Note: We will still see some errors downloading fonts regarding text styles with additional variant info in subfamily strings (such as "Italic"). But I'm keen to avoid trimming/fiddling with the subfamily string too much.

@tmdvs tmdvs marked this pull request as ready for review May 17, 2024 08:41
Comment on lines +53 to +55
font_names["subfamily"].lower() == subfamily.lower()
or font_names["subfamily"].replace(" ", "").lower()
== subfamily.replace(" ", "").lower()
Copy link
Member Author

@tmdvs tmdvs May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fonts seem to use naming conventions like either "SemiBold" or "Semi Bold", this little tweak gives us a fuzzier match while still scoped to the font family.

@arseniocosta1 arseniocosta1 self-requested a review May 17, 2024 08:47
arseniocosta1
arseniocosta1 previously approved these changes May 17, 2024
@tmdvs tmdvs force-pushed the feat/improved-webfont-matching branch from 8d5d844 to 5fe4ef1 Compare May 17, 2024 09:04
@tmdvs tmdvs merged commit 6449c86 into main May 17, 2024
4 checks passed
@tmdvs tmdvs deleted the feat/improved-webfont-matching branch May 17, 2024 09:09
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.

None yet

2 participants