From: W. Trevor King Date: Sun, 11 Mar 2012 01:26:23 +0000 (-0500) Subject: Add --target option to font-reduce.py. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8f24b6361b967143acf58af0a8b03d7b0f89d5de;p=blog.git Add --target option to font-reduce.py. This allows you to remap charachter from anywhere in the input font to their proper Unicode position in the output font. --- diff --git a/posts/font-reduce/font-reduce.py b/posts/font-reduce/font-reduce.py index a58befa..26bad59 100755 --- a/posts/font-reduce/font-reduce.py +++ b/posts/font-reduce/font-reduce.py @@ -30,16 +30,17 @@ import fontforge as _fontforge __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', @@ -113,6 +114,10 @@ if __name__ == '__main__': '-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( @@ -126,7 +131,11 @@ if __name__ == '__main__': 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)