Inconsistent glyph sizes when adding glyphs from different fonts
See original GitHub issueI am trying to rewrite a Python script in Node, replacing the fontforge
bindings with OpenTypeJS.
The script takes a bunch of font files and copies the desired glyphs into a subset font, creating the necessary font formats and a LESS file.
Expected Behavior
The resulting subset font should contain all glyphs in the same size.
Current Behavior
It works well for some fonts but as soon as a certain font file is included, those glyphs are added with smaller sizes (approx. 50%).
Possible Solution
I just might be missing a basic information or step to achieve the consistent glyph size. Alternatively, it might be necessary to patch the code so glyph sizes are correctly saved. (I don’t know much or enough about font tables so any assistance is appreciated.)
Steps to Reproduce (for bugs)
- Prepare two source fonts, entypo.ttf and fa-solid-900.ttf
- Create a subset font with OpenTypeJS and add two glyphs, one from each source font
- Compare the glyphs in the subset font with the corresponding glyphs in the source fonts
Here is a script for creating the subset font:
#!/usr/bin/env node
const fs = require('fs');
const opentype = require('opentype.js');
const glyphs = [];
const entypoFont = opentype.loadSync('entypo.ttf');
const faFont = opentype.loadSync('fa-solid-900.ttf');
const addGlyph = glyph => {
glyph.unicode = 0xe001 + glyphs.length;
glyph.unicodes = [glyph.unicode];
glyph.name = 'uni' + glyph.unicode.toString(16);
glyphs.push(glyph);
};
addGlyph(entypoFont.glyphs.get(25));
addGlyph(faFont.glyphs.get(185));
const subsetFont = new opentype.Font({
familyName: 'Test',
styleName: 'Regular',
unitsPerEm: 1000,
ascender: 800,
descender: -200,
glyphs: glyphs
});
fs.writeFileSync('test.ttf', Buffer.from(subsetFont.toArrayBuffer()));
And this is a visual comparison of the result (left) with the source glyphs:
Your Environment
- Version used: OpenTypeJS 1.1.0
- Font used: Entype and FontAweseom (see links above)
- Browser Name and version: n.a.
- Operating System and version (desktop or mobile): Manjaro Linux 18.1.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top GitHub Comments
Unfortunately my knowledge of opentype.js is very limited. Here I tried to just move the coordinates of the commands used in a glyph, which makes it bigger but not sure if this is enough.
seems the spacing and centering issues can be ironed simply by scaling some more properties accordingly:
as this solves the issue for me it could be closed. however, if someone of the opentypejs experts still would want to chime in – e.g. with a better suggestion – i leave it open for now.