From 1429c0f35720ee8dadb691138eb4cfa3c1c86150 Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Wed, 7 Sep 2022 08:40:58 +0200 Subject: [PATCH] Clamp the used variation axis values to the available interval --- lib/subsetFonts.js | 4 +++- test/subsetFonts.js | 12 ++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/subsetFonts.js b/lib/subsetFonts.js index f6fc6f35..de69d9a3 100644 --- a/lib/subsetFonts.js +++ b/lib/subsetFonts.js @@ -918,7 +918,9 @@ function warnAboutUnusedVariationAxes( } let usedValues = []; if (seenAxisValuesByAxisName.has(name) && !outOfBoundsAxes.has(name)) { - usedValues = [...seenAxisValuesByAxisName.get(name)]; + usedValues = [...seenAxisValuesByAxisName.get(name)].map((usedValue) => + _.clamp(usedValue, min, max) + ); } if (!usedValues.every((value) => value === defaultValue)) { if (!standardVariationAxes.has(name)) { diff --git a/test/subsetFonts.js b/test/subsetFonts.js index 999f96a8..b714277b 100644 --- a/test/subsetFonts.js +++ b/test/subsetFonts.js @@ -2896,7 +2896,7 @@ describe('subsetFonts', function () { infoSpy({ message: expect.it( 'to contain', - 'RobotoFlex-VariableFont_GRAD,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght.ttf:\n Unused axes: wght, wdth, GRAD, slnt, XOPQ, YOPQ, YTLC, YTUC, YTDE, YTFI\n Underutilized axes:\n YTAS: 400-750 used (649-854 available)' + 'RobotoFlex-VariableFont_GRAD,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght.ttf:\n Unused axes: wght, wdth, GRAD, slnt, XOPQ, YOPQ, YTLC, YTUC, YTDE, YTFI\n Underutilized axes:\n YTAS: 649-750 used (649-854 available)' ), }); }); @@ -3070,7 +3070,9 @@ describe('subsetFonts', function () { infoSpy({ message: expect.it( 'to contain', - 'Underutilized axes:\n slnt: 14 used (-10-0 available)' + 'Unused axes: wght, wdth, GRAD, slnt,' + // FIXME: Find a liberally licensed variable font that actually includes a slnt value of 14 so we can test that the output is: + // 'Underutilized axes:\n slnt: 14 used (-100-100 available)' ), }); }); @@ -3096,7 +3098,9 @@ describe('subsetFonts', function () { infoSpy({ message: expect.it( 'to contain', - 'Underutilized axes:\n slnt: 0-14 used (-10-0 available)' + 'Unused axes: wght, wdth, GRAD, slnt,' + // FIXME: Find a liberally licensed variable font that actually includes a slnt value of 14 so we can test that the output is: + // 'Underutilized axes:\n slnt: 0-14 used (-100-100 available)' ), }); }); @@ -3124,7 +3128,7 @@ describe('subsetFonts', function () { infoSpy({ message: expect.it( 'to contain', - 'Underutilized axes:\n YTAS: 400-750 used (649-854 available)' + 'Underutilized axes:\n YTAS: 649-750 used (649-854 available)' ), }); });