|
@@ -103,6 +103,14 @@ var Redownload = function() {
|
|
|
var metrics = {};
|
|
|
var offenders = {};
|
|
|
|
|
|
+ // Remove unused fonts that a normal browser would not download (fix #224)
|
|
|
+ results = results.filter(function(result) {
|
|
|
+ if (result && result.fontMetrics) {
|
|
|
+ return result.fontMetrics.isUsed !== false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ });
|
|
|
+
|
|
|
// Count requests
|
|
|
offenders.totalRequests = listRequestsByType(results);
|
|
|
metrics.totalRequests = offenders.totalRequests.total;
|
|
@@ -500,6 +508,8 @@ var Redownload = function() {
|
|
|
var ranges = [];
|
|
|
var others = null;
|
|
|
var rangeNames = Object.keys(req.fontMetrics.unicodeRanges);
|
|
|
+ var unicodePointsCount = 0;
|
|
|
+ var unusedRangesInFont = 0;
|
|
|
|
|
|
rangeNames.forEach(function(rangeName) {
|
|
|
var range = req.fontMetrics.unicodeRanges[rangeName];
|
|
@@ -508,18 +518,20 @@ var Redownload = function() {
|
|
|
if (rangeName === 'Others') {
|
|
|
if (range.numGlyphsInCommonWithPageContent === 0 && range.charset.length > 50) {
|
|
|
range.underused = true;
|
|
|
- unusedUnicodeRanges ++;
|
|
|
+ unusedRangesInFont ++;
|
|
|
}
|
|
|
|
|
|
+ unicodePointsCount += range.charset.length;
|
|
|
others = range;
|
|
|
} else if (range.charset.length > 0) {
|
|
|
// Now lets detect if the current Unicode range is unused.
|
|
|
// Reminder: range.coverage = glyphs declared in this range, divided by the range size
|
|
|
if (range.coverage > 0.25 && range.numGlyphsInCommonWithPageContent === 0) {
|
|
|
range.underused = true;
|
|
|
- unusedUnicodeRanges ++;
|
|
|
+ unusedRangesInFont ++;
|
|
|
}
|
|
|
|
|
|
+ unicodePointsCount += range.charset.length;
|
|
|
ranges.push(range);
|
|
|
}
|
|
|
});
|
|
@@ -539,7 +551,7 @@ var Redownload = function() {
|
|
|
|
|
|
// And if less than 5% of the icons are used, let's report it as underused
|
|
|
if (others && others.numGlyphsInCommonWithPageContent / others.charset.length <= 0.05) {
|
|
|
- unusedUnicodeRanges ++;
|
|
|
+ unusedRangesInFont = 1;
|
|
|
}
|
|
|
|
|
|
// Not an icons font
|
|
@@ -549,13 +561,21 @@ var Redownload = function() {
|
|
|
ranges.push(others);
|
|
|
}
|
|
|
|
|
|
+ var ligaturesOrHiddenChars = req.fontMetrics.numGlyphs - unicodePointsCount;
|
|
|
+ if (ligaturesOrHiddenChars > 25) {
|
|
|
+ unusedUnicodeRanges ++;
|
|
|
+ }
|
|
|
+
|
|
|
list.push({
|
|
|
url: req.url,
|
|
|
weight: req.weightCheck.bodySize,
|
|
|
isIconFont: false,
|
|
|
- unicodeRanges: ranges
|
|
|
+ unicodeRanges: ranges,
|
|
|
+ ligaturesOrHiddenChars: ligaturesOrHiddenChars
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ unusedUnicodeRanges += unusedRangesInFont;
|
|
|
}
|
|
|
});
|
|
|
|