Hiddenchars (#221)

* Fix bug where an icons font is counted as two unused unicode ranges
* Display the number of hidden chars
This commit is contained in:
Gaël Métais
2017-01-10 13:54:43 +08:00
committed by GitHub
parent 92fce802c5
commit ce16fa154c
3 changed files with 22 additions and 5 deletions
+16 -4
View File
@@ -500,6 +500,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 +510,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 +543,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 +553,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;
}
});