From 7c43ad1f778adab23037e0c99a9f487ffccf2841 Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Sun, 5 Jul 2020 22:33:11 +0200 Subject: [PATCH] Always include the space character U+20 in subsets to prevent Chrome from downloading the fallback font --- lib/subsetFonts.js | 6 ++++++ test/subsetFonts.js | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/subsetFonts.js b/lib/subsetFonts.js index f1cb0344..0792f895 100644 --- a/lib/subsetFonts.js +++ b/lib/subsetFonts.js @@ -792,6 +792,12 @@ async function subsetFonts( const usedCodepoints = fontUsage.text .split('') .map((c) => c.codePointAt(0)); + if (!usedCodepoints.includes(32)) { + // Make sure that space is always part of the subset fonts (and that it's announced in unicode-range). + // Prevents Chrome from going off and downloading the fallback: + // https://gitter.im/assetgraph/assetgraph?at=5f01f6e13a0d3931fad4021b + usedCodepoints.push(32); + } const unusedCodepoints = originalCodepoints.filter( (n) => !usedCodepoints.includes(n) ); diff --git a/test/subsetFonts.js b/test/subsetFonts.js index 6df6c6fa..fbb47113 100644 --- a/test/subsetFonts.js +++ b/test/subsetFonts.js @@ -515,7 +515,7 @@ describe('subsetFonts', function () { fontFamilies: expect.it('to be a', Set), codepoints: { original: expect.it('to be an array'), - used: [101, 108, 111, 72], + used: [101, 108, 111, 32, 72], unused: expect.it('to be an array'), }, },