mirror of
https://github.com/kiliman/operator-mono-lig.git
synced 2026-08-12 02:10:52 +02:00
Add file (list of patterns) for matching exported glyphs
This commit is contained in:
+30
-8
@@ -10,13 +10,13 @@ const hash = require('hash.js');
|
|||||||
|
|
||||||
let fontName;
|
let fontName;
|
||||||
|
|
||||||
const regEx = /^LIG$|uni(E0A0|E0B0|E0B2)|\.liga$/;
|
|
||||||
const NodeType = {};
|
const NodeType = {};
|
||||||
NodeType.TEXT_NODE = 3;
|
NodeType.TEXT_NODE = 3;
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
fontName = process.argv[2];
|
fontName = process.argv[2];
|
||||||
|
|
||||||
|
const glyphsRegEx = getGlyphsRegEx('./ligature_source/glyphs');
|
||||||
const srcFileName = `./ligature_source/${fontName}.ttx`;
|
const srcFileName = `./ligature_source/${fontName}.ttx`;
|
||||||
|
|
||||||
const folder = `./ligature/${fontName}`;
|
const folder = `./ligature/${fontName}`;
|
||||||
@@ -31,7 +31,7 @@ function main() {
|
|||||||
|
|
||||||
extractAndWrite('config', extractConfig, dom);
|
extractAndWrite('config', extractConfig, dom);
|
||||||
|
|
||||||
extractCharStrings(dom);
|
extractCharStrings(dom, glyphsRegEx);
|
||||||
|
|
||||||
extractAndWrite('subrs', extractSubrs, dom);
|
extractAndWrite('subrs', extractSubrs, dom);
|
||||||
extractAndWrite('gsubrs', extractGlobalSubrs, dom);
|
extractAndWrite('gsubrs', extractGlobalSubrs, dom);
|
||||||
@@ -39,6 +39,25 @@ function main() {
|
|||||||
console.log('Done');
|
console.log('Done');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getGlyphsRegEx(path) {
|
||||||
|
const glyphs = fs.readFileSync(path, 'utf-8');
|
||||||
|
const patterns = ['LIG'];
|
||||||
|
|
||||||
|
glyphs
|
||||||
|
.split(os.EOL)
|
||||||
|
.filter(line => line.length > 0)
|
||||||
|
.forEach(line => {
|
||||||
|
const pattern = line
|
||||||
|
.replace(/\s*#.*/, '')
|
||||||
|
.replace(/[.]/g, '\\.')
|
||||||
|
.replace(/[*]/g, '.*');
|
||||||
|
if (pattern.length) {
|
||||||
|
patterns.push(pattern);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return new RegExp(`^(${patterns.join('|')})$`);
|
||||||
|
}
|
||||||
|
|
||||||
function extractAndWrite(name, func, dom) {
|
function extractAndWrite(name, func, dom) {
|
||||||
const newDom = func(dom);
|
const newDom = func(dom);
|
||||||
console.log('Finished extracting ' + name);
|
console.log('Finished extracting ' + name);
|
||||||
@@ -86,26 +105,29 @@ const extractFromPath = (path, dom) => {
|
|||||||
return newDom.documentElement;
|
return newDom.documentElement;
|
||||||
};
|
};
|
||||||
|
|
||||||
const extractCharStrings = dom => {
|
const extractCharStrings = (dom, glyphsRegEx) => {
|
||||||
const cmap = xpath.select('/ttfont/cmap/cmap_format_4', dom);
|
|
||||||
const charStrings = xpath.select(
|
const charStrings = xpath.select(
|
||||||
'/ttFont/CFF/CFFFont/CharStrings/CharString',
|
'/ttFont/CFF/CFFFont/CharStrings/CharString',
|
||||||
dom
|
dom
|
||||||
);
|
);
|
||||||
|
|
||||||
charStrings
|
charStrings
|
||||||
.filter(node => regEx.test(node.getAttribute('name')))
|
.filter(node => glyphsRegEx.test(node.getAttribute('name')))
|
||||||
.forEach(node => writeGlyphData(dom, node, cmap));
|
.forEach(node => writeGlyphData(dom, node));
|
||||||
console.log('Finished writing charstrings');
|
console.log('Finished writing charstrings');
|
||||||
};
|
};
|
||||||
|
|
||||||
const writeGlyphData = (dom, node, cmap) => {
|
const writeGlyphData = (dom, node) => {
|
||||||
const newDom = new DOMParser().parseFromString('<Glyph/>').documentElement;
|
const newDom = new DOMParser().parseFromString('<Glyph/>').documentElement;
|
||||||
const name = node.getAttribute('name');
|
const name = node.getAttribute('name');
|
||||||
newDom.setAttribute('name', name);
|
newDom.setAttribute('name', name);
|
||||||
|
|
||||||
// get map and set code
|
// get map and set code
|
||||||
const map = xpath.select(`/ttFont/cmap/cmap_format_4/map[@name="${name}"]`, dom, true);
|
const map = xpath.select(
|
||||||
|
`/ttFont/cmap/cmap_format_4/map[@name="${name}"]`,
|
||||||
|
dom,
|
||||||
|
true
|
||||||
|
);
|
||||||
if (map) {
|
if (map) {
|
||||||
newDom.setAttribute('code', map.getAttribute('code'));
|
newDom.setAttribute('code', map.getAttribute('code'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
*
|
*.otf
|
||||||
!.gitignore
|
*.ttx
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# List of glyphs to extract
|
||||||
|
# includes patterns
|
||||||
|
|
||||||
|
*.liga # all ligatures
|
||||||
|
uniE0A0 # Powerline branch
|
||||||
|
uniE0B0 # Powerline right triangle
|
||||||
|
uniE0B2 # Powerline left triangle
|
||||||
Reference in New Issue
Block a user