if output_file is None:
base,ext = _os_path.splitext(input_file)
output_file = '{}-reduced.woff'.format(base)
+ if len(ranges) != len(targets):
+ raise ValueError(
+ 'range/target missmatch: ranges: {}, targets: {}.'.format(
+ ranges, targets))
i = _fontforge.open(input_file)
o = _fontforge.font()
+ mappings = []
for ((istart,istop),(ostart,ostop)) in zip(ranges, targets):
i.selection.select(('ranges',), istart, istop)
i.copy()
o.selection.select(('ranges',), ostart, ostop)
o.paste()
+ mappings.append((istart,istop,ostart,ostop))
for attr in ['comment', 'copyright', 'encoding', 'familyname',
'fontname', 'fullname', 'sfntRevision', 'sfnt_names',
'userdata', 'version', 'woffMetadata']:
if attr in ['fontname', 'fullname'] and value:
value = 'Reduced{}'.format(value)
setattr(o, attr, value)
- fontlog = ('Reduced to Unicode characters 0x20 through 0x7e by '
+ fontlog = ('Reduced to Unicode characters 0x{:x} through 0x{:x} by '
'font-reduce.py version {}, '
'`http://blog.tremily.us/posts/font-reduce/`.'
- ).format(__version__)
+ ).format(ranges[0][0], ranges[0][1], __version__)
+ if len(mappings) > 1:
+ fontlog += '\n\nAdditional ranges: {}'.format(', '.join(
+ '0x{:x}-0x{:x} -> 0x{:x}-0x{:x}'.format(*mapping)
+ for mapping in mappings[1:]))
if i.fontlog:
fontlog = '{}\n\n{}'.format(i.fontlog.rstrip('\n'), fontlog)
o.fontlog = fontlog