MCPcopy Create free account
hub / github.com/fontsource/fontsource / resolveFontFaces

Function resolveFontFaces

packages/core/src/utils/faces.ts:21–127  ·  view source on GitHub ↗
(
	config: FontConfig,
	axisKeys?: VariableAxisKey[],
)

Source from the content-addressed store, hash-verified

19 * Omit axisKeys for every published bundle; an empty list selects none.
20 */
21export const resolveFontFaces = (
22 config: FontConfig,
23 axisKeys?: VariableAxisKey[],
24): FontFace[] => {
25 const {
26 id,
27 family,
28 subsets,
29 weights,
30 styles,
31 unicodeRange = {},
32 subsetSlices = {},
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 requestedAxes = axisKeys ?? getVariableAxisKeys(variable);
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 requestedAxes) {
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 const characterSets = subsetSlices[subset]?.length
60 ? subsetSlices[subset]
61 : [{ id: 0, unicodeRange: unicodeRange[subset] ?? '' }];
62 for (const {
63 id: sliceIndex,
64 unicodeRange: faceRange,
65 } of characterSets) {
66 for (const style of styles) {
67 faces.push({
68 subset,
69 weight: cssWeight,
70 style: getFaceStyle(axisKey, style, axisConfig),
71 isVariable: true,
72 unicodeRange: faceRange,
73 sources: variableFormats.map((format) => ({
74 format,
75 filename: generateVariableFilename(
76 familyId,
77 subset,
78 axisKey,

Callers 6

utils.test.tsFile · 0.90
css.test.tsFile · 0.85
findCssAssetFunction · 0.85
resolveManifestFacesFunction · 0.85
buildFamilyUseCSSFunction · 0.85
getFontPreviewCSSFunction · 0.85

Calls 9

normalizeKebabCaseFunction · 0.90
getVariableAxisKeysFunction · 0.90
pickAxisConfigFunction · 0.90
formatAxisValueFunction · 0.90
findClosestWeightFunction · 0.90
getFaceStretchFunction · 0.90
getFaceStyleFunction · 0.90
generateVariableFilenameFunction · 0.90
generateStaticFilenameFunction · 0.90

Tested by

no test coverage detected