forked from fontello/svg2ttf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvg2ttf.js
executable file
·112 lines (87 loc) · 1.89 KB
/
svg2ttf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env node
/*
Author: Sergey Batishchev <sergej.batishchev@gmail.com>
Written for fontello.com project.
*/
/*eslint-disable no-console*/
'use strict';
var fs = require('fs');
var ArgumentParser = require('argparse').ArgumentParser;
var svg2ttf = require('./');
var parser = new ArgumentParser({
version: require('./package.json').version,
addHelp: true,
description: 'SVG to TTF font converter'
});
parser.addArgument(
[ '-c', '--copyright' ],
{
help: 'Copyright text',
required: false
}
);
parser.addArgument(
[ '-d', '--description' ],
{
help: 'Override default description text',
required: false,
type: 'string'
}
);
parser.addArgument(
[ '--ts' ],
{
help: 'Override font creation time (Unix time stamp)',
required: false,
type: 'int'
}
);
parser.addArgument(
[ '-u', '--url' ],
{
help: 'Override default manufacturer url',
required: false,
type: 'string'
}
);
parser.addArgument(
[ '--vs' ],
{
help: 'Override default font version string (Version 1.0), can be "x.y" or "Version x.y"',
required: false,
type: 'string'
}
);
parser.addArgument(
[ 'infile' ],
{
nargs: 1,
help: 'Input file'
}
);
parser.addArgument(
[ 'outfile' ],
{
nargs: 1,
help: 'Output file'
}
);
var args = parser.parseArgs();
var svg;
var options = {};
try {
svg = fs.readFileSync(args.infile[0], 'utf-8');
} catch (e) {
console.error("Can't open input file (%s)", args.infile[0]);
process.exit(1);
}
if (args.copyright) options.copyright = args.copyright;
if (args.description) options.description = args.description;
if (args.ts !== null) options.ts = args.ts;
if (args.url) options.url = args.url;
if (args.vs) options.version = args.vs;
var result = Buffer.from ?
Buffer.from(svg2ttf(svg, options).buffer)
:
new Buffer(svg2ttf(svg, options).buffer);
fs.writeFileSync(args.outfile[0], result);