|
|
@@ -166,7 +166,7 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
|
|
|
.filter(fontInfo => fontInfo.fontFamily == familyName && fontInfo.fontStyle == fontStyle && testFontVariant(fontInfo, fontVariant))
|
|
|
.map(fontInfo => fontInfo.fontWeight)
|
|
|
.sort((weight1, weight2) => weight1 - weight2);
|
|
|
- const usedFontWeights = optionalUsedFonts.map(fontInfo => findFontWeight(fontInfo[1], declaredFontsWeights));
|
|
|
+ const usedFontWeights = optionalUsedFonts.map(fontInfo => getUsedFontWeight(fontInfo, fontStyle, fontVariant, declaredFontsWeights));
|
|
|
test = usedFontWeights.includes(fontWeight);
|
|
|
} else {
|
|
|
test = true;
|
|
|
@@ -222,27 +222,30 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
|
|
|
return fontFamilyNames;
|
|
|
}
|
|
|
|
|
|
- function findFontWeight(fontWeight, fontWeights) {
|
|
|
+ function getUsedFontWeight(fontInfo, fontStyle, fontVariant, fontWeights) {
|
|
|
let foundWeight;
|
|
|
- if (fontWeight >= 400 && fontWeight <= 500) {
|
|
|
- foundWeight = fontWeights.find(weight => weight >= fontWeight && weight <= 500);
|
|
|
- if (!foundWeight) {
|
|
|
- foundWeight = findDescendingFontWeight(fontWeight, fontWeights);
|
|
|
- }
|
|
|
- if (!foundWeight) {
|
|
|
- foundWeight = findAscendingFontWeight(fontWeight, fontWeights);
|
|
|
+ if (fontInfo[2] == fontStyle && fontInfo[3] == fontVariant) {
|
|
|
+ let fontWeight = Number(fontInfo[1]);
|
|
|
+ if (fontWeight >= 400 && fontWeight <= 500) {
|
|
|
+ foundWeight = fontWeights.find(weight => weight >= fontWeight && weight <= 500);
|
|
|
+ if (!foundWeight) {
|
|
|
+ foundWeight = findDescendingFontWeight(fontWeight, fontWeights);
|
|
|
+ }
|
|
|
+ if (!foundWeight) {
|
|
|
+ foundWeight = findAscendingFontWeight(fontWeight, fontWeights);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- if (fontWeight < 400) {
|
|
|
- foundWeight = fontWeights.slice().reverse().find(weight => weight <= fontWeight);
|
|
|
- if (!foundWeight) {
|
|
|
- foundWeight = findAscendingFontWeight(fontWeight, fontWeights);
|
|
|
+ if (fontWeight < 400) {
|
|
|
+ foundWeight = fontWeights.slice().reverse().find(weight => weight <= fontWeight);
|
|
|
+ if (!foundWeight) {
|
|
|
+ foundWeight = findAscendingFontWeight(fontWeight, fontWeights);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- if (fontWeight > 500) {
|
|
|
- foundWeight = fontWeights.find(weight => weight >= fontWeight);
|
|
|
- if (!foundWeight) {
|
|
|
- foundWeight = findDescendingFontWeight(fontWeight, fontWeights);
|
|
|
+ if (fontWeight > 500) {
|
|
|
+ foundWeight = fontWeights.find(weight => weight >= fontWeight);
|
|
|
+ if (!foundWeight) {
|
|
|
+ foundWeight = findDescendingFontWeight(fontWeight, fontWeights);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return foundWeight;
|