__version__ = '0.1'
-def convert(input_file, output_file=None, ranges=[(0x20,0x7e)], **kwargs):
+def convert(input_file, output_file=None, ranges=[(0x20,0x7e)],
+ targets=[(0x20,0x7e)], **kwargs):
if output_file is None:
base,ext = _os_path.splitext(input_file)
output_file = '{}-reduced.woff'.format(base)
i = _fontforge.open(input_file)
o = _fontforge.font()
- for start,stop in ranges:
- i.selection.select(("ranges",), start, stop)
+ for ((istart,istop),(ostart,ostop)) in zip(ranges, targets):
+ i.selection.select(('ranges',), istart, istop)
i.copy()
- o.selection.select(("ranges",), start, stop)
+ o.selection.select(('ranges',), ostart, ostop)
o.paste()
for attr in ['comment', 'copyright', 'encoding', 'familyname',
'fontname', 'fullname', 'sfntRevision', 'sfnt_names',
'-s', '--source', help='override font source URL')
parser.add_argument(
'-r', '--range', action='append', default=['0x20,0x7e'],
+ help=('add an additional range of indices to copy from the original '
+ "font (e.g '0x7f,0xff')"))
+ parser.add_argument(
+ '-t', '--target', action='append', default=['0x20,0x7e'],
help=('add an additional range of indices to copy to the reduced font '
"(e.g '0x7f,0xff')"))
parser.add_argument(
for r in args.range:
start,stop = [int(x, 0) for x in r.split(',')]
ranges.append((start,stop))
+ targets = []
+ for r in args.target:
+ start,stop = [int(x, 0) for x in r.split(',')]
+ targets.append((start,stop))
for font in args.font:
- convert(font, output_file=args.output, ranges=ranges,
+ convert(font, output_file=args.output, ranges=ranges, targets=targets,
license=args.license, source=args.source)