[subset] Preserve the .notdef glyph width when removing its outlines

This commit is contained in:
Miguel Sousa 2015-11-13 17:43:22 -08:00
parent 270b155d45
commit 6db7d30ed9

View File

@ -7,6 +7,7 @@ from fontTools.misc.py23 import *
from fontTools import ttLib from fontTools import ttLib
from fontTools.ttLib.tables import otTables from fontTools.ttLib.tables import otTables
from fontTools.misc import psCharStrings from fontTools.misc import psCharStrings
from fontTools.pens.boundsPen import BoundsPen
import sys import sys
import struct import struct
import time import time
@ -1623,10 +1624,19 @@ def prune_pre_subset(self, options):
if options.notdef_glyph and not options.notdef_outline: if options.notdef_glyph and not options.notdef_outline:
for fontname in cff.keys(): for fontname in cff.keys():
font = cff[fontname] font = cff[fontname]
c,_ = font.CharStrings.getItemAndSelector('.notdef') c,sel = font.CharStrings.getItemAndSelector('.notdef')
# XXX we should preserve the glyph width if hasattr(font, 'FDArray') and font.FDArray is not None:
c.bytecode = '\x0e' # endchar private = font.FDArray[font.FDSelect[sel]].Private
c.program = None else:
private = font.Private
dfltWdX = private.defaultWidthX
nmnlWdX = private.nominalWidthX
pen = BoundsPen(None)
c.draw(pen) # this will set the charstring's width
if c.width != dfltWdX:
c.program = [c.width - nmnlWdX, 'endchar']
else:
c.program = ['endchar']
return True # bool(cff.fontNames) return True # bool(cff.fontNames)