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

@ -313,12 +313,13 @@ Configuration of build plans are organized under `[buildPlans.<plan name>]` sect
* `family`: String, defines the family name of your custom variant.
* `spacing`: Optional, String, denotes the spacing of the custom variant. Valid values include:
- `term`: Make the symbols' width suitable for terminal emulators. Arrows and geometric symbols ill become narrower.
- `fontconfig-mono`: Apply `term` spacing changes and further:
- `fontconfig-mono`: Apply `term` spacing changes and further apply changes to be compatible with FontConfig's Mono spacing, which recognizes a font as monospace if and only if its every non-combining characters having the same width. The changes include:
- Completely remove wide glyphs. All non-combining glyphs will be exactly the same width.
- As a consequence, the following characters will be **removed**:
- `U+27F5` LONG LEFTWARDS ARROW
- `U+27F6` LONG RIGHTWARDS ARROW
- Remove `NWID` and `WWID` OpenType feature.
This spacing is recommended for Linux users who customize for their terminal fonts: certain applications, including FontConfig, recognizes a font as monospace if and only if its every non-combining glyphs having the same width.
- `fixed`: Apply `fontconfig-mono` changes and remove ligations.
- `fixed`: Apply `fontconfig-mono` changes and further remove ligations.
* `serifs`: Optional, String, configures style of serifs.
- When set to `slab`, the font will be converted into slab-serif.
- Otherwise the font will be sans-serif.

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");
}
}

View file

@ -597,6 +597,7 @@ glyph-block Symbol-Arrow : for-width-kinds WideWidth1
if (MosaicWidthScalar == 1) : begin
glyph-block-export ArrowShape
if (MosaicNameSuffix === '.WWID') : begin
if (!para.forceMonospace && MosaicNameSuffix === '.WWID') : begin
alias 'longArrowLeft' 0x27F5 'arrowleft.WWID'
alias 'longArrowRight' 0x27F6 'arrowright.WWID'