(
config: FontConfig,
options: ResolveFontFaceOptions = {},
)
| 20 | * Get the full list of font faces to generate for a given font configuration. |
| 21 | */ |
| 22 | export const resolveFontFaces = ( |
| 23 | config: FontConfig, |
| 24 | options: ResolveFontFaceOptions = {}, |
| 25 | ): FontFace[] => { |
| 26 | const { |
| 27 | id, |
| 28 | family, |
| 29 | subsets, |
| 30 | weights, |
| 31 | styles, |
| 32 | unicodeRange = {}, |
| 33 | variable, |
| 34 | formats = ['woff2'], |
| 35 | } = config; |
| 36 | |
| 37 | const faces: FontFace[] = []; |
| 38 | const isVariable = !!variable; |
| 39 | const familyId = id ?? normalizeKebabCase(family); |
| 40 | |
| 41 | if (isVariable) { |
| 42 | const axisKeys = getRequestedAxisKeys(variable, options.axisKeys); |
| 43 | |
| 44 | // Filter out ttf formats for variable fonts. |
| 45 | const variableFormats = formats.filter( |
| 46 | (format): format is WebFontFormat => format !== 'ttf', |
| 47 | ); |
| 48 | |
| 49 | // Generate one face per axis key, with the weight set to the closest available weight. |
| 50 | for (const axisKey of axisKeys) { |
| 51 | const axisConfig = pickAxisConfig(variable, axisKey); |
| 52 | const cssWeight = axisConfig.wght |
| 53 | ? formatAxisValue(axisConfig.wght) |
| 54 | : `${findClosestWeight(weights)}`; |
| 55 | |
| 56 | const stretch = getFaceStretch(axisKey, axisConfig); |
| 57 | |
| 58 | for (const subset of subsets) { |
| 59 | for (const style of styles) { |
| 60 | faces.push({ |
| 61 | subset, |
| 62 | weight: cssWeight, |
| 63 | style: getFaceStyle(axisKey, style, axisConfig), |
| 64 | isVariable: true, |
| 65 | unicodeRange: unicodeRange[subset] ?? '', |
| 66 | sources: variableFormats.map((format) => ({ |
| 67 | format, |
| 68 | filename: generateVariableFilename( |
| 69 | familyId, |
| 70 | subset, |
| 71 | axisKey, |
| 72 | style, |
| 73 | 0, |
| 74 | format, |
| 75 | ), |
| 76 | })), |
| 77 | axisKey, |
| 78 | stretch, |
| 79 | sliceIndex: 0, |
no test coverage detected