export-kerning
Version:
Export kernings of a Opentype font
20 lines (18 loc) • 635 B
JavaScript
// Utility to convert SVG-style optimized kerning format back to simple kerning pairs
// Input: { unitsPerEm, kerningPairs: [ { left: [...], right: [...], value: ... }, ... ] }
// Output: { unitsPerEm, kerningPairs: { 'AV': -80, ... } }
function convertOptimizedToSimple(optimizedData) {
const result = {};
for (const group of optimizedData.kerningPairs) {
for (const left of group.left) {
for (const right of group.right) {
result[left + right] = group.value;
}
}
}
return {
unitsPerEm: optimizedData.unitsPerEm,
kerningPairs: result
};
}
module.exports = { convertOptimizedToSimple };