diff --git a/lib/subsetFonts.js b/lib/subsetFonts.js index de69d9a3..c3e1e1fe 100644 --- a/lib/subsetFonts.js +++ b/lib/subsetFonts.js @@ -795,6 +795,19 @@ function warnAboutUnusedVariationAxes( const seenAxisValuesByFontUrlAndAxisName = new Map(); const outOfBoundsAxesByFontUrl = new Map(); + function noteUsedValue(fontUrl, axisName, axisValue) { + let seenAxes = seenAxisValuesByFontUrlAndAxisName.get(fontUrl); + if (!seenAxes) { + seenAxes = new Map(); + seenAxisValuesByFontUrlAndAxisName.set(fontUrl, seenAxes); + } + if (seenAxes.has(axisName)) { + seenAxes.get(axisName).push(axisValue); + } else { + seenAxes.set(axisName, [axisValue]); + } + } + for (const { fontUsages } of htmlOrSvgAssetTextsWithProps) { for (const { fontUrl, @@ -805,83 +818,49 @@ function warnAboutUnusedVariationAxes( hasOutOfBoundsAnimationTimingFunction, props, } of fontUsages) { - let seenAxes = seenAxisValuesByFontUrlAndAxisName.get(fontUrl); - if (!seenAxes) { - seenAxes = new Map(); - seenAxisValuesByFontUrlAndAxisName.set(fontUrl, seenAxes); - } - const seenItalValues = []; if (fontStyles.has('italic')) { - seenItalValues.push(1); + noteUsedValue(fontUrl, 'ital', 1); } // If any font-style value except italic is seen (including normal or oblique) // we're also utilizing value 0: if (fontStyles.size > fontStyles.has('italic') ? 1 : 0) { - seenItalValues.push(0); + noteUsedValue(fontUrl, 'ital', 0); } - if (seenItalValues.length > 0) { - if (seenAxes.has('ital')) { - seenAxes.get('ital').push(...seenItalValues); - } else { - seenAxes.set('ital', seenItalValues); - } - } - const seenSlntValues = []; if (fontStyles.has('oblique')) { // https://www.w3.org/TR/css-fonts-4/#font-style-prop // oblique ? // [...] The lack of an represents 14deg. - seenSlntValues.push(14); + noteUsedValue(fontUrl, 'slnt', 14); } // If any font-style value except oblique is seen (including normal or italic) // we're also utilizing value 0: if (fontStyles.size > fontStyles.has('oblique') ? 1 : 0) { - seenSlntValues.push(0); - } - if (seenSlntValues.length > 0) { - if (seenAxes.has('slnt')) { - seenAxes.get('slnt').push(...seenSlntValues); - } else { - seenAxes.set('slnt', seenSlntValues); - } + noteUsedValue(fontUrl, 'slnt', 0); } const minMaxFontWeight = parseFontWeightRange(props['font-weight']); - const seenFontWeightValues = []; for (const fontWeight of fontWeights) { - seenFontWeightValues.push(_.clamp(fontWeight, ...minMaxFontWeight)); - } - if (seenFontWeightValues.length > 0) { - if (seenAxes.has('wght')) { - seenAxes.get('wght').push(...seenFontWeightValues); - } else { - seenAxes.set('wght', seenFontWeightValues); - } + noteUsedValue( + fontUrl, + 'wght', + _.clamp(fontWeight, ...minMaxFontWeight) + ); } const minMaxFontStretch = parseFontStretchRange(props['font-stretch']); - const seenFontStretchValues = []; for (const fontStrech of fontStretches) { - seenFontStretchValues.push(_.clamp(fontStrech, ...minMaxFontStretch)); - } - if (seenFontStretchValues.length > 0) { - if (seenAxes.has('wdth')) { - seenAxes.get('wdth').push(...seenFontStretchValues); - } else { - seenAxes.set('wdth', seenFontStretchValues); - } + noteUsedValue( + fontUrl, + 'wdth', + _.clamp(fontStrech, ...minMaxFontStretch) + ); } for (const fontVariationSettingsValue of fontVariationSettings) { for (const [axisName, axisValue] of parseFontVariationSettings( fontVariationSettingsValue )) { - const seenAxisValues = seenAxes.get(axisName); - if (seenAxisValues) { - seenAxisValues.push(axisValue); - } else { - seenAxes.set(axisName, [axisValue]); - } + noteUsedValue(fontUrl, axisName, axisValue); if (hasOutOfBoundsAnimationTimingFunction) { let outOfBoundsAxes = outOfBoundsAxesByFontUrl.get(fontUrl); if (!outOfBoundsAxes) {