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:
@@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user