Leverage better fontconfig-mono building and validation

This commit is contained in:
be5invis 2020-11-23 17:35:25 -08:00
parent 735218ed9e
commit e2ff6698d1
3 changed files with 17 additions and 15 deletions

View file

@ -4,19 +4,19 @@ const finalizeGlyphs = require("./glyphs");
const gcFont = require("./gc");
module.exports = function finalizeFont(para, glyphStore, excludedCodePoints, restFont) {
glyphStore = forceMonospaceIfNeeded(para, glyphStore);
glyphStore = gcFont(glyphStore, excludedCodePoints, restFont, {});
glyphStore = finalizeGlyphs(para, glyphStore);
validateMonospace(para, glyphStore);
return glyphStore;
};
function forceMonospaceIfNeeded(para, glyphStore) {
const unitWidth = Math.round(para.width);
if (!para.forceMonospace || para.spacing > 0) return glyphStore;
return glyphStore.filterByGlyph({
has: g => {
const gw = Math.round(g.advanceWidth || 0);
return gw === 0 || gw === unitWidth;
}
});
function validateMonospace(para, glyphStore) {
if (!para.forceMonospace) return;
let awSet = new Set();
for (const g of glyphStore.glyphs()) {
awSet.add(Math.round(g.advanceWidth || 0));
}
if (awSet.size > 2) {
throw new Error("Unreachable! Fixed variant has wide characters");
}
}