From fcad60602adc32b60af18383376c4280a86d97f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs?= Date: Wed, 11 Jul 2018 20:06:07 -0500 Subject: rename file svg2ttf.py fix: svgs2ttf.py to svg2ttf.py --- build.sh | 2 +- lab/svg2ttf.py | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lab/svgs2ttf.py | 91 --------------------------------------------------------- 3 files changed, 92 insertions(+), 92 deletions(-) create mode 100755 lab/svg2ttf.py delete mode 100755 lab/svgs2ttf.py diff --git a/build.sh b/build.sh index 5a13c16..cac9c9f 100755 --- a/build.sh +++ b/build.sh @@ -4,7 +4,7 @@ # build if [[ -n "$(ls -a ./lab/)" && -f ./lab/metadata.json && -f ./lab/svgs2ttf.py ]]; then - ./lab/svgs2ttf.py ./lab/metadata.json + ./lab/svg2ttf.py ./lab/metadata.json fi # copy files to fonts diff --git a/lab/svg2ttf.py b/lab/svg2ttf.py new file mode 100755 index 0000000..bd2425a --- /dev/null +++ b/lab/svg2ttf.py @@ -0,0 +1,91 @@ +#!/usr/bin/fontforge -script +# +# Copyright (c) 2017 GNU Developers +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import sys +import os.path +import json + +IMPORT_OPTIONS = ('removeoverlap', 'correctdir') + +try: + unicode +except NameError: + unicode = str + + +def loadConfig(filename='font.json'): + with open(filename) as f: + return json.load(f) + + +def setProperties(font, config): + props = config['props'] + lang = props.pop('lang', 'English (US)') + family = props.pop('family', None) + style = props.pop('style', 'Regular') + props['encoding'] = props.get('encoding', 'UnicodeFull') + if family is not None: + font.familyname = family + font.fontname = family + '-' + style + font.fullname = family + ' ' + style + for k, v in config['props'].items(): + if hasattr(font, k): + if isinstance(v, list): + v = tuple(v) + setattr(font, k, v) + else: + font.appendSFNTName(lang, k, v) + for t in config.get('sfnt_names', []): + font.appendSFNTName(str(t[0]), str(t[1]), unicode(t[2])) + + +def addGlyphs(font, config): + for k, v in config['glyphs'].items(): + g = font.createMappedChar(int(k, 0)) + # Get outlines + src = '%s.svg' % k + if not isinstance(v, dict): + v = {'src': v or src} + src = '%s%s%s' % (config.get('input', '.'), + os.path.sep, v.pop('src', src)) + g.importOutlines(src, IMPORT_OPTIONS) + g.removeOverlap() + # Copy attributes + for k2, v2 in v.items(): + if hasattr(g, k2): + if isinstance(v2, list): + v2 = tuple(v2) + setattr(g, k2, v2) + + +def main(config_file): + config = loadConfig(config_file) + os.chdir(os.path.dirname(config_file) or '.') + font = fontforge.font() + setProperties(font, config) + addGlyphs(font, config) + for outfile in config['output']: + sys.stderr.write('Generating %s...\n' % outfile) + font.generate(outfile) + +if __name__ == '__main__': + if len(sys.argv) > 1: + main(sys.argv[1]) + else: + sys.stderr.write("\nUsage: %s something.json\n" % sys.argv[0]) + +# vim: set filetype=python: diff --git a/lab/svgs2ttf.py b/lab/svgs2ttf.py deleted file mode 100755 index bd2425a..0000000 --- a/lab/svgs2ttf.py +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/fontforge -script -# -# Copyright (c) 2017 GNU Developers -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import sys -import os.path -import json - -IMPORT_OPTIONS = ('removeoverlap', 'correctdir') - -try: - unicode -except NameError: - unicode = str - - -def loadConfig(filename='font.json'): - with open(filename) as f: - return json.load(f) - - -def setProperties(font, config): - props = config['props'] - lang = props.pop('lang', 'English (US)') - family = props.pop('family', None) - style = props.pop('style', 'Regular') - props['encoding'] = props.get('encoding', 'UnicodeFull') - if family is not None: - font.familyname = family - font.fontname = family + '-' + style - font.fullname = family + ' ' + style - for k, v in config['props'].items(): - if hasattr(font, k): - if isinstance(v, list): - v = tuple(v) - setattr(font, k, v) - else: - font.appendSFNTName(lang, k, v) - for t in config.get('sfnt_names', []): - font.appendSFNTName(str(t[0]), str(t[1]), unicode(t[2])) - - -def addGlyphs(font, config): - for k, v in config['glyphs'].items(): - g = font.createMappedChar(int(k, 0)) - # Get outlines - src = '%s.svg' % k - if not isinstance(v, dict): - v = {'src': v or src} - src = '%s%s%s' % (config.get('input', '.'), - os.path.sep, v.pop('src', src)) - g.importOutlines(src, IMPORT_OPTIONS) - g.removeOverlap() - # Copy attributes - for k2, v2 in v.items(): - if hasattr(g, k2): - if isinstance(v2, list): - v2 = tuple(v2) - setattr(g, k2, v2) - - -def main(config_file): - config = loadConfig(config_file) - os.chdir(os.path.dirname(config_file) or '.') - font = fontforge.font() - setProperties(font, config) - addGlyphs(font, config) - for outfile in config['output']: - sys.stderr.write('Generating %s...\n' % outfile) - font.generate(outfile) - -if __name__ == '__main__': - if len(sys.argv) > 1: - main(sys.argv[1]) - else: - sys.stderr.write("\nUsage: %s something.json\n" % sys.argv[0]) - -# vim: set filetype=python: -- cgit v1.2.3