This document explains how to add and use different font providers in the Wordmark application.
The application now supports multiple font providers:
- Google Fonts (default)
- Adobe Fonts (Typekit)
- Font Squirrel (self-hosted web fonts)
- Custom Fonts (locally hosted fonts)
- Font Source (fonts from font-source-fonts.json)
Google Fonts are already integrated via the data/fonts.json file. To add more Google Fonts, you can update this file with additional entries following the same format.
To add Adobe Fonts:
- Create a Typekit project at Adobe Fonts
- Get your project ID
- Update the
TYPEKIT_IDconstant inlib/fontProviders/adobe.ts - Add your font entries to the
adobeFontListarray in the same file
Example entry:
{
family: 'adobe-caslon-pro',
variants: ['regular', 'italic', '700'],
subsets: ['latin'],
version: '1.0',
lastModified: '2023-01-01',
files: {
regular: '' // Adobe fonts don't need direct file URLs
},
category: 'serif',
kind: 'webfont',
menu: '',
provider: 'adobe',
kitId: TYPEKIT_ID
}The Font Squirrel integration now uses the official Font Squirrel API to automatically load all available fonts. The following API endpoints are used:
- Classifications:
https://www.fontsquirrel.com/api/classifications- Get categories with font counts - Font Families:
https://www.fontsquirrel.com/api/fontlist/all- Get all font families - Family Info:
https://www.fontsquirrel.com/api/familyinfo/{family_urlname}- Get details about specific fonts - Font Kit:
https://www.fontsquirrel.com/fontfacekit/{family_urlname}- Download the font-face kit
The Font Squirrel fonts are loaded automatically when the application starts. The provider fetches all available fonts from the Font Squirrel API and makes them available in the font selector.
While the API integration should provide all fonts automatically, you can still manually add specific Font Squirrel fonts if needed:
// In lib/fontProviders/fontSquirrel.ts
fontSquirrelList.push({
family: "your-font-name",
variants: ["regular", "italic", "bold", "bold-italic"],
subsets: ["latin"],
version: "1.0",
lastModified: "2023-11-01",
files: {
regular: "https://www.fontsquirrel.com/fontfacekit/your-font-name",
},
category: "sans-serif",
kind: "webfont",
menu: "",
provider: "fontSquirrel",
kitUrl: "https://www.fontsquirrel.com/fontfacekit/your-font-name",
});If you prefer to host the fonts yourself:
- Download fonts from Font Squirrel
- Generate web fonts using their Webfont Generator
- Place the web font files in your project at
/public/fonts/[font-name]/ - Create a CSS file for the font (or use the one generated)
- Add font entries to the
fontSquirrelListarray inlib/fontProviders/fontSquirrel.ts
Example entry for self-hosted fonts:
{
family: 'metropolis',
variants: ['regular', 'italic', 'bold', 'bold-italic'],
subsets: ['latin'],
version: '1.0',
lastModified: '2023-01-01',
files: {
regular: '/fonts/metropolis/metropolis-regular-webfont.woff2',
italic: '/fonts/metropolis/metropolis-italic-webfont.woff2',
bold: '/fonts/metropolis/metropolis-bold-webfont.woff2',
boldItalic: '/fonts/metropolis/metropolis-bold-italic-webfont.woff2'
},
category: 'sans-serif',
kind: 'webfont',
menu: '',
provider: 'fontSquirrel',
cssUrl: '/fonts/metropolis/stylesheet.css',
directLoad: false
}To add custom fonts:
- Add your font files (WOFF2 format recommended) to
/public/fonts/custom/ - Add font entries to the
customFontListarray inlib/fontProviders/custom.ts
Example entry:
{
family: 'MyCustomFont',
variants: ['regular', 'bold'],
subsets: ['latin'],
version: '1.0',
lastModified: '2023-01-01',
files: {
regular: '/fonts/custom/my-custom-font.woff2',
bold: '/fonts/custom/my-custom-font-bold.woff2'
},
category: 'sans-serif',
kind: 'webfont',
menu: '',
provider: 'custom',
fontFace: [
{
family: 'MyCustomFont',
style: 'normal',
weight: '400',
src: '/fonts/custom/my-custom-font.woff2'
},
{
family: 'MyCustomFont',
style: 'normal',
weight: '700',
src: '/fonts/custom/my-custom-font-bold.woff2'
}
]
}The Font Source provider uses fonts from the data/font-source-fonts.json file. This provider automatically processes the JSON data and makes the fonts available in the application.
If you want to add more fonts to the Font Source provider:
- Add new entries to the
data/font-source-fonts.jsonfile following the same structure:
{
"id": "font-id",
"family": "Font Family Name",
"subsets": ["latin", "latin-ext"],
"weights": [400, 700],
"styles": ["normal", "italic"],
"defSubset": "latin",
"variable": false,
"lastModified": "2024-01-01",
"category": "sans-serif",
"license": "OFL-1.1",
"type": "google"
}- By default, only the first 200 fonts are loaded for performance reasons. If you want to change this limit, modify the
getFontSourceSubsetfunction call inlib/fontProviders/index.ts:
const fontSourceListSubset = getFontSourceSubset(0, 200); // Change 200 to your desired limitCurrently, the Font Source provider fully supports Google fonts. Support for other font types can be added by expanding the generateFontUrl function in lib/fontProviders/fontSource.ts.
The font provider system consists of several components:
- Provider-specific modules in
lib/fontProviders/for each provider - Combined interface in
lib/fontProviders/index.tsthat brings all providers together - FontProviderSelector component that allows switching between providers
- Updated FontSelector component that works with all providers
To add a new font provider:
- Create a new file in
lib/fontProviders/for the provider - Implement the provider interface with proper loading mechanism
- Update the
ExtendedFontIteminterface inlib/fontProviders/index.ts - Add the new provider to the
allFontListin the index file - Update the provider names in the
FontProviderSelectorcomponent