font-reduce.py: Add special space handling
authorW. Trevor King <wking@tremily.us>
Wed, 9 Jan 2013 18:38:51 +0000 (13:38 -0500)
committerW. Trevor King <wking@tremily.us>
Wed, 9 Jan 2013 18:38:51 +0000 (13:38 -0500)
For some reason, FontForge doesn't like selecting spaces with
`select(('ranges',),...)`.  No idea why, but this works around the
problem.

Reported-by: David Loyall <david.loyall@nebraska.gov>
posts/font-reduce/font-reduce.py

index f65d98323662fc0d9365db685229c20020554e54..67a187fc15a19df1617a2f0ab8dd2a6c4074d6dd 100755 (executable)
@@ -42,12 +42,20 @@ def convert(input_file, output_file=None, ranges=[(0x20,0x7e)],
     i = _fontforge.open(input_file)
     o = _fontforge.font()
     mappings = []
+    copy_space = False
     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))
+        if istart <= 0x20 and istop >= 20:
+            copy_space = True  # HACK: FF doesn't like spaces?
+    if copy_space:
+        i.selection.select('space')
+        i.copy()
+        o.selection.select('space')
+        o.paste()
     for attr in ['comment', 'copyright', 'encoding', 'familyname',
                  'fontname', 'fullname', 'sfntRevision', 'sfnt_names',
                  'userdata', 'version', 'woffMetadata']: