__version__ = '0.1'
-def convert(input_file, output_file=None, **kwargs):
+def convert(input_file, output_file=None, ranges=[(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)
- i.selection.select(("ranges",), 0x20, 0x7e)
- i.copy()
o = _fontforge.font()
- o.selection.select(("ranges",), 0x20, 0x7e)
- o.paste()
+ for start,stop in ranges:
+ i.selection.select(("ranges",), start, stop)
+ i.copy()
+ o.selection.select(("ranges",), start, stop)
+ o.paste()
for attr in ['comment', 'copyright', 'encoding', 'familyname',
'fontname', 'fullname', 'sfntRevision', 'sfnt_names',
'userdata', 'version', 'woffMetadata']:
'-l', '--license', help='override font license text')
parser.add_argument(
'-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 to the reduced font '
+ "(e.g '0x7f,0xff')"))
parser.add_argument(
'-o', '--output', help='override path to output file')
parser.add_argument(
args = parser.parse_args()
+ ranges = []
+ for r in args.range:
+ start,stop = [int(x, 0) for x in r.split(',')]
+ ranges.append((start,stop))
+
for font in args.font:
- convert(font, output_file=args.output, license=args.license,
- source=args.source)
+ convert(font, output_file=args.output, ranges=ranges,
+ license=args.license, source=args.source)