From 739e68a0a9100cd381ee857698748d66759d9628 Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Mon, 18 Sep 2023 19:39:18 +0200 Subject: [PATCH] If we don't find the optimum reference layer, then use the default layer, and not the last we happened to look at --- src/fontra/client/core/glyph-controller.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/fontra/client/core/glyph-controller.js b/src/fontra/client/core/glyph-controller.js index 522215147..a351199b6 100644 --- a/src/fontra/client/core/glyph-controller.js +++ b/src/fontra/client/core/glyph-controller.js @@ -227,15 +227,17 @@ export class VariableGlyphController { ].slice(0, Math.ceil(layerNames.length / 2)); const errors = {}; - let referenceLayerName; - for (referenceLayerName of layerNames) { - errors[referenceLayerName] = checkInterpolationCompatibility( - referenceLayerName, + let referenceLayerName = defaultSourceLayerName; + for (const layerName of layerNames) { + errors[layerName] = checkInterpolationCompatibility( + layerName, layerGlyphs, errors ); - if (Object.keys(errors[referenceLayerName]).length <= this.sources.length / 2) { - // good enough + if (Object.keys(errors[layerName]).length <= this.sources.length / 2) { + // The number of incompatible sources is half of all sources or less: + // we've found the optimal reference layer. + referenceLayerName = layerName; break; } }